@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,38 @@
|
|
|
1
|
+
import { Command, Config, HelpBase, Interfaces } from '@oclif/core';
|
|
2
|
+
interface HelpBaseDerived {
|
|
3
|
+
new (config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>): HelpBase;
|
|
4
|
+
}
|
|
5
|
+
type Options = {
|
|
6
|
+
aliases?: boolean;
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
multi?: boolean;
|
|
9
|
+
nestedTopicsDepth?: number;
|
|
10
|
+
outputDir: string;
|
|
11
|
+
pluginDir?: string;
|
|
12
|
+
readmePath: string;
|
|
13
|
+
repositoryPrefix?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
};
|
|
16
|
+
export default class ReadmeGenerator {
|
|
17
|
+
private config;
|
|
18
|
+
private options;
|
|
19
|
+
constructor(config: Config, options: Options);
|
|
20
|
+
protected commandCode(c: Command.Cached): string | undefined;
|
|
21
|
+
protected commands(commands: Command.Cached[]): Promise<string>;
|
|
22
|
+
protected createTopicFile(file: string, topic: Interfaces.Topic, commands: Command.Cached[]): Promise<void>;
|
|
23
|
+
generate(): Promise<string>;
|
|
24
|
+
protected multiCommands(commands: Command.Cached[], dir: string, nestedTopicsDepth: number | undefined): Promise<string>;
|
|
25
|
+
protected read(): Promise<string>;
|
|
26
|
+
protected renderCommand(c: Command.Cached, HelpClass: HelpBaseDerived): string;
|
|
27
|
+
protected replaceTag(readme: string, tag: string, body: string): string;
|
|
28
|
+
protected tableOfContents(readme: string): Promise<string>;
|
|
29
|
+
protected usage(): string;
|
|
30
|
+
protected write(file: string, content: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* fetches the path to a command
|
|
33
|
+
*/
|
|
34
|
+
private commandPath;
|
|
35
|
+
private commandUsage;
|
|
36
|
+
private repo;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,305 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const core_1 = require("@oclif/core");
|
|
40
|
+
const debug_1 = __importDefault(require("debug"));
|
|
41
|
+
const ejs_1 = require("ejs");
|
|
42
|
+
const fs = __importStar(require("fs-extra"));
|
|
43
|
+
const promises_1 = require("node:fs/promises");
|
|
44
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
45
|
+
const node_url_1 = require("node:url");
|
|
46
|
+
const normalize_package_data_1 = __importDefault(require("normalize-package-data"));
|
|
47
|
+
const help_compatibility_1 = require("./help-compatibility");
|
|
48
|
+
const columns = Number.parseInt(process.env.COLUMNS, 10) || 120;
|
|
49
|
+
const util_1 = require("./util");
|
|
50
|
+
const debug = (0, debug_1.default)('readme');
|
|
51
|
+
async function slugify(str) {
|
|
52
|
+
const { default: GithubSlugger } = await import('github-slugger');
|
|
53
|
+
const slugify = new GithubSlugger();
|
|
54
|
+
return slugify.slug(str);
|
|
55
|
+
}
|
|
56
|
+
class ReadmeGenerator {
|
|
57
|
+
config;
|
|
58
|
+
options;
|
|
59
|
+
constructor(config, options) {
|
|
60
|
+
this.config = config;
|
|
61
|
+
this.options = options;
|
|
62
|
+
}
|
|
63
|
+
commandCode(c) {
|
|
64
|
+
const pluginName = c.pluginName;
|
|
65
|
+
if (!pluginName)
|
|
66
|
+
return;
|
|
67
|
+
const plugin = this.config.plugins.get(pluginName);
|
|
68
|
+
if (!plugin)
|
|
69
|
+
return;
|
|
70
|
+
const repo = this.repo(plugin);
|
|
71
|
+
if (!repo)
|
|
72
|
+
return;
|
|
73
|
+
let label = plugin.name;
|
|
74
|
+
let version = plugin.version;
|
|
75
|
+
const commandPath = this.commandPath(plugin, c);
|
|
76
|
+
if (!commandPath)
|
|
77
|
+
return;
|
|
78
|
+
if (this.config.name === plugin.name) {
|
|
79
|
+
label = commandPath;
|
|
80
|
+
version = this.options.version || version;
|
|
81
|
+
}
|
|
82
|
+
const template = this.options.repositoryPrefix ||
|
|
83
|
+
plugin.pjson.oclif.repositoryPrefix ||
|
|
84
|
+
'<%- repo %>/blob/v<%- version %>/<%- commandPath %>';
|
|
85
|
+
return `_See code: [${label}](${(0, ejs_1.render)(template, { c, commandPath, config: this.config, repo, version })})_`;
|
|
86
|
+
}
|
|
87
|
+
async commands(commands) {
|
|
88
|
+
const helpClass = await (0, core_1.loadHelpClass)(this.config);
|
|
89
|
+
return [
|
|
90
|
+
...(await Promise.all(commands.map(async (c) => {
|
|
91
|
+
const usage = this.commandUsage(c);
|
|
92
|
+
return usage
|
|
93
|
+
? `* [\`${this.config.bin} ${usage}\`](#${await slugify(`${this.config.bin}-${usage}`)})`
|
|
94
|
+
: `* [\`${this.config.bin}\`](#${await slugify(`${this.config.bin}`)})`;
|
|
95
|
+
}))),
|
|
96
|
+
'',
|
|
97
|
+
...commands.map((c) => this.renderCommand({ ...c }, helpClass)).map((s) => s.trim() + '\n'),
|
|
98
|
+
]
|
|
99
|
+
.join('\n')
|
|
100
|
+
.trim();
|
|
101
|
+
}
|
|
102
|
+
async createTopicFile(file, topic, commands) {
|
|
103
|
+
const bin = `\`${this.config.bin} ${topic.name}\``;
|
|
104
|
+
const doc = [
|
|
105
|
+
bin,
|
|
106
|
+
'='.repeat(bin.length),
|
|
107
|
+
'',
|
|
108
|
+
(0, ejs_1.render)(topic.description || '', { config: this.config }).trim(),
|
|
109
|
+
'',
|
|
110
|
+
await this.commands(commands),
|
|
111
|
+
]
|
|
112
|
+
.join('\n')
|
|
113
|
+
.trim() + '\n';
|
|
114
|
+
await this.write(node_path_1.default.resolve(this.options.pluginDir ?? process.cwd(), file), doc);
|
|
115
|
+
}
|
|
116
|
+
async generate() {
|
|
117
|
+
let readme = await this.read();
|
|
118
|
+
const commands = (0, util_1.uniqBy)(this.config.commands
|
|
119
|
+
.filter((c) => !c.hidden && c.pluginType === 'core')
|
|
120
|
+
.filter((c) => (this.options.aliases ? true : !c.aliases.includes(c.id)))
|
|
121
|
+
.map((c) => (this.config.isSingleCommandCLI ? { ...c, id: '' } : c))
|
|
122
|
+
.sort((a, b) => a.id.localeCompare(b.id)), (c) => c.id);
|
|
123
|
+
debug('commands:', commands.map((c) => c.id).length);
|
|
124
|
+
readme = this.replaceTag(readme, 'usage', this.usage());
|
|
125
|
+
readme = this.replaceTag(readme, 'commands', this.options.multi
|
|
126
|
+
? await this.multiCommands(commands, this.options.outputDir, this.options.nestedTopicsDepth)
|
|
127
|
+
: await this.commands(commands));
|
|
128
|
+
readme = this.replaceTag(readme, 'toc', await this.tableOfContents(readme));
|
|
129
|
+
readme = readme.trimEnd();
|
|
130
|
+
readme += '\n';
|
|
131
|
+
await this.write(this.options.readmePath, readme);
|
|
132
|
+
return readme;
|
|
133
|
+
}
|
|
134
|
+
async multiCommands(commands, dir, nestedTopicsDepth) {
|
|
135
|
+
let topics = this.config.topics;
|
|
136
|
+
topics = nestedTopicsDepth
|
|
137
|
+
? topics.filter((t) => !t.hidden && (t.name.match(/:/g) || []).length < nestedTopicsDepth)
|
|
138
|
+
: topics.filter((t) => !t.hidden && !t.name.includes(':'));
|
|
139
|
+
topics = topics.filter((t) => commands.find((c) => c.id.startsWith(t.name)));
|
|
140
|
+
topics = (0, util_1.uniqBy)((0, util_1.sortBy)(topics, (t) => t.name), (t) => t.name);
|
|
141
|
+
for (const topic of topics) {
|
|
142
|
+
// eslint-disable-next-line no-await-in-loop
|
|
143
|
+
await this.createTopicFile(node_path_1.default.join('.', dir, topic.name.replaceAll(':', '/') + '.md'), topic, commands.filter((c) => c.id === topic.name || c.id.startsWith(topic.name + ':')));
|
|
144
|
+
}
|
|
145
|
+
return ([
|
|
146
|
+
'# Command Topics\n',
|
|
147
|
+
...topics.map((t) => (0, util_1.compact)([
|
|
148
|
+
`* [\`${this.config.bin} ${t.name.replaceAll(':', this.config.topicSeparator)}\`](${dir}/${t.name.replaceAll(':', '/')}.md)`,
|
|
149
|
+
(0, ejs_1.render)(t.description || '', { config: this.config })
|
|
150
|
+
.trim()
|
|
151
|
+
.split('\n')[0],
|
|
152
|
+
]).join(' - ')),
|
|
153
|
+
]
|
|
154
|
+
.join('\n')
|
|
155
|
+
.trim() + '\n');
|
|
156
|
+
}
|
|
157
|
+
async read() {
|
|
158
|
+
return (0, promises_1.readFile)(this.options.readmePath, 'utf8');
|
|
159
|
+
}
|
|
160
|
+
renderCommand(c, HelpClass) {
|
|
161
|
+
debug('rendering command', c.id);
|
|
162
|
+
const title = (0, ejs_1.render)(c.summary ?? c.description ?? '', { command: c, config: this.config })
|
|
163
|
+
.trim()
|
|
164
|
+
.split('\n')[0];
|
|
165
|
+
const help = new HelpClass(this.config, { maxWidth: columns, respectNoCacheDefault: true, stripAnsi: true });
|
|
166
|
+
const wrapper = new help_compatibility_1.HelpCompatibilityWrapper(help);
|
|
167
|
+
const header = () => {
|
|
168
|
+
const usage = this.commandUsage(c);
|
|
169
|
+
return usage ? `## \`${this.config.bin} ${usage}\`` : `## \`${this.config.bin}\``;
|
|
170
|
+
};
|
|
171
|
+
try {
|
|
172
|
+
// copy c to keep the command ID with colons, see:
|
|
173
|
+
// https://github.com/oclif/oclif/pull/1165#discussion_r1282305242
|
|
174
|
+
const command = { ...c };
|
|
175
|
+
return (0, util_1.compact)([
|
|
176
|
+
header(),
|
|
177
|
+
title,
|
|
178
|
+
'```\n' + wrapper.formatCommand(c).trim() + '\n```',
|
|
179
|
+
this.commandCode(command),
|
|
180
|
+
]).join('\n\n');
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
const { message } = error;
|
|
184
|
+
core_1.ux.error(message);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
replaceTag(readme, tag, body) {
|
|
188
|
+
if (readme.includes(`<!-- ${tag} -->`)) {
|
|
189
|
+
if (readme.includes(`<!-- ${tag}stop -->`)) {
|
|
190
|
+
readme = readme.replace(new RegExp(`<!-- ${tag} -->(.|\n)*<!-- ${tag}stop -->`, 'm'), `<!-- ${tag} -->`);
|
|
191
|
+
}
|
|
192
|
+
core_1.ux.stdout(`replacing <!-- ${tag} --> in ${this.options.readmePath}`);
|
|
193
|
+
}
|
|
194
|
+
return readme.replace(`<!-- ${tag} -->`, `<!-- ${tag} -->\n${body}\n<!-- ${tag}stop -->`);
|
|
195
|
+
}
|
|
196
|
+
async tableOfContents(readme) {
|
|
197
|
+
const toc = await Promise.all(readme
|
|
198
|
+
.split('\n')
|
|
199
|
+
.filter((l) => l.startsWith('# '))
|
|
200
|
+
.map((l) => l.trim().slice(2))
|
|
201
|
+
.map(async (l) => `* [${l}](#${await slugify(l)})`));
|
|
202
|
+
return toc.join('\n');
|
|
203
|
+
}
|
|
204
|
+
usage() {
|
|
205
|
+
const versionFlags = ['--version', ...(this.config.pjson.oclif.additionalVersionFlags ?? []).sort()];
|
|
206
|
+
const versionFlagsString = `(${versionFlags.join('|')})`;
|
|
207
|
+
return [
|
|
208
|
+
`\`\`\`sh-session
|
|
209
|
+
$ npm install -g ${this.config.name}
|
|
210
|
+
$ ${this.config.bin} COMMAND
|
|
211
|
+
running command...
|
|
212
|
+
$ ${this.config.bin} ${versionFlagsString}
|
|
213
|
+
${this.config.name}/${this.options.version || this.config.version} ${process.platform}-${process.arch} node-v${process.versions.node}
|
|
214
|
+
$ ${this.config.bin} --help [COMMAND]
|
|
215
|
+
USAGE
|
|
216
|
+
$ ${this.config.bin} COMMAND
|
|
217
|
+
...
|
|
218
|
+
\`\`\`\n`,
|
|
219
|
+
]
|
|
220
|
+
.join('\n')
|
|
221
|
+
.trim();
|
|
222
|
+
}
|
|
223
|
+
async write(file, content) {
|
|
224
|
+
if (!this.options.dryRun)
|
|
225
|
+
await fs.outputFile(file, content);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* fetches the path to a command
|
|
229
|
+
*/
|
|
230
|
+
// eslint-disable-next-line complexity
|
|
231
|
+
commandPath(plugin, c) {
|
|
232
|
+
const strategy = typeof plugin.pjson.oclif?.commands === 'string' ? 'pattern' : plugin.pjson.oclif?.commands?.strategy;
|
|
233
|
+
// if the strategy is explicit, we can't determine the path so return undefined
|
|
234
|
+
if (strategy === 'explicit')
|
|
235
|
+
return;
|
|
236
|
+
const commandsDir = typeof plugin.pjson.oclif?.commands === 'string'
|
|
237
|
+
? plugin.pjson.oclif?.commands
|
|
238
|
+
: plugin.pjson.oclif?.commands?.target;
|
|
239
|
+
if (!commandsDir)
|
|
240
|
+
return;
|
|
241
|
+
const hasTypescript = plugin.pjson.devDependencies?.typescript || plugin.pjson.dependencies?.typescript;
|
|
242
|
+
let p = node_path_1.default.join(plugin.root, commandsDir, ...c.id.split(':'));
|
|
243
|
+
const outDir = node_path_1.default.dirname(commandsDir.replace(/^.\/|.\\/, '')); // remove leading ./ or .\ from path
|
|
244
|
+
const outDirRegex = new RegExp('^' + outDir + (node_path_1.default.sep === '\\' ? '\\\\' : node_path_1.default.sep));
|
|
245
|
+
if (fs.pathExistsSync(node_path_1.default.join(p, 'index.js'))) {
|
|
246
|
+
p = node_path_1.default.join(p, 'index.js');
|
|
247
|
+
}
|
|
248
|
+
else if (fs.pathExistsSync(p + '.js')) {
|
|
249
|
+
p += '.js';
|
|
250
|
+
}
|
|
251
|
+
else if (hasTypescript) {
|
|
252
|
+
// check if non-compiled scripts are available
|
|
253
|
+
const base = p.replace(plugin.root + node_path_1.default.sep, '');
|
|
254
|
+
p = node_path_1.default.join(plugin.root, base.replace(outDirRegex, 'src' + node_path_1.default.sep));
|
|
255
|
+
if (fs.pathExistsSync(node_path_1.default.join(p, 'index.ts'))) {
|
|
256
|
+
p = node_path_1.default.join(p, 'index.ts');
|
|
257
|
+
}
|
|
258
|
+
else if (fs.pathExistsSync(p + '.ts')) {
|
|
259
|
+
p += '.ts';
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
return;
|
|
266
|
+
p = p.replace(plugin.root + node_path_1.default.sep, '');
|
|
267
|
+
if (hasTypescript) {
|
|
268
|
+
p = p.replace(outDirRegex, 'src' + node_path_1.default.sep).replace(/\.js$/, '.ts');
|
|
269
|
+
}
|
|
270
|
+
p = p.replaceAll('\\', '/'); // Replace windows '\' by '/'
|
|
271
|
+
return p;
|
|
272
|
+
}
|
|
273
|
+
commandUsage(command) {
|
|
274
|
+
const arg = (arg) => {
|
|
275
|
+
const name = arg.name.toUpperCase();
|
|
276
|
+
if (arg.required)
|
|
277
|
+
return `${name}`;
|
|
278
|
+
return `[${name}]`;
|
|
279
|
+
};
|
|
280
|
+
const id = (0, core_1.toConfiguredId)(command.id, this.config);
|
|
281
|
+
const defaultUsage = () => (0, util_1.compact)([
|
|
282
|
+
id,
|
|
283
|
+
Object.values(command.args)
|
|
284
|
+
.filter((a) => !a.hidden)
|
|
285
|
+
.map((a) => arg(a))
|
|
286
|
+
.join(' '),
|
|
287
|
+
]).join(' ');
|
|
288
|
+
const usages = (0, util_1.castArray)(command.usage);
|
|
289
|
+
return (0, ejs_1.render)(usages.length === 0 ? defaultUsage() : usages[0], { command, config: this.config });
|
|
290
|
+
}
|
|
291
|
+
repo(plugin) {
|
|
292
|
+
const pjson = { ...plugin.pjson };
|
|
293
|
+
(0, normalize_package_data_1.default)(pjson);
|
|
294
|
+
const repo = pjson.repository && pjson.repository.url;
|
|
295
|
+
if (!repo)
|
|
296
|
+
return;
|
|
297
|
+
const url = new node_url_1.URL(repo);
|
|
298
|
+
if (!['github.com', 'gitlab.com'].includes(url.hostname) &&
|
|
299
|
+
!pjson.oclif.repositoryPrefix &&
|
|
300
|
+
!this.options.repositoryPrefix)
|
|
301
|
+
return;
|
|
302
|
+
return `https://${url.hostname}${url.pathname.replace(/\.git$/, '')}`;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.default = ReadmeGenerator;
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.writeBinScripts = writeBinScripts;
|
|
40
|
+
const node_child_process_1 = require("node:child_process");
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
+
const node_util_1 = require("node:util");
|
|
44
|
+
const exec = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
45
|
+
async function writeBinScripts({ baseWorkspace, config, nodeOptions, nodeVersion, }) {
|
|
46
|
+
const binPathEnvVar = config.scopedEnvVarKey('BINPATH');
|
|
47
|
+
const redirectedEnvVar = config.scopedEnvVarKey('REDIRECTED');
|
|
48
|
+
const clientHomeEnvVar = config.scopedEnvVarKey('OCLIF_CLIENT_HOME');
|
|
49
|
+
const writeWin32 = async (bin) => {
|
|
50
|
+
await fs.promises.writeFile(node_path_1.default.join(baseWorkspace, 'bin', `${bin}.cmd`), `@echo off
|
|
51
|
+
setlocal enableextensions
|
|
52
|
+
|
|
53
|
+
if not "%${redirectedEnvVar}%"=="1" if exist "%LOCALAPPDATA%\\${bin}\\client\\bin\\${bin}.cmd" (
|
|
54
|
+
set ${redirectedEnvVar}=1
|
|
55
|
+
"%LOCALAPPDATA%\\${bin}\\client\\bin\\${bin}.cmd" %*
|
|
56
|
+
goto:EOF
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if not defined ${binPathEnvVar} set ${binPathEnvVar}="%~dp0${bin}.cmd"
|
|
60
|
+
|
|
61
|
+
if exist "%~dp0..\\bin\\node.exe" (
|
|
62
|
+
"%~dp0..\\bin\\node.exe" ${`${nodeOptions.join(' ')} `}"%~dp0..\\bin\\run" %*
|
|
63
|
+
) else if exist "%LOCALAPPDATA%\\oclif\\node\\node-${nodeVersion}.exe" (
|
|
64
|
+
"%LOCALAPPDATA%\\oclif\\node\\node-${nodeVersion}.exe" ${`${nodeOptions.join(' ')} `}"%~dp0..\\bin\\run" %*
|
|
65
|
+
) else (
|
|
66
|
+
node ${`${nodeOptions.join(' ')} `}"%~dp0..\\bin\\run" %*
|
|
67
|
+
)
|
|
68
|
+
`);
|
|
69
|
+
};
|
|
70
|
+
const writeUnix = async () => {
|
|
71
|
+
const bin = node_path_1.default.join(baseWorkspace, 'bin', config.bin);
|
|
72
|
+
await fs.promises.writeFile(bin, `#!/usr/bin/env bash
|
|
73
|
+
set -e
|
|
74
|
+
echoerr() { echo "$@" 1>&2; }
|
|
75
|
+
|
|
76
|
+
get_script_dir () {
|
|
77
|
+
SOURCE="\${BASH_SOURCE[0]}"
|
|
78
|
+
# While \$SOURCE is a symlink, resolve it
|
|
79
|
+
while [ -h "\$SOURCE" ]; do
|
|
80
|
+
DIR="\$( cd -P "\$( dirname "\$SOURCE" )" && pwd )"
|
|
81
|
+
SOURCE="\$( readlink "\$SOURCE" )"
|
|
82
|
+
# If \$SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory
|
|
83
|
+
[[ \$SOURCE != /* ]] && SOURCE="\$DIR/\$SOURCE"
|
|
84
|
+
done
|
|
85
|
+
DIR="\$( cd -P "\$( dirname "\$SOURCE" )" && pwd )"
|
|
86
|
+
echo "\$DIR"
|
|
87
|
+
}
|
|
88
|
+
DIR=\$(get_script_dir)
|
|
89
|
+
CLI_HOME=\$(cd && pwd)
|
|
90
|
+
XDG_DATA_HOME=\${XDG_DATA_HOME:="\$CLI_HOME/.local/share"}
|
|
91
|
+
CLIENT_HOME=\${${clientHomeEnvVar}:=$XDG_DATA_HOME/${config.dirname}/client}
|
|
92
|
+
BIN_PATH="\$CLIENT_HOME/bin/${config.bin}"
|
|
93
|
+
if [ -z "\$${redirectedEnvVar}" ] && [ -x "\$BIN_PATH" ] && [[ ! "\$DIR/${config.bin}" -ef "\$BIN_PATH" ]]; then
|
|
94
|
+
if [ "\$DEBUG" == "*" ]; then
|
|
95
|
+
echoerr "\$BIN_PATH" "\$@"
|
|
96
|
+
fi
|
|
97
|
+
${binPathEnvVar}="\$BIN_PATH" ${redirectedEnvVar}=1 "\$BIN_PATH" "\$@"
|
|
98
|
+
else
|
|
99
|
+
export ${binPathEnvVar}=\${${binPathEnvVar}:="\$DIR/${config.bin}"}
|
|
100
|
+
if [ -x "$(command -v "\$XDG_DATA_HOME/oclif/node/node-custom")" ]; then
|
|
101
|
+
NODE="\$XDG_DATA_HOME/oclif/node/node-custom"
|
|
102
|
+
elif [ -x "$(command -v "\$DIR/node")" ]; then
|
|
103
|
+
NODE="\$DIR/node"
|
|
104
|
+
elif [ -x "$(command -v "\$XDG_DATA_HOME/oclif/node/node-${nodeVersion}")" ]; then
|
|
105
|
+
NODE="\$XDG_DATA_HOME/oclif/node/node-${nodeVersion}"
|
|
106
|
+
elif [ -x "$(command -v node)" ]; then
|
|
107
|
+
NODE=node
|
|
108
|
+
else
|
|
109
|
+
echoerr 'Error: node is not installed.' >&2
|
|
110
|
+
exit 1
|
|
111
|
+
fi
|
|
112
|
+
if [ "\$DEBUG" == "*" ]; then
|
|
113
|
+
echoerr ${binPathEnvVar}="\$${binPathEnvVar}" "\$NODE" ${`${nodeOptions.join(' ')} `}"\$DIR/run" "\$@"
|
|
114
|
+
fi
|
|
115
|
+
"\$NODE" ${`${nodeOptions.join(' ')} `}"\$DIR/run" "\$@"
|
|
116
|
+
fi
|
|
117
|
+
`, { mode: 0o755 });
|
|
118
|
+
};
|
|
119
|
+
await Promise.all([
|
|
120
|
+
writeWin32(config.bin),
|
|
121
|
+
writeUnix(),
|
|
122
|
+
...(config.binAliases?.map((alias) => process.platform === 'win32'
|
|
123
|
+
? writeWin32(alias)
|
|
124
|
+
: exec(`ln -sf ${config.bin} ${alias}`, { cwd: node_path_1.default.join(baseWorkspace, 'bin') })) ?? []),
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BuildConfig } from './config';
|
|
2
|
+
type BuildOptions = {
|
|
3
|
+
pack?: boolean;
|
|
4
|
+
parallel?: boolean;
|
|
5
|
+
platform?: string;
|
|
6
|
+
pruneLockfiles?: boolean;
|
|
7
|
+
tarball?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function build(c: BuildConfig, options?: BuildOptions): Promise<void>;
|
|
10
|
+
export {};
|