@granularjs/cli
v0.1.1
Published
Umbrella CLI for the Granular ecosystem. Dispatches to @granularjs/lint, @granularjs/codemods and @granularjs/create-app under a single `granular` command.
Maintainers
Readme
@granularjs/cli
Umbrella CLI for the Granular ecosystem. Exposes a single granular command that dispatches to the dedicated tooling packages:
| Subcommand | Delegated to | Purpose |
|---|---|---|
| granular lint | @granularjs/lint | Lint Granular code |
| granular audit | @granularjs/lint | Aggregated lint report |
| granular create | @granularjs/create-app | Scaffold a new app |
| granular migrate | @granularjs/codemods | Convert a React project to Granular |
| granular docs | @granularjs/core | Serve the module docs viewer locally |
@granularjs/core itself stays runtime-only and dependency-free. All tooling lives here or in the dedicated packages above.
Install
Globally (recommended for casual use):
npm install -g @granularjs/cli
granular --helpOr per-project:
npm install --save-dev @granularjs/cli
npx granular --helpMigrating from
@granularjs/core2.x? Thegranularbin used to ship with@granularjs/core. Starting with@granularjs/core3.x it lives in this package. Uninstall the old global if you have it, then install@granularjs/cli:npm uninstall -g @granularjs/core npm install -g @granularjs/cli
Usage
granular <command> [options]
Commands:
lint <path ...> Lint Granular code (delegates to @granularjs/lint)
audit <path ...> Aggregated lint report across files
create <appName> [options] Scaffold a new app (delegates to @granularjs/create-app)
migrate <source> [options] Convert a React project to Granular (delegates to @granularjs/codemods)
docs [--port N] [--open] Serve the Granular module docs viewer locally
Options:
-h, --help Show this help
-v, --version Show CLI versiongranular lint
Forwards every argument to the granular-lint binary from @granularjs/lint. Run granular lint --help for the full list of options.
granular lint .
granular lint src --format=json
granular lint --list-rulesgranular audit
Runs granular-lint --format=json against the given paths (defaults to .) and produces an aggregated report:
Granular Audit Report
=====================
Files analyzed: 124
Files with issues: 17
Total errors: 2
Total warnings: 31
Findings by rule:
no-state-truthy-and 8
no-get-at-top-of-list-render 7
prefer-list-over-map 6
...granular create
Forwards arguments to the create-granular-app binary from @granularjs/create-app.
granular create my-app
granular create my-app --jsx
granular create my-app --ssrgranular migrate
Wraps the codemods + project rewrites pipeline from @granularjs/codemods. Always writes to a NEW folder so the source tree stays intact for diffing.
granular migrate ./my-react-app
granular migrate ./my-react-app --out ./my-granular-app
granular migrate ./my-react-app --dry-run
granular migrate ./my-react-app --steps deps,configRun granular migrate --help for the full list of steps and codemods.
granular docs
Serves the Granular module docs viewer over HTTP. Reads markdown from @granularjs/core/docs/modules (which ships with core 3.x).
granular docs
granular docs --port 4000 --openProgrammatic API
import { dispatch, printUsage, readVersion } from '@granularjs/cli';
import { runMigrate } from '@granularjs/cli/migrate';
import { runDocs } from '@granularjs/cli/docs';
await dispatch('lint', ['src']);
await runMigrate(['./my-react-app', '--dry-run']);
await runDocs(['--port', '4000']);Why an umbrella CLI?
Before 0.1.0, the granular binary lived inside @granularjs/core. That coupled the runtime to Babel parser/traverse and tied global installs to tooling versions, in violation of the core's "zero runtime dependencies" rule.
Splitting the CLI out lets each tool ship and version independently while still presenting users with a single, familiar granular command.
License
Apache-2.0. Same as @granularjs/core.
