piral-cli 0.14.0-beta.3184 → 0.14.0-beta.3216

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.
Files changed (50) hide show
  1. package/lib/apps/build-pilet.d.ts +11 -0
  2. package/lib/apps/build-pilet.js +8 -1
  3. package/lib/apps/build-pilet.js.map +1 -1
  4. package/lib/apps/build-piral.d.ts +13 -0
  5. package/lib/apps/build-piral.js +14 -3
  6. package/lib/apps/build-piral.js.map +1 -1
  7. package/lib/apps/debug-pilet.d.ts +11 -0
  8. package/lib/apps/debug-pilet.js +12 -3
  9. package/lib/apps/debug-pilet.js.map +1 -1
  10. package/lib/apps/debug-piral.d.ts +11 -0
  11. package/lib/apps/debug-piral.js +8 -1
  12. package/lib/apps/debug-piral.js.map +1 -1
  13. package/lib/apps/new-pilet.js +4 -3
  14. package/lib/apps/new-pilet.js.map +1 -1
  15. package/lib/apps/new-piral.js +2 -1
  16. package/lib/apps/new-piral.js.map +1 -1
  17. package/lib/apps/upgrade-pilet.d.ts +4 -0
  18. package/lib/apps/upgrade-pilet.js +7 -4
  19. package/lib/apps/upgrade-pilet.js.map +1 -1
  20. package/lib/commands.js +4 -0
  21. package/lib/commands.js.map +1 -1
  22. package/lib/common/emulator.js +3 -1
  23. package/lib/common/emulator.js.map +1 -1
  24. package/lib/common/log.js +7 -4
  25. package/lib/common/log.js.map +1 -1
  26. package/lib/common/package.d.ts +4 -4
  27. package/lib/common/package.js +41 -22
  28. package/lib/common/package.js.map +1 -1
  29. package/lib/common/scaffold.d.ts +14 -2
  30. package/lib/common/scaffold.js +19 -7
  31. package/lib/common/scaffold.js.map +1 -1
  32. package/lib/common/template.d.ts +1 -0
  33. package/lib/common/template.js +29 -2
  34. package/lib/common/template.js.map +1 -1
  35. package/lib/types/common.d.ts +1 -0
  36. package/package.json +2 -2
  37. package/src/apps/build-pilet.ts +22 -0
  38. package/src/apps/build-piral.ts +36 -2
  39. package/src/apps/debug-pilet.ts +27 -6
  40. package/src/apps/debug-piral.ts +21 -0
  41. package/src/apps/new-pilet.ts +5 -3
  42. package/src/apps/new-piral.ts +4 -2
  43. package/src/apps/upgrade-pilet.ts +14 -3
  44. package/src/commands.ts +4 -0
  45. package/src/common/emulator.ts +3 -1
  46. package/src/common/log.ts +9 -4
  47. package/src/common/package.ts +51 -16
  48. package/src/common/scaffold.ts +36 -20
  49. package/src/common/template.ts +24 -1
  50. package/src/types/common.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/common/template.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAiC;AACjC,+BAA+B;AAC/B,+BAA4B;AAE5B,6BAA6C;AAE7C,SAAgB,YAAY,CAAC,IAAY,EAAE,OAAY,EAAE;IACvD,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC;IACxE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,IAAA,SAAG,EAAC,mBAAmB,EAAE,mCAAmC,IAAI,IAAI,CAAC,CAAC;QACtE,IAAA,gBAAU,EAAC,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAClC,IAAI,GAAG,EAAE;gBACP,MAAM,CAAC,GAAG,CAAC,CAAC;aACb;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,CAAC;aACd;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAZD,oCAYC;AAED,SAAsB,iCAAiC,CACrD,MAAc,EACd,SAAiB,EACjB,QAAgB,EAChB,cAA+B,EAC/B,IAAU;;QAEV,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,GAAG,MAAM,IAAI,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;QAClE,MAAM,IAAA,0BAAqB,EAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IAC5E,CAAC;CAAA;AATD,8EASC"}
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/common/template.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAiC;AACjC,2BAA+B;AAC/B,+BAA+B;AAC/B,+BAA4B;AAE5B,6BAA6C;AAE7C,SAAsB,aAAa,CAAC,IAAY,EAAE,IAA4B;;QAC5E,MAAM,OAAO,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5D,IAAA,SAAG,EAAC,mBAAmB,EAAE,wBAAwB,IAAI,IAAI,CAAC,CAAC;YAC3D,IAAA,gBAAU,EAAC,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBAClC,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC,CAAC;iBACb;qBAAM;oBACL,OAAO,CAAC,GAAG,CAAC,CAAC;iBACd;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1C,IAAA,cAAS,EAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;gBACvC,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC,CAAC;iBACb;qBAAM;oBACL,OAAO,EAAE,CAAC;iBACX;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AApBD,sCAoBC;AAED,SAAgB,YAAY,CAAC,IAAY,EAAE,OAAY,EAAE;IACvD,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,MAAM,CAAC,CAAC;IACxE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,IAAA,SAAG,EAAC,mBAAmB,EAAE,uBAAuB,IAAI,SAAS,IAAI,IAAI,CAAC,CAAC;QACvE,IAAA,gBAAU,EAAC,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAClC,IAAI,GAAG,EAAE;gBACP,MAAM,CAAC,GAAG,CAAC,CAAC;aACb;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,CAAC;aACd;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAZD,oCAYC;AAED,SAAsB,iCAAiC,CACrD,MAAc,EACd,SAAiB,EACjB,QAAgB,EAChB,cAA+B,EAC/B,IAAU;;QAEV,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,GAAG,MAAM,IAAI,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;QAClE,MAAM,IAAA,0BAAqB,EAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IAC5E,CAAC;CAAA;AATD,8EASC"}
@@ -44,6 +44,7 @@ export interface ReleaseProvider {
44
44
  export interface TemplateFileLocation {
45
45
  from: string;
46
46
  to: string;
47
+ template?: boolean;
47
48
  deep?: boolean;
48
49
  once?: boolean;
49
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "0.14.0-beta.3184",
3
+ "version": "0.14.0-beta.3216",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -77,5 +77,5 @@
77
77
  "typescript": "^4.0.2",
78
78
  "yargs": "^15.4.1"
79
79
  },
80
- "gitHead": "2d00bfdcdf47c737ffb8d58f700945362ab9ac6d"
80
+ "gitHead": "4ae646f90377893373f4ebc575eb0b8a707f8b94"
81
81
  }
@@ -83,6 +83,18 @@ export interface BuildPiletOptions {
83
83
  * Additional arguments for a specific bundler.
84
84
  */
85
85
  _?: Record<string, any>;
86
+
87
+ /**
88
+ * Hooks to be triggered at various stages.
89
+ */
90
+ hooks?: {
91
+ onBegin?(e: any): Promise<void>;
92
+ beforeBuild?(e: any): Promise<void>;
93
+ afterBuild?(e: any): Promise<void>;
94
+ beforeDeclaration?(e: any): Promise<void>;
95
+ afterDeclaration?(e: any): Promise<void>;
96
+ onEnd?(e: any): Promise<void>;
97
+ };
86
98
  }
87
99
 
88
100
  export const buildPiletDefaults: BuildPiletOptions = {
@@ -111,11 +123,14 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
111
123
  schemaVersion = buildPiletDefaults.schemaVersion,
112
124
  declaration = buildPiletDefaults.declaration,
113
125
  _ = {},
126
+ hooks = {},
114
127
  bundlerName,
115
128
  app,
116
129
  } = options;
117
130
  const fullBase = resolve(process.cwd(), baseDir);
118
131
  setLogLevel(logLevel);
132
+
133
+ await hooks.onBegin?.({ options, fullBase });
119
134
  progress('Reading configuration ...');
120
135
  const allEntries = await matchAnyPilet(fullBase, [entry]);
121
136
 
@@ -139,6 +154,8 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
139
154
 
140
155
  logInfo('Bundle pilet ...');
141
156
 
157
+ await hooks.beforeBuild?.({ root, outDir, importmap, entryModule, schemaVersion, piletPackage });
158
+
142
159
  await callPiletBuild(
143
160
  {
144
161
  root,
@@ -161,9 +178,14 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
161
178
  bundlerName,
162
179
  );
163
180
 
181
+ await hooks.afterBuild?.({ root, outDir, importmap, entryModule, schemaVersion, piletPackage });
182
+
164
183
  if (declaration) {
184
+ await hooks.beforeDeclaration?.({ root, outDir, entryModule, piletPackage });
165
185
  await createPiletDeclaration(piletPackage.name, root, entryModule, externals, outDir, ForceOverwrite.yes, logLevel);
186
+ await hooks.afterDeclaration?.({ root, outDir, entryModule, piletPackage });
166
187
  }
167
188
 
168
189
  logDone('Pilet built successfully!');
190
+ await hooks.onEnd?.({ root });
169
191
  }
@@ -107,6 +107,20 @@ export interface BuildPiralOptions {
107
107
  * Additional arguments for a specific bundler.
108
108
  */
109
109
  _?: Record<string, any>;
110
+
111
+ /**
112
+ * Hooks to be triggered at various stages.
113
+ */
114
+ hooks?: {
115
+ onBegin?(e: any): Promise<void>;
116
+ beforeBuild?(e: any): Promise<void>;
117
+ afterBuild?(e: any): Promise<void>;
118
+ beforeEmulator?(e: any): Promise<void>;
119
+ afterEmulator?(e: any): Promise<void>;
120
+ beforePackage?(e: any): Promise<void>;
121
+ afterPackage?(e: any): Promise<void>;
122
+ onEnd?(e: any): Promise<void>;
123
+ };
110
124
  }
111
125
 
112
126
  export const buildPiralDefaults: BuildPiralOptions = {
@@ -149,11 +163,14 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
149
163
  type = buildPiralDefaults.type,
150
164
  optimizeModules = buildPiralDefaults.optimizeModules,
151
165
  _ = {},
166
+ hooks = {},
152
167
  bundlerName,
153
168
  } = options;
154
169
  const fullBase = resolve(process.cwd(), baseDir);
155
170
  const useSubdir = type === 'all' || subdir;
156
171
  setLogLevel(logLevel);
172
+
173
+ await hooks.onBegin?.({ options, fullBase });
157
174
  progress('Reading configuration ...');
158
175
  const entryFiles = await retrievePiralRoot(fullBase, entry);
159
176
  const { name, root, ignored, externals, scripts } = await retrievePiletsInfo(entryFiles);
@@ -174,8 +191,10 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
174
191
  // since we create this anyway let's just pretend we want to have it clean!
175
192
  await removeDirectory(targetDir);
176
193
 
194
+ await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name });
195
+
177
196
  logInfo(`Bundle ${emulatorName} ...`);
178
- const { dir: outDir, name: outFile } = await callPiralBuild(
197
+ const { dir: outDir, name: outFile, hash } = await callPiralBuild(
179
198
  {
180
199
  root,
181
200
  piral: name,
@@ -196,13 +215,21 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
196
215
  bundlerName,
197
216
  );
198
217
 
218
+ await hooks.afterBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name, outDir, hash, outFile });
219
+
199
220
  await runLifecycle(root, scripts, 'piral:postbuild');
200
221
  await runLifecycle(root, scripts, `piral:postbuild-${emulatorName}`);
222
+
223
+ await hooks.beforeEmulator?.({ root, externals, targetDir, outDir });
201
224
 
202
225
  const rootDir = await createEmulatorSources(root, outDir, outFile, logLevel);
226
+
227
+ await hooks.afterEmulator?.({ root, externals, targetDir, outDir, rootDir });
203
228
 
204
229
  if (type !== emulatorSourcesName) {
230
+ await hooks.beforePackage?.({ root, externals, targetDir, outDir, rootDir });
205
231
  await packageEmulator(rootDir);
232
+ await hooks.afterPackage?.({ root, externals, targetDir, outDir, rootDir });
206
233
  logDone(`Emulator package available in "${rootDir}".`);
207
234
  } else {
208
235
  logDone(`Emulator sources available in "${rootDir}".`);
@@ -220,7 +247,10 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
220
247
  await removeDirectory(targetDir);
221
248
 
222
249
  logInfo(`Bundle ${releaseName} ...`);
223
- const { dir: outDir } = await callPiralBuild(
250
+
251
+ await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name });
252
+
253
+ const { dir: outDir, name: outFile, hash } = await callPiralBuild(
224
254
  {
225
255
  root,
226
256
  piral: name,
@@ -240,6 +270,8 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
240
270
  },
241
271
  bundlerName,
242
272
  );
273
+
274
+ await hooks.afterBuild?.({ root, publicUrl, externals, entryFiles, targetDir, name, outDir, outFile, hash });
243
275
 
244
276
  await runLifecycle(root, scripts, 'piral:postbuild');
245
277
  await runLifecycle(root, scripts, `piral:postbuild-${releaseName}`);
@@ -247,4 +279,6 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
247
279
  logDone(`Files for publication available in "${outDir}".`);
248
280
  logReset();
249
281
  }
282
+
283
+ await hooks.onEnd?.({ root });
250
284
  }
@@ -73,6 +73,18 @@ export interface DebugPiletOptions {
73
73
  * Additional arguments for a specific bundler.
74
74
  */
75
75
  _?: Record<string, any>;
76
+
77
+ /**
78
+ * Hooks to be triggered at various stages.
79
+ */
80
+ hooks?: {
81
+ onBegin?(e: any): Promise<void>;
82
+ beforeBuild?(e: any): Promise<void>;
83
+ afterBuild?(e: any): Promise<void>;
84
+ beforeOnline?(e: any): Promise<void>;
85
+ afterOnline?(e: any): Promise<void>;
86
+ onEnd?(e: any): Promise<void>;
87
+ };
76
88
  }
77
89
 
78
90
  export const debugPiletDefaults: DebugPiletOptions = {
@@ -142,19 +154,23 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
142
154
  optimizeModules = debugPiletDefaults.optimizeModules,
143
155
  schemaVersion = debugPiletDefaults.schemaVersion,
144
156
  _ = {},
157
+ hooks = {},
145
158
  bundlerName,
146
159
  app,
147
160
  feed,
148
161
  } = options;
162
+ const fullBase = resolve(process.cwd(), baseDir);
149
163
  setLogLevel(logLevel);
164
+
165
+ await hooks.onBegin?.({ options, fullBase });
150
166
  progress('Reading configuration ...');
151
167
  const krasConfig = readKrasConfig({ port }, krasrc);
152
168
  const api = config.piletApi;
153
169
  const entryList = Array.isArray(entry) ? entry : [entry];
154
170
  const multi = entryList.length > 1 || entryList[0].indexOf('*') !== -1;
155
- log('generalDebug_0003', `Looking for (${multi ? 'multi' : 'single'}) "${entryList.join('", "')}" in "${baseDir}".`);
171
+ log('generalDebug_0003', `Looking for (${multi ? 'multi' : 'single'}) "${entryList.join('", "')}" in "${fullBase}".`);
156
172
 
157
- const allEntries = await matchAnyPilet(baseDir, entryList);
173
+ const allEntries = await matchAnyPilet(fullBase, entryList);
158
174
  log('generalDebug_0003', `Found the following entries: ${allEntries.join(', ')}`);
159
175
 
160
176
  if (krasConfig.sources === undefined) {
@@ -168,10 +184,8 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
168
184
  const pilets = await Promise.all(
169
185
  allEntries.map(async (entryModule) => {
170
186
  const targetDir = dirname(entryModule);
171
- const { peerDependencies, peerModules, root, appPackage, appFile, ignored, emulator, importmap } = await retrievePiletData(
172
- targetDir,
173
- app,
174
- );
187
+ const { peerDependencies, peerModules, root, appPackage, appFile, ignored, emulator, importmap } =
188
+ await retrievePiletData(targetDir, app);
175
189
  const externals = [...Object.keys(peerDependencies), ...peerModules];
176
190
  const mocks = join(targetDir, 'mocks');
177
191
  const exists = await checkExistingDirectory(mocks);
@@ -184,6 +198,8 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
184
198
  krasConfig.sources.push(mocks);
185
199
  }
186
200
 
201
+ await hooks.beforeBuild?.({ root, importmap, entryModule, schemaVersion });
202
+
187
203
  const bundler = await callPiletDebug(
188
204
  {
189
205
  root,
@@ -202,6 +218,8 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
202
218
  bundlerName,
203
219
  );
204
220
 
221
+ await hooks.afterBuild?.({ root, importmap, entryModule, schemaVersion, bundler });
222
+
205
223
  return {
206
224
  emulator,
207
225
  appFile,
@@ -260,7 +278,10 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
260
278
  ),
261
279
  );
262
280
 
281
+ await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets });
263
282
  await krasServer.start();
264
283
  openBrowser(open, port);
284
+ await hooks.afterOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets });
265
285
  await new Promise((resolve) => krasServer.on('close', resolve));
286
+ await hooks.onEnd?.({});
266
287
  }
@@ -60,6 +60,18 @@ export interface DebugPiralOptions {
60
60
  * Additional arguments for a specific bundler.
61
61
  */
62
62
  _?: Record<string, any>;
63
+
64
+ /**
65
+ * Hooks to be triggered at various stages.
66
+ */
67
+ hooks?: {
68
+ onBegin?(e: any): Promise<void>;
69
+ beforeBuild?(e: any): Promise<void>;
70
+ afterBuild?(e: any): Promise<void>;
71
+ beforeOnline?(e: any): Promise<void>;
72
+ afterOnline?(e: any): Promise<void>;
73
+ onEnd?(e: any): Promise<void>;
74
+ };
63
75
  }
64
76
 
65
77
  export const debugPiralDefaults: DebugPiralOptions = {
@@ -84,10 +96,13 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
84
96
  logLevel = debugPiralDefaults.logLevel,
85
97
  optimizeModules = debugPiralDefaults.optimizeModules,
86
98
  _ = {},
99
+ hooks = {},
87
100
  bundlerName,
88
101
  } = options;
89
102
  const fullBase = resolve(process.cwd(), baseDir);
90
103
  setLogLevel(logLevel);
104
+
105
+ await hooks.onBegin?.({ options, fullBase });
91
106
  progress('Reading configuration ...');
92
107
  const entryFiles = await retrievePiralRoot(fullBase, entry);
93
108
  const { externals, name, root, ignored } = await retrievePiletsInfo(entryFiles);
@@ -115,6 +130,8 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
115
130
  krasConfig.injectors = defaultConfig.injectors;
116
131
  }
117
132
 
133
+ await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, name });
134
+
118
135
  const bundler = await callPiralDebug(
119
136
  {
120
137
  root,
@@ -130,6 +147,7 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
130
147
  },
131
148
  bundlerName,
132
149
  );
150
+ await hooks.afterBuild?.({ root, publicUrl, externals, entryFiles, name, bundler });
133
151
 
134
152
  const injectorConfig = {
135
153
  active: true,
@@ -146,7 +164,10 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
146
164
  krasServer.removeAllListeners('open');
147
165
  krasServer.on('open', notifyServerOnline([bundler], krasConfig.api));
148
166
 
167
+ await hooks.beforeOnline?.({ krasServer, krasConfig, open, port });
149
168
  await krasServer.start();
150
169
  openBrowser(open, port);
170
+ await hooks.afterOnline?.({ krasServer, krasConfig, open, port });
151
171
  await new Promise((resolve) => krasServer.on('close', resolve));
172
+ await hooks.onEnd?.({});
152
173
  }
@@ -30,6 +30,7 @@ import {
30
30
  getPiralPath,
31
31
  detectMonorepo,
32
32
  bootstrapMonorepo,
33
+ getPiletScaffoldData,
33
34
  } from '../common';
34
35
 
35
36
  export interface NewPiletOptions {
@@ -193,16 +194,17 @@ always-auth=true`,
193
194
 
194
195
  progress(`Taking care of templating ...`);
195
196
 
196
- await scaffoldPiletSourceFiles(template, registry, language, root, packageName, forceOverwrite, variables);
197
+ const data = getPiletScaffoldData(language, root, packageName, variables);
198
+ await scaffoldPiletSourceFiles(template, registry, data, forceOverwrite);
197
199
 
198
200
  if (isEmulator) {
199
201
  // in the emulator case we get the files (and files_once) from the contained tarballs
200
- await copyPiralFiles(root, packageName, piralInfo, ForceOverwrite.yes);
202
+ await copyPiralFiles(root, packageName, piralInfo, ForceOverwrite.yes, data);
201
203
  } else {
202
204
  // otherwise, we perform the same action as in the emulator creation
203
205
  // just with a different target; not a created directory, but the root
204
206
  const packageRoot = getPiralPath(root, packageName);
205
- await copyScaffoldingFiles(packageRoot, root, files, piralInfo);
207
+ await copyScaffoldingFiles(packageRoot, root, files, piralInfo, data);
206
208
  }
207
209
 
208
210
  await patchPiletPackage(root, packageName, packageVersion, piralInfo, isEmulator, {
@@ -18,6 +18,7 @@ import {
18
18
  determineNpmClient,
19
19
  defaultRegistry,
20
20
  cliVersion,
21
+ getPiralScaffoldData,
21
22
  } from '../common';
22
23
 
23
24
  export interface NewPiralOptions {
@@ -166,8 +167,9 @@ always-auth=true`,
166
167
  await installPackage(npmClient, packageRef, root);
167
168
 
168
169
  progress(`Taking care of templating ...`);
169
-
170
- await scaffoldPiralSourceFiles(template, registry, language, root, app, framework, forceOverwrite, variables);
170
+
171
+ const data = getPiralScaffoldData(language, root, app, framework, variables);
172
+ await scaffoldPiralSourceFiles(template, registry, data, forceOverwrite);
171
173
 
172
174
  if (install) {
173
175
  progress(`Installing dependencies ...`);
@@ -25,6 +25,8 @@ import {
25
25
  detectMonorepo,
26
26
  bootstrapMonorepo,
27
27
  isMonorepoPackageRef,
28
+ getPiletScaffoldData,
29
+ SourceLanguage,
28
30
  } from '../common';
29
31
 
30
32
  export interface UpgradePiletOptions {
@@ -63,6 +65,11 @@ export interface UpgradePiletOptions {
63
65
  * works against Lerna, pnpm, and Yarn.
64
66
  */
65
67
  npmClient?: NpmClientType;
68
+
69
+ /**
70
+ * Places additional variables that should used when scaffolding.
71
+ */
72
+ variables?: Record<string, string>;
66
73
  }
67
74
 
68
75
  export const upgradePiletDefaults: UpgradePiletOptions = {
@@ -72,6 +79,7 @@ export const upgradePiletDefaults: UpgradePiletOptions = {
72
79
  logLevel: LogLevels.info,
73
80
  install: true,
74
81
  npmClient: undefined,
82
+ variables: {},
75
83
  };
76
84
 
77
85
  export async function upgradePilet(baseDir = process.cwd(), options: UpgradePiletOptions = {}) {
@@ -81,6 +89,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
81
89
  forceOverwrite = upgradePiletDefaults.forceOverwrite,
82
90
  logLevel = upgradePiletDefaults.logLevel,
83
91
  install = upgradePiletDefaults.install,
92
+ variables = upgradePiletDefaults.variables,
84
93
  } = options;
85
94
  const fullBase = resolve(process.cwd(), baseDir);
86
95
  const root = resolve(fullBase, target);
@@ -93,10 +102,11 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
93
102
 
94
103
  const npmClient = await determineNpmClient(root, options.npmClient);
95
104
  const pckg = await readJson(root, 'package.json');
96
- const { devDependencies = {}, dependencies = {}, piral } = pckg;
105
+ const { devDependencies = {}, dependencies = {}, piral, source } = pckg;
97
106
 
98
107
  if (piral && typeof piral === 'object') {
99
108
  const sourceName = piral.name;
109
+ const language = /\.jsx?$/.test(source) ? SourceLanguage.js : SourceLanguage.ts;
100
110
 
101
111
  if (!sourceName || typeof sourceName !== 'string') {
102
112
  fail('invalidPiletPackage_0042');
@@ -137,16 +147,17 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
137
147
  }
138
148
 
139
149
  progress(`Taking care of templating ...`);
150
+ const data = getPiletScaffoldData(language, root, sourceName, variables);
140
151
 
141
152
  if (isEmulator) {
142
153
  // in the emulator case we get the files from the contained tarball
143
- await copyPiralFiles(root, sourceName, piralInfo, forceOverwrite, originalFiles);
154
+ await copyPiralFiles(root, sourceName, piralInfo, forceOverwrite, data, originalFiles);
144
155
  } else {
145
156
  // otherwise, we perform the same action as in the emulator creation
146
157
  // just with a different target; not a created directory, but the root
147
158
  const packageRoot = getPiralPath(root, sourceName);
148
159
  const notOnceFiles = files.filter((m) => typeof m === 'string' || !m.once);
149
- await copyScaffoldingFiles(packageRoot, root, notOnceFiles, piralInfo);
160
+ await copyScaffoldingFiles(packageRoot, root, notOnceFiles, piralInfo, data);
150
161
  }
151
162
 
152
163
  await patchPiletPackage(root, sourceName, packageVersion, piralInfo, isEmulator);
package/src/commands.ts CHANGED
@@ -682,6 +682,9 @@ const allCommands: Array<ToolCommand<any>> = [
682
682
  .choices('npm-client', clientTypeKeys)
683
683
  .describe('npm-client', 'Sets the npm client to be used when upgrading.')
684
684
  .default('npm-client', apps.upgradePiletDefaults.npmClient)
685
+ .option('vars', undefined)
686
+ .describe('vars', 'Sets additional variables to be used when scaffolding.')
687
+ .default('vars', apps.upgradePiletDefaults.variables)
685
688
  .string('base')
686
689
  .default('base', process.cwd())
687
690
  .describe('base', 'Sets the base directory. By default the current directory is used.');
@@ -694,6 +697,7 @@ const allCommands: Array<ToolCommand<any>> = [
694
697
  forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
695
698
  install: args.install as boolean,
696
699
  npmClient: args['npm-client'] as NpmClientType,
700
+ variables: args.vars as Record<string, string>,
697
701
  });
698
702
  },
699
703
  },
@@ -46,11 +46,13 @@ export async function createEmulatorSources(
46
46
  const filesOnceDir = resolve(rootDir, filesOnceTar);
47
47
 
48
48
  const filesMap = files
49
+ .filter((file) => file && (typeof file === 'string' || typeof file === 'object'))
49
50
  .map((file) => (typeof file === 'string' ? { from: file, to: file } : file))
51
+ .filter((file) => typeof file.to === 'string' && typeof file.from === 'string')
50
52
  .map((file) => ({
51
53
  ...file,
52
54
  to: file.to.replace(/\\/g, '/'),
53
- from: join('files', file.from).replace(/\\/g, '/'),
55
+ from: join('files', file.to).replace(/\\/g, '/'),
54
56
  }));
55
57
 
56
58
  // do not modify an existing JSON
package/src/common/log.ts CHANGED
@@ -11,10 +11,15 @@ type MessageTypes = keyof Messages;
11
11
 
12
12
  const logger = (() => {
13
13
  try {
14
- return require('@parcel/logger');
15
- } catch {
16
- return require('../external').logger;
17
- }
14
+ const logger = require('@parcel/logger');
15
+
16
+ // check to see if this is really right
17
+ if (typeof logger.verbose === 'function') {
18
+ return logger;
19
+ }
20
+ } catch {}
21
+
22
+ return require('../external').logger;
18
23
  })();
19
24
 
20
25
  // unfortunately, Parcel's support for verbose logging on Windows is broken