diff --git a/docs/cli-flags.md b/docs/cli-flags.md index fafb4cf..d708955 100644 --- a/docs/cli-flags.md +++ b/docs/cli-flags.md @@ -1,5 +1,7 @@ # CLI flags -| Flag | Description | Type | -| ------------ | ------------------------------------------------------------------------------------------- | ------------------ | -| -c, --config | Config file path | `string` optional | +| Flag | Description | Type | +| -------------------- | ------------------------------------------ | ------------------------------------------- | +| -c, --config | Config file path | `string` optional | +| --subProject | Override `subProject` config value | `string` optional | +| --defaultCompression | Override `defaultCompression` config value | `"none"` \| `"gzip"` \| `"brotli"` optional | diff --git a/packages/bundlemon-markdown-output/package.json b/packages/bundlemon-markdown-output/package.json index bf8819d..40e6666 100644 --- a/packages/bundlemon-markdown-output/package.json +++ b/packages/bundlemon-markdown-output/package.json @@ -15,6 +15,7 @@ "module": "./lib/esm/index.js", "types": "./lib/esm/index.d.ts", "scripts": { + "test": "echo no tests", "build": "rimraf lib/ && tsc -p tsconfig.release.json && tsc -p tsconfig-cjs.json", "prepublishOnly": "yarn test && yarn lint && yarn build", "lint": "yarn eslint --config ../../.eslintrc.json --max-warnings=0 \"src/**/*.ts\"", diff --git a/packages/bundlemon/src/cli/index.ts b/packages/bundlemon/src/cli/index.ts index f1a8915..47b8af6 100644 --- a/packages/bundlemon/src/cli/index.ts +++ b/packages/bundlemon/src/cli/index.ts @@ -1,12 +1,20 @@ -import { program } from 'commander'; -import { Status } from 'bundlemon-utils'; +import { program, Option } from 'commander'; +import { Compression, Status } from 'bundlemon-utils'; import bundlemon from '../main'; import logger from '../common/logger'; import { version } from '../common/consts'; -import type { CliOptions } from './types'; import { loadConfigFile } from './configFile'; -program.version(version).option('-c, --config [path]', 'Config file path'); +import type { CliOptions } from './types'; +import type { Config } from '../main/types'; + +program + .version(version) + .addOption(new Option('-c, --config ', 'config file path')) + .addOption(new Option('--subProject ', 'sub project name')) + .addOption( + new Option('--defaultCompression ', 'default compression').choices(Object.values(Compression)) + ); export default async (): Promise => { try { @@ -21,7 +29,7 @@ export default async (): Promise => { process.exit(1); } - const report = await bundlemon(config); + const report = await bundlemon(mergeCliOptions(config, options)); process.exit(report.status === Status.Pass ? 0 : 1); } catch (err) { @@ -29,3 +37,17 @@ export default async (): Promise => { process.exit(1); } }; + +function mergeCliOptions(config: Config, options: CliOptions): Config { + const newConfig = { ...config }; + + if (options.subProject) { + newConfig.subProject = options.subProject; + } + + if (options.defaultCompression) { + newConfig.defaultCompression = options.defaultCompression; + } + + return newConfig; +} diff --git a/packages/bundlemon/src/cli/types.ts b/packages/bundlemon/src/cli/types.ts index fdd6779..773bfdf 100644 --- a/packages/bundlemon/src/cli/types.ts +++ b/packages/bundlemon/src/cli/types.ts @@ -1,3 +1,7 @@ +import type { Compression } from 'bundlemon-utils'; + export interface CliOptions { config?: string; + subProject?: string; + defaultCompression?: Compression; }