GeezerVison is showing github.com — refactor(@angular-devkit/architect-cli): replace parser with yargs-pa… · angular/angular-cli@c7556b6
File treeExpand file treeCollapse file tree Open diff view settings packages/angular_devkit/architect_cli
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: package.json -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 104 | 104 | "@types/karma": "^6.3.0", | 105 | 105 | "@types/loader-utils": "^2.0.0", | 106 | 106 | "@types/minimatch": "3.0.5", | 107 | | - "@types/minimist": "^1.2.0", | 108 | 107 | "@types/node": "~12.12.6", | 109 | 108 | "@types/node-fetch": "^2.1.6", | 110 | 109 | "@types/npm-package-arg": "^6.1.0", | | 168 | 167 | "magic-string": "0.25.7", | 169 | 168 | "mini-css-extract-plugin": "2.5.3", | 170 | 169 | "minimatch": "5.0.1", | 171 | | - "minimist": "^1.2.0", | 172 | 170 | "ng-packagr": "14.0.0-next.1", | 173 | 171 | "node-fetch": "^2.2.0", | 174 | 172 | "npm-package-arg": "9.0.0", | |
Collapse file Copy file name to clipboardExpand all lines: packages/angular_devkit/architect_cli/BUILD.bazel +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,9 +20,9 @@ ts_library( | 20 | 20 | "//packages/angular_devkit/architect/node", | 21 | 21 | "//packages/angular_devkit/core", | 22 | 22 | "//packages/angular_devkit/core/node", | 23 | | - "@npm//@types/minimist", | 24 | 23 | "@npm//@types/node", | 25 | 24 | "@npm//@types/progress", | | 25 | + "@npm//@types/yargs-parser", | 26 | 26 | "@npm//ansi-colors", | 27 | 27 | "@npm//rxjs", | 28 | 28 | ], | |
Collapse file Copy file name to clipboardExpand all lines: packages/angular_devkit/architect_cli/bin/architect.ts +36-9Lines changed: 36 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import { Architect, BuilderInfo, BuilderProgressState, Target } from '@angular-devkit/architect'; | 11 | 11 | import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node'; | 12 | | -import { logging, schema, tags, workspaces } from '@angular-devkit/core'; | | 12 | +import { json, logging, schema, tags, workspaces } from '@angular-devkit/core'; | 13 | 13 | import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node'; | 14 | 14 | import * as ansiColors from 'ansi-colors'; | 15 | 15 | import { existsSync } from 'fs'; | 16 | | -import minimist from 'minimist'; | 17 | 16 | import * as path from 'path'; | 18 | 17 | import { tap } from 'rxjs/operators'; | | 18 | +import yargsParser from 'yargs-parser'; | 19 | 19 | import { MultiProgressBar } from '../src/progress'; | 20 | 20 |
| 21 | 21 | function findUp(names: string | string[], from: string) { | @@ -78,24 +78,43 @@ async function _executeTarget( | 78 | 78 | parentLogger: logging.Logger, | 79 | 79 | workspace: workspaces.WorkspaceDefinition, | 80 | 80 | root: string, | 81 | | - argv: minimist.ParsedArgs, | | 81 | + argv: yargsParser.Arguments, | 82 | 82 | registry: schema.SchemaRegistry, | 83 | 83 | ) { | 84 | 84 | const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, root); | 85 | 85 | const architect = new Architect(architectHost, registry); | 86 | 86 |
| 87 | 87 | // Split a target into its parts. | 88 | | - const targetStr = argv._.shift() || ''; | | 88 | + const { | | 89 | + _: [targetStr = ''], | | 90 | + help, | | 91 | + ...options | | 92 | + } = argv; | 89 | 93 | const [project, target, configuration] = targetStr.split(':'); | 90 | 94 | const targetSpec = { project, target, configuration }; | 91 | 95 |
| 92 | | - delete argv['help']; | 93 | 96 | const logger = new logging.Logger('jobs'); | 94 | 97 | const logs: logging.LogEntry[] = []; | 95 | 98 | logger.subscribe((entry) => logs.push({ ...entry, message: `${entry.name}: ` + entry.message })); | 96 | 99 |
| 97 | | - const { _, ...options } = argv; | 98 | | - const run = await architect.scheduleTarget(targetSpec, options, { logger }); | | 100 | + // Camelize options as yargs will return the object in kebab-case when camel casing is disabled. | | 101 | + | | 102 | + // Casting temporary until https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59065 is merged and released. | | 103 | + const { camelCase, decamelize } = yargsParser as yargsParser.Parser & { | | 104 | + camelCase(str: string): string; | | 105 | + decamelize(str: string, joinString?: string): string; | | 106 | + }; | | 107 | + | | 108 | + const camelCasedOptions: json.JsonObject = {}; | | 109 | + for (const [key, value] of Object.entries(options)) { | | 110 | + if (/[A-Z]/.test(key)) { | | 111 | + throw new Error(`Unknown argument ${key}. Did you mean ${decamelize(key)}?`); | | 112 | + } | | 113 | + | | 114 | + camelCasedOptions[camelCase(key)] = value; | | 115 | + } | | 116 | + | | 117 | + const run = await architect.scheduleTarget(targetSpec, camelCasedOptions, { logger }); | 99 | 118 | const bars = new MultiProgressBar<number, BarInfo>(':name :bar (:current/:total) :status'); | 100 | 119 |
| 101 | 120 | run.progress.subscribe((update) => { | @@ -107,7 +126,7 @@ async function _executeTarget( | 107 | 126 | name: ( | 108 | 127 | (update.target ? _targetStringFromTarget(update.target) : update.builder.name) + | 109 | 128 | ' '.repeat(80) | 110 | | - ).substr(0, 40), | | 129 | + ).substring(0, 40), | 111 | 130 | }; | 112 | 131 |
| 113 | 132 | if (update.status !== undefined) { | @@ -175,7 +194,15 @@ async function _executeTarget( | 175 | 194 |
| 176 | 195 | async function main(args: string[]): Promise<number> { | 177 | 196 | /** Parse the command line. */ | 178 | | - const argv = minimist(args, { boolean: ['help'] }); | | 197 | + const argv = yargsParser(args, { | | 198 | + boolean: ['help'], | | 199 | + configuration: { | | 200 | + 'dot-notation': false, | | 201 | + 'boolean-negation': true, | | 202 | + 'strip-aliased': true, | | 203 | + 'camel-case-expansion': false, | | 204 | + }, | | 205 | + }); | 179 | 206 |
| 180 | 207 | /** Create the DevKit Logger used through the CLI. */ | 181 | 208 | const logger = createConsoleLogger(argv['verbose'], process.stdout, process.stderr, { | |
Collapse file Copy file name to clipboardExpand all lines: packages/angular_devkit/architect_cli/package.json +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 | "@angular-devkit/architect": "0.0.0-EXPERIMENTAL-PLACEHOLDER", | 18 | 18 | "@angular-devkit/core": "0.0.0-PLACEHOLDER", | 19 | 19 | "ansi-colors": "4.1.1", | 20 | | - "minimist": "1.2.5", | 21 | 20 | "progress": "2.0.3", | 22 | 21 | "rxjs": "6.6.7", | 23 | | - "symbol-observable": "4.0.0" | | 22 | + "symbol-observable": "4.0.0", | | 23 | + "yargs-parser": "21.0.1" | 24 | 24 | }, | 25 | 25 | "devDependencies": { | 26 | 26 | "@types/progress": "2.0.5" | |
Collapse file Copy file name to clipboardExpand all lines: yarn.lock +1-6Lines changed: 1 addition & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1980 | 1980 | resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40" | 1981 | 1981 | integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ== | 1982 | 1982 |
| 1983 | | -"@types/minimist@^1.2.0": | 1984 | | - version "1.2.2" | 1985 | | - resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" | 1986 | | - integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ== | 1987 | | - | 1988 | 1983 | "@types/ms@*": | 1989 | 1984 | version "0.7.31" | 1990 | 1985 | resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" | @@ -7125,7 +7120,7 @@ minimatch@~3.0.4: | 7125 | 7120 | dependencies: | 7126 | 7121 | brace-expansion "^1.1.7" | 7127 | 7122 |
| 7128 | | -minimist@1.2.5, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: | | 7123 | +minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: | 7129 | 7124 | version "1.2.5" | 7130 | 7125 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" | 7131 | 7126 | integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== | |
|