piral-cli 0.14.0-unstable.3096 → 0.14.1-beta.3244
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/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/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/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(source, 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: {
|
|
@@ -437,6 +472,7 @@ export async function patchPiletPackage(
|
|
|
437
472
|
name: string,
|
|
438
473
|
version: string,
|
|
439
474
|
piralInfo: any,
|
|
475
|
+
fromEmulator: boolean,
|
|
440
476
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
441
477
|
) {
|
|
442
478
|
log('generalDebug_0003', `Patching the package.json in "${root}" ...`);
|
|
@@ -450,7 +486,6 @@ export async function patchPiletPackage(
|
|
|
450
486
|
...piralInfo.dependencies,
|
|
451
487
|
};
|
|
452
488
|
const typeDependencies = newInfo ? getDevDependencies(newInfo.language) : {};
|
|
453
|
-
const allExternals = makeExternals(externals);
|
|
454
489
|
const scripts = newInfo
|
|
455
490
|
? {
|
|
456
491
|
start: 'pilet debug',
|
|
@@ -460,6 +495,7 @@ export async function patchPiletPackage(
|
|
|
460
495
|
}
|
|
461
496
|
: info.scripts;
|
|
462
497
|
const peerModules = [];
|
|
498
|
+
const allExternals = makePiletExternals(externals, fromEmulator, piralInfo);
|
|
463
499
|
const peerDependencies = {
|
|
464
500
|
...allExternals.reduce((deps, name) => {
|
|
465
501
|
const valid = isValidDependency(name);
|
package/src/common/scaffold.ts
CHANGED
|
@@ -93,51 +93,67 @@ function getLanguageName(language: SourceLanguage) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
export
|
|
97
|
-
template: string,
|
|
98
|
-
registry: string,
|
|
96
|
+
export function getPiralScaffoldData(
|
|
99
97
|
language: SourceLanguage,
|
|
100
98
|
root: string,
|
|
101
99
|
app: string,
|
|
102
100
|
packageName: Framework,
|
|
103
|
-
forceOverwrite: ForceOverwrite,
|
|
104
101
|
variables: Record<string, string>,
|
|
105
102
|
) {
|
|
106
103
|
const src = dirname(join(root, app));
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
await createDirectory(src);
|
|
110
|
-
|
|
111
|
-
const files = await getTemplateFiles(templatePackageName, registry, root, {
|
|
104
|
+
return {
|
|
112
105
|
...variables,
|
|
106
|
+
root,
|
|
113
107
|
src,
|
|
114
108
|
language: getLanguageName(language),
|
|
115
109
|
packageName,
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await writeFiles(root, files, forceOverwrite);
|
|
110
|
+
};
|
|
119
111
|
}
|
|
120
112
|
|
|
121
|
-
export async function
|
|
113
|
+
export async function scaffoldPiralSourceFiles(
|
|
122
114
|
template: string,
|
|
123
115
|
registry: string,
|
|
116
|
+
data: ReturnType<typeof getPiralScaffoldData>,
|
|
117
|
+
forceOverwrite: ForceOverwrite,
|
|
118
|
+
) {
|
|
119
|
+
const { src, root } = data;
|
|
120
|
+
const templatePackageName = getTemplatePackageName('piral', template);
|
|
121
|
+
|
|
122
|
+
await createDirectory(src);
|
|
123
|
+
|
|
124
|
+
const files = await getTemplateFiles(templatePackageName, registry, root, data);
|
|
125
|
+
|
|
126
|
+
await writeFiles(root, files, forceOverwrite);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function getPiletScaffoldData(
|
|
124
130
|
language: SourceLanguage,
|
|
125
131
|
root: string,
|
|
126
132
|
sourceName: string,
|
|
127
|
-
forceOverwrite: ForceOverwrite,
|
|
128
133
|
variables: Record<string, string>,
|
|
129
134
|
) {
|
|
130
135
|
const src = join(root, 'src');
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
await createDirectory(src);
|
|
134
|
-
|
|
135
|
-
const files = await getTemplateFiles(templatePackageName, registry, root, {
|
|
136
|
+
return {
|
|
136
137
|
...variables,
|
|
138
|
+
root,
|
|
137
139
|
src,
|
|
138
140
|
language: getLanguageName(language),
|
|
139
141
|
sourceName,
|
|
140
|
-
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function scaffoldPiletSourceFiles(
|
|
146
|
+
template: string,
|
|
147
|
+
registry: string,
|
|
148
|
+
data: ReturnType<typeof getPiletScaffoldData>,
|
|
149
|
+
forceOverwrite: ForceOverwrite,
|
|
150
|
+
) {
|
|
151
|
+
const { src, root } = data;
|
|
152
|
+
const templatePackageName = getTemplatePackageName('pilet', template);
|
|
153
|
+
|
|
154
|
+
await createDirectory(src);
|
|
155
|
+
|
|
156
|
+
const files = await getTemplateFiles(templatePackageName, registry, root, data);
|
|
141
157
|
|
|
142
158
|
await writeFiles(root, files, forceOverwrite);
|
|
143
159
|
}
|
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);
|
package/src/helpers.ts
CHANGED
|
@@ -5,7 +5,7 @@ export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'none'];
|
|
|
5
5
|
export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
|
|
6
6
|
export const buildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
|
|
7
7
|
export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn'];
|
|
8
|
-
export const bundlerKeys: Array<string> = ['none', 'parcel', 'webpack', 'webpack5'];
|
|
8
|
+
export const bundlerKeys: Array<string> = ['none', 'parcel', 'webpack', 'webpack5', 'esbuild'];
|
|
9
9
|
export const availableBundlers: Array<string> = [];
|
|
10
10
|
export const availableReleaseProviders: Array<string> = [];
|
|
11
11
|
export const frameworkKeys: Array<Framework> = ['piral', 'piral-core', 'piral-base'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import PiralInjector
|
|
1
|
+
import PiralInjector from './piral';
|
|
2
2
|
import { KrasRequest, KrasResult } from 'kras';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
3
4
|
|
|
4
5
|
const bundlerMock = {
|
|
5
6
|
pending: true,
|
|
@@ -36,7 +37,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
36
37
|
bundler,
|
|
37
38
|
active: true,
|
|
38
39
|
};
|
|
39
|
-
const injector = new PiralInjector(config);
|
|
40
|
+
const injector = new PiralInjector(config, undefined, new EventEmitter());
|
|
40
41
|
expect(injector.active).toBeTruthy();
|
|
41
42
|
});
|
|
42
43
|
|
|
@@ -46,7 +47,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
46
47
|
bundler: bundlerMock,
|
|
47
48
|
active: true,
|
|
48
49
|
};
|
|
49
|
-
const injector = new PiralInjector(config);
|
|
50
|
+
const injector = new PiralInjector(config, undefined, new EventEmitter());
|
|
50
51
|
|
|
51
52
|
// Act
|
|
52
53
|
injector.active = false;
|
|
@@ -64,7 +65,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
64
65
|
bundler: bundlerMock,
|
|
65
66
|
active: true,
|
|
66
67
|
};
|
|
67
|
-
const injector = new PiralInjector(config);
|
|
68
|
+
const injector = new PiralInjector(config, undefined, new EventEmitter());
|
|
68
69
|
|
|
69
70
|
// Act
|
|
70
71
|
const res = injector.sendResponse('some/nice/invalid/path', 'sometarget.file', 'someDir', 'localhost:1234');
|
|
@@ -79,7 +80,7 @@ describe('Piral-CLI piral injector', () => {
|
|
|
79
80
|
bundler: bundlerMock,
|
|
80
81
|
active: true,
|
|
81
82
|
};
|
|
82
|
-
const injector = new PiralInjector(config);
|
|
83
|
+
const injector = new PiralInjector(config, undefined, new EventEmitter());
|
|
83
84
|
const request: KrasRequest = {
|
|
84
85
|
content: 'someFakeContent',
|
|
85
86
|
headers: {},
|
package/src/injectors/piral.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
2
3
|
import { readFileSync, existsSync, statSync } from 'fs';
|
|
3
|
-
import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig } from 'kras';
|
|
4
|
+
import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration } from 'kras';
|
|
4
5
|
import { mime } from '../external';
|
|
5
6
|
import { Bundler } from '../types';
|
|
6
7
|
|
|
@@ -16,8 +17,26 @@ export interface PiralInjectorConfig extends KrasInjectorConfig {
|
|
|
16
17
|
export default class PiralInjector implements KrasInjector {
|
|
17
18
|
public config: PiralInjectorConfig;
|
|
18
19
|
|
|
19
|
-
constructor(options: PiralInjectorConfig) {
|
|
20
|
+
constructor(options: PiralInjectorConfig, _config: KrasConfiguration, core: EventEmitter) {
|
|
20
21
|
this.config = options;
|
|
22
|
+
const api = '/$events';
|
|
23
|
+
const cbs = {};
|
|
24
|
+
|
|
25
|
+
core.on('user-connected', (e) => {
|
|
26
|
+
if (e.target === '*' && e.url === api.substr(1)) {
|
|
27
|
+
cbs[e.id] = (msg: string) => e.ws.send(msg);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
core.on('user-disconnected', (e) => {
|
|
32
|
+
delete cbs[e.id];
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.config.bundler.on((args) => {
|
|
36
|
+
for (const id of Object.keys(cbs)) {
|
|
37
|
+
cbs[id](JSON.stringify(args));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
21
40
|
}
|
|
22
41
|
|
|
23
42
|
get active() {
|