fix: use simpler command/config setup
MODIFY
package.json
package.json
"commands": "./lib/commands",
"plugins": [
"@anycli/plugin-help",
- "@anycli/plugin-not-found",
- "@anycli/plugin-version"
+ "@anycli/plugin-not-found"
],
"bin": "anycli"
},
},
"bugs": "https://github.com/anycli/cli/issues",
"dependencies": {
- "@anycli/command": "^0.3.7",
- "@anycli/config": "^0.3.0",
- "@anycli/dev-cli": "^0.1.3",
- "@anycli/engine": "^0.3.2",
- "@anycli/plugin-help": "^0.4.6",
- "@anycli/plugin-not-found": "^0.1.14",
- "@anycli/plugin-version": "^0.1.30",
+ "@anycli/command": "^1.2.4",
+ "@anycli/config": "^1.1.2",
+ "@anycli/dev-cli": "^0.1.5",
+ "@anycli/plugin-help": "^0.6.0",
+ "@anycli/plugin-not-found": "^0.1.15",
"cli-ux": "^3.3.13",
"debug": "^3.1.0",
"fixpack": "^2.3.1",
"yosay": "^2.0.1"
},
"devDependencies": {
- "@anycli/tslint": "^0.2.1",
+ "@anycli/tslint": "^0.2.5",
"@types/lodash": "^4.14.100",
"@types/read-pkg": "^3.0.0",
"@types/shelljs": "^0.7.8",
"@types/yeoman-generator": "^2.0.1",
"@types/yosay": "^0.0.29",
"chai": "^4.1.2",
- "eslint": "^4.16.0",
- "eslint-config-anycli": "^1.3.1",
+ "eslint": "^4.17.0",
+ "eslint-config-anycli": "^1.3.2",
"execa": "^0.9.0",
- "fancy-test": "^0.6.6",
+ "fancy-test": "^0.6.10",
"fs-extra": "^5.0.0",
"mocha": "^5.0.0",
"npm-run-path": "^2.0.2",

MODIFY
src/app_command.ts
src/app_command.ts
-import {flags, parse} from '@anycli/command'
+import {flags} from '@anycli/command'
import Base from './command_base'
@@ -12,18 +12,18 @@ export default abstract class AppCommand extends Base {
{name: 'path', required: false}
]
- options = parse(this.argv, AppCommand)
abstract type: string
async run() {
- const options = this.options.flags.options ? this.options.flags.options.split(',') : []
+ const {flags, args} = this.parse(AppCommand)
+ const options = flags.options ? flags.options.split(',') : []
await super.generate('app', {
type: this.type,
- path: this.options.args.path,
+ path: args.path,
options,
- defaults: this.options.flags.defaults,
- force: this.options.flags.force
+ defaults: flags.defaults,
+ force: flags.force
})
}
}

MODIFY
src/generators/app.ts
src/generators/app.ts
@@ -245,7 +245,7 @@ class App extends Generator {
this.pjson.scripts.prepublishOnly = 'yarn run build'
}
if (['plugin', 'multi'].includes(this.type)) {
- this.pjson.scripts.prepublishOnly = nps.series(this.pjson.scripts.prepublishOnly, 'anycli-dev manifest -o .anycli.manifest.json')
+ this.pjson.scripts.prepublishOnly = nps.series(this.pjson.scripts.prepublishOnly, 'anycli-dev manifest')
this.pjson.scripts.postpublish = 'rm .anycli.manifest.json'
this.pjson.files.push('.anycli.manifest.json')
}

MODIFY
src/index.ts
src/index.ts
-import run from '@anycli/engine'
-export {run}
-export default run
+export {run} from '@anycli/command'

MODIFY
templates/bin/run
templates/bin/run
#!/usr/bin/env node
-require('@anycli/engine').run()
+require('@anycli/command').run()

MODIFY
templates/plugin/bin/run
templates/plugin/bin/run
#!/usr/bin/env node
-require('@anycli/engine').run()
+require('@anycli/command').run()

MODIFY
templates/src/command.js.ejs
templates/src/command.js.ejs
-const {Command, flags, parse} = require('@anycli/command')
+const {Command, flags} = require('@anycli/command')
const {cli} = require('cli-ux')
<%_ const klass = _.upperFirst(_.camelCase(name.split(':').slice(-1).join(':') + ':command')) _%>
class <%- klass %> extends Command {
async run() {
- const options = parse(this.argv, <%- klass %>)
- const name = options.flags.name || 'world'
+ const {flags} = this.parse(<%- klass %>)
+ const name = flags.name || 'world'
cli.log(`hello ${name} from <%- name %>!`)
}
}

MODIFY
templates/src/command.ts.ejs
templates/src/command.ts.ejs
-import {Command, flags, parse} from '@anycli/command'
+import {Command, flags} from '@anycli/command'
import cli from 'cli-ux'
<%_ const klass = _.upperFirst(_.camelCase(name)) _%>
@@ -90,25 +90,15 @@ hello myname from <%- name %>!
// set it to off if you need to accept variable arguments
// static strict = false
- // runs the parser and stores the results in this.options
- // you should run this even if you have no flags/args so it properly errors out
- // (see strict above for variable argument commands)
- //
- // stores the parsed flags in options.flags[name]
- //
- // stores the parsed args in options.args[name] as an object
- // but also in options.argv as an array
- // you can get the raw args passed to the command with this.argv
- // or from this.options.argv which will remove any args that were actually flags
- options = parse(this.argv, <%- klass %>)
-
// entry point of command
async run() {
- const name = this.options.flags.name || 'world'
- cli.log(`hello ${name} from <%- name %>!`)
+ const {args, flags} = this.parse(<%- klass %>)
- // this.options.flags.force is a boolean
- // this.options.args.file and this.options.argv[0] is a string or undefined
+ const name = flags.name || 'world'
+ cli.log(`hello ${name} from <%- name %>!`)
+ if (args.file && flags.force) {
+ cli.log(`you input ${args.file}`)
+ }
}
}
<%_ if (type === 'single') { _%>

MODIFY
yarn.lock
yarn.lock
# yarn lockfile v1
-"@anycli/command@^0.3.7":
- version "0.3.7"
- resolved "https://registry.npmjs.org/@anycli/command/-/command-0.3.7.tgz#293c366ed8227fcdc675e278a46d8f93435526a5"
+"@anycli/command@^1.2.2":
+ version "1.2.2"
+ resolved "https://registry.yarnpkg.com/@anycli/command/-/command-1.2.2.tgz#1969bc3df292256e2eb0481c48eace0387cd6484"
dependencies:
- "@anycli/parser" "^3.0.4"
+ "@anycli/parser" "^3.2.1"
cli-ux "^3.3.13"
debug "^3.1.0"
+ fs-extra "^5.0.0"
+ load-json-file "^4.0.0"
lodash "^4.17.4"
- tslib "^1.9.0"
-"@anycli/config@^0.3.0":
- version "0.3.0"
- resolved "https://registry.npmjs.org/@anycli/config/-/config-0.3.0.tgz#a0938488e7afc507d69ec13a8e52c71aaecc08ea"
+"@anycli/command@^1.2.3":
+ version "1.2.3"
+ resolved "https://registry.yarnpkg.com/@anycli/command/-/command-1.2.3.tgz#b239669674f98098b1af096f081958b270fab0b6"
dependencies:
- cli-ux "^3.3.10"
+ "@anycli/parser" "^3.2.2"
+ cli-ux "^3.3.13"
debug "^3.1.0"
fs-extra "^5.0.0"
load-json-file "^4.0.0"
lodash "^4.17.4"
- read-pkg "^3.0.0"
-"@anycli/dev-cli@^0.1.3":
- version "0.1.3"
- resolved "https://registry.npmjs.org/@anycli/dev-cli/-/dev-cli-0.1.3.tgz#bd3d1229d17c2f61176f872923d4841a539a0cb3"
- dependencies:
- "@anycli/command" "^0.3.7"
- "@anycli/config" "^0.3.0"
- "@anycli/engine" "^0.3.0"
- "@anycli/plugin-help" "^0.4.0"
- "@anycli/plugin-not-found" "^0.1.10"
- "@anycli/plugin-version" "^0.1.20"
+"@anycli/command@^1.2.4":
+ version "1.2.4"
+ resolved "https://registry.yarnpkg.com/@anycli/command/-/command-1.2.4.tgz#9c42a8142a380193a949fab8f374b53ef805f4e9"
+ dependencies:
+ "@anycli/parser" "^3.2.2"
cli-ux "^3.3.13"
+ debug "^3.1.0"
fs-extra "^5.0.0"
+ load-json-file "^4.0.0"
+ lodash "^4.17.4"
-"@anycli/engine@^0.3.0", "@anycli/engine@^0.3.2":
- version "0.3.2"
- resolved "https://registry.npmjs.org/@anycli/engine/-/engine-0.3.2.tgz#fb8e8d2cf2cd20108ae5fab40b84c3a55cf706ad"
+"@anycli/config@^1.1.1":
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/@anycli/config/-/config-1.1.1.tgz#768579f33f2efb73559d430df25a6238349ce0b5"
dependencies:
- "@anycli/manifest-file" "^0.3.9"
cli-ux "^3.3.13"
debug "^3.1.0"
fs-extra "^5.0.0"
+ fs-extra-debug "^1.0.4"
globby "^7.1.1"
+ load-json-file "^4.0.0"
lodash "^4.17.4"
- semver "^5.5.0"
+ read-pkg "^3.0.0"
-"@anycli/manifest-file@^0.3.9":
- version "0.3.9"
- resolved "https://registry.npmjs.org/@anycli/manifest-file/-/manifest-file-0.3.9.tgz#d39ab157c0cd9a15471ef8bfd36654c2c4b01730"
+"@anycli/config@^1.1.2":
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/@anycli/config/-/config-1.1.2.tgz#751cf988f16a1257ec0973bb5171fbd5474b7080"
dependencies:
cli-ux "^3.3.13"
debug "^3.1.0"
fs-extra "^5.0.0"
+ fs-extra-debug "^1.0.4"
+ globby "^7.1.1"
load-json-file "^4.0.0"
lodash "^4.17.4"
- proper-lockfile "^3.0.2"
+ read-pkg "^3.0.0"
-"@anycli/parser@^3.0.4":
- version "3.0.4"
- resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.0.4.tgz#8714c4f73134625fe3781b9e2b5aa0ebb5685a82"
+"@anycli/dev-cli@^0.1.5":
+ version "0.1.5"
+ resolved "https://registry.yarnpkg.com/@anycli/dev-cli/-/dev-cli-0.1.5.tgz#efcb13ca2dd4378798e991d5e207558fdd440b09"
+ dependencies:
+ "@anycli/command" "^1.2.3"
+ "@anycli/config" "^1.1.1"
+ "@anycli/plugin-help" "^0.6.0"
+ "@anycli/plugin-not-found" "^0.1.15"
+ "@anycli/plugin-version" "^0.1.34"
+ cli-ux "^3.3.13"
+ fs-extra "^5.0.0"
+
+"@anycli/parser@^3.2.1", "@anycli/parser@^3.2.2":
+ version "3.2.2"
+ resolved "https://registry.yarnpkg.com/@anycli/parser/-/parser-3.2.2.tgz#ee2616e889e7dd78bc269638b7eee3f3096e2c91"
dependencies:
"@anycli/screen" "^0.0.3"
chalk "^2.3.0"
lodash "^4.17.4"
-"@anycli/plugin-help@^0.4.0", "@anycli/plugin-help@^0.4.6":
- version "0.4.6"
- resolved "https://registry.npmjs.org/@anycli/plugin-help/-/plugin-help-0.4.6.tgz#672a96550203968118b881fcdf8f2c685a784bf6"
+"@anycli/plugin-help@^0.6.0":
+ version "0.6.0"
+ resolved "https://registry.yarnpkg.com/@anycli/plugin-help/-/plugin-help-0.6.0.tgz#a7177b0b4afc87544ae7e7bcdc095fbeea65791f"
dependencies:
- "@anycli/command" "^0.3.7"
+ "@anycli/command" "^1.2.3"
"@anycli/screen" "^0.0.3"
chalk "^2.3.0"
cli-ux "^3.3.13"
widest-line "^2.0.0"
wrap-ansi "^3.0.1"
-"@anycli/plugin-not-found@^0.1.10", "@anycli/plugin-not-found@^0.1.14":
- version "0.1.14"
- resolved "https://registry.npmjs.org/@anycli/plugin-not-found/-/plugin-not-found-0.1.14.tgz#d7512f402357951126bc0d3d89d2808a0947c45f"
+"@anycli/plugin-not-found@^0.1.15":
+ version "0.1.15"
+ resolved "https://registry.yarnpkg.com/@anycli/plugin-not-found/-/plugin-not-found-0.1.15.tgz#738bdabd485081ee9172e0e4e4a3ee29d32178da"
dependencies:
- "@anycli/command" "^0.3.7"
+ "@anycli/command" "^1.2.2"
"@heroku-cli/color" "^1.1.3"
cli-ux "^3.3.13"
string-similarity "^1.2.0"
-"@anycli/plugin-version@^0.1.20", "@anycli/plugin-version@^0.1.30":
- version "0.1.30"
- resolved "https://registry.npmjs.org/@anycli/plugin-version/-/plugin-version-0.1.30.tgz#0c80e4c856f4a3249a5d56b4c9d553b20c514198"
+"@anycli/plugin-version@^0.1.34":
+ version "0.1.34"
+ resolved "https://registry.yarnpkg.com/@anycli/plugin-version/-/plugin-version-0.1.34.tgz#d64f990662adc531ddde048a8908b4a85db0d09d"
dependencies:
- "@anycli/command" "^0.3.7"
+ "@anycli/command" "^1.2.2"
cli-ux "^3.3.13"
"@anycli/screen@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@anycli/screen/-/screen-0.0.3.tgz#f0afd970c3ed725702948a45a874ede1fdd9362e"
-"@anycli/tslint@^0.2.1":
- version "0.2.2"
- resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.2.tgz#46e899f58019600fc6a7191e7fde47d6b4513df1"
+"@anycli/tslint@^0.2.5":
+ version "0.2.5"
+ resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.5.tgz#63feeb981b11f36326e0cb745c62f51d55c2ed67"
dependencies:
tslint "^5.9.1"
tslint-xo "^0.6.0"
@@ -539,26 +553,6 @@ cli-table@^0.3.1:
dependencies:
colors "1.0.3"
-cli-ux@^3.3.10:
- version "3.3.10"
- resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.10.tgz#54fad2bc9e1fcb56cdbd7d41682373e0fb7ce447"
- dependencies:
- "@anycli/screen" "^0.0.3"
- "@heroku/linewrap" "^1.0.0"
- ansi-styles "^3.2.0"
- cardinal "^1.0.0"
- chalk "^2.3.0"
- clean-stack "^1.3.0"
- extract-stack "^1.0.0"
- fs-extra "^5.0.0"
- indent-string "^3.2.0"
- lodash "^4.17.4"
- node-notifier "^5.2.1"
- password-prompt "^1.0.4"
- semver "^5.5.0"
- strip-ansi "^4.0.0"
- supports-color "^5.1.0"
-
cli-ux@^3.3.13:
version "3.3.13"
resolved "https://registry.npmjs.org/cli-ux/-/cli-ux-3.3.13.tgz#123e0c7a29d1f743447b919500a9055486992df6"
@@ -881,9 +875,9 @@ eslint-ast-utils@^1.0.0:
lodash.get "^4.4.2"
lodash.zip "^4.2.0"
-eslint-config-anycli@^1.3.1:
- version "1.3.1"
- resolved "https://registry.yarnpkg.com/eslint-config-anycli/-/eslint-config-anycli-1.3.1.tgz#e05fefcdbdffdd3e74069dac5252a8bc70ae7eb2"
+eslint-config-anycli@^1.3.2:
+ version "1.3.2"
+ resolved "https://registry.yarnpkg.com/eslint-config-anycli/-/eslint-config-anycli-1.3.2.tgz#0f28e63a8ae93d490623cdcd89eeafcb7635b082"
dependencies:
eslint-config-xo-space "^0.17.0"
eslint-plugin-mocha "^4.11.0"
@@ -938,9 +932,9 @@ eslint-visitor-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
-eslint@^4.16.0:
- version "4.16.0"
- resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.16.0.tgz#934ada9e98715e1d7bbfd6f6f0519ed2fab35cc1"
+eslint@^4.17.0:
+ version "4.17.0"
+ resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.17.0.tgz#dc24bb51ede48df629be7031c71d9dc0ee4f3ddf"
dependencies:
ajv "^5.3.0"
babel-code-frame "^6.22.0"
@@ -1080,9 +1074,9 @@ extract-stack@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/extract-stack/-/extract-stack-1.0.0.tgz#b97acaf9441eea2332529624b732fc5a1c8165fa"
-fancy-test@^0.6.6:
- version "0.6.6"
- resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.6.tgz#cda1afbf57ea2fb05291edbff34c0bbc2600d956"
+fancy-test@^0.6.10:
+ version "0.6.10"
+ resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-0.6.10.tgz#39001bcb117b7067c851dc58da6236a08a49e267"
dependencies:
lodash "^4.17.4"
stdout-stderr "^0.1.6"
@@ -1157,6 +1151,12 @@ from@~0:
version "0.1.7"
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"
+fs-extra-debug@^1.0.4:
+ version "1.0.4"
+ resolved "https://registry.yarnpkg.com/fs-extra-debug/-/fs-extra-debug-1.0.4.tgz#5efa3bd2a7ef6753fa79cfd810aab36445fa4788"
+ dependencies:
+ debug "^3.1.0"
+
fs-extra@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
@@ -1293,7 +1293,7 @@ got@^7.0.0:
url-parse-lax "^1.0.0"
url-to-options "^1.0.1"
-graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
+graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
@@ -2082,13 +2082,6 @@ progress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"
-proper-lockfile@^3.0.2:
- version "3.0.2"
- resolved "https://registry.yarnpkg.com/proper-lockfile/-/proper-lockfile-3.0.2.tgz#d30b3b83ecb157e08fe0d411f2393bc384b77ad1"
- dependencies:
- graceful-fs "^4.1.11"
- retry "^0.10.1"
-
ps-tree@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ps-tree/-/ps-tree-1.1.0.tgz#b421b24140d6203f1ed3c76996b4427b08e8c014"
@@ -2253,10 +2246,6 @@ restore-cursor@^2.0.0:
onetime "^2.0.0"
signal-exit "^3.0.2"
-retry@^0.10.1:
- version "0.10.1"
- resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4"
-
rimraf@^2.2.8, rimraf@^2.6.1, rimraf@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
@@ -2621,7 +2610,7 @@ tsconfig@^7.0.0:
strip-bom "^3.0.0"
strip-json-comments "^2.0.0"
-tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
+tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"

fix: use simpler command/config setup