@travetto/pack 3.0.1 → 3.0.2-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/README.md CHANGED
@@ -29,16 +29,17 @@ $ trv pack --help
29
29
  Usage: pack [options] [args...]
30
30
 
31
31
  Options:
32
- -w, --workspace <workspace> Workspace for building
33
- -c, --no-clean Disables: Clean workspace
34
- -o, --output <output> Output Location
35
- -e, --entry-point <entry-point> Entry point (default: "node_modules/@travetto/cli/support/cli.js")
36
- -ec, --entry-command <entry-command> Entry command
37
- -m, --no-minify Disables: Minify output
38
- -sm, --sourcemap Bundle source maps
39
- -is, --include-sources Include source with source maps
40
- -x, --eject-file <eject-file> Eject commands to file
41
- -h, --help display help for command
32
+ -w, --workspace <workspace> Workspace for building
33
+ -c, --no-clean Disables: Clean workspace
34
+ -o, --output <output> Output location
35
+ -es, --main-scripts <main-scripts> Create entry scripts
36
+ -f, --main-name <main-name> Main name for build artifact (default: "cli")
37
+ -e, --entry-point <entry-point> Entry point (default: "@travetto/cli/support/entry.cli")
38
+ -m, --no-minify Disables: Minify output
39
+ -sm, --sourcemap Bundle source maps
40
+ -is, --include-sources Include source with source maps
41
+ -x, --eject-file <eject-file> Eject commands to file
42
+ -h, --help display help for command
42
43
  ```
43
44
 
44
45
  This command line operation will compile your project, and produce a ready to use workspace as a deliverable. Additionally, you can pass in a file to the `eject-file` flag that will allow for a script to be produced (base on the host operating system).
@@ -90,16 +91,17 @@ $ trv pack:zip --help
90
91
  Usage: pack:zip [options] [args...]
91
92
 
92
93
  Options:
93
- -w, --workspace <workspace> Workspace for building
94
- -c, --no-clean Disables: Clean workspace
95
- -o, --output <output> Output Location (default: "travetto_pack.zip")
96
- -e, --entry-point <entry-point> Entry point (default: "node_modules/@travetto/cli/support/cli.js")
97
- -ec, --entry-command <entry-command> Entry command
98
- -m, --no-minify Disables: Minify output
99
- -sm, --sourcemap Bundle source maps
100
- -is, --include-sources Include source with source maps
101
- -x, --eject-file <eject-file> Eject commands to file
102
- -h, --help display help for command
94
+ -w, --workspace <workspace> Workspace for building
95
+ -c, --no-clean Disables: Clean workspace
96
+ -o, --output <output> Output location (default: "travetto_pack.zip")
97
+ -es, --main-scripts <main-scripts> Create entry scripts
98
+ -f, --main-name <main-name> Main name for build artifact (default: "cli")
99
+ -e, --entry-point <entry-point> Entry point (default: "@travetto/cli/support/entry.cli")
100
+ -m, --no-minify Disables: Minify output
101
+ -sm, --sourcemap Bundle source maps
102
+ -is, --include-sources Include source with source maps
103
+ -x, --eject-file <eject-file> Eject commands to file
104
+ -h, --help display help for command
103
105
  ```
104
106
 
105
107
  ## CLI - pack:docker
@@ -115,9 +117,10 @@ Usage: pack:docker [options] [args...]
115
117
  Options:
116
118
  -w, --workspace <workspace> Workspace for building
117
119
  -c, --no-clean Disables: Clean workspace
118
- -o, --output <output> Output Location
119
- -e, --entry-point <entry-point> Entry point (default: "node_modules/@travetto/cli/support/cli.js")
120
- -ec, --entry-command <entry-command> Entry command
120
+ -o, --output <output> Output location
121
+ -es, --main-scripts <main-scripts> Create entry scripts
122
+ -f, --main-name <main-name> Main name for build artifact (default: "cli")
123
+ -e, --entry-point <entry-point> Entry point (default: "@travetto/cli/support/entry.cli")
121
124
  -m, --no-minify Disables: Minify output
122
125
  -sm, --sourcemap Bundle source maps
123
126
  -is, --include-sources Include source with source maps
@@ -157,34 +160,46 @@ export MOD=@travetto/todo-app
157
160
 
158
161
  # Cleaning Output $DIST
159
162
 
163
+ echo "Cleaning Output $DIST
164
+ "
160
165
  rm -rf $DIST
161
166
  mkdir -p $DIST
162
167
 
163
168
  # Writing .env.js
164
169
 
170
+ echo "Writing .env.js
171
+ "
165
172
  echo "process.env.TRV_MANIFEST = 'node_modules/$MOD';" > $DIST/.env.js
166
173
  echo "process.env.TRV_CLI_IPC = '';" >> $DIST/.env.js
167
174
 
168
175
  # Writing package.json
169
176
 
177
+ echo "Writing package.json
178
+ "
170
179
  echo "{\"type\":\"commonjs\"}" > $DIST/package.json
171
180
 
172
181
  # Writing entry scripts cli.sh args=(run rest)
173
182
 
183
+ echo "Writing entry scripts cli.sh args=(run rest)
184
+ "
174
185
  echo "#!/bin/sh" > $DIST/cli.sh
175
186
  echo "cd \$(dirname \"\$0\")" >> $DIST/cli.sh
176
- echo "node cli run rest \$@" >> $DIST/cli.sh
187
+ echo "node cli.js run rest \$@" >> $DIST/cli.sh
177
188
  chmod 755 $DIST/cli.sh
178
189
 
179
190
  # Writing entry scripts cli.cmd args=(run rest)
180
191
 
192
+ echo "Writing entry scripts cli.cmd args=(run rest)
193
+ "
181
194
  echo "" > $DIST/cli.cmd
182
195
  echo "cd %~p0" >> $DIST/cli.cmd
183
- echo "node cli run rest %*" >> $DIST/cli.cmd
196
+ echo "node cli.js run rest %*" >> $DIST/cli.cmd
184
197
  chmod 755 $DIST/cli.cmd
185
198
 
186
199
  # Copying over resources
187
200
 
201
+ echo "Copying over resources
202
+ "
188
203
  mkdir -p $DIST/node_modules/$MOD
189
204
  cp $TRV_OUT/node_modules/$MOD/package.json $DIST/node_modules/$MOD/package.json
190
205
  mkdir -p $DIST/node_modules/@travetto/manifest
@@ -193,17 +208,23 @@ cp -r -p $ROOT/resources $DIST/resources
193
208
 
194
209
  # Generating App Cache node_modules/$MOD/trv-app-cache.json
195
210
 
211
+ echo "Generating App Cache node_modules/$MOD/trv-app-cache.json
212
+ "
196
213
  mkdir -p $DIST/node_modules/$MOD
197
214
  DEBUG=0 TRV_MODULE=$MOD npx trv main @travetto/app/support/bin/list > $DIST/node_modules/$MOD/trv-app-cache.json
198
215
 
199
216
  # Writing Manifest node_modules/$MOD
200
217
 
218
+ echo "Writing Manifest node_modules/$MOD
219
+ "
201
220
  TRV_MODULE=$MOD npx trv manifest $DIST/node_modules/$MOD prod
202
221
 
203
- # Bundling Output minify=true sourcemap= entryPoint=node_modules/@travetto/cli/support/cli.js
222
+ # Bundling Output minify=true sourcemap= entryPoint=@travetto/cli/support/entry.cli
204
223
 
205
- export BUNDLE_ENTRY=node_modules/@travetto/cli/support/cli.js
206
- export BUNDLE_ENTRY_NAME=cli
224
+ echo "Bundling Output minify=true sourcemap= entryPoint=@travetto/cli/support/entry.cli
225
+ "
226
+ export BUNDLE_ENTRY=node_modules/@travetto/cli/support/entry.cli.js
227
+ export BUNDLE_MAIN_FILE=cli.js
207
228
  export BUNDLE_COMPRESS=true
208
229
  export BUNDLE_OUTPUT=$DIST
209
230
  export BUNDLE_FORMAT=commonjs
@@ -214,6 +235,8 @@ cd $ROOT
214
235
 
215
236
  # Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.dockerfile
216
237
 
238
+ echo "Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.dockerfile
239
+ "
217
240
  echo "FROM node:18-alpine3.16" > $DIST/Dockerfile
218
241
  echo "WORKDIR /app" >> $DIST/Dockerfile
219
242
  echo "COPY . ." >> $DIST/Dockerfile
@@ -222,10 +245,14 @@ echo "ENTRYPOINT [\"/app/cli.sh\"]" >> $DIST/Dockerfile
222
245
 
223
246
  # Pulling Docker Base Image node:18-alpine3.16
224
247
 
248
+ echo "Pulling Docker Base Image node:18-alpine3.16
249
+ "
225
250
  docker pull node:18-alpine3.16
226
251
 
227
252
  # Building Docker Container latest
228
253
 
254
+ echo "Building Docker Container latest
255
+ "
229
256
  cd $DIST
230
257
  docker build -t travetto_todo-app:latest .
231
258
  cd $ROOT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.0.1",
3
+ "version": "3.0.2-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.1",
31
+ "@travetto/base": "^3.0.2-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.1"
36
+ "@travetto/cli": "^3.0.2-rc.1"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
@@ -38,7 +38,7 @@ function getFilesFromModule(m: ManifestModule): string[] {
38
38
  export function getOutput(): OutputOptions {
39
39
  const format: Package['type'] = Env.get('BUNDLE_FORMAT', 'commonjs');
40
40
  const dir = Env.get('BUNDLE_OUTPUT')!;
41
- const entryName = Env.get('BUNDLE_ENTRY_COMMAND')!;
41
+ const mainFile = Env.get('BUNDLE_MAIN_FILE')!;
42
42
  return {
43
43
  format,
44
44
  intro: INTRO[format],
@@ -50,7 +50,7 @@ export function getOutput(): OutputOptions {
50
50
  !(Env.getBoolean('BUNDLE_SOURCES') ?? false),
51
51
  compact:
52
52
  Env.getBoolean('BUNDLE_COMPRESS') ?? true,
53
- file: path.resolve(dir, `${entryName}.js`),
53
+ file: path.resolve(dir, mainFile),
54
54
  ...(format === 'commonjs' ? {} : {
55
55
  inlineDynamicImports: true
56
56
  }),
@@ -60,7 +60,7 @@ export class PackOperation {
60
60
 
61
61
  const env = Object.fromEntries(([
62
62
  ['BUNDLE_ENTRY', entryPointFile],
63
- ['BUNDLE_ENTRY_COMMAND', cfg.entryCommand],
63
+ ['BUNDLE_MAIN_FILE', `${cfg.mainName}.js`],
64
64
  ['BUNDLE_COMPRESS', cfg.minify],
65
65
  ['BUNDLE_SOURCEMAP', cfg.sourcemap],
66
66
  ['BUNDLE_SOURCES', cfg.includeSources],
@@ -140,16 +140,20 @@ export class PackOperation {
140
140
  * Create launcher scripts (.sh, .cmd) to run output
141
141
  */
142
142
  static async * writeEntryScript(cfg: CommonPackConfig): AsyncIterable<string[]> {
143
+ if (!cfg.mainScripts && !cfg.entryPoint.includes('@travetto/cli')) {
144
+ return;
145
+ }
146
+
143
147
  const title = 'Writing entry scripts';
144
148
 
145
149
  const files = ([['posix', 'sh'], ['win32', 'cmd']] as const)
146
150
  .map(([type, ext]) => ({
147
- fileTitle: cliTpl`${{ title }} ${{ path: `${cfg.entryCommand}.${ext}` }} args=(${{ param: cfg.entryArguments.join(' ') }})`,
148
- file: `${cfg.entryCommand}.${ext}`,
151
+ fileTitle: cliTpl`${{ title }} ${{ path: `${cfg.mainName}.${ext}` }} args=(${{ param: cfg.entryArguments.join(' ') }})`,
152
+ file: `${cfg.mainName}.${ext}`,
149
153
  text: [
150
154
  ShellCommands[type].scriptOpen(),
151
155
  ShellCommands[type].chdirScript(),
152
- ShellCommands[type].callCommandWithAllArgs('node', `${cfg.entryCommand}.js`, ...cfg.entryArguments),
156
+ ShellCommands[type].callCommandWithAllArgs('node', `${cfg.mainName}.js`, ...cfg.entryArguments),
153
157
  ].map(x => x.join(' '))
154
158
  }));
155
159
 
@@ -5,11 +5,12 @@ export type CommonPackConfig = {
5
5
  output: string;
6
6
  clean: boolean;
7
7
  ejectFile: string;
8
+ mainName: string;
9
+ mainScripts: boolean;
8
10
  module: string;
9
11
 
10
12
  // Bundle
11
13
  entryPoint: string;
12
- entryCommand: string;
13
14
  entryArguments: string[];
14
15
  minify: boolean;
15
16
  sourcemap: boolean;
@@ -21,6 +22,8 @@ export type CommonPackOptions = {
21
22
  output: OptionConfig<string>;
22
23
  clean: OptionConfig<boolean>;
23
24
  ejectFile: OptionConfig<string>;
25
+ mainName: OptionConfig<string>;
26
+ mainScripts: OptionConfig<boolean>;
24
27
 
25
28
  // Bundle
26
29
  entryPoint: OptionConfig<string>;
@@ -28,7 +28,7 @@ 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[] {
31
+ get entryPoints(): string[] {
32
32
  return RootIndex.findSupport({ filter: x => x.includes('entry.') })
33
33
  .map(x => x.import.replace(/[.][^.]+s$/, ''));
34
34
  }
@@ -38,13 +38,14 @@ export abstract class BasePackCommand<T extends CommonPackOptions, S extends Com
38
38
  }
39
39
 
40
40
  getCommonOptions(): CommonPackOptions {
41
- const entries = this.entries;
42
- const mainEntry = this.entries.find(x => x.startsWith('@travetto/cli'))!;
41
+ const mainEntry = this.entryPoints.find(x => x.startsWith('@travetto/cli'))!;
43
42
  return {
44
43
  workspace: this.option({ short: 'w', desc: 'Workspace for building' }),
45
44
  clean: this.boolOption({ short: 'c', desc: 'Clean workspace', def: true }),
46
- output: this.option({ short: 'o', desc: 'Output Location' }),
47
- entryPoint: this.choiceOption({ short: 'e', desc: 'Entry point', def: mainEntry, choices: entries }),
45
+ output: this.option({ short: 'o', desc: 'Output location' }),
46
+ mainScripts: this.option({ short: 'es', desc: 'Create entry scripts' }),
47
+ mainName: this.option({ short: 'f', desc: 'Main name for build artifact', def: path.basename(mainEntry).replace(/entry[.]/, '') }),
48
+ entryPoint: this.option({ short: 'e', desc: 'Entry point', def: mainEntry }),
48
49
  minify: this.boolOption({ short: 'm', desc: 'Minify output', def: true }),
49
50
  sourcemap: this.boolOption({ short: 'sm', desc: 'Bundle source maps' }),
50
51
  includeSources: this.boolOption({ short: 'is', desc: 'Include source with source maps' }),
@@ -94,7 +95,6 @@ export abstract class BasePackCommand<T extends CommonPackOptions, S extends Com
94
95
 
95
96
  async buildConfig(): Promise<S> {
96
97
  this.cmd.workspace ??= path.resolve(os.tmpdir(), RootIndex.mainModule.sourcePath.replace(/[\/\\: ]/g, '_'));
97
- this.cmd.entryCommand = path.basename(this.cmd.entryPoint).replace(/entry[.]/, '');
98
98
  this.cmd.module = RootIndex.mainModule.name;
99
99
  return this.cmd;
100
100
  }
@@ -5,5 +5,5 @@ FROM ${cfg.dockerImage}
5
5
  WORKDIR /app
6
6
  COPY . .
7
7
  ${cfg.dockerPort.map(port => `EXPOSE ${port}`).join('\n')}
8
- ENTRYPOINT ["/app/${cfg.entryCommand}.sh"]
8
+ ENTRYPOINT ["/app/${cfg.mainName}.sh"]
9
9
  `;