@travetto/pack 3.0.0 → 3.0.1-rc.2
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/config.ts +3 -1
- package/support/bin/docker-operation.ts +10 -13
- package/support/bin/operation.ts +29 -31
- package/support/bin/shell.ts +2 -0
- package/support/bin/types.ts +1 -1
- package/support/pack.base.ts +9 -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.2",
|
|
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": {
|
package/support/bin/config.ts
CHANGED
|
@@ -37,6 +37,8 @@ function getFilesFromModule(m: ManifestModule): string[] {
|
|
|
37
37
|
|
|
38
38
|
export function getOutput(): OutputOptions {
|
|
39
39
|
const format: Package['type'] = Env.get('BUNDLE_FORMAT', 'commonjs');
|
|
40
|
+
const dir = Env.get('BUNDLE_OUTPUT')!;
|
|
41
|
+
const entryName = Env.get('BUNDLE_ENTRY_COMMAND')!;
|
|
40
42
|
return {
|
|
41
43
|
format,
|
|
42
44
|
intro: INTRO[format],
|
|
@@ -48,7 +50,7 @@ export function getOutput(): OutputOptions {
|
|
|
48
50
|
!(Env.getBoolean('BUNDLE_SOURCES') ?? false),
|
|
49
51
|
compact:
|
|
50
52
|
Env.getBoolean('BUNDLE_COMPRESS') ?? true,
|
|
51
|
-
|
|
53
|
+
file: path.resolve(dir, `${entryName}.js`),
|
|
52
54
|
...(format === 'commonjs' ? {} : {
|
|
53
55
|
inlineDynamicImports: true
|
|
54
56
|
}),
|
|
@@ -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,11 @@ 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
|
-
['
|
|
62
|
+
['BUNDLE_ENTRY', entryPointFile],
|
|
63
|
+
['BUNDLE_ENTRY_COMMAND', cfg.entryCommand],
|
|
55
64
|
['BUNDLE_COMPRESS', cfg.minify],
|
|
56
65
|
['BUNDLE_SOURCEMAP', cfg.sourcemap],
|
|
57
66
|
['BUNDLE_SOURCES', cfg.includeSources],
|
|
@@ -66,10 +75,9 @@ export class PackOperation {
|
|
|
66
75
|
const props = (['minify', 'sourcemap', 'entryPoint'] as const)
|
|
67
76
|
.map(k => cliTpl`${{ subtitle: k }}=${{ param: cfg[k] }}`).join(' ');
|
|
68
77
|
|
|
69
|
-
|
|
78
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Bundling Output' }} ${props}`);
|
|
70
79
|
|
|
71
80
|
if (cfg.ejectFile) {
|
|
72
|
-
yield ActiveShellCommand.comment(title);
|
|
73
81
|
yield* Object.entries(env).filter(x => !!x[1]).map(x =>
|
|
74
82
|
ActiveShellCommand.export(x[0], x[1])
|
|
75
83
|
);
|
|
@@ -77,7 +85,6 @@ export class PackOperation {
|
|
|
77
85
|
yield bundleCommand;
|
|
78
86
|
yield ActiveShellCommand.chdir(path.cwd());
|
|
79
87
|
} else {
|
|
80
|
-
yield [title];
|
|
81
88
|
await ExecUtil.spawn(bundleCommand[0], bundleCommand.slice(1), { cwd, env, stdio: ['inherit', 'pipe', 'pipe'] }).result;
|
|
82
89
|
}
|
|
83
90
|
}
|
|
@@ -87,17 +94,16 @@ export class PackOperation {
|
|
|
87
94
|
*/
|
|
88
95
|
static async * writePackageJson(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
89
96
|
const file = 'package.json';
|
|
90
|
-
const title = cliTpl`${{ title: 'Writing' }} ${{ path: file }}`;
|
|
91
97
|
const pkg = { type: RootIndex.manifest.moduleType };
|
|
92
98
|
|
|
99
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
|
|
100
|
+
|
|
93
101
|
if (cfg.ejectFile) {
|
|
94
|
-
yield ActiveShellCommand.comment(title);
|
|
95
102
|
yield* ActiveShellCommand.createFile(
|
|
96
103
|
path.resolve(cfg.workspace, file),
|
|
97
104
|
[JSON.stringify(pkg)]
|
|
98
105
|
);
|
|
99
106
|
} else {
|
|
100
|
-
yield [title];
|
|
101
107
|
await writeRawFile(
|
|
102
108
|
path.resolve(cfg.workspace, file),
|
|
103
109
|
JSON.stringify(pkg, null, 2)
|
|
@@ -110,20 +116,19 @@ export class PackOperation {
|
|
|
110
116
|
*/
|
|
111
117
|
static async * writeEnv(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
112
118
|
const file = '.env.js';
|
|
113
|
-
const title = cliTpl`${{ title: 'Writing' }} ${{ path: file }}`;
|
|
114
119
|
const env = {
|
|
115
120
|
TRV_MANIFEST: `node_modules/${cfg.module}`,
|
|
116
121
|
TRV_CLI_IPC: ''
|
|
117
122
|
};
|
|
118
123
|
|
|
124
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
|
|
125
|
+
|
|
119
126
|
if (cfg.ejectFile) {
|
|
120
|
-
yield ActiveShellCommand.comment(title);
|
|
121
127
|
yield* ActiveShellCommand.createFile(
|
|
122
128
|
path.resolve(cfg.workspace, file),
|
|
123
129
|
PackUtil.buildEnvJS(env)
|
|
124
130
|
);
|
|
125
131
|
} else {
|
|
126
|
-
yield [title];
|
|
127
132
|
await writeRawFile(
|
|
128
133
|
path.resolve(cfg.workspace, file),
|
|
129
134
|
PackUtil.buildEnvJS(env).join('\n')
|
|
@@ -144,18 +149,18 @@ export class PackOperation {
|
|
|
144
149
|
text: [
|
|
145
150
|
ShellCommands[type].scriptOpen(),
|
|
146
151
|
ShellCommands[type].chdirScript(),
|
|
147
|
-
ShellCommands[type].callCommandWithAllArgs('node', cfg.entryCommand
|
|
152
|
+
ShellCommands[type].callCommandWithAllArgs('node', `${cfg.entryCommand}.js`, ...cfg.entryArguments),
|
|
148
153
|
].map(x => x.join(' '))
|
|
149
154
|
}));
|
|
150
155
|
|
|
151
156
|
if (cfg.ejectFile) {
|
|
152
157
|
for (const { fileTitle, text, file } of files) {
|
|
153
|
-
yield
|
|
158
|
+
yield* PackOperation.title(cfg, fileTitle);
|
|
154
159
|
yield* ActiveShellCommand.createFile(path.resolve(cfg.workspace, file), text, '755');
|
|
155
160
|
}
|
|
156
161
|
} else {
|
|
157
162
|
for (const { fileTitle, text, file } of files) {
|
|
158
|
-
yield
|
|
163
|
+
yield* PackOperation.title(cfg, fileTitle);
|
|
159
164
|
await writeRawFile(path.resolve(cfg.workspace, file), text.join('\n'), '755');
|
|
160
165
|
}
|
|
161
166
|
}
|
|
@@ -180,10 +185,9 @@ export class PackOperation {
|
|
|
180
185
|
destFolder: path.resolve(cfg.workspace, mod.outputFolder)
|
|
181
186
|
}));
|
|
182
187
|
|
|
183
|
-
|
|
188
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Copying over resources' }}`);
|
|
184
189
|
|
|
185
190
|
if (cfg.ejectFile) {
|
|
186
|
-
yield ActiveShellCommand.comment(title);
|
|
187
191
|
yield* copyFiles.flatMap(mod => [
|
|
188
192
|
ActiveShellCommand.mkdir(path.dirname(mod.dest)),
|
|
189
193
|
ActiveShellCommand.copy(mod.src, mod.dest)
|
|
@@ -192,8 +196,6 @@ export class PackOperation {
|
|
|
192
196
|
yield ActiveShellCommand.copyRecursive(resources.src, path.resolve(cfg.workspace, 'resources'));
|
|
193
197
|
}
|
|
194
198
|
} else {
|
|
195
|
-
yield [title];
|
|
196
|
-
|
|
197
199
|
for (const { src, dest, destFolder } of copyFiles) {
|
|
198
200
|
await fs.mkdir(destFolder, { recursive: true });
|
|
199
201
|
await fs.copyFile(src, dest);
|
|
@@ -210,24 +212,22 @@ export class PackOperation {
|
|
|
210
212
|
* Generate the trv-app-cache.json for @travetto/app, which is needed for 'running' programs
|
|
211
213
|
*/
|
|
212
214
|
static async * primeAppCache(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
213
|
-
const isRun = cfg.
|
|
215
|
+
const isRun = /entry[.]cli/.test(cfg.entryPoint) && cfg.entryArguments.filter(x => !x.startsWith('-'))[0] === 'run';
|
|
214
216
|
if (!isRun) {
|
|
215
217
|
return;
|
|
216
218
|
}
|
|
217
219
|
|
|
218
220
|
const appCacheCmd = ['npx', 'trv', 'main', '@travetto/app/support/bin/list'];
|
|
219
221
|
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
222
|
const env = { DEBUG: '0', TRV_MODULE: cfg.module };
|
|
222
223
|
const appCache = path.resolve(cfg.workspace, sub);
|
|
223
224
|
|
|
225
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Generating App Cache' }} ${{ path: sub }}`);
|
|
224
226
|
|
|
225
227
|
if (cfg.ejectFile) {
|
|
226
|
-
yield ActiveShellCommand.comment(title);
|
|
227
228
|
yield ActiveShellCommand.mkdir(path.dirname(appCache));
|
|
228
229
|
yield [...Object.entries(env).map(x => `${x[0]}=${x[1]}`), ...appCacheCmd, '>', appCache];
|
|
229
230
|
} else {
|
|
230
|
-
yield [title];
|
|
231
231
|
const { stdout } = await ExecUtil.spawn(appCacheCmd[0], appCacheCmd.slice(1), { env }).result;
|
|
232
232
|
|
|
233
233
|
await fs.mkdir(path.dirname(appCache), { recursive: true });
|
|
@@ -242,13 +242,12 @@ export class PackOperation {
|
|
|
242
242
|
const out = path.resolve(cfg.workspace, 'node_modules', cfg.module);
|
|
243
243
|
const cmd = ['npx', 'trv', 'manifest', out, 'prod'];
|
|
244
244
|
const env = { TRV_MODULE: cfg.module };
|
|
245
|
-
|
|
245
|
+
|
|
246
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing Manifest' }} ${{ path: path.join('node_modules', cfg.module) }}`);
|
|
246
247
|
|
|
247
248
|
if (cfg.ejectFile) {
|
|
248
|
-
yield ActiveShellCommand.comment(title);
|
|
249
249
|
yield [...Object.entries(env).map(([k, v]) => `${k}=${v}`), ...cmd];
|
|
250
250
|
} else {
|
|
251
|
-
yield [title];
|
|
252
251
|
await ExecUtil.spawn(cmd[0], cmd.slice(1), { env, stdio: ['inherit', 'ignore', 'inherit'] }).result;
|
|
253
252
|
}
|
|
254
253
|
}
|
|
@@ -257,15 +256,14 @@ export class PackOperation {
|
|
|
257
256
|
* Generate ZIP file for workspace
|
|
258
257
|
*/
|
|
259
258
|
static async * compress(cfg: CommonPackConfig): AsyncIterable<string[]> {
|
|
260
|
-
|
|
259
|
+
|
|
260
|
+
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Compressing' }} ${{ path: cfg.output }}`);
|
|
261
261
|
|
|
262
262
|
if (cfg.ejectFile) {
|
|
263
|
-
yield ActiveShellCommand.comment(title);
|
|
264
263
|
yield ActiveShellCommand.chdir(cfg.workspace);
|
|
265
264
|
yield ActiveShellCommand.zip(cfg.output);
|
|
266
265
|
yield ActiveShellCommand.chdir(path.cwd());
|
|
267
266
|
} else {
|
|
268
|
-
yield [title];
|
|
269
267
|
const [cmd, ...args] = ActiveShellCommand.zip(cfg.output);
|
|
270
268
|
await ExecUtil.spawn(cmd, args, { cwd: cfg.workspace }).result;
|
|
271
269
|
}
|
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
|
@@ -24,7 +24,6 @@ export type CommonPackOptions = {
|
|
|
24
24
|
|
|
25
25
|
// Bundle
|
|
26
26
|
entryPoint: OptionConfig<string>;
|
|
27
|
-
entryCommand: OptionConfig<string>;
|
|
28
27
|
minify: OptionConfig<boolean>;
|
|
29
28
|
sourcemap: OptionConfig<boolean>;
|
|
30
29
|
includeSources: OptionConfig<boolean>;
|
|
@@ -63,6 +62,7 @@ export type ShellCommandImpl = {
|
|
|
63
62
|
export(key: string, value: string): string[];
|
|
64
63
|
chdir(dest: string): string[];
|
|
65
64
|
comment(message: string): string[];
|
|
65
|
+
echo(text: string): string[];
|
|
66
66
|
zip(output: string): string[];
|
|
67
67
|
};
|
|
68
68
|
|
package/support/pack.base.ts
CHANGED
|
@@ -28,18 +28,23 @@ 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
|
+
|
|
31
36
|
getArgs(): string | undefined {
|
|
32
37
|
return this.monoRoot ? '<module> [args...]' : '[args...]';
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
getCommonOptions(): CommonPackOptions {
|
|
41
|
+
const entries = this.entries;
|
|
42
|
+
const mainEntry = this.entries.find(x => x.startsWith('@travetto/cli'))!;
|
|
36
43
|
return {
|
|
37
44
|
workspace: this.option({ short: 'w', desc: 'Workspace for building' }),
|
|
38
45
|
clean: this.boolOption({ short: 'c', desc: 'Clean workspace', def: true }),
|
|
39
46
|
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' }),
|
|
47
|
+
entryPoint: this.choiceOption({ short: 'e', desc: 'Entry point', def: mainEntry, choices: entries }),
|
|
43
48
|
minify: this.boolOption({ short: 'm', desc: 'Minify output', def: true }),
|
|
44
49
|
sourcemap: this.boolOption({ short: 'sm', desc: 'Bundle source maps' }),
|
|
45
50
|
includeSources: this.boolOption({ short: 'is', desc: 'Include source with source maps' }),
|
|
@@ -89,7 +94,7 @@ export abstract class BasePackCommand<T extends CommonPackOptions, S extends Com
|
|
|
89
94
|
|
|
90
95
|
async buildConfig(): Promise<S> {
|
|
91
96
|
this.cmd.workspace ??= path.resolve(os.tmpdir(), RootIndex.mainModule.sourcePath.replace(/[\/\\: ]/g, '_'));
|
|
92
|
-
this.cmd.entryCommand
|
|
97
|
+
this.cmd.entryCommand = path.basename(this.cmd.entryPoint).replace(/entry[.]/, '');
|
|
93
98
|
this.cmd.module = RootIndex.mainModule.name;
|
|
94
99
|
return this.cmd;
|
|
95
100
|
}
|