oclif 1.18.2-dev.2 → 2.0.0-dev.0

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 (105) hide show
  1. package/.oclif.manifest.json +1 -1
  2. package/CHANGELOG.md +71 -10
  3. package/README.md +223 -96
  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 +5 -5
  9. package/lib/command-base.d.ts +1 -1
  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 +7 -8
  17. package/lib/commands/pack/macos.d.ts +4 -4
  18. package/lib/commands/pack/macos.js +16 -17
  19. package/lib/commands/pack/tarballs.d.ts +4 -5
  20. package/lib/commands/pack/tarballs.js +6 -7
  21. package/lib/commands/pack/win.d.ts +4 -4
  22. package/lib/commands/pack/win.js +26 -20
  23. package/lib/commands/promote.d.ts +12 -13
  24. package/lib/commands/promote.js +27 -28
  25. package/lib/commands/readme.d.ts +11 -12
  26. package/lib/commands/readme.js +27 -28
  27. package/lib/commands/upload/deb.d.ts +2 -3
  28. package/lib/commands/upload/deb.js +7 -8
  29. package/lib/commands/upload/macos.d.ts +2 -3
  30. package/lib/commands/upload/macos.js +7 -8
  31. package/lib/commands/upload/tarballs.d.ts +5 -5
  32. package/lib/commands/upload/tarballs.js +15 -18
  33. package/lib/commands/upload/win.d.ts +2 -3
  34. package/lib/commands/upload/win.js +8 -9
  35. package/lib/generators/{app.d.ts → cli.d.ts} +1 -21
  36. package/lib/generators/cli.js +183 -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 +2 -1
  42. package/lib/tarballs/bin.d.ts +2 -2
  43. package/lib/tarballs/bin.js +1 -0
  44. package/lib/tarballs/build.js +13 -12
  45. package/lib/tarballs/config.d.ts +6 -6
  46. package/lib/tarballs/config.js +6 -5
  47. package/lib/tarballs/index.js +4 -4
  48. package/lib/tarballs/node.js +5 -4
  49. package/lib/upload-util.d.ts +3 -3
  50. package/lib/upload-util.js +1 -0
  51. package/lib/util.js +5 -2
  52. package/lib/version-indexes.d.ts +2 -4
  53. package/lib/version-indexes.js +3 -1
  54. package/package.json +5 -7
  55. package/lib/app-command.d.ts +0 -16
  56. package/lib/app-command.js +0 -26
  57. package/lib/commands/base.d.ts +0 -5
  58. package/lib/commands/base.js +0 -11
  59. package/lib/commands/command.d.ts +0 -19
  60. package/lib/commands/command.js +0 -23
  61. package/lib/commands/hook.d.ts +0 -22
  62. package/lib/commands/hook.js +0 -25
  63. package/lib/commands/multi.d.ts +0 -5
  64. package/lib/commands/multi.js +0 -11
  65. package/lib/commands/plugin.d.ts +0 -5
  66. package/lib/commands/plugin.js +0 -11
  67. package/lib/commands/single.d.ts +0 -5
  68. package/lib/commands/single.js +0 -11
  69. package/lib/generators/app.js +0 -470
  70. package/lib/generators/command.d.ts +0 -15
  71. package/lib/generators/command.js +0 -51
  72. package/lib/generators/hook.d.ts +0 -14
  73. package/lib/generators/hook.js +0 -51
  74. package/templates/LICENSE.mit +0 -21
  75. package/templates/README.md.ejs +0 -21
  76. package/templates/appveyor.yml.ejs +0 -33
  77. package/templates/base/src/index.js +0 -1
  78. package/templates/base/src/index.ts +0 -1
  79. package/templates/base/test/index.test.js +0 -8
  80. package/templates/base/test/index.test.ts +0 -9
  81. package/templates/bin/run +0 -5
  82. package/templates/bin/run.cmd +0 -3
  83. package/templates/circle.yml.ejs +0 -65
  84. package/templates/editorconfig +0 -11
  85. package/templates/eslintrc +0 -3
  86. package/templates/eslintrc.typescript +0 -12
  87. package/templates/multi/src/index.js +0 -1
  88. package/templates/multi/src/index.ts +0 -1
  89. package/templates/plugin/bin/run +0 -4
  90. package/templates/plugin/src/index.ts +0 -1
  91. package/templates/scripts/setup_git +0 -12
  92. package/templates/single/bin/run.js +0 -4
  93. package/templates/single/bin/run.ts +0 -13
  94. package/templates/src/command.js.ejs +0 -27
  95. package/templates/src/command.ts.ejs +0 -46
  96. package/templates/src/hook.js.ejs +0 -3
  97. package/templates/src/hook.ts.ejs +0 -7
  98. package/templates/test/command.test.js.ejs +0 -28
  99. package/templates/test/command.test.ts.ejs +0 -29
  100. package/templates/test/hook.test.js.ejs +0 -9
  101. package/templates/test/hook.test.ts.ejs +0 -9
  102. package/templates/test/mocha.opts +0 -4
  103. package/templates/test/tsconfig.json +0 -9
  104. package/templates/travis.yml.ejs +0 -14
  105. package/templates/tsconfig.json +0 -14
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- const command_base_1 = require("./command-base");
5
- class AppCommand extends command_base_1.default {
6
- async run() {
7
- const { flags, args } = this.parse(AppCommand);
8
- const options = flags.options ? flags.options.split(',') : [];
9
- await super.generate('app', {
10
- type: this.type,
11
- path: args.path,
12
- options,
13
- defaults: flags.defaults,
14
- force: flags.force,
15
- });
16
- }
17
- }
18
- exports.default = AppCommand;
19
- AppCommand.flags = {
20
- defaults: command_1.flags.boolean({ description: 'use defaults for every setting' }),
21
- options: command_1.flags.string({ description: '(yarn|typescript|eslint|mocha)' }),
22
- force: command_1.flags.boolean({ description: 'overwrite existing files' }),
23
- };
24
- AppCommand.args = [
25
- { name: 'path', required: false, description: 'path to project, defaults to current directory' },
26
- ];
@@ -1,5 +0,0 @@
1
- import AppCommand from '../app-command';
2
- export default class extends AppCommand {
3
- static hidden: boolean;
4
- type: string;
5
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const app_command_1 = require("../app-command");
4
- class default_1 extends app_command_1.default {
5
- constructor() {
6
- super(...arguments);
7
- this.type = 'base';
8
- }
9
- }
10
- exports.default = default_1;
11
- default_1.hidden = true;
@@ -1,19 +0,0 @@
1
- import Base from '../command-base';
2
- export interface Options {
3
- name: string;
4
- defaults?: boolean;
5
- force?: boolean;
6
- }
7
- export default abstract class AppCommand extends Base {
8
- static description: string;
9
- static flags: {
10
- defaults: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
- force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
12
- };
13
- static args: {
14
- name: string;
15
- description: string;
16
- required: boolean;
17
- }[];
18
- run(): Promise<void>;
19
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- const command_base_1 = require("../command-base");
5
- class AppCommand extends command_base_1.default {
6
- async run() {
7
- const { flags, args } = this.parse(AppCommand);
8
- await super.generate('command', {
9
- name: args.name,
10
- defaults: flags.defaults,
11
- force: flags.force,
12
- });
13
- }
14
- }
15
- exports.default = AppCommand;
16
- AppCommand.description = 'add a command to an existing CLI or plugin';
17
- AppCommand.flags = {
18
- defaults: command_1.flags.boolean({ description: 'use defaults for every setting' }),
19
- force: command_1.flags.boolean({ description: 'overwrite existing files' }),
20
- };
21
- AppCommand.args = [
22
- { name: 'name', description: 'name of command', required: true },
23
- ];
@@ -1,22 +0,0 @@
1
- import { flags } from '@oclif/command';
2
- import Base from '../command-base';
3
- export interface Options {
4
- name: string;
5
- defaults?: boolean;
6
- force?: boolean;
7
- event: string;
8
- }
9
- export default abstract class HookCommand extends Base {
10
- static description: string;
11
- static flags: {
12
- defaults: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
13
- force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
14
- event: flags.IOptionFlag<string>;
15
- };
16
- static args: {
17
- name: string;
18
- description: string;
19
- required: boolean;
20
- }[];
21
- run(): Promise<void>;
22
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- const command_base_1 = require("../command-base");
5
- class HookCommand extends command_base_1.default {
6
- async run() {
7
- const { flags, args } = this.parse(HookCommand);
8
- await super.generate('hook', {
9
- name: args.name,
10
- event: flags.event,
11
- defaults: flags.defaults,
12
- force: flags.force,
13
- });
14
- }
15
- }
16
- exports.default = HookCommand;
17
- HookCommand.description = 'add a hook to an existing CLI or plugin';
18
- HookCommand.flags = {
19
- defaults: command_1.flags.boolean({ description: 'use defaults for every setting' }),
20
- force: command_1.flags.boolean({ description: 'overwrite existing files' }),
21
- event: command_1.flags.string({ description: 'event to run hook on', default: 'init' }),
22
- };
23
- HookCommand.args = [
24
- { name: 'name', description: 'name of hook (snake_case)', required: true },
25
- ];
@@ -1,5 +0,0 @@
1
- import AppCommand from '../app-command';
2
- export default class extends AppCommand {
3
- static description: string;
4
- type: string;
5
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const app_command_1 = require("../app-command");
4
- class default_1 extends app_command_1.default {
5
- constructor() {
6
- super(...arguments);
7
- this.type = 'multi';
8
- }
9
- }
10
- exports.default = default_1;
11
- default_1.description = 'generate a new multi-command CLI';
@@ -1,5 +0,0 @@
1
- import AppCommand from '../app-command';
2
- export default class extends AppCommand {
3
- static description: string;
4
- type: string;
5
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const app_command_1 = require("../app-command");
4
- class default_1 extends app_command_1.default {
5
- constructor() {
6
- super(...arguments);
7
- this.type = 'plugin';
8
- }
9
- }
10
- exports.default = default_1;
11
- default_1.description = 'create a new CLI plugin';
@@ -1,5 +0,0 @@
1
- import AppCommand from '../app-command';
2
- export default class extends AppCommand {
3
- static description: string;
4
- type: string;
5
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const app_command_1 = require("../app-command");
4
- class default_1 extends app_command_1.default {
5
- constructor() {
6
- super(...arguments);
7
- this.type = 'single';
8
- }
9
- }
10
- exports.default = default_1;
11
- default_1.description = 'generate a new single-command CLI';
@@ -1,470 +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: '>=8.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
- if (this.options.defaults) {
86
- this.answers = defaults;
87
- }
88
- else {
89
- this.answers = await this.prompt([
90
- {
91
- type: 'input',
92
- name: 'name',
93
- message: 'npm package name',
94
- default: defaults.name,
95
- when: !this.pjson.name,
96
- },
97
- {
98
- type: 'input',
99
- name: 'bin',
100
- message: 'command bin name the CLI will export',
101
- default: (answers) => (answers.name || this._bin).split('/').pop(),
102
- when: ['single', 'multi'].includes(this.type) && !this.pjson.oclif.bin,
103
- },
104
- {
105
- type: 'input',
106
- name: 'description',
107
- message: 'description',
108
- default: defaults.description,
109
- when: !this.pjson.description,
110
- },
111
- {
112
- type: 'input',
113
- name: 'author',
114
- message: 'author',
115
- default: defaults.author,
116
- when: !this.pjson.author,
117
- },
118
- {
119
- type: 'input',
120
- name: 'version',
121
- message: 'version',
122
- default: defaults.version,
123
- when: !this.pjson.version,
124
- },
125
- {
126
- type: 'input',
127
- name: 'license',
128
- message: 'license',
129
- default: defaults.license,
130
- when: !this.pjson.license,
131
- },
132
- {
133
- type: 'input',
134
- name: 'github.user',
135
- message: 'Who is the GitHub owner of repository (https://github.com/OWNER/repo)',
136
- default: repository.split('/').slice(0, -1).pop(),
137
- when: !this.pjson.repository,
138
- },
139
- {
140
- type: 'input',
141
- name: 'github.repo',
142
- message: 'What is the GitHub name of repository (https://github.com/owner/REPO)',
143
- default: (answers) => (this.pjson.repository || answers.name || this.pjson.name).split('/').pop(),
144
- when: !this.pjson.repository,
145
- },
146
- {
147
- type: 'list',
148
- name: 'pkg',
149
- message: 'Select a package manager',
150
- choices: [
151
- { name: 'npm', value: 'npm' },
152
- { name: 'yarn', value: 'yarn' },
153
- ],
154
- default: () => this.options.yarn || hasYarn ? 1 : 0,
155
- },
156
- {
157
- type: 'confirm',
158
- name: 'typescript',
159
- message: 'TypeScript',
160
- default: () => true,
161
- },
162
- {
163
- type: 'confirm',
164
- name: 'eslint',
165
- message: 'Use eslint (linter for JavaScript and Typescript)',
166
- default: () => true,
167
- },
168
- {
169
- type: 'confirm',
170
- name: 'mocha',
171
- message: 'Use mocha (testing framework)',
172
- default: () => true,
173
- },
174
- {
175
- type: 'checkbox',
176
- name: 'ci',
177
- message: 'Add CI service config',
178
- choices: [
179
- { name: 'circleci (continuous integration/delivery service)', value: 'circleci' },
180
- { name: 'appveyor (continuous integration/delivery service)', value: 'appveyor' },
181
- { name: 'travisci (continuous integration/delivery service)', value: 'travisci' },
182
- ],
183
- filter: ((arr) => _.keyBy(arr)),
184
- },
185
- ]);
186
- }
187
- debug(this.answers);
188
- if (!this.options.defaults) {
189
- 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' });
190
- }
191
- this.ts = this.options.typescript;
192
- this.yarn = this.options.yarn;
193
- this.mocha = this.options.mocha;
194
- this.circleci = this.options.circleci;
195
- this.appveyor = this.options.appveyor;
196
- this.eslint = this.options.eslint;
197
- this.travisci = this.options.travisci;
198
- this.pjson.name = this.answers.name || defaults.name;
199
- this.pjson.description = this.answers.description || defaults.description;
200
- this.pjson.version = this.answers.version || defaults.version;
201
- this.pjson.engines.node = defaults.engines.node;
202
- this.pjson.author = this.answers.author || defaults.author;
203
- this.pjson.files = this.answers.files || defaults.files || [(this.ts ? '/lib' : '/src')];
204
- this.pjson.license = this.answers.license || defaults.license;
205
- // eslint-disable-next-line no-multi-assign
206
- this.repository = this.pjson.repository = this.answers.github ? `${this.answers.github.user}/${this.answers.github.repo}` : defaults.repository;
207
- if (this.eslint) {
208
- this.pjson.scripts.posttest = 'eslint .';
209
- }
210
- if (this.mocha) {
211
- this.pjson.scripts.test = `nyc ${this.ts ? '--extension .ts ' : ''}mocha --forbid-only "test/**/*.test.${this._ext}"`;
212
- }
213
- else {
214
- this.pjson.scripts.test = 'echo NO TESTS';
215
- }
216
- if (this.ts) {
217
- this.pjson.scripts.prepack = nps.series(`${rmrf} lib`, 'tsc -b');
218
- if (this.eslint) {
219
- this.pjson.scripts.posttest = 'eslint . --ext .ts --config .eslintrc';
220
- }
221
- }
222
- if (['plugin', 'multi'].includes(this.type)) {
223
- this.pjson.scripts.prepack = nps.series(this.pjson.scripts.prepack, 'oclif-dev manifest', 'oclif-dev readme');
224
- this.pjson.scripts.postpack = `${rmf} oclif.manifest.json`;
225
- this.pjson.scripts.version = nps.series('oclif-dev readme', 'git add README.md');
226
- this.pjson.files.push('/oclif.manifest.json');
227
- this.pjson.files.push('/npm-shrinkwrap.json');
228
- }
229
- else if (this.type === 'single') {
230
- this.pjson.scripts.prepack = nps.series(this.pjson.scripts.prepack, 'oclif-dev readme');
231
- this.pjson.scripts.version = nps.series('oclif-dev readme', 'git add README.md');
232
- }
233
- if (this.type === 'plugin' && hasYarn) {
234
- // for plugins, add yarn.lock file to package so we can lock plugin dependencies
235
- this.pjson.files.push('/yarn.lock');
236
- }
237
- this.pjson.keywords = defaults.keywords || [this.type === 'plugin' ? 'oclif-plugin' : 'oclif'];
238
- this.pjson.homepage = defaults.homepage || `https://github.com/${this.pjson.repository}`;
239
- this.pjson.bugs = defaults.bugs || `https://github.com/${this.pjson.repository}/issues`;
240
- if (['single', 'multi'].includes(this.type)) {
241
- this.pjson.oclif.bin = this.answers.bin || this._bin;
242
- this.pjson.bin = this.pjson.bin || {};
243
- this.pjson.bin[this.pjson.oclif.bin] = './bin/run';
244
- this.pjson.files.push('/bin');
245
- }
246
- else if (this.type === 'plugin') {
247
- this.pjson.oclif.bin = 'oclif-example';
248
- }
249
- if (this.type !== 'plugin') {
250
- this.pjson.main = defaults.main || (this.ts ? 'lib/index.js' : 'src/index.js');
251
- if (this.ts) {
252
- this.pjson.types = defaults.types || 'lib/index.d.ts';
253
- }
254
- }
255
- }
256
- // eslint-disable-next-line complexity
257
- writing() {
258
- this.sourceRoot(path.join(__dirname, '../../templates'));
259
- switch (this.type) {
260
- case 'multi':
261
- case 'plugin':
262
- this.pjson.oclif = Object.assign({ commands: `./${this.ts ? 'lib' : 'src'}/commands` }, this.pjson.oclif);
263
- break;
264
- default:
265
- }
266
- if (this.type === 'plugin' && !this.pjson.oclif.devPlugins) {
267
- this.pjson.oclif.devPlugins = [
268
- '@oclif/plugin-help',
269
- ];
270
- }
271
- if (this.type === 'multi' && !this.pjson.oclif.plugins) {
272
- this.pjson.oclif.plugins = [
273
- '@oclif/plugin-help',
274
- ];
275
- }
276
- if (this.pjson.oclif && Array.isArray(this.pjson.oclif.plugins)) {
277
- this.pjson.oclif.plugins.sort();
278
- }
279
- if (this.ts) {
280
- this.fs.copyTpl(this.templatePath('tsconfig.json'), this.destinationPath('tsconfig.json'), this);
281
- if (this.mocha) {
282
- this.fs.copyTpl(this.templatePath('test/tsconfig.json'), this.destinationPath('test/tsconfig.json'), this);
283
- }
284
- }
285
- if (this.eslint) {
286
- const eslintignore = this._eslintignore();
287
- if (eslintignore.trim())
288
- this.fs.write(this.destinationPath('.eslintignore'), this._eslintignore());
289
- if (this.ts) {
290
- this.fs.copyTpl(this.templatePath('eslintrc.typescript'), this.destinationPath('.eslintrc'), this);
291
- }
292
- else {
293
- this.fs.copyTpl(this.templatePath('eslintrc'), this.destinationPath('.eslintrc'), this);
294
- }
295
- }
296
- if (this.mocha) {
297
- this.fs.copyTpl(this.templatePath('test/mocha.opts'), this.destinationPath('test/mocha.opts'), this);
298
- }
299
- if (this.fs.exists(this.destinationPath('./package.json'))) {
300
- fixpack(this.destinationPath('./package.json'), require('@oclif/fixpack/config.json'));
301
- }
302
- if (_.isEmpty(this.pjson.oclif))
303
- delete this.pjson.oclif;
304
- this.pjson.files = _.uniq((this.pjson.files || []).sort());
305
- this.fs.writeJSON(this.destinationPath('./package.json'), sortPjson(this.pjson));
306
- this.fs.copyTpl(this.templatePath('editorconfig'), this.destinationPath('.editorconfig'), this);
307
- if (this.circleci) {
308
- this.fs.copyTpl(this.templatePath('circle.yml.ejs'), this.destinationPath('.circleci/config.yml'), this);
309
- }
310
- if (this.appveyor) {
311
- this.fs.copyTpl(this.templatePath('appveyor.yml.ejs'), this.destinationPath('appveyor.yml'), this);
312
- }
313
- if (this.travisci) {
314
- this.fs.copyTpl(this.templatePath('travis.yml.ejs'), this.destinationPath('.travis.yml'), this);
315
- }
316
- this.fs.copyTpl(this.templatePath('README.md.ejs'), this.destinationPath('README.md'), this);
317
- if (this.pjson.license === 'MIT' && (this.pjson.repository.startsWith('oclif') || this.pjson.repository.startsWith('heroku'))) {
318
- this.fs.copyTpl(this.templatePath('LICENSE.mit'), this.destinationPath('LICENSE'), this);
319
- }
320
- this.fs.write(this.destinationPath('.gitignore'), this._gitignore());
321
- switch (this.type) {
322
- case 'single':
323
- this._writeSingle();
324
- break;
325
- case 'plugin':
326
- this._writePlugin();
327
- break;
328
- case 'multi':
329
- this._writeMulti();
330
- break;
331
- default:
332
- this._writeBase();
333
- }
334
- }
335
- install() {
336
- const dependencies = [];
337
- const devDependencies = [];
338
- switch (this.type) {
339
- case 'base': break;
340
- case 'single':
341
- dependencies.push('@oclif/config@^1', '@oclif/command@^1', '@oclif/plugin-help@^3');
342
- devDependencies.push('@oclif/dev-cli@^1');
343
- break;
344
- case 'plugin':
345
- dependencies.push('@oclif/command@^1', '@oclif/config@^1');
346
- devDependencies.push('@oclif/dev-cli@^1', '@oclif/plugin-help@^3', 'globby@^10');
347
- break;
348
- case 'multi':
349
- dependencies.push('@oclif/config@^1', '@oclif/command@^1', '@oclif/plugin-help@^3');
350
- devDependencies.push('@oclif/dev-cli@^1', 'globby@^10');
351
- }
352
- if (this.mocha) {
353
- devDependencies.push('mocha@^5', 'nyc@^14', 'chai@^4');
354
- if (this.type !== 'base')
355
- devDependencies.push('@oclif/test@^1');
356
- }
357
- if (this.ts) {
358
- dependencies.push('tslib@^1');
359
- devDependencies.push('@types/node@^10', 'typescript@^3.3', 'ts-node@^8');
360
- if (this.mocha) {
361
- devDependencies.push('@types/chai@^4', '@types/mocha@^5');
362
- }
363
- }
364
- if (this.eslint) {
365
- devDependencies.push('eslint@^7.3.0', // this should stay in sync with the eslint dependency in this repo's package.json
366
- 'eslint-config-oclif@^3.1');
367
- if (this.ts) {
368
- devDependencies.push('eslint-config-oclif-typescript@^0.2.0');
369
- }
370
- }
371
- if (isWindows)
372
- devDependencies.push('rimraf');
373
- const yarnOpts = {};
374
- if (process.env.YARN_MUTEX)
375
- yarnOpts.mutex = process.env.YARN_MUTEX;
376
- const install = (deps, opts) => this.yarn ? this.yarnInstall(deps, opts) : this.npmInstall(deps, opts);
377
- const dev = this.yarn ? { dev: true } : { 'save-dev': true };
378
- const save = this.yarn ? {} : { save: true };
379
- return Promise.all([
380
- install(devDependencies, Object.assign(Object.assign(Object.assign({}, yarnOpts), dev), { ignoreScripts: true })),
381
- install(dependencies, Object.assign(Object.assign({}, yarnOpts), save)),
382
- ]).then(() => {
383
- // if (!this.yarn) {
384
- // return this.spawnCommand('npm', ['shrinkwrap'])
385
- // }
386
- });
387
- }
388
- end() {
389
- if (['plugin', 'multi', 'single'].includes(this.type)) {
390
- this.spawnCommandSync(path.join('.', 'node_modules/.bin/oclif-dev'), ['readme']);
391
- }
392
- console.log(`\nCreated ${this.pjson.name} in ${this.destinationRoot()}`);
393
- }
394
- _gitignore() {
395
- const existing = this.fs.exists(this.destinationPath('.gitignore')) ? this.fs.read(this.destinationPath('.gitignore')).split('\n') : [];
396
- return _([
397
- '*-debug.log',
398
- '*-error.log',
399
- 'node_modules',
400
- '/tmp',
401
- '/dist',
402
- '/.nyc_output',
403
- this.yarn ? '/package-lock.json' : '/yarn.lock',
404
- this.ts && '/lib',
405
- ])
406
- .concat(existing)
407
- .compact()
408
- .uniq()
409
- .sort()
410
- .join('\n') + '\n';
411
- }
412
- _eslintignore() {
413
- const existing = this.fs.exists(this.destinationPath('.eslintignore')) ? this.fs.read(this.destinationPath('.eslintignore')).split('\n') : [];
414
- return _([
415
- this.ts && '/lib',
416
- ])
417
- .concat(existing)
418
- .compact()
419
- .uniq()
420
- .sort()
421
- .join('\n') + '\n';
422
- }
423
- _writeBase() {
424
- if (!fs.existsSync('src')) {
425
- this.fs.copyTpl(this.templatePath(`base/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this);
426
- }
427
- if (this.mocha && !fs.existsSync('test')) {
428
- this.fs.copyTpl(this.templatePath(`base/test/index.test.${this._ext}`), this.destinationPath(`test/index.test.${this._ext}`), this);
429
- }
430
- }
431
- _writePlugin() {
432
- const bin = this._bin;
433
- const cmd = `${bin} hello`;
434
- const opts = Object.assign(Object.assign({}, this), { _, bin, cmd });
435
- this.fs.copyTpl(this.templatePath('plugin/bin/run'), this.destinationPath('bin/run'), opts);
436
- this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts);
437
- const commandPath = this.destinationPath(`src/commands/hello.${this._ext}`);
438
- if (!fs.existsSync('src/commands')) {
439
- this.fs.copyTpl(this.templatePath(`src/command.${this._ext}.ejs`), commandPath, Object.assign(Object.assign({}, opts), { name: 'hello', path: commandPath.replace(process.cwd(), '.') }));
440
- }
441
- if (this.ts && this.type !== 'multi') {
442
- this.fs.copyTpl(this.templatePath('plugin/src/index.ts'), this.destinationPath('src/index.ts'), opts);
443
- }
444
- if (this.mocha && !fs.existsSync('test')) {
445
- 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' }));
446
- }
447
- }
448
- _writeSingle() {
449
- const bin = this._bin;
450
- const opts = Object.assign(Object.assign({}, this), { _, bin, cmd: bin, name: this.pjson.name });
451
- this.fs.copyTpl(this.templatePath(`single/bin/run.${this._ext}`), this.destinationPath('bin/run'), opts);
452
- this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), opts);
453
- const commandPath = this.destinationPath(`src/index.${this._ext}`);
454
- if (!this.fs.exists(`src/index.${this._ext}`)) {
455
- 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(), '.') }));
456
- }
457
- if (this.mocha && !this.fs.exists(`test/index.test.${this._ext}`)) {
458
- this.fs.copyTpl(this.templatePath(`test/command.test.${this._ext}.ejs`), this.destinationPath(`test/index.test.${this._ext}`), opts);
459
- }
460
- }
461
- _writeMulti() {
462
- this._writePlugin();
463
- this.fs.copyTpl(this.templatePath('bin/run'), this.destinationPath('bin/run'), this);
464
- this.fs.copyTpl(this.templatePath('bin/run.cmd'), this.destinationPath('bin/run.cmd'), this);
465
- if (!this.fs.exists(`src/index.${this._ext}`)) {
466
- this.fs.copyTpl(this.templatePath(`multi/src/index.${this._ext}`), this.destinationPath(`src/index.${this._ext}`), this);
467
- }
468
- }
469
- }
470
- module.exports = App;