enable-generate-constants
v1.0.1
Published
CLI to query MongoDB and generate constant/permission JSON files.
Readme
enable-generate-constants
CLI tool to query a MongoDB collection and generate constant/permission JSON files
(e.g., _permissions.json or custom target) in specified target package directories.
Output files are written into <targetFolder>/src/<filename> if a src/ folder
exists, otherwise <targetFolder>/<filename>.
Usage
npx enable-generate-constants --collection <collection> --folders <folders> [options]Options
| Flag | Description |
|------|-------------|
| -f, --find <query> | Optional MongoDB query as JSON or field=val pairs (default: {}) |
| -r, --repoRoot <path> | Repository root containing .env (default: current directory) |
| -o, --folders <paths> | Comma-separated list of folders to write output to (required) |
| -c, --collection <name> | MongoDB collection containing codes (required) |
| -n, --name <field> | Field name to extract (default: code) |
| -F, --file <filename> | Output JSON filename (default: _permissions.json) |
| -d, --database <name> | Database name override (defaults to MONGODB_DATABASE in .env) |
| -u, --connectionString <uri> | MongoDB connection URI override (defaults to .env) |
| --dry-run | Query database and display results without writing files |
| -h, --help | Show usage help |
Examples
# Generate permissions for UX packages from feature collection
npx enable-generate-constants --find "{}" --collection feature --folders ux/saas,ux/portal
# Generate constants with a custom output file and field name
npx enable-generate-constants --collection roles --name roleKey --file _roles.json --folders packages/auth
# Preview output with --dry-run
npx enable-generate-constants --collection feature --folders ux/saas --dry-run