Development¶
Prerequisites¶
- Node.js 18+
- npm 9+
Setup¶
git clone git@github.com:subscribed-aps/tools-package-subscribed-cli.git
cd tools-package-subscribed-cli
npm install
npm run compose # builds and links the `subscribed` binary globally
After npm run compose, the subscribed command is available in your terminal and reflects the current build. Re-run it after making changes.
Project structure¶
src/
bin/
subscribed.ts # binary entry point (just imports index.ts)
commands/
auth.ts # auth login/logout/status
deploy.ts # deploy command
log-sniff.ts # log-sniff implementation
logs.ts # logs subcommand group (wraps log-sniff)
workflow.ts # workflow run command
lib/
config.ts # config dir + auth token storage (~/.config/subscribed-cli)
github.ts # Octokit client, branch/workflow fetching, workflow dispatch
projects.ts # project registry (sites and packages)
build-info.ts # version from package.json, build stamp, stale-build warning
index.ts # commander setup and command registration
scripts/
write-build-info.mjs # runs after tsc, writes dist/build-info.json
test/
*.test.mjs # node:test unit tests, run against dist/
dist/ # compiled output (do not edit)
docs/ # this documentation
Build¶
npm run build # tsc → dist/, then writes dist/build-info.json
npm run dev # build + run dist/index.js directly (no global link needed)
Tests¶
Tests use Node's built-in node:test runner and import from dist/, so there is no extra test dependency. Keep pure logic (formatting, parsing, decisions) in functions without I/O so it can be tested this way.
Which build am I running?¶
The version comes from package.json. The rest is the commit, branch and time of the build, written by scripts/write-build-info.mjs. A -dirty suffix means src/ or package.json had uncommitted changes when it was built.
When the CLI runs from a source checkout (after npm run compose), it also checks on every command whether dist/ is behind: a different HEAD than the built commit, or files in src/ newer than the build. If so, it prints a warning and tells you to run npm run compose. The check is skipped for registry installs and can be turned off with SUBSCRIBED_SKIP_BUILD_CHECK=1.
TypeScript is compiled with NodeNext module resolution. All local imports must use .js extensions (e.g. import { foo } from './lib/config.js'), even though the source files are .ts. This is a requirement of Node.js ESM.
Adding a command¶
- Create
src/commands/your-command.tsand export aregisterYourCommand(program: Command): voidfunction. - Import and call it in
src/index.ts. - Add a docs page at
docs/commands/your-command.md. - Update the commands table in
README.md.
Adding a project¶
Open src/lib/projects.ts and add an entry to the PROJECTS array:
{
key: 'my-project', // used as CLI argument: subscribed deploy my-project
name: 'My Project', // display name in prompts
repo: 'subscribed-aps/my-project-repo',
type: 'site', // 'site' | 'package'
deployWorkflow: 'deploy.yml',
environments: ['develop', 'production'],
productionEnvironment: 'production', // optional — defaults to 'production'
// set if your workflow uses a different name
dispatchBranch: { // optional — dispatch the workflow on a stable branch
develop: 'develop', // and send the chosen branch as the "ref" input.
production: 'main', // Required for deploying feature branches to staging.
}, // Production never receives the "ref" input.
}
No other files need to change.
Branching¶
Never commit directly to main. Always create a feature branch and open a PR: