piral-cli 0.14.0-beta.3183 → 0.14.0-beta.3215
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/lib/apps/build-pilet.d.ts +11 -0
- package/lib/apps/build-pilet.js +8 -1
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.d.ts +13 -0
- package/lib/apps/build-piral.js +14 -3
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.d.ts +11 -0
- package/lib/apps/debug-pilet.js +12 -3
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.d.ts +11 -0
- package/lib/apps/debug-piral.js +8 -1
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/new-pilet.js +3 -2
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/upgrade-pilet.d.ts +4 -0
- package/lib/apps/upgrade-pilet.js +5 -3
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/commands.js +4 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/emulator.js +3 -1
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/log.js +7 -4
- package/lib/common/log.js.map +1 -1
- package/lib/common/package.d.ts +4 -4
- package/lib/common/package.js +41 -22
- package/lib/common/package.js.map +1 -1
- package/lib/common/template.d.ts +1 -0
- package/lib/common/template.js +29 -2
- package/lib/common/template.js.map +1 -1
- package/lib/types/common.d.ts +1 -0
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +22 -0
- package/src/apps/build-piral.ts +36 -2
- package/src/apps/debug-pilet.ts +27 -6
- package/src/apps/debug-piral.ts +21 -0
- package/src/apps/new-pilet.ts +3 -2
- package/src/apps/upgrade-pilet.ts +10 -2
- package/src/commands.ts +4 -0
- package/src/common/emulator.ts +3 -1
- package/src/common/log.ts +9 -4
- package/src/common/package.ts +51 -16
- package/src/common/template.ts +24 -1
- package/src/types/common.ts +1 -0
package/src/apps/build-piral.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/apps/debug-pilet.ts
CHANGED
|
@@ -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 "${
|
|
171
|
+
log('generalDebug_0003', `Looking for (${multi ? 'multi' : 'single'}) "${entryList.join('", "')}" in "${fullBase}".`);
|
|
156
172
|
|
|
157
|
-
const allEntries = await matchAnyPilet(
|
|
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 } =
|
|
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
|
}
|
package/src/apps/debug-piral.ts
CHANGED
|
@@ -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
|
}
|
package/src/apps/new-pilet.ts
CHANGED
|
@@ -192,17 +192,18 @@ always-auth=true`,
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
progress(`Taking care of templating ...`);
|
|
195
|
+
variables.sourceName = sourceName;
|
|
195
196
|
|
|
196
197
|
await scaffoldPiletSourceFiles(template, registry, language, root, packageName, forceOverwrite, variables);
|
|
197
198
|
|
|
198
199
|
if (isEmulator) {
|
|
199
200
|
// in the emulator case we get the files (and files_once) from the contained tarballs
|
|
200
|
-
await copyPiralFiles(root, packageName, piralInfo, ForceOverwrite.yes);
|
|
201
|
+
await copyPiralFiles(root, packageName, piralInfo, ForceOverwrite.yes, variables);
|
|
201
202
|
} else {
|
|
202
203
|
// otherwise, we perform the same action as in the emulator creation
|
|
203
204
|
// just with a different target; not a created directory, but the root
|
|
204
205
|
const packageRoot = getPiralPath(root, packageName);
|
|
205
|
-
await copyScaffoldingFiles(packageRoot, root, files, piralInfo);
|
|
206
|
+
await copyScaffoldingFiles(packageRoot, root, files, piralInfo, variables);
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
await patchPiletPackage(root, packageName, packageVersion, piralInfo, isEmulator, {
|
|
@@ -63,6 +63,11 @@ export interface UpgradePiletOptions {
|
|
|
63
63
|
* works against Lerna, pnpm, and Yarn.
|
|
64
64
|
*/
|
|
65
65
|
npmClient?: NpmClientType;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Places additional variables that should used when scaffolding.
|
|
69
|
+
*/
|
|
70
|
+
variables?: Record<string, string>;
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
export const upgradePiletDefaults: UpgradePiletOptions = {
|
|
@@ -72,6 +77,7 @@ export const upgradePiletDefaults: UpgradePiletOptions = {
|
|
|
72
77
|
logLevel: LogLevels.info,
|
|
73
78
|
install: true,
|
|
74
79
|
npmClient: undefined,
|
|
80
|
+
variables: {},
|
|
75
81
|
};
|
|
76
82
|
|
|
77
83
|
export async function upgradePilet(baseDir = process.cwd(), options: UpgradePiletOptions = {}) {
|
|
@@ -81,6 +87,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
81
87
|
forceOverwrite = upgradePiletDefaults.forceOverwrite,
|
|
82
88
|
logLevel = upgradePiletDefaults.logLevel,
|
|
83
89
|
install = upgradePiletDefaults.install,
|
|
90
|
+
variables = upgradePiletDefaults.variables,
|
|
84
91
|
} = options;
|
|
85
92
|
const fullBase = resolve(process.cwd(), baseDir);
|
|
86
93
|
const root = resolve(fullBase, target);
|
|
@@ -137,16 +144,17 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
progress(`Taking care of templating ...`);
|
|
147
|
+
variables.sourceName = sourceName;
|
|
140
148
|
|
|
141
149
|
if (isEmulator) {
|
|
142
150
|
// in the emulator case we get the files from the contained tarball
|
|
143
|
-
await copyPiralFiles(root, sourceName, piralInfo, forceOverwrite, originalFiles);
|
|
151
|
+
await copyPiralFiles(root, sourceName, piralInfo, forceOverwrite, variables, originalFiles);
|
|
144
152
|
} else {
|
|
145
153
|
// otherwise, we perform the same action as in the emulator creation
|
|
146
154
|
// just with a different target; not a created directory, but the root
|
|
147
155
|
const packageRoot = getPiralPath(root, sourceName);
|
|
148
156
|
const notOnceFiles = files.filter((m) => typeof m === 'string' || !m.once);
|
|
149
|
-
await copyScaffoldingFiles(packageRoot, root, notOnceFiles, piralInfo);
|
|
157
|
+
await copyScaffoldingFiles(packageRoot, root, notOnceFiles, piralInfo, variables);
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
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
|
},
|
package/src/common/emulator.ts
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
package/src/common/package.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { SourceLanguage, ForceOverwrite } from './enums';
|
|
|
7
7
|
import { checkAppShellCompatibility } from './compatibility';
|
|
8
8
|
import { deepMerge } from './merge';
|
|
9
9
|
import { getHashFromUrl } from './http';
|
|
10
|
-
import {
|
|
10
|
+
import { applyTemplate } from './template';
|
|
11
|
+
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, makePiletExternals, makeExternals } from './npm';
|
|
11
12
|
import { filesTar, filesOnceTar, declarationEntryExtensions } from './constants';
|
|
12
13
|
import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
13
14
|
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
@@ -31,6 +32,7 @@ function getDependencyVersion(
|
|
|
31
32
|
interface FileDescriptor {
|
|
32
33
|
sourcePath: string;
|
|
33
34
|
targetPath: string;
|
|
35
|
+
template: boolean;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
const globPatternStartIndicators = ['*', '?', '[', '!(', '?(', '+(', '@('];
|
|
@@ -40,7 +42,12 @@ async function getMatchingFiles(
|
|
|
40
42
|
target: string,
|
|
41
43
|
file: string | TemplateFileLocation,
|
|
42
44
|
): Promise<Array<FileDescriptor>> {
|
|
43
|
-
const {
|
|
45
|
+
const {
|
|
46
|
+
from,
|
|
47
|
+
to,
|
|
48
|
+
deep = true,
|
|
49
|
+
template = false,
|
|
50
|
+
} = typeof file === 'string' ? { from: file, to: file, deep: true } : file;
|
|
44
51
|
const sourcePath = resolve(source, from);
|
|
45
52
|
const targetPath = resolve(target, to);
|
|
46
53
|
const isDirectory = await checkIsDirectory(sourcePath);
|
|
@@ -52,6 +59,7 @@ async function getMatchingFiles(
|
|
|
52
59
|
return files.map((file) => ({
|
|
53
60
|
sourcePath: file,
|
|
54
61
|
targetPath: resolve(targetPath, relative(sourcePath, file)),
|
|
62
|
+
template,
|
|
55
63
|
}));
|
|
56
64
|
} else if (globPatternStartIndicators.some((m) => from.indexOf(m) !== -1)) {
|
|
57
65
|
log('generalDebug_0003', `Matching using glob "${sourcePath}".`);
|
|
@@ -73,6 +81,7 @@ async function getMatchingFiles(
|
|
|
73
81
|
return files.map((file) => ({
|
|
74
82
|
sourcePath: file,
|
|
75
83
|
targetPath: resolve(tarRoot, relative(relRoot, file)),
|
|
84
|
+
template,
|
|
76
85
|
}));
|
|
77
86
|
}
|
|
78
87
|
|
|
@@ -82,6 +91,7 @@ async function getMatchingFiles(
|
|
|
82
91
|
{
|
|
83
92
|
sourcePath,
|
|
84
93
|
targetPath,
|
|
94
|
+
template,
|
|
85
95
|
},
|
|
86
96
|
];
|
|
87
97
|
}
|
|
@@ -174,26 +184,35 @@ export function getPiralPackage(
|
|
|
174
184
|
};
|
|
175
185
|
}
|
|
176
186
|
|
|
177
|
-
async function getAvailableFiles(
|
|
187
|
+
async function getAvailableFiles(
|
|
188
|
+
root: string,
|
|
189
|
+
name: string,
|
|
190
|
+
dirName: string,
|
|
191
|
+
fileMap: Array<TemplateFileLocation>,
|
|
192
|
+
): Promise<Array<FileDescriptor>> {
|
|
178
193
|
const source = getPiralPath(root, name);
|
|
179
|
-
|
|
180
|
-
|
|
194
|
+
const tgz = `${dirName}.tar`;
|
|
195
|
+
log('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
|
|
196
|
+
const exists = await checkExists(resolve(source, tgz));
|
|
181
197
|
|
|
182
198
|
if (exists) {
|
|
183
|
-
await unpackTarball(source,
|
|
199
|
+
await unpackTarball(source, tgz);
|
|
184
200
|
}
|
|
185
201
|
|
|
186
202
|
log('generalDebug_0003', `Get matching files from "${source}".`);
|
|
187
|
-
const base = resolve(source,
|
|
203
|
+
const base = resolve(source, dirName);
|
|
188
204
|
const files = await matchFiles(base, '**/*');
|
|
205
|
+
|
|
189
206
|
return files.map((file) => ({
|
|
190
207
|
sourcePath: file,
|
|
191
208
|
targetPath: resolve(root, relative(base, file)),
|
|
209
|
+
template: fileMap.find((m) => resolve(base, m.from) === file)?.template || false,
|
|
192
210
|
}));
|
|
193
211
|
}
|
|
194
212
|
|
|
195
|
-
export async function getFileStats(root: string, name: string) {
|
|
196
|
-
const files = await getAvailableFiles(root, name, filesTar);
|
|
213
|
+
export async function getFileStats(root: string, name: string, fileMap: Array<TemplateFileLocation> = []) {
|
|
214
|
+
const files = await getAvailableFiles(root, name, filesTar, fileMap);
|
|
215
|
+
|
|
197
216
|
return await Promise.all(
|
|
198
217
|
files.map(async (file) => {
|
|
199
218
|
const { sourcePath, targetPath } = file;
|
|
@@ -214,15 +233,20 @@ async function copyFiles(
|
|
|
214
233
|
subfiles: Array<FileDescriptor>,
|
|
215
234
|
forceOverwrite: ForceOverwrite,
|
|
216
235
|
originalFiles: Array<FileInfo>,
|
|
236
|
+
variables?: Record<string, string>,
|
|
217
237
|
) {
|
|
218
238
|
for (const subfile of subfiles) {
|
|
219
|
-
const { sourcePath, targetPath } = subfile;
|
|
239
|
+
const { sourcePath, targetPath, template } = subfile;
|
|
220
240
|
const exists = await checkExists(sourcePath);
|
|
221
241
|
|
|
222
242
|
if (exists) {
|
|
223
243
|
const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
|
|
224
244
|
const force = overwrite ? ForceOverwrite.yes : forceOverwrite;
|
|
225
|
-
await copy(sourcePath, targetPath, force);
|
|
245
|
+
const written = await copy(sourcePath, targetPath, force);
|
|
246
|
+
|
|
247
|
+
if (written && template && variables) {
|
|
248
|
+
await applyTemplate(targetPath, variables);
|
|
249
|
+
}
|
|
226
250
|
} else {
|
|
227
251
|
fail('cannotFindFile_0046', sourcePath);
|
|
228
252
|
}
|
|
@@ -234,6 +258,7 @@ export async function copyScaffoldingFiles(
|
|
|
234
258
|
target: string,
|
|
235
259
|
files: Array<string | TemplateFileLocation>,
|
|
236
260
|
piralInfo?: any,
|
|
261
|
+
variables?: Record<string, string>,
|
|
237
262
|
) {
|
|
238
263
|
log('generalDebug_0003', `Copying the scaffolding files ...`);
|
|
239
264
|
const allFiles: Array<FileDescriptor> = [];
|
|
@@ -247,7 +272,7 @@ export async function copyScaffoldingFiles(
|
|
|
247
272
|
await extendPackageOverridesFromTemplateFragment(target, piralInfo, allFiles);
|
|
248
273
|
}
|
|
249
274
|
|
|
250
|
-
await copyFiles(allFiles, ForceOverwrite.yes, []);
|
|
275
|
+
await copyFiles(allFiles, ForceOverwrite.yes, [], variables);
|
|
251
276
|
}
|
|
252
277
|
|
|
253
278
|
async function extendPackageOverridesFromTemplateFragment(root: string, piralInfo: any, files: Array<FileDescriptor>) {
|
|
@@ -276,24 +301,31 @@ async function extendPackageOverridesFromTemplateFragment(root: string, piralInf
|
|
|
276
301
|
}
|
|
277
302
|
}
|
|
278
303
|
|
|
304
|
+
function isTemplateFileLocation(item: string | TemplateFileLocation): item is TemplateFileLocation {
|
|
305
|
+
return typeof item === 'object';
|
|
306
|
+
}
|
|
307
|
+
|
|
279
308
|
export async function copyPiralFiles(
|
|
280
309
|
root: string,
|
|
281
310
|
name: string,
|
|
282
311
|
piralInfo: any,
|
|
283
312
|
forceOverwrite: ForceOverwrite,
|
|
313
|
+
variables: Record<string, string>,
|
|
284
314
|
originalFiles?: Array<FileInfo>,
|
|
285
315
|
) {
|
|
286
316
|
log('generalDebug_0003', `Copying the Piral files ...`);
|
|
287
|
-
const files =
|
|
317
|
+
const { files: _files } = getPiletsInfo(piralInfo);
|
|
318
|
+
const fileMap = _files.filter(isTemplateFileLocation);
|
|
319
|
+
const files = await getAvailableFiles(root, name, filesTar, fileMap);
|
|
288
320
|
|
|
289
321
|
if (originalFiles === undefined) {
|
|
290
|
-
const initialFiles = await getAvailableFiles(root, name, filesOnceTar);
|
|
322
|
+
const initialFiles = await getAvailableFiles(root, name, filesOnceTar, fileMap);
|
|
291
323
|
files.push(...initialFiles);
|
|
292
324
|
originalFiles = [];
|
|
293
325
|
}
|
|
294
326
|
|
|
295
327
|
await extendPackageOverridesFromTemplateFragment(root, piralInfo, files);
|
|
296
|
-
await copyFiles(files, forceOverwrite, originalFiles);
|
|
328
|
+
await copyFiles(files, forceOverwrite, originalFiles, variables);
|
|
297
329
|
}
|
|
298
330
|
|
|
299
331
|
export function getPiletsInfo(piralInfo: any): PiletsInfo {
|
|
@@ -410,9 +442,12 @@ export async function retrievePiletsInfo(entryFile: string) {
|
|
|
410
442
|
}
|
|
411
443
|
|
|
412
444
|
const packageInfo = require(packageJson);
|
|
445
|
+
const info = getPiletsInfo(packageInfo);
|
|
446
|
+
const externals = makeExternals(info.externals);
|
|
413
447
|
|
|
414
448
|
return {
|
|
415
|
-
...
|
|
449
|
+
...info,
|
|
450
|
+
externals,
|
|
416
451
|
name: packageInfo.name,
|
|
417
452
|
version: packageInfo.version,
|
|
418
453
|
dependencies: {
|
package/src/common/template.ts
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { renderFile } from 'ejs';
|
|
2
|
+
import { writeFile } from 'fs';
|
|
2
3
|
import { resolve } from 'path';
|
|
3
4
|
import { log } from './log';
|
|
4
5
|
import { ForceOverwrite } from './enums';
|
|
5
6
|
import { createFileIfNotExists } from './io';
|
|
6
7
|
|
|
8
|
+
export async function applyTemplate(file: string, data: Record<string, string>) {
|
|
9
|
+
const content = await new Promise<string>((resolve, reject) => {
|
|
10
|
+
log('generalDebug_0003', `Filling template in "${file}".`);
|
|
11
|
+
renderFile(file, data, (err, str) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
reject(err);
|
|
14
|
+
} else {
|
|
15
|
+
resolve(str);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
await new Promise<void>((resolve, reject) => {
|
|
20
|
+
writeFile(file, content, 'utf8', (err) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
} else {
|
|
24
|
+
resolve();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
7
30
|
export function fillTemplate(name: string, data: any = {}) {
|
|
8
31
|
const path = resolve(__dirname, '..', '..', 'templates', `${name}.ejs`);
|
|
9
32
|
return new Promise<string>((resolve, reject) => {
|
|
10
|
-
log('generalDebug_0003', `Rendering template "{name}" in "${path}".`);
|
|
33
|
+
log('generalDebug_0003', `Rendering template "${name}" in "${path}".`);
|
|
11
34
|
renderFile(path, data, (err, str) => {
|
|
12
35
|
if (err) {
|
|
13
36
|
reject(err);
|