@travetto/pack 3.0.0 → 3.0.1-rc.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/package.json +3 -3
- package/support/bin/docker-operation.ts +10 -13
- package/support/bin/operation.ts +28 -31
- package/support/bin/shell.ts +2 -0
- package/support/bin/types.ts +2 -1
- package/support/pack.base.ts +20 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/pack",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1-rc.1",
|
|
4
4
|
"description": "Code packing utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"travetto",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"@rollup/plugin-json": "^6.0.0",
|
|
29
29
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
30
30
|
"@rollup/plugin-terser": "^0.4.0",
|
|
31
|
-
"@travetto/base": "^3.0.
|
|
31
|
+
"@travetto/base": "^3.0.1-rc.1",
|
|
32
32
|
"rollup": "^3.17.2",
|
|
33
33
|
"rollup-plugin-sourcemaps": "^0.6.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/cli": "^3.0.
|
|
36
|
+
"@travetto/cli": "^3.0.1-rc.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
39
|
"@travetto/cli": {
|
|
@@ -6,6 +6,7 @@ import { cliTpl } from '@travetto/cli';
|
|
|
6
6
|
|
|
7
7
|
import { ActiveShellCommand } from './shell';
|
|
8
8
|
import { DockerPackConfig, DockerPackFactoryModule } from './types';
|
|
9
|
+
import { PackOperation } from './operation';
|
|
9
10
|
|
|
10
11
|
export class DockerPackOperation {
|
|
11
12
|
|
|
@@ -18,7 +19,7 @@ export class DockerPackOperation {
|
|
|
18
19
|
*/
|
|
19
20
|
static async* writeDockerFile(cfg: DockerPackConfig): AsyncIterable<string[]> {
|
|
20
21
|
const dockerFile = path.resolve(cfg.workspace, 'Dockerfile');
|
|
21
|
-
|
|
22
|
+
|
|
22
23
|
const factory = RootIndex.getFromImport(cfg.dockerFactory);
|
|
23
24
|
if (!factory) {
|
|
24
25
|
throw new Error(`Unable to resolve docker factory at ${cfg.dockerFactory}`);
|
|
@@ -26,11 +27,11 @@ export class DockerPackOperation {
|
|
|
26
27
|
const mod: DockerPackFactoryModule = await import(factory.import);
|
|
27
28
|
const content = (await mod.factory(cfg)).trim();
|
|
28
29
|
|
|
30
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Generating Docker File' }} ${{ path: dockerFile }} ${{ param: cfg.dockerFactory }}`);
|
|
31
|
+
|
|
29
32
|
if (cfg.ejectFile) {
|
|
30
|
-
yield ActiveShellCommand.comment(title);
|
|
31
33
|
yield* ActiveShellCommand.createFile(dockerFile, content.split(/\n/));
|
|
32
34
|
} else {
|
|
33
|
-
yield [title];
|
|
34
35
|
await fs.writeFile(dockerFile, content, 'utf8');
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -39,15 +40,13 @@ export class DockerPackOperation {
|
|
|
39
40
|
* Pull Docker Base Image
|
|
40
41
|
*/
|
|
41
42
|
static async* pullDockerBaseImage(cfg: DockerPackConfig): AsyncIterable<string[]> {
|
|
42
|
-
const title = cliTpl`${{ title: 'Pulling Docker Base Image' }} ${{ param: cfg.dockerImage }}`;
|
|
43
|
-
|
|
44
43
|
const command = ['docker', 'pull', cfg.dockerImage];
|
|
45
44
|
|
|
45
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Pulling Docker Base Image' }} ${{ param: cfg.dockerImage }}`);
|
|
46
|
+
|
|
46
47
|
if (cfg.ejectFile) {
|
|
47
|
-
yield ActiveShellCommand.comment(title);
|
|
48
48
|
yield command;
|
|
49
49
|
} else {
|
|
50
|
-
yield [title];
|
|
51
50
|
await ExecUtil.spawn(command[0], command.slice(1), {}).result;
|
|
52
51
|
}
|
|
53
52
|
}
|
|
@@ -56,16 +55,15 @@ export class DockerPackOperation {
|
|
|
56
55
|
* Building Docker Container
|
|
57
56
|
*/
|
|
58
57
|
static async* buildDockerContainer(cfg: DockerPackConfig): AsyncIterable<string[]> {
|
|
59
|
-
const title = cliTpl`${{ title: 'Building Docker Container' }} ${{ param: cfg.dockerTag?.join(',') }}`;
|
|
60
58
|
const cmd = ['docker', 'build', ...DockerPackOperation.getDockerTags(cfg).flatMap(x => ['-t', x]), '.'];
|
|
61
59
|
|
|
60
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Building Docker Container' }} ${{ param: cfg.dockerTag?.join(',') }}`);
|
|
61
|
+
|
|
62
62
|
if (cfg.ejectFile) {
|
|
63
|
-
yield ActiveShellCommand.comment(title);
|
|
64
63
|
yield ActiveShellCommand.chdir(cfg.workspace);
|
|
65
64
|
yield cmd;
|
|
66
65
|
yield ActiveShellCommand.chdir(path.cwd());
|
|
67
66
|
} else {
|
|
68
|
-
yield [title];
|
|
69
67
|
await ExecUtil.spawn(cmd[0], cmd.slice(1), { cwd: cfg.workspace, stdio: [0, 'pipe', 2] }).result;
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -78,16 +76,15 @@ export class DockerPackOperation {
|
|
|
78
76
|
return;
|
|
79
77
|
}
|
|
80
78
|
const tags = DockerPackOperation.getDockerTags(cfg);
|
|
81
|
-
const title = cliTpl`${{ title: 'Push Container to registry' }} ${{ param: cfg.dockerRegistry }}`;
|
|
82
79
|
const cmd = ['docker', 'image', 'push'];
|
|
83
80
|
|
|
81
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Push Container to registry' }} ${{ param: cfg.dockerRegistry }}`);
|
|
82
|
+
|
|
84
83
|
if (cfg.ejectFile) {
|
|
85
|
-
yield ActiveShellCommand.comment(title);
|
|
86
84
|
for (const tag of tags) {
|
|
87
85
|
yield [...cmd, tag];
|
|
88
86
|
}
|
|
89
87
|
} else {
|
|
90
|
-
yield [title];
|
|
91
88
|
for (const tag of tags) {
|
|
92
89
|
await ExecUtil.spawn(cmd[0], [...cmd.slice(1), tag], { stdio: [0, 'pipe', 2] }).result;
|
|
93
90
|
}
|
package/support/bin/operation.ts
CHANGED
|
@@ -14,6 +14,15 @@ async function writeRawFile(file: string, contents: string, mode?: string): Prom
|
|
|
14
14
|
|
|
15
15
|
export class PackOperation {
|
|
16
16
|
|
|
17
|
+
static async * title(cfg: CommonPackConfig, title: string): AsyncIterable<string[]> {
|
|
18
|
+
if (cfg.ejectFile) {
|
|
19
|
+
yield ActiveShellCommand.comment(title);
|
|
20
|
+
yield ActiveShellCommand.echo(title);
|
|
21
|
+
} else {
|
|
22
|
+
yield [title];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
/**
|
|
18
27
|
* Clean out pack workspace, removing all content
|
|
19
28
|
*/
|
|
@@ -22,17 +31,15 @@ export class PackOperation {
|
|
|
22
31
|
return;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Cleaning Output' }} ${{ path: cfg.workspace }}`);
|
|
26
35
|
|
|
27
36
|
if (cfg.ejectFile) {
|
|
28
|
-
yield ActiveShellCommand.comment(title);
|
|
29
37
|
yield ActiveShellCommand.rmRecursive(cfg.workspace);
|
|
30
38
|
if (cfg.output) {
|
|
31
39
|
yield ActiveShellCommand.rmRecursive(cfg.output);
|
|
32
40
|
}
|
|
33
41
|
yield ActiveShellCommand.mkdir(cfg.workspace);
|
|
34
42
|
} else {
|
|
35
|
-
yield [title];
|
|
36
43
|
await fs.rm(cfg.workspace, { recursive: true, force: true });
|
|
37
44
|
if (cfg.output) {
|
|
38
45
|
await fs.rm(cfg.output, { recursive: true, force: true });
|
|
@@ -49,9 +56,10 @@ export class PackOperation {
|
|
|
49
56
|
|
|
50
57
|
const bundleCommand = ['npx', 'rollup', '-c', 'node_modules/@travetto/pack/support/bin/rollup.js'];
|
|
51
58
|
|
|
59
|
+
const entryPointFile = RootIndex.getFromImport(cfg.entryPoint)!.outputFile.split(`${RootIndex.manifest.outputFolder}/`)[1];
|
|
60
|
+
|
|
52
61
|
const env = Object.fromEntries(([
|
|
53
|
-
['BUNDLE_ENTRY',
|
|
54
|
-
['BUNDLE_ENTRY_NAME', cfg.entryCommand],
|
|
62
|
+
['BUNDLE_ENTRY', entryPointFile],
|
|
55
63
|
['BUNDLE_COMPRESS', cfg.minify],
|
|
56
64
|
['BUNDLE_SOURCEMAP', cfg.sourcemap],
|
|
57
65
|
['BUNDLE_SOURCES', cfg.includeSources],
|
|
@@ -66,10 +74,9 @@ export class PackOperation {
|
|
|
66
74
|
const props = (['minify', 'sourcemap', 'entryPoint'] as const)
|
|
67
75
|
.map(k => cliTpl`${{ subtitle: k }}=${{ param: cfg[k] }}`).join(' ');
|
|
68
76
|
|
|
69
|
-
|
|
77
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Bundling Output' }} ${props}`);
|
|
70
78
|
|
|
71
79
|
if (cfg.ejectFile) {
|
|
72
|
-
yield ActiveShellCommand.comment(title);
|
|
73
80
|
yield* Object.entries(env).filter(x => !!x[1]).map(x =>
|
|
74
81
|
ActiveShellCommand.export(x[0], x[1])
|
|
75
82
|
);
|
|
@@ -77,7 +84,6 @@ export class PackOperation {
|
|
|
77
84
|
yield bundleCommand;
|
|
78
85
|
yield ActiveShellCommand.chdir(path.cwd());
|
|
79
86
|
} else {
|
|
80
|
-
yield [title];
|
|
81
87
|
await ExecUtil.spawn(bundleCommand[0], bundleCommand.slice(1), { cwd, env, stdio: ['inherit', 'pipe', 'pipe'] }).result;
|
|
82
88
|
}
|
|
83
89
|
}
|
|
@@ -87,17 +93,16 @@ export class PackOperation {
|
|
|
87
93
|
*/
|
|
88
94
|
static async * writePackageJson(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
89
95
|
const file = 'package.json';
|
|
90
|
-
const title = cliTpl`${{ title: 'Writing' }} ${{ path: file }}`;
|
|
91
96
|
const pkg = { type: RootIndex.manifest.moduleType };
|
|
92
97
|
|
|
98
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
|
|
99
|
+
|
|
93
100
|
if (cfg.ejectFile) {
|
|
94
|
-
yield ActiveShellCommand.comment(title);
|
|
95
101
|
yield* ActiveShellCommand.createFile(
|
|
96
102
|
path.resolve(cfg.workspace, file),
|
|
97
103
|
[JSON.stringify(pkg)]
|
|
98
104
|
);
|
|
99
105
|
} else {
|
|
100
|
-
yield [title];
|
|
101
106
|
await writeRawFile(
|
|
102
107
|
path.resolve(cfg.workspace, file),
|
|
103
108
|
JSON.stringify(pkg, null, 2)
|
|
@@ -110,20 +115,19 @@ export class PackOperation {
|
|
|
110
115
|
*/
|
|
111
116
|
static async * writeEnv(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
112
117
|
const file = '.env.js';
|
|
113
|
-
const title = cliTpl`${{ title: 'Writing' }} ${{ path: file }}`;
|
|
114
118
|
const env = {
|
|
115
119
|
TRV_MANIFEST: `node_modules/${cfg.module}`,
|
|
116
120
|
TRV_CLI_IPC: ''
|
|
117
121
|
};
|
|
118
122
|
|
|
123
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
|
|
124
|
+
|
|
119
125
|
if (cfg.ejectFile) {
|
|
120
|
-
yield ActiveShellCommand.comment(title);
|
|
121
126
|
yield* ActiveShellCommand.createFile(
|
|
122
127
|
path.resolve(cfg.workspace, file),
|
|
123
128
|
PackUtil.buildEnvJS(env)
|
|
124
129
|
);
|
|
125
130
|
} else {
|
|
126
|
-
yield [title];
|
|
127
131
|
await writeRawFile(
|
|
128
132
|
path.resolve(cfg.workspace, file),
|
|
129
133
|
PackUtil.buildEnvJS(env).join('\n')
|
|
@@ -144,18 +148,18 @@ export class PackOperation {
|
|
|
144
148
|
text: [
|
|
145
149
|
ShellCommands[type].scriptOpen(),
|
|
146
150
|
ShellCommands[type].chdirScript(),
|
|
147
|
-
ShellCommands[type].callCommandWithAllArgs('node', cfg.
|
|
151
|
+
ShellCommands[type].callCommandWithAllArgs('node', cfg.entrySource, ...cfg.entryArguments),
|
|
148
152
|
].map(x => x.join(' '))
|
|
149
153
|
}));
|
|
150
154
|
|
|
151
155
|
if (cfg.ejectFile) {
|
|
152
156
|
for (const { fileTitle, text, file } of files) {
|
|
153
|
-
yield
|
|
157
|
+
yield* PackOperation.title(cfg, fileTitle);
|
|
154
158
|
yield* ActiveShellCommand.createFile(path.resolve(cfg.workspace, file), text, '755');
|
|
155
159
|
}
|
|
156
160
|
} else {
|
|
157
161
|
for (const { fileTitle, text, file } of files) {
|
|
158
|
-
yield
|
|
162
|
+
yield* PackOperation.title(cfg, fileTitle);
|
|
159
163
|
await writeRawFile(path.resolve(cfg.workspace, file), text.join('\n'), '755');
|
|
160
164
|
}
|
|
161
165
|
}
|
|
@@ -180,10 +184,9 @@ export class PackOperation {
|
|
|
180
184
|
destFolder: path.resolve(cfg.workspace, mod.outputFolder)
|
|
181
185
|
}));
|
|
182
186
|
|
|
183
|
-
|
|
187
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Copying over resources' }}`);
|
|
184
188
|
|
|
185
189
|
if (cfg.ejectFile) {
|
|
186
|
-
yield ActiveShellCommand.comment(title);
|
|
187
190
|
yield* copyFiles.flatMap(mod => [
|
|
188
191
|
ActiveShellCommand.mkdir(path.dirname(mod.dest)),
|
|
189
192
|
ActiveShellCommand.copy(mod.src, mod.dest)
|
|
@@ -192,8 +195,6 @@ export class PackOperation {
|
|
|
192
195
|
yield ActiveShellCommand.copyRecursive(resources.src, path.resolve(cfg.workspace, 'resources'));
|
|
193
196
|
}
|
|
194
197
|
} else {
|
|
195
|
-
yield [title];
|
|
196
|
-
|
|
197
198
|
for (const { src, dest, destFolder } of copyFiles) {
|
|
198
199
|
await fs.mkdir(destFolder, { recursive: true });
|
|
199
200
|
await fs.copyFile(src, dest);
|
|
@@ -210,24 +211,22 @@ export class PackOperation {
|
|
|
210
211
|
* Generate the trv-app-cache.json for @travetto/app, which is needed for 'running' programs
|
|
211
212
|
*/
|
|
212
213
|
static async * primeAppCache(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
213
|
-
const isRun = cfg.
|
|
214
|
+
const isRun = /entry[.]cli/.test(cfg.entryPoint) && cfg.entryArguments.filter(x => !x.startsWith('-'))[0] === 'run';
|
|
214
215
|
if (!isRun) {
|
|
215
216
|
return;
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
const appCacheCmd = ['npx', 'trv', 'main', '@travetto/app/support/bin/list'];
|
|
219
220
|
const sub = path.join(RootIndex.manifest.modules[RootIndex.mainModule.name].outputFolder, 'trv-app-cache.json');
|
|
220
|
-
const title = cliTpl`${{ title: 'Generating App Cache' }} ${{ path: sub }}`;
|
|
221
221
|
const env = { DEBUG: '0', TRV_MODULE: cfg.module };
|
|
222
222
|
const appCache = path.resolve(cfg.workspace, sub);
|
|
223
223
|
|
|
224
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Generating App Cache' }} ${{ path: sub }}`);
|
|
224
225
|
|
|
225
226
|
if (cfg.ejectFile) {
|
|
226
|
-
yield ActiveShellCommand.comment(title);
|
|
227
227
|
yield ActiveShellCommand.mkdir(path.dirname(appCache));
|
|
228
228
|
yield [...Object.entries(env).map(x => `${x[0]}=${x[1]}`), ...appCacheCmd, '>', appCache];
|
|
229
229
|
} else {
|
|
230
|
-
yield [title];
|
|
231
230
|
const { stdout } = await ExecUtil.spawn(appCacheCmd[0], appCacheCmd.slice(1), { env }).result;
|
|
232
231
|
|
|
233
232
|
await fs.mkdir(path.dirname(appCache), { recursive: true });
|
|
@@ -242,13 +241,12 @@ export class PackOperation {
|
|
|
242
241
|
const out = path.resolve(cfg.workspace, 'node_modules', cfg.module);
|
|
243
242
|
const cmd = ['npx', 'trv', 'manifest', out, 'prod'];
|
|
244
243
|
const env = { TRV_MODULE: cfg.module };
|
|
245
|
-
|
|
244
|
+
|
|
245
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing Manifest' }} ${{ path: path.join('node_modules', cfg.module) }}`);
|
|
246
246
|
|
|
247
247
|
if (cfg.ejectFile) {
|
|
248
|
-
yield ActiveShellCommand.comment(title);
|
|
249
248
|
yield [...Object.entries(env).map(([k, v]) => `${k}=${v}`), ...cmd];
|
|
250
249
|
} else {
|
|
251
|
-
yield [title];
|
|
252
250
|
await ExecUtil.spawn(cmd[0], cmd.slice(1), { env, stdio: ['inherit', 'ignore', 'inherit'] }).result;
|
|
253
251
|
}
|
|
254
252
|
}
|
|
@@ -257,15 +255,14 @@ export class PackOperation {
|
|
|
257
255
|
* Generate ZIP file for workspace
|
|
258
256
|
*/
|
|
259
257
|
static async * compress(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
260
|
-
|
|
258
|
+
|
|
259
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Compressing' }} ${{ path: cfg.output }}`);
|
|
261
260
|
|
|
262
261
|
if (cfg.ejectFile) {
|
|
263
|
-
yield ActiveShellCommand.comment(title);
|
|
264
262
|
yield ActiveShellCommand.chdir(cfg.workspace);
|
|
265
263
|
yield ActiveShellCommand.zip(cfg.output);
|
|
266
264
|
yield ActiveShellCommand.chdir(path.cwd());
|
|
267
265
|
} else {
|
|
268
|
-
yield [title];
|
|
269
266
|
const [cmd, ...args] = ActiveShellCommand.zip(cfg.output);
|
|
270
267
|
await ExecUtil.spawn(cmd, args, { cwd: cfg.workspace }).result;
|
|
271
268
|
}
|
package/support/bin/shell.ts
CHANGED
|
@@ -27,6 +27,7 @@ export const ShellCommands: Record<'win32' | 'posix', ShellCommandImpl> = {
|
|
|
27
27
|
export: (key, value) => ['set', `${key}=${value}`],
|
|
28
28
|
chdir: (dest) => ['cd', dest],
|
|
29
29
|
comment: (message) => ['\nREM', stripAnsiCodes(message), '\n'],
|
|
30
|
+
echo: (message) => ['echo', `"${escape(stripAnsiCodes(message))}\n"`],
|
|
30
31
|
zip: (outputFile) => ['powershell', 'Compress-Archive', '-Path', '.', '-DestinationPath', outputFile]
|
|
31
32
|
},
|
|
32
33
|
posix: {
|
|
@@ -46,6 +47,7 @@ export const ShellCommands: Record<'win32' | 'posix', ShellCommandImpl> = {
|
|
|
46
47
|
export: (key, value) => ['export', `${key}=${value}`],
|
|
47
48
|
chdir: (dest) => ['cd', dest],
|
|
48
49
|
comment: (message) => ['\n#', stripAnsiCodes(message), '\n'],
|
|
50
|
+
echo: (message) => ['echo', `"${escape(stripAnsiCodes(message))}\n"`],
|
|
49
51
|
zip: (outputFile) => ['zip', '-r', outputFile, '.']
|
|
50
52
|
},
|
|
51
53
|
};
|
package/support/bin/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type CommonPackConfig = {
|
|
|
10
10
|
// Bundle
|
|
11
11
|
entryPoint: string;
|
|
12
12
|
entryCommand: string;
|
|
13
|
+
entrySource: string;
|
|
13
14
|
entryArguments: string[];
|
|
14
15
|
minify: boolean;
|
|
15
16
|
sourcemap: boolean;
|
|
@@ -24,7 +25,6 @@ export type CommonPackOptions = {
|
|
|
24
25
|
|
|
25
26
|
// Bundle
|
|
26
27
|
entryPoint: OptionConfig<string>;
|
|
27
|
-
entryCommand: OptionConfig<string>;
|
|
28
28
|
minify: OptionConfig<boolean>;
|
|
29
29
|
sourcemap: OptionConfig<boolean>;
|
|
30
30
|
includeSources: OptionConfig<boolean>;
|
|
@@ -63,6 +63,7 @@ export type ShellCommandImpl = {
|
|
|
63
63
|
export(key: string, value: string): string[];
|
|
64
64
|
chdir(dest: string): string[];
|
|
65
65
|
comment(message: string): string[];
|
|
66
|
+
echo(text: string): string[];
|
|
66
67
|
zip(output: string): string[];
|
|
67
68
|
};
|
|
68
69
|
|
package/support/pack.base.ts
CHANGED
|
@@ -28,18 +28,33 @@ export abstract class BasePackCommand<T extends CommonPackOptions, S extends Com
|
|
|
28
28
|
return !!RootIndex.manifest.monoRepo && path.cwd() === RootIndex.manifest.workspacePath;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
get entries(): string[] {
|
|
32
|
+
return RootIndex.findSupport({ filter: x => x.includes('entry.') })
|
|
33
|
+
.map(x => x.import.replace(/[.][^.]+s$/, ''));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Add help output
|
|
38
|
+
*/
|
|
39
|
+
async help(): Promise<string> {
|
|
40
|
+
const entryPoints = this.entries.map(x => cliTpl`${{ subtitle: '*' }} ${{ identifier: x }}`);
|
|
41
|
+
|
|
42
|
+
return ['', cliTpl`${{ title: 'Available Entry Points:' }}`, '', ...entryPoints, ''].join('\n');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
31
46
|
getArgs(): string | undefined {
|
|
32
47
|
return this.monoRoot ? '<module> [args...]' : '[args...]';
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
getCommonOptions(): CommonPackOptions {
|
|
51
|
+
const entries = this.entries;
|
|
52
|
+
const mainEntry = this.entries.find(x => x.startsWith('@travetto/cli'))!;
|
|
36
53
|
return {
|
|
37
54
|
workspace: this.option({ short: 'w', desc: 'Workspace for building' }),
|
|
38
55
|
clean: this.boolOption({ short: 'c', desc: 'Clean workspace', def: true }),
|
|
39
56
|
output: this.option({ short: 'o', desc: 'Output Location' }),
|
|
40
|
-
|
|
41
|
-
entryPoint: this.option({ short: 'e', desc: 'Entry point', def: 'node_modules/@travetto/cli/support/cli.js' }),
|
|
42
|
-
entryCommand: this.option({ short: 'ec', desc: 'Entry command' }),
|
|
57
|
+
entryPoint: this.choiceOption({ short: 'e', desc: 'Entry point', def: mainEntry, choices: entries }),
|
|
43
58
|
minify: this.boolOption({ short: 'm', desc: 'Minify output', def: true }),
|
|
44
59
|
sourcemap: this.boolOption({ short: 'sm', desc: 'Bundle source maps' }),
|
|
45
60
|
includeSources: this.boolOption({ short: 'is', desc: 'Include source with source maps' }),
|
|
@@ -89,7 +104,8 @@ export abstract class BasePackCommand<T extends CommonPackOptions, S extends Com
|
|
|
89
104
|
|
|
90
105
|
async buildConfig(): Promise<S> {
|
|
91
106
|
this.cmd.workspace ??= path.resolve(os.tmpdir(), RootIndex.mainModule.sourcePath.replace(/[\/\\: ]/g, '_'));
|
|
92
|
-
this.cmd.
|
|
107
|
+
this.cmd.entrySource = `${path.basename(this.cmd.entryPoint)}.js`;
|
|
108
|
+
this.cmd.entryCommand = path.basename(this.cmd.entryPoint).replace(/entry[.]/, '');
|
|
93
109
|
this.cmd.module = RootIndex.mainModule.name;
|
|
94
110
|
return this.cmd;
|
|
95
111
|
}
|