fix: improve experience when overwiting existing base
MODIFY
package.json
package.json
"dependencies": {
"@anycli/command": "^0.3.3",
"@anycli/config": "^0.2.11",
- "@anycli/engine": "^0.1.42",
+ "@anycli/engine": "^0.1.45",
"@anycli/version": "^0.1.19",
"cli-ux": "^3.3.12",
"debug": "^3.1.0",

MODIFY
src/generators/app.ts
src/generators/app.ts
// tslint:disable no-floating-promises
// tslint:disable no-console
+import * as fs from 'fs'
import * as _ from 'lodash'
import * as path from 'path'
import * as Generator from 'yeoman-generator'
@@ -11,19 +12,19 @@ const fixpack = require('fixpack')
const debug = require('debug')('generator-anycli')
const {version} = require('../../package.json')
-function stringToArray(s: string) {
- const keywords: string[] = []
+// function stringToArray(s: string) {
+// const keywords: string[] = []
- s.split(',').forEach((keyword: string) => {
- if (!keyword.length) {
- return false
- }
+// s.split(',').forEach((keyword: string) => {
+// if (!keyword.length) {
+// return false
+// }
- return keywords.push(keyword.trim())
- })
+// return keywords.push(keyword.trim())
+// })
- return keywords
-}
+// return keywords
+// }
class App extends Generator {
options: {
@@ -118,6 +119,10 @@ class App extends Generator {
},
options: this.options,
}
+ try {
+ let yml = this.fs.read('.circleci/config.yml')
+ this.options['semantic-release'] = yml.includes('semantic-release')
+ } catch { }
if (this.options.defaults) {
this.answers = defaults
} else {
@@ -175,7 +180,7 @@ class App extends Generator {
type: 'input',
name: 'github.repo',
message: 'github name of repository (https://github.com/owner/REPO)',
- default: (answers: any) => (this.pjson.repository ? this.pjson.repository : answers.name).split('/').pop(),
+ default: (answers: any) => (this.pjson.repository || answers.name || this.pjson.name).split('/').pop(),
when: !this.pjson.repository,
},
{
@@ -185,17 +190,17 @@ class App extends Generator {
choices: [
{name: 'mocha', checked: !!this.pjson.devDependencies.mocha},
{name: 'typescript', checked: !!this.pjson.devDependencies.typescript},
- {name: 'semantic-release', checked: !!this.fs.exists('.commitlintrc.js')},
+ {name: 'semantic-release', checked: this.options['semantic-release']},
],
filter: ((arr: string[]) => _.keyBy(arr)) as any,
},
- {
- type: 'string',
- name: 'files',
- message: 'npm files to pack',
- default: (answers: any) => answers.options.typescript ? '/lib' : '/src',
- filter: stringToArray as any,
- },
+ // {
+ // type: 'string',
+ // name: 'files',
+ // message: 'npm files to pack',
+ // default: (answers: any) => answers.options.typescript ? '/lib' : '/src',
+ // filter: stringToArray as any,
+ // },
]) as any
}
debug(this.answers)
@@ -231,8 +236,8 @@ class App extends Generator {
this.pjson.scripts.prepublishOnly = 'yarn run build'
}
this.pjson.keywords = defaults.keywords || [this.type === 'plugin' ? 'anycli-plugin' : 'anycli']
- this.pjson.homepage = defaults.homepage || `https://github.com/${defaults.repository}`
- this.pjson.bugs = defaults.bugs || `https://github.com/${defaults.repository}/issues`
+ this.pjson.homepage = defaults.homepage || `https://github.com/${this.pjson.repository}`
+ this.pjson.bugs = defaults.bugs || `https://github.com/${this.pjson.repository}/issues`
if (this.type !== 'plugin') {
this.pjson.main = defaults.main || (this.ts ? 'lib/index.js' : 'src/index.js')
@@ -258,14 +263,14 @@ class App extends Generator {
}
if (this.type === 'plugin' && !this.pjson.anycli.devPlugins) {
this.pjson.anycli.plugins = [
- '@anycli/help',
+ '@anycli/help-plugin',
]
}
if (this.type === 'multi' && !this.pjson.anycli.plugins) {
this.pjson.anycli.plugins = [
- '@anycli/version',
- '@anycli/help',
- '@anycli/not-found',
+ '@anycli/version-plugin',
+ '@anycli/help-plugin',
+ '@anycli/not-found-plugin',
]
}
@@ -280,7 +285,7 @@ class App extends Generator {
this.fs.copyTpl(this.templatePath('test/tsconfig.json'), this.destinationPath('test/tsconfig.json'), this)
}
}
- if (this.mocha) {
+ if (this.mocha && !this.fs.exists('test')) {
this.fs.copyTpl(this.templatePath('test/helpers/init.js'), this.destinationPath('test/helpers/init.js'), this)
this.fs.copyTpl(this.templatePath('test/mocha.opts'), this.destinationPath('test/mocha.opts'), this)
}
@@ -431,8 +436,10 @@ class App extends Generator {
}
private _writeBase() {
+ if (!fs.existsSync('src')) {
this.fs.copyTpl(this.templatePath(`base/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
- if (this.mocha) {
+ }
+ if (this.mocha && !fs.existsSync('test')) {
this.fs.copyTpl(this.templatePath(`base/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this)
}
}
@@ -443,11 +450,13 @@ class App extends Generator {
const opts = {...this as any, _, bin, cmd}
this.fs.copyTpl(this.templatePath('plugin/bin/run'), this.destinationPath('bin/run'), opts)
this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts)
+ if (!this.fs.exists(`src/commands/hello.test.${this._ext}`)) {
this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/commands/hello.${this._ext}`), {...opts, name: 'hello'})
+ }
if (this.ts) {
this.fs.copyTpl(this.templatePath('plugin/src/index.ts'), this.destinationPath('src/index.ts'), opts)
}
- if (this.mocha) {
+ if (this.mocha && !this.fs.exists(`test/commands/hello.test.${this._ext}`)) {
this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/commands/hello.test.${this._ext}`), {...opts, name: 'hello'})
}
}
@@ -457,8 +466,10 @@ class App extends Generator {
const opts = {...this as any, _, bin, cmd: bin, name: this.pjson.name}
this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), opts)
this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts)
+ if (!this.fs.exists(`src/index.${this._ext}`)) {
this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), opts)
- if (this.mocha) {
+ }
+ if (this.mocha && !this.fs.exists(`test/index.test.${this._ext}`)) {
this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/index.test.${this._ext}`), opts)
}
}
@@ -467,8 +478,10 @@ class App extends Generator {
this._writePlugin()
this.fs.copyTpl(this.templatePath('bin/run'), this.destinationPath('bin/run'), this)
this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), this)
+ if (!this.fs.exists(`src/index.${this._ext}`)) {
this.fs.copyTpl(this.templatePath(`multi/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this)
}
}
+}
export = App

MODIFY
yarn.lock
yarn.lock
tslib "^1.9.0"
"@anycli/command@^0.3.3":
- version "0.3.3"
- resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.3.3.tgz#38f2d56fee0c18ad528c3a42d90ae9c97b17d652"
+ version "0.3.4"
+ resolved "https://registry.yarnpkg.com/@anycli/command/-/command-0.3.4.tgz#c02b07f0f309192021cd76fa66b3f88db173025e"
dependencies:
"@anycli/parser" "^3.0.4"
cli-ux "^3.3.12"
lodash "^4.17.4"
read-pkg "^3.0.0"
-"@anycli/engine@^0.1.42":
- version "0.1.42"
- resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.42.tgz#584274b6c4c9a8b8ad5563cc3070921afbe0910d"
+"@anycli/engine@^0.1.45":
+ version "0.1.45"
+ resolved "https://registry.yarnpkg.com/@anycli/engine/-/engine-0.1.45.tgz#5fc102c3d3bad895b1b2fe7c628e1b28d7ee5e8b"
dependencies:
- "@anycli/manifest-file" "^0.3.3"
+ "@anycli/manifest-file" "^0.3.8"
cli-ux "^3.3.12"
debug "^3.1.0"
fs-extra "^5.0.0"
globby "^7.1.1"
lodash "^4.17.4"
-"@anycli/manifest-file@^0.3.3":
- version "0.3.3"
- resolved "https://registry.yarnpkg.com/@anycli/manifest-file/-/manifest-file-0.3.3.tgz#9cf398b411037be01b00b0d1fd3cf2a40178dcf5"
+"@anycli/manifest-file@^0.3.8":
+ version "0.3.8"
+ resolved "https://registry.yarnpkg.com/@anycli/manifest-file/-/manifest-file-0.3.8.tgz#d175a27e1d2009a14080c7e8dd808c1c856de468"
dependencies:
+ cli-ux "^3.3.12"
debug "^3.1.0"
fs-extra "^5.0.0"
load-json-file "^4.0.0"
lodash "^4.17.4"
- rwlockfile "^2.0.23"
+ proper-lockfile "^3.0.2"
"@anycli/parser@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@anycli/screen/-/screen-0.0.3.tgz#f0afd970c3ed725702948a45a874ede1fdd9362e"
"@anycli/tslint@^0.2.1":
- version "0.2.1"
- resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.1.tgz#17295a3a4c579884cd3aea7ed1d8c07d11ecc624"
+ version "0.2.2"
+ resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.2.tgz#46e899f58019600fc6a7191e7fde47d6b4513df1"
dependencies:
tslint "^5.9.1"
tslint-xo "^0.6.0"
@@ -1276,7 +1277,7 @@ got@^7.0.0:
url-parse-lax "^1.0.0"
url-to-options "^1.0.1"
-graceful-fs@^4.1.2, graceful-fs@^4.1.6:
+graceful-fs@^4.1.11, 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"
@@ -1456,12 +1457,6 @@ is-plain-obj@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
-is-process-active@^1.0.1:
- version "1.0.1"
- resolved "https://registry.yarnpkg.com/is-process-active/-/is-process-active-1.0.1.tgz#63616541f447d84b71783cb2002360cf7e690b4f"
- dependencies:
- debug "^3.1.0"
-
is-promise@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
@@ -2071,6 +2066,13 @@ 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"
@@ -2235,6 +2237,10 @@ 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"
@@ -2247,14 +2253,6 @@ run-async@^2.0.0, run-async@^2.2.0:
dependencies:
is-promise "^2.1.0"
-rwlockfile@^2.0.23:
- version "2.0.23"
- resolved "https://registry.yarnpkg.com/rwlockfile/-/rwlockfile-2.0.23.tgz#1bc2341e9d63b78a0b5399220dfcecfbc4c0edc1"
- dependencies:
- fs-extra "^5.0.0"
- is-process-active "^1.0.1"
- uuid "^3.2.1"
-
rx-lite-aggregates@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz#753b87a89a11c95467c4ac1626c4efc4e05c67be"
@@ -2705,10 +2703,6 @@ uuid@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
-uuid@^3.2.1:
- version "3.2.1"
- resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14"
-
v8flags@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-3.0.1.tgz#dce8fc379c17d9f2c9e9ed78d89ce00052b1b76b"

fix: improve experience when overwiting existing base