Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add pnpm add-function command #54

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <group-name>/<function-name>`. 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:

<a href="https://github.com/orgs/radashi-org/discussions/20">
<img src="https://github.com/radashi-org/radashi/raw/main/.github/img/ethos-button.png" alt="The ethos of Radashi" width="250px" />
</a>

## You're ready to push a change?

Expand All @@ -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.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
55 changes: 55 additions & 0 deletions scripts/add-function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
NAME="$1"

if [ -z "$NAME" ]; then
echo "Usage: $0 <group-name>/<function-name>"
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 <group-name>/<function-name>"
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/<group-name>/<function-name>.ts
# - tests/<group-name>/<function-name>.test.ts
# - benchmarks/<group-name>/<function-name>.bench.ts
# - docs/<group-name>/<function-name>.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
Loading