From be13411d708557b0bdccb7d23c0f72d45ede8c79 Mon Sep 17 00:00:00 2001 From: enyinnaya1234 Date: Mon, 24 Mar 2025 04:22:26 +0100 Subject: [PATCH] feat: Packaging and Publishing Regex Utility as a Cairo Library #201 --- docs/CAIRO_LIBRARY.md | 56 +++++++++++++++++++++++++ examples/cairo/scripts/regex/README.md | 44 +++++++++++++++++++ examples/cairo/scripts/regex/Scarb.toml | 6 +++ 3 files changed, 106 insertions(+) create mode 100644 docs/CAIRO_LIBRARY.md create mode 100644 examples/cairo/scripts/regex/README.md diff --git a/docs/CAIRO_LIBRARY.md b/docs/CAIRO_LIBRARY.md new file mode 100644 index 0000000..10270b7 --- /dev/null +++ b/docs/CAIRO_LIBRARY.md @@ -0,0 +1,56 @@ +# Publishing a Cairo package as library + +**This document explains how to organize and publish Cairo package that can be imported and used as dependency by other developers** + +## Getting started +First, you need a Cairo package. You can create one with: +```sh +scarb new project_name +``` + +For more details, check out [this documentation](https://github.com/KaizeNodeLabs/starkiro/blob/main/README.md). + +## Preparing your package +### Defining the library target +In your Scarb.toml manifest, add a `[lib]` section. This tells Scarb that your package exports a reusable library. + +### Adding package metadata +In the `[package]` section, you can include basic fields that provide useful information for other developers. Although these fields are optional, it is recommended that you add: +- `description`: A short explanation of your package's purpose +- `documentation`: A link to the package’s documentation +- `repository`: A URL to the GitHub repository where the source code is hosted +- `license`: The license under which the package is distributed +- `homepage`: A link to the project's website or landing page + +For a complete list of available metadata fields, please refer to the [scarb documentation](https://docs.swmansion.com/scarb/docs/reference/manifest.html). + +## Publishing your package + +### Official Scarb registry (recommended) + +The official [Scarb registry](https://scarbs.xyz/) is a central hub where developers can list, discover, and retrieve packages. Publishing your package here makes it easy for others to use your library. + +To publish your package: + +1. **Generate an API Token** +Log into the registry dashboard and create a token with the `publish` scope. + +2. **Run the Publish Command** +```sh +SCARB_REGISTRY_AUTH_TOKEN=scrb_mytoken scarb publish +``` +The publish command automatically packages and verifies your package. Then it will publish your package to the official scarbs.xyz registry. **Once the package is published, it's impossible to unpublish it.** + +### Alternative Option +If your package is hosted on GitHub, you can directly add it as a dependency in your project without publishing to the official registry. For example: + +```sh +scarb add your_package --git https://github.com/username/your_package.git +``` + +This method pulls the package directly from the GitHub repository. However, using the official registry is recommended for better discoverability and integration. + +## Resources +- [Scarb Documentation](https://docs.swmansion.com/scarb/docs/guides/dependencies.html) +- [Scarb Package Registery](https://scarbs.xyz/) +- [Cairo Library Example](https://github.com/KaizeNodeLabs/starkiro/tree/main/examples/cairo/scripts/regex) \ No newline at end of file diff --git a/examples/cairo/scripts/regex/README.md b/examples/cairo/scripts/regex/README.md new file mode 100644 index 0000000..ff584f8 --- /dev/null +++ b/examples/cairo/scripts/regex/README.md @@ -0,0 +1,44 @@ +# Regex + +**A Cairo library providing a simplified regex engine supporting essential pattern matching features** + +## Prerequisites +Install [Scarb](https://docs.swmansion.com/scarb/) (we recommend using [asdf](https://asdf-vm.com/) version manager). + +## Installation + +In your project directory, run the following command to add the library as a dependency: + +```sh +scarb add regex@0.1.0 +``` + +Alternatively, you can manually add the dependency. In your Scarb.toml file, include: + +```toml +[dependencies] +regex = "0.1.0" +``` + +## Usage + +Import and use the library in your Cairo file: + +```cairo +use regex::RegexTrait; + +fn main() { + // Create a new Regex instance + let mut pattern = RegexTrait::new("H.llo"); + + // Sample text + let text = "Hello, World!"; + + // Check if the text matches the pattern + let is_match = pattern.matches(text.into()); + + println!("Match Found: {}", is_match); +} +``` + +For a detailed example of how to integrate and use this library in a Cairo project, check the [examples](./examples) folder. diff --git a/examples/cairo/scripts/regex/Scarb.toml b/examples/cairo/scripts/regex/Scarb.toml index 28d4f13..398da92 100644 --- a/examples/cairo/scripts/regex/Scarb.toml +++ b/examples/cairo/scripts/regex/Scarb.toml @@ -1,11 +1,17 @@ [package] name = "regex" version = "0.1.0" +description = "A cairo library providing a simplified regex engine supporting essential pattern matching features" +repository = "https://github.com/KaizeNodeLabs/starkiro/tree/main/examples/cairo/scripts/regex" edition = "2024_07" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html +Create-type = ["lib"] + [dependencies] [dev-dependencies] cairo_test = "2.9.2" + +[lib]