@sceon/microstack-cli
v0.1.2
Published
Scaffolding CLI for @sceon/microstack microservices
Readme
microstack-cli
A scaffolding CLI for @sceon/microstack microservices. Pick the modules you want and it generates a ready-to-run NestJS service with exactly the right packages, AppBuilder calls, YAML config, and .env — all kept in sync.
It works like nest new: a global microstack binary collects your selection via an interactive checkbox, then runs a bundled NestJS/Angular-DevKit schematic to generate the project and install dependencies.
Install
npm install -g @sceon/microstack-cliUsage
# Interactive — prompts you to pick modules
microstack new orders
# Non-interactive — pass modules explicitly
microstack new orders --modules mongo,redis,cache
# Useful flags
microstack new orders --skip-install # generate without npm install
microstack new orders --dry-run # show what would be written
microstack new orders -p pnpm # use pnpm/yarn for the install
microstack new orders -d services/orders # custom output directory
# See the available modules
microstack listSelectable modules
Each maps to one optional withXxx() builder method. Selecting one adds its npm
package(s), the withXxx() call in src/main.ts, a config block in
config/local.example.yaml, and its .env vars.
| Module | Builder | Packages added | Notes |
| --- | --- | --- | --- |
| mongo | withMongo | mongoose, @nestjs/mongoose | |
| mysql | withMySQL | typeorm, mysql2, @nestjs/typeorm | configured with discrete fields (needs database) |
| redis | withRedis | ioredis | |
| elastic | withElastic | @elastic/elasticsearch | |
| cache | withCache | — | Redis-backed; auto-enables redis |
| lock | withLock | redlock | Redlock; auto-enables redis |
| alert | withAlert | — | dispatches to the alarmist service |
| rabbitmqApi | withRabbitmqApi | — | RabbitMQ HTTP management client |
Core modules (config, logger, tracing, metrics, Swagger, health, graceful
shutdown, AMQP, events, RPC service, discovery, ACL) are always enabled — they
are wired automatically by AppBuilder and need no flag.
What gets generated
orders/
├── src/main.ts # AppBuilder.create('orders').withConfig(...)<selected withXxx()>
├── src/app.{module,controller,service}.ts
├── config/local.example.yaml # committed template (core + selected module blocks)
├── config/local.yaml # working copy (gitignored), created for you
├── .env.example # committed template
├── .env # working copy (gitignored), created for you
├── package.json # base deps + the selected modules' packages
├── tsconfig*.json, nest-cli.json, eslint.config.mjs, .prettierrc, .gitignore
└── test/ # e2e + unit test scaffoldingCommit the *.example files; the gitignored config/local.yaml and .env hold your real values. Configuration uses ${ENV_VAR:default} interpolation resolved by the microstack ConfigModule.
How it works
The single source of truth is schematics/microservice/manifest.ts: one ModuleDef per optional module, declaring its withXxx method, npm deps, YAML config block, .env vars, and any requires (e.g. cache/lock require redis). Both the interactive prompt and the schematic read from it, so adding a new module is a one-entry change.
src/bin/microstack.ts— thecommanderprogram (new,list).src/commands/new.command.ts— the@inquirer/promptscheckbox +requiresresolution.src/lib/run-schematic.ts— drives the schematic through an Angular-DevKitNodeWorkflow.schematics/microservice/index.ts— the rule factory that renders templates, merges deps, materializes working config copies, and schedulesnpm install.
Development
npm install
npm run build # tsc + copy schematic assets into dist/
node dist/src/bin/microstack.js new demo --modules mongo,cache --dry-run
# The schematic can also be run directly:
# schematics ./dist/schematics/collection.json:microservice --name=demo --modules=redisLicense
UNLICENSED
