oclif 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.oclif.manifest.json +1 -1
  2. package/CHANGELOG.md +100 -11
  3. package/README.md +228 -101
  4. package/bin/dev +19 -0
  5. package/bin/dev.cmd +3 -0
  6. package/bin/run +5 -2
  7. package/lib/aws.d.ts +5 -5
  8. package/lib/aws.js +7 -5
  9. package/lib/command-base.d.ts +2 -2
  10. package/lib/command-base.js +3 -3
  11. package/lib/commands/generate.d.ts +11 -0
  12. package/lib/commands/generate.js +19 -0
  13. package/lib/commands/manifest.d.ts +1 -2
  14. package/lib/commands/manifest.js +4 -7
  15. package/lib/commands/pack/deb.d.ts +3 -3
  16. package/lib/commands/pack/deb.js +11 -12
  17. package/lib/commands/pack/macos.d.ts +4 -3
  18. package/lib/commands/pack/macos.js +19 -13
  19. package/lib/commands/pack/tarballs.d.ts +6 -3
  20. package/lib/commands/pack/tarballs.js +9 -7
  21. package/lib/commands/pack/win.d.ts +4 -3
  22. package/lib/commands/pack/win.js +29 -16
  23. package/lib/commands/promote.d.ts +14 -3
  24. package/lib/commands/promote.js +27 -28
  25. package/lib/commands/readme.d.ts +13 -11
  26. package/lib/commands/readme.js +33 -34
  27. package/lib/commands/upload/deb.d.ts +2 -3
  28. package/lib/commands/upload/deb.js +8 -9
  29. package/lib/commands/upload/macos.d.ts +2 -3
  30. package/lib/commands/upload/macos.js +8 -9
  31. package/lib/commands/upload/tarballs.d.ts +7 -3
  32. package/lib/commands/upload/tarballs.js +23 -20
  33. package/lib/commands/upload/win.d.ts +2 -3
  34. package/lib/commands/upload/win.js +10 -11
  35. package/lib/generators/{app.d.ts → cli.d.ts} +2 -22
  36. package/lib/generators/cli.js +182 -0
  37. package/lib/help-compatibility.d.ts +4 -5
  38. package/lib/help-compatibility.js +1 -0
  39. package/lib/index.d.ts +1 -1
  40. package/lib/index.js +3 -2
  41. package/lib/log.js +3 -2
  42. package/lib/tarballs/bin.d.ts +2 -2
  43. package/lib/tarballs/bin.js +2 -1
  44. package/lib/tarballs/build.js +29 -28
  45. package/lib/tarballs/config.d.ts +6 -7
  46. package/lib/tarballs/config.js +24 -12
  47. package/lib/tarballs/index.js +4 -4
  48. package/lib/tarballs/node.d.ts +7 -4
  49. package/lib/tarballs/node.js +5 -5
  50. package/lib/upload-util.d.ts +3 -3
  51. package/lib/upload-util.js +5 -2
  52. package/lib/util.js +24 -20
  53. package/lib/version-indexes.d.ts +2 -4
  54. package/lib/version-indexes.js +3 -1
  55. package/package.json +27 -27
  56. package/lib/app-command.d.ts +0 -12
  57. package/lib/app-command.js +0 -26
  58. package/lib/commands/base.d.ts +0 -5
  59. package/lib/commands/base.js +0 -11
  60. package/lib/commands/command.d.ts +0 -17
  61. package/lib/commands/command.js +0 -23
  62. package/lib/commands/hook.d.ts +0 -18
  63. package/lib/commands/hook.js +0 -25
  64. package/lib/commands/multi.d.ts +0 -5
  65. package/lib/commands/multi.js +0 -11
  66. package/lib/commands/plugin.d.ts +0 -5
  67. package/lib/commands/plugin.js +0 -11
  68. package/lib/commands/single.d.ts +0 -5
  69. package/lib/commands/single.js +0 -11
  70. package/lib/generators/app.js +0 -459
  71. package/lib/generators/command.d.ts +0 -15
  72. package/lib/generators/command.js +0 -51
  73. package/lib/generators/hook.d.ts +0 -14
  74. package/lib/generators/hook.js +0 -51
  75. package/templates/LICENSE.mit +0 -21
  76. package/templates/README.md.ejs +0 -21
  77. package/templates/appveyor.yml.ejs +0 -33
  78. package/templates/base/src/index.js +0 -1
  79. package/templates/base/src/index.ts +0 -1
  80. package/templates/base/test/index.test.js +0 -8
  81. package/templates/base/test/index.test.ts +0 -9
  82. package/templates/bin/run +0 -5
  83. package/templates/bin/run.cmd +0 -3
  84. package/templates/circle.yml.ejs +0 -65
  85. package/templates/editorconfig +0 -11
  86. package/templates/eslintrc +0 -7
  87. package/templates/eslintrc.typescript +0 -10
  88. package/templates/multi/src/index.js +0 -1
  89. package/templates/multi/src/index.ts +0 -1
  90. package/templates/plugin/bin/run +0 -4
  91. package/templates/plugin/src/index.ts +0 -1
  92. package/templates/scripts/setup_git +0 -12
  93. package/templates/single/bin/run.js +0 -4
  94. package/templates/single/bin/run.ts +0 -13
  95. package/templates/src/command.js.ejs +0 -27
  96. package/templates/src/command.ts.ejs +0 -46
  97. package/templates/src/hook.js.ejs +0 -3
  98. package/templates/src/hook.ts.ejs +0 -7
  99. package/templates/test/command.test.js.ejs +0 -28
  100. package/templates/test/command.test.ts.ejs +0 -29
  101. package/templates/test/hook.test.js.ejs +0 -9
  102. package/templates/test/hook.test.ts.ejs +0 -9
  103. package/templates/test/mocha.opts +0 -4
  104. package/templates/test/tsconfig.json +0 -9
  105. package/templates/travis.yml.ejs +0 -14
  106. package/templates/tsconfig.json +0 -15
@@ -1,459 +0,0 @@
1
- "use strict";
2
- const child_process_1 = require("child_process");
3
- const fs = require("fs");
4
- const _ = require("lodash");
5
- const path = require("path");
6
- const Generator = require("yeoman-generator");
7
- const yosay = require("yosay");
8
- const nps = require('nps-utils');
9
- const sortPjson = require('sort-pjson');
10
- const fixpack = require('@oclif/fixpack');
11
- const debug = require('debug')('generator-oclif');
12
- const { version } = require('../../package.json');
13
- const isWindows = process.platform === 'win32';
14
- const rmrf = isWindows ? 'rimraf' : 'rm -rf';
15
- const rmf = isWindows ? 'rimraf' : 'rm -f';
16
- let hasYarn = false;
17
- try {
18
- child_process_1.execSync('yarn -v', { stdio: 'ignore' });
19
- hasYarn = true;
20
- }
21
- catch (_a) { }
22
- // function stringToArray(s: string) {
23
- // const keywords: string[] = []
24
- // s.split(',').forEach((keyword: string) => {
25
- // if (!keyword.length) {
26
- // return false
27
- // }
28
- // return keywords.push(keyword.trim())
29
- // })
30
- // return keywords
31
- // }
32
- class App extends Generator {
33
- constructor(args, opts) {
34
- super(args, opts);
35
- this.type = opts.type;
36
- this.path = opts.path;
37
- this.options = {
38
- defaults: opts.defaults,
39
- mocha: opts.options.includes('mocha'),
40
- circleci: opts.options.includes('circleci'),
41
- appveyor: opts.options.includes('appveyor'),
42
- typescript: opts.options.includes('typescript'),
43
- eslint: opts.options.includes('eslint'),
44
- yarn: opts.options.includes('yarn') || hasYarn,
45
- travisci: opts.options.includes('travisci'),
46
- };
47
- }
48
- get _ext() {
49
- return this.ts ? 'ts' : 'js';
50
- }
51
- get _bin() {
52
- let bin = (this.pjson.oclif && (this.pjson.oclif.bin || this.pjson.oclif.dirname)) || this.pjson.name;
53
- if (bin.includes('/'))
54
- bin = bin.split('/').pop();
55
- return bin;
56
- }
57
- // eslint-disable-next-line complexity
58
- async prompting() {
59
- let msg;
60
- switch (this.type) {
61
- case 'single':
62
- msg = 'Time to build a single-command CLI with oclif!';
63
- break;
64
- case 'multi':
65
- msg = 'Time to build a multi-command CLI with oclif!';
66
- break;
67
- default:
68
- msg = `Time to build a oclif ${this.type}!`;
69
- }
70
- this.log(yosay(`${msg} Version: ${version}`));
71
- if (this.path) {
72
- this.destinationRoot(path.resolve(this.path));
73
- process.chdir(this.destinationRoot());
74
- }
75
- this.githubUser = await this.user.github.username().catch(debug);
76
- this.pjson = Object.assign({ scripts: {}, engines: {}, devDependencies: {}, dependencies: {}, oclif: {} }, this.fs.readJSON('package.json', {}));
77
- let repository = this.destinationRoot().split(path.sep).slice(-2).join('/');
78
- if (this.githubUser)
79
- repository = `${this.githubUser}/${repository.split('/')[1]}`;
80
- const defaults = Object.assign(Object.assign({ name: this.determineAppname().replace(/ /g, '-'), version: '0.0.0', license: 'MIT', author: this.githubUser ? `${this.user.git.name()} @${this.githubUser}` : this.user.git.name(), dependencies: {}, repository }, this.pjson), { engines: Object.assign({ node: '>=12.0.0' }, this.pjson.engines), options: this.options });
81
- this.repository = defaults.repository;
82
- if (this.repository && this.repository.url) {
83
- this.repository = this.repository.url;
84
- }
85
- this.answers = this.options.defaults ? defaults : await this.prompt([
86
- {
87
- type: 'input',
88
- name: 'name',
89
- message: 'npm package name',
90
- default: defaults.name,
91
- when: !this.pjson.name,
92
- },
93
- {
94
- type: 'input',
95
- name: 'bin',
96
- message: 'command bin name the CLI will export',
97
- default: (answers) => (answers.name || this._bin).split('/').pop(),
98
- when: ['single', 'multi'].includes(this.type) && !this.pjson.oclif.bin,
99
- },
100
- {
101
- type: 'input',
102
- name: 'description',
103
- message: 'description',
104
- default: defaults.description,
105
- when: !this.pjson.description,
106
- },
107
- {
108
- type: 'input',
109
- name: 'author',
110
- message: 'author',
111
- default: defaults.author,
112
- when: !this.pjson.author,
113
- },
114
- {
115
- type: 'input',
116
- name: 'version',
117
- message: 'version',
118
- default: defaults.version,
119
- when: !this.pjson.version,
120
- },
121
- {
122
- type: 'input',
123
- name: 'license',
124
- message: 'license',
125
- default: defaults.license,
126
- when: !this.pjson.license,
127
- },
128
- {
129
- type: 'input',
130
- name: 'github.user',
131
- message: 'Who is the GitHub owner of repository (https://github.com/OWNER/repo)',
132
- default: repository.split('/').slice(0, -1).pop(),
133
- when: !this.pjson.repository,
134
- },
135
- {
136
- type: 'input',
137
- name: 'github.repo',
138
- message: 'What is the GitHub name of repository (https://github.com/owner/REPO)',
139
- default: (answers) => (this.pjson.repository || answers.name || this.pjson.name).split('/').pop(),
140
- when: !this.pjson.repository,
141
- },
142
- {
143
- type: 'list',
144
- name: 'pkg',
145
- message: 'Select a package manager',
146
- choices: [
147
- { name: 'npm', value: 'npm' },
148
- { name: 'yarn', value: 'yarn' },
149
- ],
150
- default: () => this.options.yarn || hasYarn ? 1 : 0,
151
- },
152
- {
153
- type: 'confirm',
154
- name: 'typescript',
155
- message: 'TypeScript',
156
- default: () => true,
157
- },
158
- {
159
- type: 'confirm',
160
- name: 'eslint',
161
- message: 'Use eslint (linter for JavaScript and Typescript)',
162
- default: () => true,
163
- },
164
- {
165
- type: 'confirm',
166
- name: 'mocha',
167
- message: 'Use mocha (testing framework)',
168
- default: () => true,
169
- },
170
- {
171
- type: 'checkbox',
172
- name: 'ci',
173
- message: 'Add CI service config',
174
- choices: [
175
- { name: 'circleci (continuous integration/delivery service)', value: 'circleci' },
176
- { name: 'appveyor (continuous integration/delivery service)', value: 'appveyor' },
177
- { name: 'travisci (continuous integration/delivery service)', value: 'travisci' },
178
- ],
179
- filter: ((arr) => _.keyBy(arr)),
180
- },
181
- ]);
182
- debug(this.answers);
183
- if (!this.options.defaults) {
184
- this.options = Object.assign(Object.assign({}, this.answers.ci), { mocha: this.answers.mocha, eslint: this.answers.eslint, typescript: this.answers.typescript, yarn: this.answers.pkg === 'yarn' });
185
- }
186
- this.ts = this.options.typescript;
187
- this.yarn = this.options.yarn;
188
- this.mocha = this.options.mocha;
189
- this.circleci = this.options.circleci;
190
- this.appveyor = this.options.appveyor;
191
- this.eslint = this.options.eslint;
192
- this.travisci = this.options.travisci;
193
- this.pjson.name = this.answers.name || defaults.name;
194
- this.pjson.description = this.answers.description || defaults.description;
195
- this.pjson.version = this.answers.version || defaults.version;
196
- this.pjson.engines.node = defaults.engines.node;
197
- this.pjson.author = this.answers.author || defaults.author;
198
- this.pjson.files = this.answers.files || defaults.files || [(this.ts ? '/lib' : '/src')];
199
- this.pjson.license = this.answers.license || defaults.license;
200
- // eslint-disable-next-line no-multi-assign
201
- this.repository = this.pjson.repository = this.answers.github ? `${this.answers.github.user}/${this.answers.github.repo}` : defaults.repository;
202
- if (this.eslint) {
203
- this.pjson.scripts.posttest = 'eslint .';
204
- }
205
- this.pjson.scripts.test = this.mocha ? `nyc ${this.ts ? '--extension .ts ' : ''}mocha --forbid-only "test/**/*.test.${this._ext}"` : 'echo NO TESTS';
206
- if (this.ts) {
207
- this.pjson.scripts.prepack = nps.series(`${rmrf} lib`, 'tsc -b');
208
- if (this.eslint) {
209
- this.pjson.scripts.posttest = 'eslint . --ext .ts --config .eslintrc';
210
- }
211
- }
212
- if (['plugin', 'multi'].includes(this.type)) {
213
- this.pjson.scripts.prepack = nps.series(this.pjson.scripts.prepack, 'oclif-dev manifest', 'oclif-dev readme');
214
- this.pjson.scripts.postpack = `${rmf} oclif.manifest.json`;
215
- this.pjson.scripts.version = nps.series('oclif-dev readme', 'git add README.md');
216
- this.pjson.files.push('/oclif.manifest.json', '/npm-shrinkwrap.json');
217
- }
218
- else if (this.type === 'single') {
219
- this.pjson.scripts.prepack = nps.series(this.pjson.scripts.prepack, 'oclif-dev readme');
220
- this.pjson.scripts.version = nps.series('oclif-dev readme', 'git add README.md');
221
- }
222
- if (this.type === 'plugin' && hasYarn) {
223
- // for plugins, add yarn.lock file to package so we can lock plugin dependencies
224
- this.pjson.files.push('/yarn.lock');
225
- }
226
- this.pjson.keywords = defaults.keywords || [this.type === 'plugin' ? 'oclif-plugin' : 'oclif'];
227
- this.pjson.homepage = defaults.homepage || `https://github.com/${this.pjson.repository}`;
228
- this.pjson.bugs = defaults.bugs || `https://github.com/${this.pjson.repository}/issues`;
229
- if (['single', 'multi'].includes(this.type)) {
230
- this.pjson.oclif.bin = this.answers.bin || this._bin;
231
- this.pjson.bin = this.pjson.bin || {};
232
- this.pjson.bin[this.pjson.oclif.bin] = './bin/run';
233
- this.pjson.files.push('/bin');
234
- }
235
- else if (this.type === 'plugin') {
236
- this.pjson.oclif.bin = 'oclif-example';
237
- }
238
- if (this.type !== 'plugin') {
239
- this.pjson.main = defaults.main || (this.ts ? 'lib/index.js' : 'src/index.js');
240
- if (this.ts) {
241
- this.pjson.types = defaults.types || 'lib/index.d.ts';
242
- }
243
- }
244
- }
245
- // eslint-disable-next-line complexity
246
- writing() {
247
- this.sourceRoot(path.join(__dirname, '../../templates'));
248
- switch (this.type) {
249
- case 'multi':
250
- case 'plugin':
251
- this.pjson.oclif = Object.assign({ commands: `./${this.ts ? 'lib' : 'src'}/commands` }, this.pjson.oclif);
252
- break;
253
- default:
254
- }
255
- if (this.type === 'plugin' && !this.pjson.oclif.devPlugins) {
256
- this.pjson.oclif.devPlugins = [
257
- '@oclif/plugin-help',
258
- ];
259
- }
260
- if (this.type === 'multi' && !this.pjson.oclif.plugins) {
261
- this.pjson.oclif.plugins = [
262
- '@oclif/plugin-help',
263
- ];
264
- }
265
- if (this.pjson.oclif && Array.isArray(this.pjson.oclif.plugins)) {
266
- this.pjson.oclif.plugins.sort();
267
- }
268
- if (this.ts) {
269
- this.fs.copyTpl(this.templatePath('tsconfig.json'), this.destinationPath('tsconfig.json'), this);
270
- if (this.mocha) {
271
- this.fs.copyTpl(this.templatePath('test/tsconfig.json'), this.destinationPath('test/tsconfig.json'), this);
272
- }
273
- }
274
- if (this.eslint) {
275
- const eslintignore = this._eslintignore();
276
- if (eslintignore.trim())
277
- this.fs.write(this.destinationPath('.eslintignore'), this._eslintignore());
278
- if (this.ts) {
279
- this.fs.copyTpl(this.templatePath('eslintrc.typescript'), this.destinationPath('.eslintrc'), this);
280
- }
281
- else {
282
- this.fs.copyTpl(this.templatePath('eslintrc'), this.destinationPath('.eslintrc'), this);
283
- }
284
- }
285
- if (this.mocha) {
286
- this.fs.copyTpl(this.templatePath('test/mocha.opts'), this.destinationPath('test/mocha.opts'), this);
287
- }
288
- if (this.fs.exists(this.destinationPath('./package.json'))) {
289
- fixpack(this.destinationPath('./package.json'), require('@oclif/fixpack/config.json'));
290
- }
291
- if (_.isEmpty(this.pjson.oclif))
292
- delete this.pjson.oclif;
293
- this.pjson.files = _.uniq((this.pjson.files || []).sort());
294
- this.fs.writeJSON(this.destinationPath('./package.json'), sortPjson(this.pjson));
295
- this.fs.copyTpl(this.templatePath('editorconfig'), this.destinationPath('.editorconfig'), this);
296
- if (this.circleci) {
297
- this.fs.copyTpl(this.templatePath('circle.yml.ejs'), this.destinationPath('.circleci/config.yml'), this);
298
- }
299
- if (this.appveyor) {
300
- this.fs.copyTpl(this.templatePath('appveyor.yml.ejs'), this.destinationPath('appveyor.yml'), this);
301
- }
302
- if (this.travisci) {
303
- this.fs.copyTpl(this.templatePath('travis.yml.ejs'), this.destinationPath('.travis.yml'), this);
304
- }
305
- this.fs.copyTpl(this.templatePath('README.md.ejs'), this.destinationPath('README.md'), this);
306
- if (this.pjson.license === 'MIT' && (this.pjson.repository.startsWith('oclif') || this.pjson.repository.startsWith('heroku'))) {
307
- this.fs.copyTpl(this.templatePath('LICENSE.mit'), this.destinationPath('LICENSE'), this);
308
- }
309
- this.fs.write(this.destinationPath('.gitignore'), this._gitignore());
310
- switch (this.type) {
311
- case 'single':
312
- this._writeSingle();
313
- break;
314
- case 'plugin':
315
- this._writePlugin();
316
- break;
317
- case 'multi':
318
- this._writeMulti();
319
- break;
320
- default:
321
- this._writeBase();
322
- }
323
- }
324
- install() {
325
- const dependencies = [];
326
- const devDependencies = [];
327
- switch (this.type) {
328
- case 'base': break;
329
- case 'single':
330
- dependencies.push('@oclif/config@^1', '@oclif/command@^1', '@oclif/plugin-help@^3');
331
- devDependencies.push('@oclif/dev-cli@^1');
332
- break;
333
- case 'plugin':
334
- dependencies.push('@oclif/command@^1', '@oclif/config@^1');
335
- devDependencies.push('@oclif/dev-cli@^1', '@oclif/plugin-help@^3', 'globby@^10');
336
- break;
337
- case 'multi':
338
- dependencies.push('@oclif/config@^1', '@oclif/command@^1', '@oclif/plugin-help@^3');
339
- devDependencies.push('@oclif/dev-cli@^1', 'globby@^10');
340
- }
341
- if (this.mocha) {
342
- devDependencies.push('mocha@^5', 'nyc@^14', 'chai@^4');
343
- if (this.type !== 'base')
344
- devDependencies.push('@oclif/test@^1');
345
- }
346
- if (this.ts) {
347
- dependencies.push('tslib@^1');
348
- devDependencies.push('@types/node@^10', 'typescript@^3.3', 'ts-node@^8');
349
- if (this.mocha) {
350
- devDependencies.push('@types/chai@^4', '@types/mocha@^5');
351
- }
352
- }
353
- if (this.eslint) {
354
- devDependencies.push('eslint@^7.32.0', 'eslint-config-oclif@^3.1.2');
355
- if (this.ts) {
356
- devDependencies.push('eslint-config-oclif-typescript@^0.2.0');
357
- }
358
- }
359
- if (isWindows)
360
- devDependencies.push('rimraf');
361
- const yarnOpts = {};
362
- if (process.env.YARN_MUTEX)
363
- yarnOpts.mutex = process.env.YARN_MUTEX;
364
- // eslint-disable-next-line @typescript-eslint/ban-types,unicorn/consistent-function-scoping
365
- const install = (deps, opts) => this.yarn ? this.yarnInstall(deps, opts) : this.npmInstall(deps, opts);
366
- const dev = this.yarn ? { dev: true } : { 'save-dev': true };
367
- const save = this.yarn ? {} : { save: true };
368
- return Promise.all([
369
- install(devDependencies, Object.assign(Object.assign(Object.assign({}, yarnOpts), dev), { ignoreScripts: true })),
370
- install(dependencies, Object.assign(Object.assign({}, yarnOpts), save)),
371
- ]).then(() => {
372
- // if (!this.yarn) {
373
- // return this.spawnCommand('npm', ['shrinkwrap'])
374
- // }
375
- });
376
- }
377
- end() {
378
- if (['plugin', 'multi', 'single'].includes(this.type)) {
379
- this.spawnCommandSync(path.join('.', 'node_modules/.bin/oclif-dev'), ['readme']);
380
- }
381
- console.log(`\nCreated ${this.pjson.name} in ${this.destinationRoot()}`);
382
- }
383
- _gitignore() {
384
- const existing = this.fs.exists(this.destinationPath('.gitignore')) ? this.fs.read(this.destinationPath('.gitignore')).split('\n') : [];
385
- return _([
386
- '*-debug.log',
387
- '*-error.log',
388
- 'node_modules',
389
- '/tmp',
390
- '/dist',
391
- '/.nyc_output',
392
- this.yarn ? '/package-lock.json' : '/yarn.lock',
393
- this.ts && '/lib',
394
- ...existing,
395
- ])
396
- .compact()
397
- .uniq()
398
- .sort()
399
- .join('\n') + '\n';
400
- }
401
- _eslintignore() {
402
- const existing = this.fs.exists(this.destinationPath('.eslintignore')) ? this.fs.read(this.destinationPath('.eslintignore')).split('\n') : [];
403
- return _([
404
- this.ts && '/lib',
405
- ...existing,
406
- ])
407
- .compact()
408
- .uniq()
409
- .sort()
410
- .join('\n') + '\n';
411
- }
412
- _writeBase() {
413
- if (!fs.existsSync('src')) {
414
- this.fs.copyTpl(this.templatePath(`base/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this);
415
- }
416
- if (this.mocha && !fs.existsSync('test')) {
417
- this.fs.copyTpl(this.templatePath(`base/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this);
418
- }
419
- }
420
- _writePlugin() {
421
- const bin = this._bin;
422
- const cmd = `${bin} hello`;
423
- const opts = Object.assign(Object.assign({}, this), { _, bin, cmd });
424
- this.fs.copyTpl(this.templatePath('plugin/bin/run'), this.destinationPath('bin/run'), opts);
425
- this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts);
426
- const commandPath = this.destinationPath(`src/commands/hello.${this._ext}`);
427
- if (!fs.existsSync('src/commands')) {
428
- this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), commandPath, Object.assign(Object.assign({}, opts), { name: 'hello', path: commandPath.replace(process.cwd(), '.') }));
429
- }
430
- if (this.ts && this.type !== 'multi') {
431
- this.fs.copyTpl(this.templatePath('plugin/src/index.ts'), this.destinationPath('src/index.ts'), opts);
432
- }
433
- if (this.mocha && !fs.existsSync('test')) {
434
- this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/commands/hello.test.${this._ext}`), Object.assign(Object.assign({}, opts), { name: 'hello' }));
435
- }
436
- }
437
- _writeSingle() {
438
- const bin = this._bin;
439
- const opts = Object.assign(Object.assign({}, this), { _, bin, cmd: bin, name: this.pjson.name });
440
- this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), opts);
441
- this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts);
442
- const commandPath = this.destinationPath(`src/index.${this._ext}`);
443
- if (!this.fs.exists(`src/index.${this._ext}`)) {
444
- this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), this.destinationPath(`src/index.${this._ext}`), Object.assign(Object.assign({}, opts), { path: commandPath.replace(process.cwd(), '.') }));
445
- }
446
- if (this.mocha && !this.fs.exists(`test/index.test.${this._ext}`)) {
447
- this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/index.test.${this._ext}`), opts);
448
- }
449
- }
450
- _writeMulti() {
451
- this._writePlugin();
452
- this.fs.copyTpl(this.templatePath('bin/run'), this.destinationPath('bin/run'), this);
453
- this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), this);
454
- if (!this.fs.exists(`src/index.${this._ext}`)) {
455
- this.fs.copyTpl(this.templatePath(`multi/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this);
456
- }
457
- }
458
- }
459
- module.exports = App;
@@ -1,15 +0,0 @@
1
- import * as Generator from 'yeoman-generator';
2
- import { Options } from '../commands/command';
3
- declare class CommandGenerator extends Generator {
4
- options: Options;
5
- pjson: any;
6
- get _path(): string;
7
- get _ts(): any;
8
- get _ext(): "ts" | "js";
9
- get _mocha(): any;
10
- constructor(args: any, options: Options);
11
- prompting(): Promise<void>;
12
- writing(): void;
13
- end(): void;
14
- }
15
- export = CommandGenerator;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- const _ = require("lodash");
3
- const path = require("path");
4
- const Generator = require("yeoman-generator");
5
- const yosay = require("yosay");
6
- const { version } = require('../../package.json');
7
- class CommandGenerator extends Generator {
8
- constructor(args, options) {
9
- super(args, options);
10
- this.options = options;
11
- }
12
- get _path() {
13
- return this.options.name.split(':').join('/');
14
- }
15
- get _ts() {
16
- return this.pjson.devDependencies.typescript;
17
- }
18
- get _ext() {
19
- return this._ts ? 'ts' : 'js';
20
- }
21
- get _mocha() {
22
- return this.pjson.devDependencies.mocha;
23
- }
24
- async prompting() {
25
- this.pjson = this.fs.readJSON('package.json');
26
- if (!this.pjson)
27
- throw new Error('not in a project directory');
28
- this.pjson.oclif = this.pjson.oclif || {};
29
- this.log(yosay(`Adding a command to ${this.pjson.name} Version: ${version}`));
30
- }
31
- writing() {
32
- this.sourceRoot(path.join(__dirname, '../../templates'));
33
- let bin = this.pjson.oclif.bin || this.pjson.oclif.dirname || this.pjson.name;
34
- if (bin.includes('/'))
35
- bin = bin.split('/').pop();
36
- const cmd = `${bin} ${this.options.name}`;
37
- const commandPath = this.destinationPath(`src/commands/${this._path}.${this._ext}`);
38
- const opts = Object.assign(Object.assign({}, this.options), { bin, cmd, _, type: 'command', path: commandPath });
39
- this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), commandPath, opts);
40
- // this.fs.copyTpl(this.templatePath(`plugin/src/hooks/init.${this._ext}`), this.destinationPath(`src/hooks/init.${this._ext}`), this)
41
- if (this._mocha) {
42
- // this.fs.copyTpl(this.templatePath(`plugin/test/hooks/init.test.${this._ext}`), this.destinationPath(`test/hooks/init.test.${this._ext}`), this)
43
- this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/commands/${this._path}.test.${this._ext}`), opts);
44
- }
45
- // this.fs.writeJSON(this.destinationPath('./package.json'), this.pjson)
46
- }
47
- end() {
48
- this.spawnCommandSync(path.join('.', 'node_modules/.bin/oclif-dev'), ['readme']);
49
- }
50
- }
51
- module.exports = CommandGenerator;
@@ -1,14 +0,0 @@
1
- import * as Generator from 'yeoman-generator';
2
- import { Options } from '../commands/hook';
3
- declare class HookGenerator extends Generator {
4
- options: Options;
5
- pjson: any;
6
- get _path(): string;
7
- get _ts(): any;
8
- get _ext(): "ts" | "js";
9
- get _mocha(): any;
10
- constructor(args: any, options: Options);
11
- prompting(): Promise<void>;
12
- writing(): void;
13
- }
14
- export = HookGenerator;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- const _ = require("lodash");
3
- const path = require("path");
4
- const Generator = require("yeoman-generator");
5
- const yosay = require("yosay");
6
- const { version } = require('../../package.json');
7
- class HookGenerator extends Generator {
8
- constructor(args, options) {
9
- super(args, options);
10
- this.options = options;
11
- }
12
- get _path() {
13
- return this.options.name.split(':').join('/');
14
- }
15
- get _ts() {
16
- return this.pjson.devDependencies.typescript;
17
- }
18
- get _ext() {
19
- return this._ts ? 'ts' : 'js';
20
- }
21
- get _mocha() {
22
- return this.pjson.devDependencies.mocha;
23
- }
24
- async prompting() {
25
- this.pjson = this.fs.readJSON('package.json');
26
- this.pjson.oclif = this.pjson.oclif || {};
27
- if (!this.pjson)
28
- throw new Error('not in a project directory');
29
- this.log(yosay(`Adding a ${this.options.event} hook to ${this.pjson.name} Version: ${version}`));
30
- }
31
- writing() {
32
- this.sourceRoot(path.join(__dirname, '../../templates'));
33
- this.fs.copyTpl(this.templatePath(`src/hook.${this._ext}.ejs`), this.destinationPath(`src/hooks/${this.options.event}/${this.options.name}.${this._ext}`), this);
34
- if (this._mocha) {
35
- this.fs.copyTpl(this.templatePath(`test/hook.test.${this._ext}.ejs`), this.destinationPath(`test/commands/${this._path}.test.${this._ext}`), this);
36
- }
37
- this.pjson.oclif = this.pjson.oclif || {};
38
- this.pjson.oclif.hooks = this.pjson.oclif.hooks || {};
39
- const hooks = this.pjson.oclif.hooks;
40
- const p = `./${this._ts ? 'lib' : 'src'}/hooks/${this.options.event}/${this.options.name}`;
41
- if (hooks[this.options.event]) {
42
- hooks[this.options.event] = _.castArray(hooks[this.options.event]);
43
- hooks[this.options.event].push(p);
44
- }
45
- else {
46
- this.pjson.oclif.hooks[this.options.event] = p;
47
- }
48
- this.fs.writeJSON(this.destinationPath('./package.json'), this.pjson);
49
- }
50
- }
51
- module.exports = HookGenerator;
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 <%- pjson.author %>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,21 +0,0 @@
1
- <%= pjson.name %>
2
- <%= '='.repeat(pjson.name.length) %>
3
-
4
- <%= pjson.description %>
5
-
6
- [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
7
- [![Version](https://img.shields.io/npm/v/<%= pjson.name %>.svg)](https://npmjs.org/package/<%= pjson.name %>)
8
- <%_ if (circleci) { _%>
9
- [![CircleCI](https://circleci.com/gh/<%= repository %>/tree/master.svg?style=shield)](https://circleci.com/gh/<%= repository %>/tree/master)
10
- <%_ } _%>
11
- <%_ if (appveyor) { _%>
12
- [![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/<%= repository %>?branch=master&svg=true)](https://ci.appveyor.com/project/<%= repository %>/branch/master)
13
- <%_ } _%>
14
- [![Downloads/week](https://img.shields.io/npm/dw/<%= pjson.name %>.svg)](https://npmjs.org/package/<%= pjson.name %>)
15
- [![License](https://img.shields.io/npm/l/<%= pjson.name %>.svg)](https://github.com/<%= repository %>/blob/master/package.json)
16
-
17
- <!-- toc -->
18
- # Usage
19
- <!-- usage -->
20
- # Commands
21
- <!-- commands -->
@@ -1,33 +0,0 @@
1
- environment:
2
- nodejs_version: "10"
3
- cache:
4
- <%_ if (yarn) { _%>
5
- - '%LOCALAPPDATA%\Yarn -> appveyor.yml'
6
- - node_modules -> yarn.lock
7
- <%_ } else { _%>
8
- - '%AppData%\npm-cache -> appveyor.yml'
9
- - node_modules -> package-lock.json
10
- <%_ } _%>
11
-
12
- install:
13
- - ps: Install-Product node $env:nodejs_version x64
14
- <%_ if (yarn) { _%>
15
- - yarn
16
- <%_ } else { _%>
17
- - npm install
18
- <%_ } _%>
19
- test_script:
20
- <%_ if (type === 'single' || type === 'multi') { _%>
21
- - .\bin\run --version
22
- - .\bin\run --help
23
- <%_ } else if (type === 'plugin') { _%>
24
- - .\bin\run --help
25
- <%_ } _%>
26
- - <%- yarn ? 'yarn' : 'npm' %> test
27
- <% if (mocha) { %>
28
- after_test:
29
- - .\node_modules\.bin\nyc report --reporter text-lcov > coverage.lcov
30
- <% } %>
31
-
32
- build: off
33
-
@@ -1 +0,0 @@
1
- exports.add = (a, b) => a + b