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.
- 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 +4 -3
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +2 -1
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.d.ts +4 -0
- package/lib/apps/upgrade-pilet.js +7 -4
- 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/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/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 +5 -3
- package/src/apps/new-piral.ts +4 -2
- package/src/apps/upgrade-pilet.ts +14 -3
- 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/scaffold.ts +36 -20
- package/src/common/template.ts +24 -1
- package/src/types/common.ts +1 -0
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: {
|
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);
|