create-onion-nest
v0.1.2
Published
Create NestJS APIs with Onion/Clean Architecture defaults.
Maintainers
Readme
create-onion-nest
Create a NestJS API shaped around Onion/Clean Architecture in one command.
npm create onion-nest@latest my-api
# or
npx create-onion-nest my-apiThe generated app separates business rules from framework details:
src/domainfor entities and repository contractssrc/applicationfor use cases and orchestrationsrc/infrastructurefor persistence and external adapterssrc/presentationfor NestJS controllers/modulessrc/sharedfor cross-cutting primitives
Usage
create-onion-nest <project-name> [--cwd <parent-dir>]
create-onion-nest module <name> [--cwd <project-dir>]Examples:
npx create-onion-nest my-api
cd my-api
npm install
npm run start:dev
npx create-onion-nest module billing --cwd ./my-apiThe project command is non-interactive. Use --cwd to choose the parent directory when running from another location. It validates that the target directory does not already contain files, copies the template, renames _gitignore to .gitignore, and replaces package-name tokens.
The module command adds a small vertical slice to an existing generated project:
src/domain/entities/<name>.entity.tssrc/domain/repositories/<name>.repository.tssrc/application/use-cases/get-<name>.use-case.tssrc/infrastructure/persistence/in-memory-<name>.repository.tssrc/presentation/controllers/<name>.controller.tssrc/presentation/<name>.module.ts
It also imports the new module in src/app.module.ts when the file matches the generated app shape.
Generated Project Commands
npm run build
npm run start
npm run start:dev
npm test
npm run lintPublishing This Package
This repository includes a manual GitHub Action for versioned uploads to npm. You decide the version when you run the workflow.
Versioned Release Action
Architecture:
- GitHub Actions is the release entry point.
workflow_dispatchasks for the exactversionand npm tag.npm version <version>updatespackage.jsonandpackage-lock.json, then creates the release commit and Git tag.npm run buildverifies the TypeScript package before publishing.npm publish --access public --tag <tag>uploads the package to npm.- The workflow pushes the release commit and tag back to GitHub.
Required setup:
- Create an npm access token with publish permissions.
- Add it in GitHub as repository secret
NPM_TOKEN. - Make sure GitHub Actions has write permission for repository contents.
How to use it:
- Go to GitHub > Actions > Release > Run workflow.
- Write the version you want to publish, for example
1.2.0. - Pick the npm tag, usually
latest. - Run the workflow.
If a published version needs a fix, publish a new patch version. For example, if 1.2.0 had a bug, fix the code and run the workflow with 1.2.1. npm does not allow publishing the exact same version twice.
Use semantic versions like this:
1.2.0: new minor feature or planned upload.1.2.1: fix for the same release line.2.0.0: breaking change.
Manual publish is still possible:
npm install
npm run build
npm pack --dry-run
npm publish --access publicprepublishOnly runs a clean TypeScript build. The npm package includes only dist, templates, README.md, and LICENSE.
Requirements
- Node.js 20 or newer
- npm 9 or newer recommended
License
MIT
