From 6ddafe6ca09b853320d23801001fd20405bd6011 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 1 Jul 2024 00:27:46 -0400 Subject: [PATCH 1/2] chore: add `pnpm add-function` command Call it like `pnpm add-function array/filter` --- package.json | 3 ++- scripts/add-function.sh | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 scripts/add-function.sh diff --git a/package.json b/package.json index db27f600..a57d3ea2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "format": "biome check --fix --unsafe", "test": "vitest run --coverage", "bench": "vitest bench", - "prepublishOnly": "tsc && biome check --fix && pnpm -s build" + "prepublishOnly": "tsc && biome check --fix && pnpm -s build", + "add-function": "bash ./scripts/add-function.sh" }, "devDependencies": { "@biomejs/biome": "^1.8.3", diff --git a/scripts/add-function.sh b/scripts/add-function.sh new file mode 100644 index 00000000..2a4d5554 --- /dev/null +++ b/scripts/add-function.sh @@ -0,0 +1,55 @@ +NAME="$1" + +if [ -z "$NAME" ]; then + echo "Usage: $0 /" + exit 1 +fi + +# Split NAME into GROUP_NAME and FUNC_NAME +IFS='/' read -r GROUP_NAME FUNC_NAME <<< "$NAME" + +if [ -z "$GROUP_NAME" ] || [ -z "$FUNC_NAME" ]; then + echo "Error: Invalid input format. Please use /" + exit 1 +fi + +# Check if the group directory exists in src +if [ ! -d "src/$GROUP_NAME" ]; then + echo "Warning: The group '$GROUP_NAME' does not exist in the src directory." + read -n 1 -p "Are you sure you want to create a new group? (Y/n) " confirm + echo + if [ "$confirm" == "n" ]; then + echo "Operation cancelled." + exit 1 + fi +fi + +# Prompt the user for a description: +echo "Enter a description for $FUNC_NAME:" +read -r DESCRIPTION + +# Make the group in the following parent directories: +# - src +# - docs +# - tests +# - benchmarks +SRC_DIR="src/$GROUP_NAME" +DOCS_DIR="docs/$GROUP_NAME" +TESTS_DIR="tests/$GROUP_NAME" +BENCHMARKS_DIR="benchmarks/$GROUP_NAME" + +mkdir -p $SRC_DIR $DOCS_DIR $TESTS_DIR $BENCHMARKS_DIR + +# Create the function in the following files: +# - src//.ts +# - tests//.test.ts +# - benchmarks//.bench.ts +# - docs//.mdx + +echo -e "export function $FUNC_NAME(): void {}\n" > $SRC_DIR/$FUNC_NAME.ts + +echo -e "import * as _ from 'radashi'\n\ndescribe('$FUNC_NAME', () => {\n test('does a thing', () => {\n expect(_.$FUNC_NAME()).toBe(undefined)\n })\n})\n" > $TESTS_DIR/$FUNC_NAME.test.ts + +echo -e "import * as _ from 'radashi'\nimport { bench } from 'vitest'\n\ndescribe('$FUNC_NAME', () => {\n bench('with no arguments', () => {\n _.$FUNC_NAME()\n })\n})\n" > $BENCHMARKS_DIR/$FUNC_NAME.bench.ts + +echo -e "---\ntitle: $FUNC_NAME\ndescription: $DESCRIPTION\n---\n\n## Basic usage\n\nDoes a thing. Returns a value.\n\n\`\`\`ts\nimport * as _ from 'radashi'\n\n_.$FUNC_NAME()\n\`\`\`" > $DOCS_DIR/$FUNC_NAME.mdx \ No newline at end of file From 46ea682e9d9334b54a4c740803ce6a96a8cb9e18 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 1 Jul 2024 00:43:09 -0400 Subject: [PATCH 2/2] chore: update contributing.md --- .github/contributing.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/contributing.md b/.github/contributing.md index 7ab8b2b9..c3acae65 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -17,11 +17,16 @@ Scan through the [existing issues](https://github.com/aleclarson/radashi/issues) ## You want to write code? - To get started, run `pnpm i` in the project's root directory to install the dependencies. +- You can add a new function with `pnpm add-function /`. This will create the necessary files and open a PR with the new function. Try to use a `group-name` that already exists, if possible (check the `src` directory). Note that you will need to manually export the function from `src/mod.ts` before you can use it. - You can run the unit tests with `pnpm test`. They require Node v16+. You can run `nvm use` in the root directory to change to the correct Node version. The tests should pass (duh) and maintain 100% code coverage. +- You can lint your code with `pnpm lint`. - To get familiar with the existing code I would recommend looking through the docs and the codebase in parallel. For each function in the docs, find the implementation in the source and skim over the code. -- When coding, try not to create internal APIs (any function or module that is not exported to be used by the client). -- Also, try not to use functions from other Radashi modules. This is a softer rule but we want to make it easy for readers to understand a function without having to navigate the codebase. As a utility library users should ideally be able to copy/paste a function from Radashi into their project. Most Radashi functions should be easy to write in isolation. -- If an implementation needs more than ~20 lines of code it might be better suited for another package or library. This is another softer rule. + +Please review _“The ethos of Radashi”_ before getting started: + + + The ethos of Radashi + ## You're ready to push a change? @@ -35,4 +40,4 @@ Once you submit your PR, one of Radashi's maintainers will review it. They might ## Your PR gets merged! -Congratulations :tada::tada: Currently, the package publishing process is manual. Your PR will be updated with a comment when the next release is published. This should happen within 24-48 hours of your PR being merged. +Congratulations :tada::tada: Currently, official versions are published manually. But beta versions are published automatically, every day, at 5:00AM UTC (if a PR has been merged). Your PR will be updated with a comment when the next release is published.