piral-cli 0.14.0-unstable.3068 → 0.14.0
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 +5 -2
- 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 +16 -5
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.d.ts +11 -0
- package/lib/apps/debug-pilet.js +15 -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 +11 -1
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/new-pilet.d.ts +1 -1
- package/lib/apps/new-pilet.js +11 -7
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.d.ts +1 -1
- package/lib/apps/new-piral.js +4 -3
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.js +1 -1
- package/lib/apps/publish-pilet.d.ts +1 -1
- package/lib/apps/publish-pilet.js +1 -1
- package/lib/apps/upgrade-pilet.d.ts +6 -2
- package/lib/apps/upgrade-pilet.js +9 -6
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.d.ts +2 -2
- package/lib/apps/upgrade-piral.js +1 -1
- package/lib/build/bundler-calls.d.ts +3 -0
- package/lib/build/bundler-calls.js +107 -0
- package/lib/build/bundler-calls.js.map +1 -0
- package/lib/build/run-build-pilet.d.ts +1 -0
- package/lib/build/run-build-pilet.js +65 -0
- package/lib/build/run-build-pilet.js.map +1 -0
- package/lib/build/run-build-piral.d.ts +1 -0
- package/lib/build/run-build-piral.js +66 -0
- package/lib/build/run-build-piral.js.map +1 -0
- package/lib/build/run-debug-mono-piral.d.ts +1 -0
- package/lib/build/run-debug-mono-piral.js +71 -0
- package/lib/build/run-debug-mono-piral.js.map +1 -0
- package/lib/build/run-debug-pilet.d.ts +1 -0
- package/lib/build/run-debug-pilet.js +90 -0
- package/lib/build/run-debug-pilet.js.map +1 -0
- package/lib/build/run-debug-piral.d.ts +1 -0
- package/lib/build/run-debug-piral.js +86 -0
- package/lib/build/run-debug-piral.js.map +1 -0
- package/lib/bundler.js +50 -13
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +12 -8
- package/lib/commands.js.map +1 -1
- package/lib/common/clients/npm.js +10 -10
- package/lib/common/constants.d.ts +1 -1
- package/lib/common/constants.js +2 -2
- package/lib/common/constants.js.map +1 -1
- package/lib/common/emulator.js +5 -2
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/io.js +1 -0
- package/lib/common/io.js.map +1 -1
- package/lib/common/log.js +7 -4
- package/lib/common/log.js.map +1 -1
- package/lib/common/npm.d.ts +3 -1
- package/lib/common/npm.js +31 -11
- package/lib/common/npm.js.map +1 -1
- package/lib/common/package.d.ts +5 -5
- package/lib/common/package.js +43 -24
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.d.ts +14 -2
- package/lib/common/scaffold.js +19 -7
- package/lib/common/scaffold.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/external/index.js +119 -155
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/injectors/piral.d.ts +4 -2
- package/lib/injectors/piral.js +16 -1
- package/lib/injectors/piral.js.map +1 -1
- package/lib/messages.d.ts +25 -21
- package/lib/messages.js +30 -22
- package/lib/messages.js.map +1 -1
- package/lib/types/common.d.ts +1 -0
- package/lib/types/public.d.ts +63 -11
- package/package.json +3 -3
- package/src/apps/build-pilet.ts +22 -0
- package/src/apps/build-piral.ts +38 -4
- package/src/apps/debug-pilet.ts +29 -6
- package/src/apps/debug-piral.ts +24 -0
- package/src/apps/new-pilet.ts +13 -8
- package/src/apps/new-piral.ts +7 -5
- package/src/apps/pack-pilet.test.ts +2 -2
- package/src/apps/pack-pilet.ts +1 -1
- package/src/apps/publish-pilet.ts +2 -2
- package/src/apps/upgrade-pilet.ts +18 -7
- package/src/apps/upgrade-piral.ts +3 -3
- package/src/build/bundler-calls.ts +121 -0
- package/src/build/run-build-pilet.ts +89 -0
- package/src/build/run-build-piral.ts +88 -0
- package/src/build/run-debug-mono-piral.ts +87 -0
- package/src/build/run-debug-pilet.ts +114 -0
- package/src/build/run-debug-piral.ts +106 -0
- package/src/bundler.test.ts +65 -46
- package/src/bundler.ts +53 -13
- package/src/commands.ts +20 -10
- package/src/common/clients/npm.ts +10 -10
- package/src/common/constants.ts +1 -1
- package/src/common/emulator.ts +5 -2
- package/src/common/io.ts +1 -0
- package/src/common/log.ts +9 -4
- package/src/common/npm.test.ts +18 -18
- package/src/common/npm.ts +27 -8
- package/src/common/package.ts +53 -17
- package/src/common/scaffold.ts +36 -20
- package/src/common/template.ts +24 -1
- package/src/helpers.ts +1 -1
- package/src/injectors/piral.test.ts +6 -5
- package/src/injectors/piral.ts +21 -2
- package/src/messages.ts +43 -35
- package/src/types/common.ts +1 -0
- package/src/types/public.ts +68 -20
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,16 +215,24 @@ 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);
|
|
206
|
-
|
|
207
|
-
} else {
|
|
232
|
+
await hooks.afterPackage?.({ root, externals, targetDir, outDir, rootDir });
|
|
208
233
|
logDone(`Emulator package available in "${rootDir}".`);
|
|
234
|
+
} else {
|
|
235
|
+
logDone(`Emulator sources available in "${rootDir}".`);
|
|
209
236
|
}
|
|
210
237
|
|
|
211
238
|
logReset();
|
|
@@ -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,10 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
|
|
|
202
218
|
bundlerName,
|
|
203
219
|
);
|
|
204
220
|
|
|
221
|
+
bundler.on((args) => {
|
|
222
|
+
hooks.afterBuild?.({ ...args, root, importmap, entryModule, schemaVersion, bundler });
|
|
223
|
+
});
|
|
224
|
+
|
|
205
225
|
return {
|
|
206
226
|
emulator,
|
|
207
227
|
appFile,
|
|
@@ -260,7 +280,10 @@ export async function debugPilet(baseDir = process.cwd(), options: DebugPiletOpt
|
|
|
260
280
|
),
|
|
261
281
|
);
|
|
262
282
|
|
|
283
|
+
await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets });
|
|
263
284
|
await krasServer.start();
|
|
264
285
|
openBrowser(open, port);
|
|
286
|
+
await hooks.afterOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets });
|
|
265
287
|
await new Promise((resolve) => krasServer.on('close', resolve));
|
|
288
|
+
await hooks.onEnd?.({});
|
|
266
289
|
}
|
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,
|
|
@@ -131,6 +148,10 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
|
|
|
131
148
|
bundlerName,
|
|
132
149
|
);
|
|
133
150
|
|
|
151
|
+
bundler.on((args) => {
|
|
152
|
+
hooks.afterBuild?.({ ...args, root, publicUrl, externals, entryFiles, name, bundler });
|
|
153
|
+
});
|
|
154
|
+
|
|
134
155
|
const injectorConfig = {
|
|
135
156
|
active: true,
|
|
136
157
|
handle: ['/'],
|
|
@@ -146,7 +167,10 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
|
|
|
146
167
|
krasServer.removeAllListeners('open');
|
|
147
168
|
krasServer.on('open', notifyServerOnline([bundler], krasConfig.api));
|
|
148
169
|
|
|
170
|
+
await hooks.beforeOnline?.({ krasServer, krasConfig, open, port });
|
|
149
171
|
await krasServer.start();
|
|
150
172
|
openBrowser(open, port);
|
|
173
|
+
await hooks.afterOnline?.({ krasServer, krasConfig, open, port });
|
|
151
174
|
await new Promise((resolve) => krasServer.on('close', resolve));
|
|
175
|
+
await hooks.onEnd?.({});
|
|
152
176
|
}
|
package/src/apps/new-pilet.ts
CHANGED
|
@@ -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 {
|
|
@@ -76,7 +77,7 @@ export interface NewPiletOptions {
|
|
|
76
77
|
logLevel?: LogLevels;
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
|
-
* The
|
|
80
|
+
* The npm client to be used when scaffolding.
|
|
80
81
|
* @example 'yarn'
|
|
81
82
|
*/
|
|
82
83
|
npmClient?: NpmClientType;
|
|
@@ -154,7 +155,7 @@ export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions
|
|
|
154
155
|
);
|
|
155
156
|
|
|
156
157
|
if (registry !== newPiletDefaults.registry) {
|
|
157
|
-
progress(`Setting up
|
|
158
|
+
progress(`Setting up npm registry (%s) ...`, registry);
|
|
158
159
|
|
|
159
160
|
await createFileIfNotExists(
|
|
160
161
|
root,
|
|
@@ -170,11 +171,11 @@ always-auth=true`,
|
|
|
170
171
|
if (!isLocal) {
|
|
171
172
|
const packageRef = combinePackageRef(sourceName, sourceVersion, type);
|
|
172
173
|
|
|
173
|
-
progress(`Installing
|
|
174
|
+
progress(`Installing npm package %s ...`, packageRef);
|
|
174
175
|
|
|
175
176
|
await installPackage(npmClient, packageRef, root, '--save-dev');
|
|
176
177
|
} else {
|
|
177
|
-
progress(`Using locally available
|
|
178
|
+
progress(`Using locally available npm package %s ...`, sourceName);
|
|
178
179
|
}
|
|
179
180
|
|
|
180
181
|
const packageName = await getPackageName(root, sourceName, type);
|
|
@@ -193,19 +194,23 @@ always-auth=true`,
|
|
|
193
194
|
|
|
194
195
|
progress(`Taking care of templating ...`);
|
|
195
196
|
|
|
196
|
-
|
|
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
|
-
await patchPiletPackage(root, packageName, packageVersion, piralInfo,
|
|
210
|
+
await patchPiletPackage(root, packageName, packageVersion, piralInfo, isEmulator, {
|
|
211
|
+
language,
|
|
212
|
+
bundler: bundlerName,
|
|
213
|
+
});
|
|
209
214
|
|
|
210
215
|
if (install) {
|
|
211
216
|
progress(`Installing dependencies ...`);
|
package/src/apps/new-piral.ts
CHANGED
|
@@ -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 {
|
|
@@ -72,7 +73,7 @@ export interface NewPiralOptions {
|
|
|
72
73
|
logLevel?: LogLevels;
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
|
-
* Sets the
|
|
76
|
+
* Sets the npm client to be used when scaffolding. (e.g. 'yarn')
|
|
76
77
|
*/
|
|
77
78
|
npmClient?: NpmClientType;
|
|
78
79
|
|
|
@@ -148,7 +149,7 @@ export async function newPiral(baseDir = process.cwd(), options: NewPiralOptions
|
|
|
148
149
|
);
|
|
149
150
|
|
|
150
151
|
if (registry !== newPiralDefaults.registry) {
|
|
151
|
-
progress(`Setting up
|
|
152
|
+
progress(`Setting up npm registry (%s) ...`, registry);
|
|
152
153
|
|
|
153
154
|
await createFileIfNotExists(
|
|
154
155
|
root,
|
|
@@ -161,13 +162,14 @@ always-auth=true`,
|
|
|
161
162
|
|
|
162
163
|
await updateExistingJson(root, 'package.json', getPiralPackage(app, language, version, framework, bundlerName));
|
|
163
164
|
|
|
164
|
-
progress(`Installing
|
|
165
|
+
progress(`Installing npm package ${packageRef} ...`);
|
|
165
166
|
|
|
166
167
|
await installPackage(npmClient, packageRef, root);
|
|
167
168
|
|
|
168
169
|
progress(`Taking care of templating ...`);
|
|
169
|
-
|
|
170
|
-
|
|
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 ...`);
|
|
@@ -8,7 +8,7 @@ function createTempDir() {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
describe('Pack Pilet Command', () => {
|
|
11
|
-
it('can pack a standard
|
|
11
|
+
it('can pack a standard npm package to a specified target', async () => {
|
|
12
12
|
const dir = createTempDir();
|
|
13
13
|
const target = 'foo.tgz';
|
|
14
14
|
const packageJson = resolve(dir, 'package.json');
|
|
@@ -28,7 +28,7 @@ describe('Pack Pilet Command', () => {
|
|
|
28
28
|
expect(existsSync(resolve(dir, target))).toBeTruthy();
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
it('can pack a standard
|
|
31
|
+
it('can pack a standard npm package to a the default target using the process directory', async () => {
|
|
32
32
|
const originalDir = process.cwd();
|
|
33
33
|
const dir = createTempDir();
|
|
34
34
|
const packageJson = resolve(dir, 'package.json');
|
package/src/apps/pack-pilet.ts
CHANGED
|
@@ -59,7 +59,7 @@ export interface PublishPiletOptions {
|
|
|
59
59
|
/**
|
|
60
60
|
* Changing the publish source makes it possible to publish pilets that have
|
|
61
61
|
* been stored on non-local paths, e.g., when a pilet was already published to
|
|
62
|
-
* an
|
|
62
|
+
* an npm feed.
|
|
63
63
|
*/
|
|
64
64
|
from?: PiletPublishSource;
|
|
65
65
|
|
|
@@ -114,7 +114,7 @@ async function getFiles(
|
|
|
114
114
|
log('generalDebug_0003', `Download file from "${source}".`);
|
|
115
115
|
return await downloadFile(source, ca);
|
|
116
116
|
case 'npm':
|
|
117
|
-
log('generalDebug_0003', `View
|
|
117
|
+
log('generalDebug_0003', `View npm package "${source}".`);
|
|
118
118
|
const url = await findTarball(source);
|
|
119
119
|
log('generalDebug_0003', `Download file from "${url}".`);
|
|
120
120
|
return await downloadFile(url, ca);
|
|
@@ -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 {
|
|
@@ -58,11 +60,16 @@ export interface UpgradePiletOptions {
|
|
|
58
60
|
install?: boolean;
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
|
-
* Defines the used
|
|
63
|
+
* Defines the used npm client. By default, "npm" is used
|
|
62
64
|
* if no other client is autodetected. The autodetection
|
|
63
|
-
* works against Lerna,
|
|
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');
|
|
@@ -120,7 +130,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
120
130
|
|
|
121
131
|
if (!monorepoRef) {
|
|
122
132
|
// only install the latest if the shell does come from remote
|
|
123
|
-
progress(`Updating
|
|
133
|
+
progress(`Updating npm package to %s ...`, packageRef);
|
|
124
134
|
await installPackage(npmClient, packageRef, root, '--no-save');
|
|
125
135
|
}
|
|
126
136
|
|
|
@@ -137,19 +147,20 @@ 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
|
-
await patchPiletPackage(root, sourceName, packageVersion, piralInfo);
|
|
163
|
+
await patchPiletPackage(root, sourceName, packageVersion, piralInfo, isEmulator);
|
|
153
164
|
|
|
154
165
|
if (install) {
|
|
155
166
|
progress(`Updating dependencies ...`);
|
|
@@ -42,9 +42,9 @@ export interface UpgradePiralOptions {
|
|
|
42
42
|
install?: boolean;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Defines the used
|
|
45
|
+
* Defines the used npm client. By default, "npm" is used
|
|
46
46
|
* if no other client is autodetected. The autodetection
|
|
47
|
-
* works against Lerna,
|
|
47
|
+
* works against Lerna, pnpm, and Yarn.
|
|
48
48
|
*/
|
|
49
49
|
npmClient?: NpmClientType;
|
|
50
50
|
}
|
|
@@ -112,7 +112,7 @@ export async function upgradePiral(baseDir = process.cwd(), options: UpgradePira
|
|
|
112
112
|
await updateExistingJson(root, 'package.json', pckg);
|
|
113
113
|
|
|
114
114
|
if (install) {
|
|
115
|
-
progress(`Updating the
|
|
115
|
+
progress(`Updating the npm packages to %s ...`, version);
|
|
116
116
|
await installDependencies(npmClient, root);
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { fork, ChildProcess } from 'child_process';
|
|
3
|
+
import { Bundler, BundleDetails, BaseBundleParameters } from '../types';
|
|
4
|
+
|
|
5
|
+
function getPath(name: string) {
|
|
6
|
+
return resolve(__dirname, '..', '..', 'lib', 'build', `run-${name}.js`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type BundleListener = (args: any) => void;
|
|
10
|
+
|
|
11
|
+
function createBundler(cwd: string, ps: ChildProcess, args: any) {
|
|
12
|
+
let promise = Promise.resolve();
|
|
13
|
+
const listeners: Array<BundleListener> = [];
|
|
14
|
+
const bundle: BundleDetails = {
|
|
15
|
+
dir: cwd,
|
|
16
|
+
hash: '',
|
|
17
|
+
name: '',
|
|
18
|
+
};
|
|
19
|
+
const setPending = () => {
|
|
20
|
+
promise = new Promise((done) => {
|
|
21
|
+
const f = () => {
|
|
22
|
+
done();
|
|
23
|
+
bundler.off(f);
|
|
24
|
+
};
|
|
25
|
+
bundler.on(f);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const bundler = {
|
|
29
|
+
bundle,
|
|
30
|
+
start() {
|
|
31
|
+
ps.send({
|
|
32
|
+
type: 'bundle',
|
|
33
|
+
...args,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
on(cb: BundleListener) {
|
|
37
|
+
listeners.push(cb);
|
|
38
|
+
},
|
|
39
|
+
off(cb: BundleListener) {
|
|
40
|
+
listeners.splice(listeners.indexOf(cb), 1);
|
|
41
|
+
},
|
|
42
|
+
emit(args: any) {
|
|
43
|
+
[...listeners].forEach((cb) => cb(args));
|
|
44
|
+
},
|
|
45
|
+
ready() {
|
|
46
|
+
return promise;
|
|
47
|
+
},
|
|
48
|
+
setPending,
|
|
49
|
+
};
|
|
50
|
+
setPending();
|
|
51
|
+
return bundler;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function callDynamic<T extends BaseBundleParameters>(name: string, path: string, args: T) {
|
|
55
|
+
const cwd = args.root;
|
|
56
|
+
return new Promise<Bundler>((resolve, reject) => {
|
|
57
|
+
const ps = fork(getPath(name), [], { cwd });
|
|
58
|
+
const bundler = createBundler(cwd, ps, args);
|
|
59
|
+
const setup = {
|
|
60
|
+
type: 'init',
|
|
61
|
+
path,
|
|
62
|
+
};
|
|
63
|
+
const start = () => {
|
|
64
|
+
ps.send({
|
|
65
|
+
type: 'start',
|
|
66
|
+
...args,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
ps.on('message', (msg: any) => {
|
|
71
|
+
switch (msg.type) {
|
|
72
|
+
case 'pending':
|
|
73
|
+
bundler.setPending();
|
|
74
|
+
break;
|
|
75
|
+
case 'update':
|
|
76
|
+
bundler.bundle.hash = msg.outHash;
|
|
77
|
+
bundler.bundle.name = msg.outName;
|
|
78
|
+
bundler.emit(msg.args);
|
|
79
|
+
break;
|
|
80
|
+
case 'done':
|
|
81
|
+
bundler.bundle.dir = msg.outDir;
|
|
82
|
+
return resolve(bundler);
|
|
83
|
+
case 'fail':
|
|
84
|
+
return reject(msg.error);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
ps.send(setup, start);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function callStatic<T extends BaseBundleParameters>(name: string, path: string, args: T) {
|
|
93
|
+
const cwd = args.root;
|
|
94
|
+
return new Promise<Bundler>((resolve, reject) => {
|
|
95
|
+
const ps = fork(getPath(name), [], { cwd });
|
|
96
|
+
const bundler = createBundler(cwd, ps, args);
|
|
97
|
+
const setup = {
|
|
98
|
+
type: 'init',
|
|
99
|
+
path,
|
|
100
|
+
};
|
|
101
|
+
const start = () => {
|
|
102
|
+
ps.send({
|
|
103
|
+
type: 'start',
|
|
104
|
+
...args,
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
ps.on('message', (msg: any) => {
|
|
109
|
+
switch (msg.type) {
|
|
110
|
+
case 'done':
|
|
111
|
+
bundler.bundle.dir = msg.outDir;
|
|
112
|
+
bundler.bundle.name = msg.outFile;
|
|
113
|
+
return resolve(bundler);
|
|
114
|
+
case 'fail':
|
|
115
|
+
return reject(msg.error);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
ps.send(setup, start);
|
|
120
|
+
});
|
|
121
|
+
}
|