@depup/oclif 4.22.92-depup.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.
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +7 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +7 -0
- package/changes.json +62 -0
- package/lib/aws.d.ts +22 -0
- package/lib/aws.js +146 -0
- package/lib/commands/generate/command.d.ts +12 -0
- package/lib/commands/generate/command.js +44 -0
- package/lib/commands/generate/hook.d.ts +12 -0
- package/lib/commands/generate/hook.js +87 -0
- package/lib/commands/generate.d.ts +67 -0
- package/lib/commands/generate.js +269 -0
- package/lib/commands/init.d.ts +39 -0
- package/lib/commands/init.js +165 -0
- package/lib/commands/lock.d.ts +4 -0
- package/lib/commands/lock.js +70 -0
- package/lib/commands/manifest.d.ts +13 -0
- package/lib/commands/manifest.js +156 -0
- package/lib/commands/pack/deb.d.ts +13 -0
- package/lib/commands/pack/deb.js +194 -0
- package/lib/commands/pack/macos.d.ts +14 -0
- package/lib/commands/pack/macos.js +273 -0
- package/lib/commands/pack/tarballs.d.ts +15 -0
- package/lib/commands/pack/tarballs.js +77 -0
- package/lib/commands/pack/win.d.ts +16 -0
- package/lib/commands/pack/win.js +398 -0
- package/lib/commands/promote.d.ts +20 -0
- package/lib/commands/promote.js +305 -0
- package/lib/commands/readme.d.ts +19 -0
- package/lib/commands/readme.js +143 -0
- package/lib/commands/upload/deb.d.ts +10 -0
- package/lib/commands/upload/deb.js +113 -0
- package/lib/commands/upload/macos.d.ts +11 -0
- package/lib/commands/upload/macos.js +92 -0
- package/lib/commands/upload/tarballs.d.ts +12 -0
- package/lib/commands/upload/tarballs.js +135 -0
- package/lib/commands/upload/win.d.ts +11 -0
- package/lib/commands/upload/win.js +97 -0
- package/lib/generator.d.ts +57 -0
- package/lib/generator.js +184 -0
- package/lib/help-compatibility.d.ts +11 -0
- package/lib/help-compatibility.js +22 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/log.d.ts +2 -0
- package/lib/log.js +13 -0
- package/lib/readme-generator.d.ts +38 -0
- package/lib/readme-generator.js +305 -0
- package/lib/tarballs/bin.d.ts +7 -0
- package/lib/tarballs/bin.js +126 -0
- package/lib/tarballs/build.d.ts +10 -0
- package/lib/tarballs/build.js +250 -0
- package/lib/tarballs/config.d.ts +45 -0
- package/lib/tarballs/config.js +132 -0
- package/lib/tarballs/index.d.ts +4 -0
- package/lib/tarballs/index.js +20 -0
- package/lib/tarballs/node.d.ts +10 -0
- package/lib/tarballs/node.js +78 -0
- package/lib/upload-util.d.ts +17 -0
- package/lib/upload-util.js +56 -0
- package/lib/util.d.ts +18 -0
- package/lib/util.js +160 -0
- package/lib/version-indexes.d.ts +9 -0
- package/lib/version-indexes.js +119 -0
- package/oclif.manifest.json +1199 -0
- package/package.json +217 -0
- package/templates/cli/commonjs/.mocharc.json.ejs +11 -0
- package/templates/cli/commonjs/.vscode/launch.json.ejs +20 -0
- package/templates/cli/commonjs/bin/dev.cmd.ejs +3 -0
- package/templates/cli/commonjs/bin/dev.js.ejs +7 -0
- package/templates/cli/commonjs/bin/run.cmd.ejs +3 -0
- package/templates/cli/commonjs/bin/run.js.ejs +7 -0
- package/templates/cli/commonjs/eslint.config.mjs.ejs +19 -0
- package/templates/cli/commonjs/tsconfig.json.ejs +11 -0
- package/templates/cli/esm/.mocharc.json.ejs +15 -0
- package/templates/cli/esm/.vscode/launch.json.ejs +22 -0
- package/templates/cli/esm/bin/dev.cmd.ejs +3 -0
- package/templates/cli/esm/bin/dev.js.ejs +5 -0
- package/templates/cli/esm/bin/run.cmd.ejs +3 -0
- package/templates/cli/esm/bin/run.js.ejs +5 -0
- package/templates/cli/esm/eslint.config.mjs.ejs +9 -0
- package/templates/cli/esm/tsconfig.json.ejs +15 -0
- package/templates/cli/shared/.github/workflows/onPushToMain.yml.ejs +56 -0
- package/templates/cli/shared/.github/workflows/onRelease.yml.ejs +21 -0
- package/templates/cli/shared/.github/workflows/test.yml.ejs +23 -0
- package/templates/cli/shared/.gitignore.ejs +27 -0
- package/templates/cli/shared/.prettierrc.json.ejs +1 -0
- package/templates/cli/shared/README.md.ejs +396 -0
- package/templates/cli/shared/package.json.ejs +73 -0
- package/templates/cli/shared/src/commands/hello/index.ts.ejs +22 -0
- package/templates/cli/shared/src/commands/hello/world.ts.ejs +16 -0
- package/templates/cli/shared/src/index.ts.ejs +1 -0
- package/templates/cli/shared/test/commands/hello/index.test.ts.ejs +9 -0
- package/templates/cli/shared/test/commands/hello/world.test.ts.ejs +9 -0
- package/templates/cli/shared/test/tsconfig.json.ejs +9 -0
- package/templates/src/command.ts.ejs +27 -0
- package/templates/src/hook.ts.ejs +7 -0
- package/templates/src/init/dev.cmd.ejs +12 -0
- package/templates/src/init/dev.js.ejs +17 -0
- package/templates/src/init/run.cmd.ejs +3 -0
- package/templates/src/init/run.js.ejs +17 -0
- package/templates/test/command.test.ts.ejs +14 -0
- package/templates/test/hook.test.ts.ejs +9 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const errors_1 = require("@oclif/core/errors");
|
|
8
|
+
const ansis_1 = require("ansis");
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const promises_1 = require("node:fs/promises");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
13
|
+
const generator_1 = require("../generator");
|
|
14
|
+
const log_1 = require("../log");
|
|
15
|
+
const util_1 = require("../util");
|
|
16
|
+
const debug = log_1.debug.new('generate');
|
|
17
|
+
async function fetchGithubUserFromAPI() {
|
|
18
|
+
const token = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN;
|
|
19
|
+
if (!token)
|
|
20
|
+
return;
|
|
21
|
+
const { default: got } = await import('got');
|
|
22
|
+
const headers = {
|
|
23
|
+
Accept: 'application/vnd.github.v3+json',
|
|
24
|
+
Authorization: `Bearer ${token}`,
|
|
25
|
+
};
|
|
26
|
+
try {
|
|
27
|
+
const { login, name } = await got('https://api.github.com/user', { headers }).json();
|
|
28
|
+
return { login, name };
|
|
29
|
+
}
|
|
30
|
+
catch { }
|
|
31
|
+
}
|
|
32
|
+
async function fetchGithubUserFromGit() {
|
|
33
|
+
try {
|
|
34
|
+
const result = await (0, generator_1.exec)('git config --get user.name');
|
|
35
|
+
return result.stdout.trim();
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
}
|
|
39
|
+
async function fetchGithubUser() {
|
|
40
|
+
return (await fetchGithubUserFromAPI()) ?? { name: await fetchGithubUserFromGit() };
|
|
41
|
+
}
|
|
42
|
+
function determineDefaultAuthor(user, defaultValue) {
|
|
43
|
+
const { login, name } = user ?? { login: undefined, name: undefined };
|
|
44
|
+
if (name && login)
|
|
45
|
+
return `${name} @${login}`;
|
|
46
|
+
if (name)
|
|
47
|
+
return name;
|
|
48
|
+
if (login)
|
|
49
|
+
return `@${login}`;
|
|
50
|
+
return defaultValue;
|
|
51
|
+
}
|
|
52
|
+
const FLAGGABLE_PROMPTS = {
|
|
53
|
+
author: {
|
|
54
|
+
message: 'Author',
|
|
55
|
+
validate: (d) => d.length > 0 || 'Author cannot be empty',
|
|
56
|
+
},
|
|
57
|
+
bin: {
|
|
58
|
+
message: 'Command bin name the CLI will export',
|
|
59
|
+
validate: (d) => (0, util_1.validateBin)(d) || 'Invalid bin name',
|
|
60
|
+
},
|
|
61
|
+
description: {
|
|
62
|
+
message: 'Description',
|
|
63
|
+
validate: (d) => d.length > 0 || 'Description cannot be empty',
|
|
64
|
+
},
|
|
65
|
+
license: {
|
|
66
|
+
message: 'License',
|
|
67
|
+
validate: (d) => d.length > 0 || 'License cannot be empty',
|
|
68
|
+
},
|
|
69
|
+
'module-type': {
|
|
70
|
+
message: 'Select a module type',
|
|
71
|
+
options: ['CommonJS', 'ESM'],
|
|
72
|
+
validate: (d) => ['CommonJS', 'ESM'].includes(d) || 'Invalid module type',
|
|
73
|
+
},
|
|
74
|
+
name: {
|
|
75
|
+
message: 'NPM package name',
|
|
76
|
+
validate: (d) => (0, validate_npm_package_name_1.default)(d).validForNewPackages || 'Invalid package name',
|
|
77
|
+
},
|
|
78
|
+
owner: {
|
|
79
|
+
message: 'Who is the GitHub owner of repository (https://github.com/OWNER/repo)',
|
|
80
|
+
validate: (d) => d.length > 0 || 'Owner cannot be empty',
|
|
81
|
+
},
|
|
82
|
+
'package-manager': {
|
|
83
|
+
message: 'Select a package manager',
|
|
84
|
+
options: ['npm', 'yarn', 'pnpm'],
|
|
85
|
+
validate: (d) => ['npm', 'pnpm', 'yarn'].includes(d) || 'Invalid package manager',
|
|
86
|
+
},
|
|
87
|
+
repository: {
|
|
88
|
+
message: 'What is the GitHub name of repository (https://github.com/owner/REPO)',
|
|
89
|
+
validate: (d) => d.length > 0 || 'Repo cannot be empty',
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
class Generate extends generator_1.GeneratorCommand {
|
|
93
|
+
static args = {
|
|
94
|
+
name: core_1.Args.string({ description: 'Directory name of new project.', required: true }),
|
|
95
|
+
};
|
|
96
|
+
static description = `This will generate a fully functional oclif CLI that you can build on. It will prompt you for all the necessary information to get started. If you want to skip the prompts, you can pass the --yes flag to accept the defaults for all prompts. You can also pass individual flags to set specific values for prompts.
|
|
97
|
+
|
|
98
|
+
Head to oclif.io/docs/introduction to learn more about building CLIs with oclif.`;
|
|
99
|
+
static examples = [
|
|
100
|
+
{
|
|
101
|
+
command: '<%= config.bin %> <%= command.id %> my-cli',
|
|
102
|
+
description: 'Generate a new CLI with prompts for all properties',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
command: '<%= config.bin %> <%= command.id %> my-cli --yes',
|
|
106
|
+
description: 'Automatically accept default values for all prompts',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
command: '<%= config.bin %> <%= command.id %> my-cli --module-type CommonJS --author "John Doe"',
|
|
110
|
+
description: 'Supply answers for specific prompts',
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
command: '<%= config.bin %> <%= command.id %> my-cli --module-type CommonJS --author "John Doe" --yes',
|
|
114
|
+
description: 'Supply answers for specific prompts and accept default values for the rest',
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
static flaggablePrompts = FLAGGABLE_PROMPTS;
|
|
118
|
+
static flags = {
|
|
119
|
+
...(0, generator_1.makeFlags)(FLAGGABLE_PROMPTS),
|
|
120
|
+
'dry-run': core_1.Flags.boolean({
|
|
121
|
+
char: 'n',
|
|
122
|
+
description: 'Print the files that would be created without actually creating them.',
|
|
123
|
+
}),
|
|
124
|
+
'output-dir': core_1.Flags.directory({
|
|
125
|
+
char: 'd',
|
|
126
|
+
description: 'Directory to build the CLI in.',
|
|
127
|
+
}),
|
|
128
|
+
yes: core_1.Flags.boolean({
|
|
129
|
+
aliases: ['defaults'],
|
|
130
|
+
char: 'y',
|
|
131
|
+
description: 'Use defaults for all prompts. Individual flags will override defaults.',
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
134
|
+
static summary = 'Generate a new CLI';
|
|
135
|
+
async run() {
|
|
136
|
+
const location = this.flags['output-dir'] ? (0, node_path_1.join)(this.flags['output-dir'], this.args.name) : (0, node_path_1.resolve)(this.args.name);
|
|
137
|
+
this.log(`Generating ${this.args.name} in ${(0, ansis_1.green)(location)}`);
|
|
138
|
+
if ((0, node_fs_1.existsSync)(location)) {
|
|
139
|
+
throw new core_1.Errors.CLIError(`The directory ${location} already exists.`);
|
|
140
|
+
}
|
|
141
|
+
const moduleType = await this.getFlagOrPrompt({
|
|
142
|
+
defaultValue: 'ESM',
|
|
143
|
+
name: 'module-type',
|
|
144
|
+
type: 'select',
|
|
145
|
+
});
|
|
146
|
+
const githubUser = await fetchGithubUser();
|
|
147
|
+
const name = await this.getFlagOrPrompt({ defaultValue: this.args.name, name: 'name', type: 'input' });
|
|
148
|
+
const bin = await this.getFlagOrPrompt({ defaultValue: name, name: 'bin', type: 'input' });
|
|
149
|
+
const description = await this.getFlagOrPrompt({
|
|
150
|
+
defaultValue: 'A new CLI generated with oclif',
|
|
151
|
+
name: 'description',
|
|
152
|
+
type: 'input',
|
|
153
|
+
});
|
|
154
|
+
const author = await this.getFlagOrPrompt({
|
|
155
|
+
defaultValue: determineDefaultAuthor(githubUser, 'Your Name Here'),
|
|
156
|
+
name: 'author',
|
|
157
|
+
type: 'input',
|
|
158
|
+
});
|
|
159
|
+
const license = await this.getFlagOrPrompt({
|
|
160
|
+
defaultValue: 'MIT',
|
|
161
|
+
name: 'license',
|
|
162
|
+
type: 'input',
|
|
163
|
+
});
|
|
164
|
+
const owner = await this.getFlagOrPrompt({
|
|
165
|
+
defaultValue: githubUser?.login ?? location.split(node_path_1.sep).at(-2) ?? 'Your Name Here',
|
|
166
|
+
name: 'owner',
|
|
167
|
+
type: 'input',
|
|
168
|
+
});
|
|
169
|
+
const repository = await this.getFlagOrPrompt({
|
|
170
|
+
defaultValue: name.split('/').at(-1) ?? name,
|
|
171
|
+
name: 'repository',
|
|
172
|
+
type: 'input',
|
|
173
|
+
});
|
|
174
|
+
const packageManager = await this.getFlagOrPrompt({
|
|
175
|
+
defaultValue: 'npm',
|
|
176
|
+
name: 'package-manager',
|
|
177
|
+
type: 'select',
|
|
178
|
+
});
|
|
179
|
+
const [sharedFiles, moduleSpecificFiles] = await Promise.all(['shared', moduleType.toLowerCase()].map((f) => (0, node_path_1.join)(this.templatesDir, 'cli', f)).map(findEjsFiles(location)));
|
|
180
|
+
debug('shared files %O', sharedFiles);
|
|
181
|
+
debug(`${moduleType} files %O`, moduleSpecificFiles);
|
|
182
|
+
await Promise.all([...sharedFiles, ...moduleSpecificFiles].map(async (file) => {
|
|
183
|
+
switch (file.name) {
|
|
184
|
+
case '.gitignore.ejs': {
|
|
185
|
+
await this.template(file.src, file.destination, { packageManager });
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case 'onPushToMain.yml.ejs':
|
|
189
|
+
case 'onRelease.yml.ejs':
|
|
190
|
+
case 'test.yml.ejs': {
|
|
191
|
+
await this.template(file.src, file.destination, {
|
|
192
|
+
exec: packageManager === 'yarn' ? packageManager : `${packageManager} exec`,
|
|
193
|
+
install: packageManager === 'yarn' ? packageManager : `${packageManager} install`,
|
|
194
|
+
packageManager,
|
|
195
|
+
run: packageManager === 'yarn' ? packageManager : `${packageManager} run`,
|
|
196
|
+
});
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case 'package.json.ejs': {
|
|
200
|
+
const data = {
|
|
201
|
+
author,
|
|
202
|
+
bin,
|
|
203
|
+
description,
|
|
204
|
+
license,
|
|
205
|
+
moduleType,
|
|
206
|
+
name,
|
|
207
|
+
owner,
|
|
208
|
+
pkgManagerScript: packageManager === 'yarn' ? 'yarn' : `${packageManager} run`,
|
|
209
|
+
repository,
|
|
210
|
+
};
|
|
211
|
+
await this.template(file.src, file.destination, data);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 'README.md.ejs': {
|
|
215
|
+
await this.template(file.src, file.destination, { description, name, repository });
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
default: {
|
|
219
|
+
await this.template(file.src, file.destination);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
if (this.flags['dry-run']) {
|
|
224
|
+
this.log(`\n[DRY RUN] Created ${(0, ansis_1.green)(name)}`);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
if (process.platform !== 'win32') {
|
|
228
|
+
await Promise.all([
|
|
229
|
+
(0, generator_1.exec)(`chmod +x ${(0, node_path_1.join)(location, 'bin', 'run.js')}`),
|
|
230
|
+
(0, generator_1.exec)(`chmod +x ${(0, node_path_1.join)(location, 'bin', 'dev.js')}`),
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
await (0, generator_1.exec)(`${packageManager} install`, { cwd: location, silent: false });
|
|
234
|
+
await (0, generator_1.exec)(`${packageManager} run build`, { cwd: location, silent: false });
|
|
235
|
+
await (0, generator_1.exec)(`${(0, node_path_1.join)(location, 'node_modules', '.bin', 'oclif')} readme`, {
|
|
236
|
+
cwd: location,
|
|
237
|
+
// When testing this command in development, you get noisy compilation errors as a result of running
|
|
238
|
+
// this in a spawned process. Setting the NODE_ENV to production will silence these warnings. This
|
|
239
|
+
// doesn't affect the behavior of the command in production since the NODE_ENV is already set to production
|
|
240
|
+
// in that scenario.
|
|
241
|
+
env: { ...process.env, NODE_ENV: 'production' },
|
|
242
|
+
silent: false,
|
|
243
|
+
});
|
|
244
|
+
this.log(`\nCreated ${(0, ansis_1.green)(name)}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.default = Generate;
|
|
249
|
+
const findEjsFiles = (location) => async (dir) => (await (0, promises_1.readdir)(dir, { recursive: true, withFileTypes: true }))
|
|
250
|
+
.filter((f) => f.isFile() && f.name.endsWith('.ejs'))
|
|
251
|
+
.map((f) => {
|
|
252
|
+
debug({
|
|
253
|
+
location,
|
|
254
|
+
name: f.name,
|
|
255
|
+
parentPath: f.parentPath,
|
|
256
|
+
path: f.path,
|
|
257
|
+
});
|
|
258
|
+
const path = f.path ?? f.parentPath;
|
|
259
|
+
if (!path) {
|
|
260
|
+
(0, errors_1.warn)(`Could not determine path for file ${f.name}. Skipping.`);
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
destination: (0, node_path_1.join)(path.replace(dir, location), f.name.replace('.ejs', '')),
|
|
265
|
+
name: f.name,
|
|
266
|
+
src: (0, node_path_1.join)(path, f.name),
|
|
267
|
+
};
|
|
268
|
+
})
|
|
269
|
+
.filter((f) => f !== null);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { GeneratorCommand } from '../generator';
|
|
2
|
+
export default class Generate extends GeneratorCommand<typeof Generate> {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: {
|
|
5
|
+
command: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}[];
|
|
8
|
+
static flaggablePrompts: {
|
|
9
|
+
bin: {
|
|
10
|
+
message: string;
|
|
11
|
+
validate: (d: string) => true | "Invalid bin name";
|
|
12
|
+
};
|
|
13
|
+
'module-type': {
|
|
14
|
+
message: string;
|
|
15
|
+
options: readonly ["ESM", "CommonJS"];
|
|
16
|
+
validate: (d: string) => true | "Invalid module type";
|
|
17
|
+
};
|
|
18
|
+
'package-manager': {
|
|
19
|
+
message: string;
|
|
20
|
+
options: readonly ["npm", "yarn", "pnpm"];
|
|
21
|
+
validate: (d: string) => true | "Invalid package manager";
|
|
22
|
+
};
|
|
23
|
+
'topic-separator': {
|
|
24
|
+
message: string;
|
|
25
|
+
options: string[];
|
|
26
|
+
validate: (d: string) => true | "Invalid topic separator";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
static flags: {
|
|
30
|
+
'output-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
|
+
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
32
|
+
bin: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
33
|
+
"module-type": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
|
+
"package-manager": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
|
+
"topic-separator": import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
36
|
+
};
|
|
37
|
+
static summary: string;
|
|
38
|
+
run(): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const ansis_1 = require("ansis");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const generator_1 = require("../generator");
|
|
8
|
+
const util_1 = require("../util");
|
|
9
|
+
const VALID_MODULE_TYPES = ['ESM', 'CommonJS'];
|
|
10
|
+
const VALID_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm'];
|
|
11
|
+
function isPackageManager(d) {
|
|
12
|
+
return VALID_PACKAGE_MANAGERS.includes(d);
|
|
13
|
+
}
|
|
14
|
+
function isModuleType(d) {
|
|
15
|
+
return VALID_MODULE_TYPES.includes(d);
|
|
16
|
+
}
|
|
17
|
+
const FLAGGABLE_PROMPTS = {
|
|
18
|
+
bin: {
|
|
19
|
+
message: 'Command bin name the CLI will export',
|
|
20
|
+
validate: (d) => (0, util_1.validateBin)(d) || 'Invalid bin name',
|
|
21
|
+
},
|
|
22
|
+
'module-type': {
|
|
23
|
+
message: 'Select a module type',
|
|
24
|
+
options: VALID_MODULE_TYPES,
|
|
25
|
+
validate: (d) => isModuleType(d) || 'Invalid module type',
|
|
26
|
+
},
|
|
27
|
+
'package-manager': {
|
|
28
|
+
message: 'Select a package manager',
|
|
29
|
+
options: VALID_PACKAGE_MANAGERS,
|
|
30
|
+
validate: (d) => isPackageManager(d) || 'Invalid package manager',
|
|
31
|
+
},
|
|
32
|
+
'topic-separator': {
|
|
33
|
+
message: 'Select a topic separator',
|
|
34
|
+
options: ['colons', 'spaces'],
|
|
35
|
+
validate: (d) => d === 'colons' || d === 'spaces' || 'Invalid topic separator',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
class Generate extends generator_1.GeneratorCommand {
|
|
39
|
+
static description = 'This will add the necessary oclif bin files, add oclif config to package.json, and install @oclif/core and ts-node.';
|
|
40
|
+
static examples = [
|
|
41
|
+
{
|
|
42
|
+
command: '<%= config.bin %> <%= command.id %>',
|
|
43
|
+
description: 'Initialize a new CLI in the current directory',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
command: '<%= config.bin %> <%= command.id %> --output-dir "/path/to/existing/project"',
|
|
47
|
+
description: 'Initialize a new CLI in a different directory',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
command: '<%= config.bin %> <%= command.id %> --topic-separator colons --bin mycli',
|
|
51
|
+
description: 'Supply answers for specific prompts',
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
static flaggablePrompts = FLAGGABLE_PROMPTS;
|
|
55
|
+
static flags = {
|
|
56
|
+
...(0, generator_1.makeFlags)(FLAGGABLE_PROMPTS),
|
|
57
|
+
'output-dir': core_1.Flags.directory({
|
|
58
|
+
char: 'd',
|
|
59
|
+
description: 'Directory to initialize the CLI in.',
|
|
60
|
+
exists: true,
|
|
61
|
+
}),
|
|
62
|
+
yes: core_1.Flags.boolean({
|
|
63
|
+
aliases: ['defaults'],
|
|
64
|
+
char: 'y',
|
|
65
|
+
description: 'Use defaults for all prompts. Individual flags will override defaults.',
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
static summary = 'Initialize a new oclif CLI';
|
|
69
|
+
async run() {
|
|
70
|
+
const outputDir = this.flags['output-dir'] ?? process.cwd();
|
|
71
|
+
const location = (0, node_path_1.resolve)(outputDir);
|
|
72
|
+
this.log(`Initializing oclif in ${(0, ansis_1.green)(location)}`);
|
|
73
|
+
const packageJSON = (await (0, generator_1.readPJSON)(location));
|
|
74
|
+
if (!packageJSON) {
|
|
75
|
+
throw new core_1.Errors.CLIError(`Could not find a package.json file in ${location}`);
|
|
76
|
+
}
|
|
77
|
+
const bin = await this.getFlagOrPrompt({
|
|
78
|
+
defaultValue: location.split(node_path_1.sep).at(-1) || '',
|
|
79
|
+
name: 'bin',
|
|
80
|
+
type: 'input',
|
|
81
|
+
});
|
|
82
|
+
const topicSeparator = await this.getFlagOrPrompt({
|
|
83
|
+
defaultValue: 'spaces',
|
|
84
|
+
name: 'topic-separator',
|
|
85
|
+
type: 'select',
|
|
86
|
+
});
|
|
87
|
+
const moduleType = await this.getFlagOrPrompt({
|
|
88
|
+
defaultValue: packageJSON.type === 'module' ? 'ESM' : 'CommonJS',
|
|
89
|
+
async maybeOtherValue() {
|
|
90
|
+
return packageJSON.type === 'module' ? 'ESM' : packageJSON.type === 'commonjs' ? 'CommonJS' : undefined;
|
|
91
|
+
},
|
|
92
|
+
name: 'module-type',
|
|
93
|
+
type: 'select',
|
|
94
|
+
});
|
|
95
|
+
const packageManager = await this.getFlagOrPrompt({
|
|
96
|
+
defaultValue: 'npm',
|
|
97
|
+
async maybeOtherValue() {
|
|
98
|
+
const rootFiles = await (0, promises_1.readdir)(location);
|
|
99
|
+
if (rootFiles.includes('package-lock.json')) {
|
|
100
|
+
return 'npm';
|
|
101
|
+
}
|
|
102
|
+
if (rootFiles.includes('yarn.lock')) {
|
|
103
|
+
return 'yarn';
|
|
104
|
+
}
|
|
105
|
+
if (rootFiles.includes('pnpm-lock.yaml')) {
|
|
106
|
+
return 'pnpm';
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
name: 'package-manager',
|
|
110
|
+
type: 'select',
|
|
111
|
+
});
|
|
112
|
+
this.log(`Using module type ${(0, ansis_1.green)(moduleType)}`);
|
|
113
|
+
this.log(`Using package manager ${(0, ansis_1.green)(packageManager)}`);
|
|
114
|
+
const projectBinPath = (0, node_path_1.join)(location, 'bin');
|
|
115
|
+
const templateBinPath = (0, node_path_1.join)(this.templatesDir, 'cli', moduleType.toLowerCase(), 'bin');
|
|
116
|
+
await this.template((0, node_path_1.join)(templateBinPath, 'dev.cmd.ejs'), (0, node_path_1.join)(projectBinPath, 'dev.cmd'));
|
|
117
|
+
await this.template((0, node_path_1.join)(templateBinPath, 'dev.js.ejs'), (0, node_path_1.join)(projectBinPath, 'dev.js'));
|
|
118
|
+
await this.template((0, node_path_1.join)(templateBinPath, 'run.cmd.ejs'), (0, node_path_1.join)(projectBinPath, 'run.cmd'));
|
|
119
|
+
await this.template((0, node_path_1.join)(templateBinPath, 'run.js.ejs'), (0, node_path_1.join)(projectBinPath, 'run.js'));
|
|
120
|
+
if (process.platform !== 'win32') {
|
|
121
|
+
await (0, generator_1.exec)(`chmod +x "${(0, node_path_1.join)(projectBinPath, 'run.js')}"`);
|
|
122
|
+
await (0, generator_1.exec)(`chmod +x "${(0, node_path_1.join)(projectBinPath, 'dev.js')}"`);
|
|
123
|
+
}
|
|
124
|
+
const updatedPackageJSON = {
|
|
125
|
+
...packageJSON,
|
|
126
|
+
bin: {
|
|
127
|
+
...packageJSON.bin,
|
|
128
|
+
[bin]: './bin/run.js',
|
|
129
|
+
},
|
|
130
|
+
oclif: {
|
|
131
|
+
bin,
|
|
132
|
+
commands: './dist/commands',
|
|
133
|
+
dirname: bin,
|
|
134
|
+
topicSeparator: topicSeparator === 'colons' ? ':' : ' ',
|
|
135
|
+
...packageJSON.oclif,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(location, 'package.json'), JSON.stringify(updatedPackageJSON, null, 2));
|
|
139
|
+
const installedDeps = Object.keys(packageJSON.dependencies ?? {});
|
|
140
|
+
if (!installedDeps.includes('@oclif/core')) {
|
|
141
|
+
this.log('Installing @oclif/core');
|
|
142
|
+
await (0, generator_1.exec)(`${packageManager} ${packageManager === 'yarn' ? 'add' : 'install'} @oclif/core`, {
|
|
143
|
+
cwd: location,
|
|
144
|
+
silent: false,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const allInstalledDeps = new Set([...installedDeps, ...Object.keys(packageJSON.devDependencies ?? {})]);
|
|
148
|
+
if (!allInstalledDeps.has('ts-node')) {
|
|
149
|
+
this.log('Installing ts-node');
|
|
150
|
+
await (0, generator_1.exec)(`${packageManager} ${packageManager === 'yarn' ? 'add --dev' : 'install --save-dev'} ts-node`, {
|
|
151
|
+
cwd: location,
|
|
152
|
+
silent: false,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!allInstalledDeps.has('@types/node')) {
|
|
156
|
+
this.log('@types/node');
|
|
157
|
+
await (0, generator_1.exec)(`${packageManager} ${packageManager === 'yarn' ? 'add --dev' : 'install --save-dev'} @types/node@^18`, {
|
|
158
|
+
cwd: location,
|
|
159
|
+
silent: false,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
this.log(`\nCreated CLI ${(0, ansis_1.green)(bin)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.default = Generate;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const core_1 = require("@oclif/core");
|
|
37
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
38
|
+
const fileExists = async (path) => {
|
|
39
|
+
try {
|
|
40
|
+
await fs.access(path);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
class Lock extends core_1.Command {
|
|
48
|
+
async run() {
|
|
49
|
+
if (await fileExists('yarn.lock')) {
|
|
50
|
+
this.log('Copying yarn.lock to oclif.lock');
|
|
51
|
+
await fs.copyFile('yarn.lock', 'oclif.lock');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw this.error('yarn.lock does not exist');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
static {
|
|
58
|
+
this.hidden = true;
|
|
59
|
+
this.state = 'deprecated';
|
|
60
|
+
this.summary = 'Copy the yarn.lock to oclif.lock';
|
|
61
|
+
this.deprecationOptions = {
|
|
62
|
+
message: 'oclif.lock is deprecated and will be removed in @oclif/plugin-plugins v5.0.0 and above.',
|
|
63
|
+
};
|
|
64
|
+
this.description = `Using oclif.lock allows your plugins dependencies to be locked to the version specified in the lock file during plugin install.
|
|
65
|
+
Once the oclif.lock file is created you can include it your npm package by adding it to the files property of your package.json. We do not recommend committing the oclif.lock file to git.
|
|
66
|
+
|
|
67
|
+
PLEASE NOTE: the oclif.lock will only work for @oclif/plugin-plugins v3.4.0 and above. It will NOT be supported in v5.0.0 and above.`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.default = Lock;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command, Interfaces } from '@oclif/core';
|
|
2
|
+
export default class Manifest extends Command {
|
|
3
|
+
static args: {
|
|
4
|
+
path: Interfaces.Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static flags: {
|
|
8
|
+
jit: Interfaces.BooleanFlag<boolean>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<Interfaces.Manifest>;
|
|
11
|
+
private downloadTarball;
|
|
12
|
+
private executeCommand;
|
|
13
|
+
}
|