piral-cli 1.4.0-beta.6250 → 1.4.0-beta.6253
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/api.js +8 -17
- package/lib/api.js.map +1 -1
- package/lib/apps/add-piral-instance-pilet.js +20 -31
- package/lib/apps/add-piral-instance-pilet.js.map +1 -1
- package/lib/apps/build-pilet.js +139 -147
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.js +130 -144
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.js +107 -119
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +62 -70
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/declaration-piral.js +6 -17
- package/lib/apps/declaration-piral.js.map +1 -1
- package/lib/apps/new-pilet.js +71 -82
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +42 -53
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.js +7 -18
- package/lib/apps/pack-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.js +127 -141
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +48 -63
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/remove-piral-instance-pilet.js +30 -35
- package/lib/apps/remove-piral-instance-pilet.js.map +1 -1
- package/lib/apps/run-emulator-piral.js +49 -61
- package/lib/apps/run-emulator-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +64 -76
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +31 -43
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/apps/validate-pilet.js +34 -45
- package/lib/apps/validate-pilet.js.map +1 -1
- package/lib/apps/validate-piral.js +29 -51
- package/lib/apps/validate-piral.js.map +1 -1
- package/lib/build/bundler-calls.js +12 -3
- package/lib/build/bundler-calls.js.map +1 -1
- package/lib/build/run-build-pilet.js +5 -14
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js +5 -14
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/build/run-debug-mono-piral.js +5 -14
- package/lib/build/run-debug-mono-piral.js.map +1 -1
- package/lib/build/run-debug-pilet.js +5 -14
- package/lib/build/run-debug-pilet.js.map +1 -1
- package/lib/build/run-debug-piral.js +5 -14
- package/lib/build/run-debug-piral.js.map +1 -1
- package/lib/bundler.js +100 -127
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +5 -1
- package/lib/commands.js.map +1 -1
- package/lib/common/browser.js +13 -26
- package/lib/common/browser.js.map +1 -1
- package/lib/common/compatibility.js +10 -21
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/declaration.js +80 -101
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +186 -182
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/http.js +7 -4
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.js +172 -187
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/injectors.js +4 -1
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.js +5 -2
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.js +9 -15
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.js +256 -299
- package/lib/common/io.js.map +1 -1
- package/lib/common/language.js +21 -5
- package/lib/common/language.js.map +1 -1
- package/lib/common/npm.js +193 -228
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +71 -86
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.js +428 -448
- package/lib/common/package.js.map +1 -1
- package/lib/common/parallel.js +12 -23
- package/lib/common/parallel.js.map +1 -1
- package/lib/common/patcher.js +54 -71
- package/lib/common/patcher.js.map +1 -1
- package/lib/common/platform.js +1 -12
- package/lib/common/platform.js.map +1 -1
- package/lib/common/port.js +11 -24
- package/lib/common/port.js.map +1 -1
- package/lib/common/rules.js +6 -17
- package/lib/common/rules.js.map +1 -1
- package/lib/common/scaffold.js +52 -59
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/shell.js +50 -58
- package/lib/common/shell.js.map +1 -1
- package/lib/common/spec.js +1 -1
- package/lib/common/spec.js.map +1 -1
- package/lib/common/template.js +3 -14
- package/lib/common/template.js.map +1 -1
- package/lib/common/watcher.js +7 -16
- package/lib/common/watcher.js.map +1 -1
- package/lib/common/website.d.ts +5 -1
- package/lib/common/website.js +71 -57
- package/lib/common/website.js.map +1 -1
- package/lib/injectors/pilet-injector.js +138 -145
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/lib/injectors/piral-injector.js +55 -67
- package/lib/injectors/piral-injector.js.map +1 -1
- package/lib/messages.d.ts +81 -0
- package/lib/messages.js +94 -1
- package/lib/messages.js.map +1 -1
- package/lib/npm-clients/bun.js +36 -60
- package/lib/npm-clients/bun.js.map +1 -1
- package/lib/npm-clients/index.js +10 -21
- package/lib/npm-clients/index.js.map +1 -1
- package/lib/npm-clients/lerna.js +48 -72
- package/lib/npm-clients/lerna.js.map +1 -1
- package/lib/npm-clients/npm.js +69 -105
- package/lib/npm-clients/npm.js.map +1 -1
- package/lib/npm-clients/pnp.js +35 -59
- package/lib/npm-clients/pnp.js.map +1 -1
- package/lib/npm-clients/pnpm.js +35 -59
- package/lib/npm-clients/pnpm.js.map +1 -1
- package/lib/npm-clients/rush.js +53 -77
- package/lib/npm-clients/rush.js.map +1 -1
- package/lib/npm-clients/yarn.js +35 -59
- package/lib/npm-clients/yarn.js.map +1 -1
- package/lib/platforms/node.js +4 -17
- package/lib/platforms/node.js.map +1 -1
- package/lib/platforms/web.js +81 -96
- package/lib/platforms/web.js.map +1 -1
- package/lib/plugin.js +56 -75
- package/lib/plugin.js.map +1 -1
- package/lib/questionnaire.js +46 -12
- package/lib/questionnaire.js.map +1 -1
- package/lib/release.js +32 -47
- package/lib/release.js.map +1 -1
- package/lib/rules/index.js +10 -23
- package/lib/rules/index.js.map +1 -1
- package/lib/rules/pilet-has-externals-as-peers.js +34 -45
- package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
- package/lib/rules/pilet-has-no-self-reference.js +16 -27
- package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
- package/lib/rules/pilet-has-non-conflicting-css.js +27 -42
- package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
- package/lib/rules/pilet-stays-small.js +20 -33
- package/lib/rules/pilet-stays-small.js.map +1 -1
- package/lib/rules/pilet-uses-latest-piral.js +17 -28
- package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
- package/lib/rules/piral-has-valid-devDependencies.js +4 -1
- package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
- package/lib/runner.js +3 -12
- package/lib/runner.js.map +1 -1
- package/lib/select.js +21 -32
- package/lib/select.js.map +1 -1
- package/lib/start.js +6 -17
- package/lib/start.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/build-piral.test.ts +1 -1
- package/src/common/package.ts +23 -17
- package/src/common/shell.ts +2 -1
- package/src/common/website.ts +47 -16
- package/src/injectors/pilet-injector.ts +12 -2
- package/src/messages.ts +93 -0
package/lib/common/io.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -49,16 +40,14 @@ function getDestination(entryFiles, target) {
|
|
|
49
40
|
}
|
|
50
41
|
}
|
|
51
42
|
exports.getDestination = getDestination;
|
|
52
|
-
function removeAny(target) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
});
|
|
43
|
+
async function removeAny(target) {
|
|
44
|
+
const isDir = await checkIsDirectory(target);
|
|
45
|
+
if (isDir) {
|
|
46
|
+
await removeDirectory(target);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
await removeFile(target);
|
|
50
|
+
}
|
|
62
51
|
}
|
|
63
52
|
exports.removeAny = removeAny;
|
|
64
53
|
function removeDirectory(targetDir) {
|
|
@@ -66,40 +55,36 @@ function removeDirectory(targetDir) {
|
|
|
66
55
|
return new Promise((resolve, reject) => (0, rimraf_1.default)(targetDir, (err) => (err ? reject(err) : resolve())));
|
|
67
56
|
}
|
|
68
57
|
exports.removeDirectory = removeDirectory;
|
|
69
|
-
function createDirectory(targetDir) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
});
|
|
58
|
+
async function createDirectory(targetDir) {
|
|
59
|
+
try {
|
|
60
|
+
(0, log_1.log)('generalDebug_0003', `Trying to create "${targetDir}" ...`);
|
|
61
|
+
await new Promise((resolve, reject) => {
|
|
62
|
+
(0, fs_2.mkdir)(targetDir, { recursive: true }, (err) => (err ? reject(err) : resolve()));
|
|
63
|
+
});
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
(0, log_1.log)('cannotCreateDirectory_0044');
|
|
68
|
+
(0, log_1.log)('generalDebug_0003', `Error while creating ${targetDir}: ${e}`);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
84
71
|
}
|
|
85
72
|
exports.createDirectory = createDirectory;
|
|
86
|
-
function getEntryFiles(content, basePath) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
results.push(filePath);
|
|
99
|
-
}
|
|
73
|
+
async function getEntryFiles(content, basePath) {
|
|
74
|
+
(0, log_1.log)('generalDebug_0003', `Extract entry files from "${basePath}".`);
|
|
75
|
+
const matcher = /<script\s.*?src=(?:"(.*?)"|'(.*?)'|([^\s>]*)).*?>/gi;
|
|
76
|
+
const results = [];
|
|
77
|
+
let result = undefined;
|
|
78
|
+
while ((result = matcher.exec(content))) {
|
|
79
|
+
const src = result[1] || result[2] || result[3];
|
|
80
|
+
(0, log_1.log)('generalDebug_0003', `Found potential entry file "${src}".`);
|
|
81
|
+
const filePath = (0, path_1.resolve)(basePath, src);
|
|
82
|
+
const exists = await checkExists(filePath);
|
|
83
|
+
if (exists) {
|
|
84
|
+
results.push(filePath);
|
|
100
85
|
}
|
|
101
|
-
|
|
102
|
-
|
|
86
|
+
}
|
|
87
|
+
return results;
|
|
103
88
|
}
|
|
104
89
|
exports.getEntryFiles = getEntryFiles;
|
|
105
90
|
function makeTempDir(prefix) {
|
|
@@ -124,15 +109,13 @@ function checkExists(target) {
|
|
|
124
109
|
});
|
|
125
110
|
}
|
|
126
111
|
exports.checkExists = checkExists;
|
|
127
|
-
function checkExistingDirectory(target) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return false;
|
|
135
|
-
});
|
|
112
|
+
async function checkExistingDirectory(target) {
|
|
113
|
+
(0, log_1.log)('generalDebug_0003', `Checking directory "${target}" ...`);
|
|
114
|
+
if (await checkExists(target)) {
|
|
115
|
+
(0, log_1.log)('generalDebug_0003', `Target exists, but not yet clear if directory.`);
|
|
116
|
+
return await checkIsDirectory(target);
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
136
119
|
}
|
|
137
120
|
exports.checkExistingDirectory = checkExistingDirectory;
|
|
138
121
|
function checkIsDirectory(target) {
|
|
@@ -154,22 +137,20 @@ function getFileNames(target) {
|
|
|
154
137
|
});
|
|
155
138
|
}
|
|
156
139
|
exports.getFileNames = getFileNames;
|
|
157
|
-
function findFile(topDir, fileName, stopDir = (0, path_1.resolve)(topDir, '/')) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return path;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (topDir !== stopDir) {
|
|
168
|
-
const parentDir = (0, path_1.resolve)(topDir, '..');
|
|
169
|
-
return yield findFile(parentDir, fileNames, stopDir);
|
|
140
|
+
async function findFile(topDir, fileName, stopDir = (0, path_1.resolve)(topDir, '/')) {
|
|
141
|
+
const fileNames = Array.isArray(fileName) ? fileName : [fileName];
|
|
142
|
+
for (const fn of fileNames) {
|
|
143
|
+
const path = (0, path_1.join)(topDir, fn);
|
|
144
|
+
const exists = await checkExists(path);
|
|
145
|
+
if (exists) {
|
|
146
|
+
return path;
|
|
170
147
|
}
|
|
171
|
-
|
|
172
|
-
|
|
148
|
+
}
|
|
149
|
+
if (topDir !== stopDir) {
|
|
150
|
+
const parentDir = (0, path_1.resolve)(topDir, '..');
|
|
151
|
+
return await findFile(parentDir, fileNames, stopDir);
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
173
154
|
}
|
|
174
155
|
exports.findFile = findFile;
|
|
175
156
|
function matchPattern(baseDir, pattern) {
|
|
@@ -188,102 +169,98 @@ function matchPattern(baseDir, pattern) {
|
|
|
188
169
|
});
|
|
189
170
|
});
|
|
190
171
|
}
|
|
191
|
-
function matchAnyPattern(baseDir, pattern) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
};
|
|
198
|
-
});
|
|
172
|
+
async function matchAnyPattern(baseDir, pattern) {
|
|
173
|
+
const matches = await Promise.all(pattern.patterns.map((pattern) => matchPattern(baseDir, pattern)));
|
|
174
|
+
return {
|
|
175
|
+
pattern: pattern.original,
|
|
176
|
+
results: matches.reduce((agg, curr) => [...agg, ...curr], []),
|
|
177
|
+
};
|
|
199
178
|
}
|
|
200
179
|
const preferences = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.esm', '.es', '.es6', '.html'];
|
|
201
|
-
function matchAnyPilet(baseDir, patterns) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
matched(name, target);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
(0, log_1.log)('generalDebug_0003', `Source target "${target}" does not exist. Skipped.`);
|
|
253
|
-
}
|
|
180
|
+
async function matchAnyPilet(baseDir, patterns) {
|
|
181
|
+
const matches = [];
|
|
182
|
+
const pilets = [];
|
|
183
|
+
const matched = (name, path) => {
|
|
184
|
+
pilets.push(name);
|
|
185
|
+
matches.push(path);
|
|
186
|
+
};
|
|
187
|
+
const exts = preferences.map((s) => s.substring(1)).join(',');
|
|
188
|
+
const allPatterns = patterns.reduce((agg, curr) => {
|
|
189
|
+
const patterns = [];
|
|
190
|
+
if (/[a-zA-Z0-9\-\*]$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
|
|
191
|
+
patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${constants_1.packageJson}`, `${curr}/${constants_1.piletJson}`);
|
|
192
|
+
}
|
|
193
|
+
else if (curr.endsWith('/')) {
|
|
194
|
+
patterns.push(`${curr}index.{${exts}}`, `${curr}${constants_1.packageJson}`, `${curr}${constants_1.piletJson}`);
|
|
195
|
+
}
|
|
196
|
+
else if (curr === '.' || curr === '..') {
|
|
197
|
+
patterns.push(`${curr}/index.{${exts}}`, `${curr}/${constants_1.packageJson}`, `${curr}/${constants_1.piletJson}`);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
patterns.push(curr);
|
|
201
|
+
}
|
|
202
|
+
agg.push({ original: curr, patterns });
|
|
203
|
+
return agg;
|
|
204
|
+
}, []);
|
|
205
|
+
await Promise.all(allPatterns.map((patterns) => matchAnyPattern(baseDir, patterns).then(async ({ results, pattern }) => {
|
|
206
|
+
if (!results.length) {
|
|
207
|
+
(0, log_1.log)('generalDebug_0003', `Found no potential entry points using "${pattern}".`);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
//TODO -> shouldn't take the first one,
|
|
211
|
+
// should be the first one, yes, but, PER pilet
|
|
212
|
+
// so that multiple pilets can be considered, too
|
|
213
|
+
(0, log_1.log)('generalDebug_0003', `Found ${results.length} potential entry points in "${pattern}".`);
|
|
214
|
+
for (const result of results) {
|
|
215
|
+
const fileName = (0, path_1.basename)(result);
|
|
216
|
+
if (fileName === constants_1.packageJson) {
|
|
217
|
+
(0, log_1.log)('generalDebug_0003', `Entry point is a "${constants_1.packageJson}" and needs further inspection.`);
|
|
218
|
+
const targetDir = (0, path_1.dirname)(result);
|
|
219
|
+
const { source, name } = await readJson(targetDir, fileName);
|
|
220
|
+
if (!pilets.includes(name)) {
|
|
221
|
+
if (typeof source === 'string') {
|
|
222
|
+
(0, log_1.log)('generalDebug_0003', `Found a "source" field with value "${source}".`);
|
|
223
|
+
const target = (0, path_1.resolve)(targetDir, source);
|
|
224
|
+
const exists = await checkExists(target);
|
|
225
|
+
if (exists) {
|
|
226
|
+
(0, log_1.log)('generalDebug_0003', `Taking existing target as "${target}".`);
|
|
227
|
+
matched(name, target);
|
|
254
228
|
}
|
|
255
229
|
else {
|
|
256
|
-
(0, log_1.log)('generalDebug_0003', `
|
|
257
|
-
const files = yield matchPattern(targetDir, `src/index.{${exts}}`);
|
|
258
|
-
if (files.length > 0) {
|
|
259
|
-
(0, log_1.log)('generalDebug_0003', `Found a result; taking "${files[0]}".`);
|
|
260
|
-
matched(name, files[0]);
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
(0, log_1.log)('generalDebug_0003', `Found no results in "src". Skipped.`);
|
|
264
|
-
}
|
|
230
|
+
(0, log_1.log)('generalDebug_0003', `Source target "${target}" does not exist. Skipped.`);
|
|
265
231
|
}
|
|
266
232
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
233
|
+
else {
|
|
234
|
+
(0, log_1.log)('generalDebug_0003', `No "source" field found. Trying combinations in "src".`);
|
|
235
|
+
const files = await matchPattern(targetDir, `src/index.{${exts}}`);
|
|
236
|
+
if (files.length > 0) {
|
|
237
|
+
(0, log_1.log)('generalDebug_0003', `Found a result; taking "${files[0]}".`);
|
|
238
|
+
matched(name, files[0]);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
(0, log_1.log)('generalDebug_0003', `Found no results in "src". Skipped.`);
|
|
276
242
|
}
|
|
277
243
|
}
|
|
278
|
-
|
|
279
|
-
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const packageJsonPath = await findFile(result, constants_1.packageJson);
|
|
248
|
+
if (packageJsonPath) {
|
|
249
|
+
const targetDir = (0, path_1.dirname)(packageJsonPath);
|
|
250
|
+
const { name } = await readJson(targetDir, constants_1.packageJson);
|
|
251
|
+
if (!pilets.includes(name)) {
|
|
252
|
+
(0, log_1.log)('generalDebug_0003', `Entry point result is "${result}".`);
|
|
253
|
+
matched(name, result);
|
|
280
254
|
}
|
|
281
255
|
}
|
|
256
|
+
else {
|
|
257
|
+
(0, log_1.log)('generalDebug_0003', `Could not find "${constants_1.packageJson}" for entry "${result}". Skipping.`);
|
|
258
|
+
}
|
|
282
259
|
}
|
|
283
260
|
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
261
|
+
}
|
|
262
|
+
})));
|
|
263
|
+
return matches;
|
|
287
264
|
}
|
|
288
265
|
exports.matchAnyPilet = matchAnyPilet;
|
|
289
266
|
function matchFiles(baseDir, pattern) {
|
|
@@ -303,75 +280,65 @@ function matchFiles(baseDir, pattern) {
|
|
|
303
280
|
});
|
|
304
281
|
}
|
|
305
282
|
exports.matchFiles = matchFiles;
|
|
306
|
-
function createFileIfNotExists(targetDir, fileName, content, forceOverwrite = enums_1.ForceOverwrite.no) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
yield writeText(targetDir, fileName, content);
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
yield writeBinary(targetDir, fileName, content);
|
|
321
|
-
}
|
|
283
|
+
async function createFileIfNotExists(targetDir, fileName, content, forceOverwrite = enums_1.ForceOverwrite.no) {
|
|
284
|
+
const targetFile = (0, path_1.join)(targetDir, fileName);
|
|
285
|
+
(0, log_1.log)('generalDebug_0003', `Checking if file "${targetFile}" exists ...`);
|
|
286
|
+
const exists = await checkExists(targetFile);
|
|
287
|
+
if (!exists ||
|
|
288
|
+
forceOverwrite === enums_1.ForceOverwrite.yes ||
|
|
289
|
+
(forceOverwrite === enums_1.ForceOverwrite.prompt && (await promptOverwrite(targetFile)))) {
|
|
290
|
+
await createDirectory((0, path_1.dirname)(targetFile));
|
|
291
|
+
(0, log_1.log)('generalDebug_0003', `Creating file "${targetFile}" ...`);
|
|
292
|
+
if (typeof content === 'string') {
|
|
293
|
+
await writeText(targetDir, fileName, content);
|
|
322
294
|
}
|
|
323
|
-
|
|
295
|
+
else {
|
|
296
|
+
await writeBinary(targetDir, fileName, content);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
324
299
|
}
|
|
325
300
|
exports.createFileIfNotExists = createFileIfNotExists;
|
|
326
|
-
function updateExistingFile(targetDir, fileName, content) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
});
|
|
301
|
+
async function updateExistingFile(targetDir, fileName, content) {
|
|
302
|
+
const targetFile = (0, path_1.join)(targetDir, fileName);
|
|
303
|
+
(0, log_1.log)('generalDebug_0003', `Checking if file "${targetFile}" exists ...`);
|
|
304
|
+
const exists = await checkExists(targetFile);
|
|
305
|
+
if (exists) {
|
|
306
|
+
(0, log_1.log)('generalDebug_0003', `Updating file "${targetFile}" ...`);
|
|
307
|
+
await new Promise((resolve, reject) => {
|
|
308
|
+
(0, fs_3.writeFile)(targetFile, content, 'utf8', (err) => (err ? reject(err) : resolve()));
|
|
309
|
+
});
|
|
310
|
+
}
|
|
338
311
|
}
|
|
339
312
|
exports.updateExistingFile = updateExistingFile;
|
|
340
|
-
function getHash(targetFile) {
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
(0, fs_3.readFile)(targetFile, (err, c) => (err ? resolve(undefined) : resolve((0, hash_1.computeHash)(c))));
|
|
344
|
-
});
|
|
313
|
+
async function getHash(targetFile) {
|
|
314
|
+
return new Promise((resolve) => {
|
|
315
|
+
(0, fs_3.readFile)(targetFile, (err, c) => (err ? resolve(undefined) : resolve((0, hash_1.computeHash)(c))));
|
|
345
316
|
});
|
|
346
317
|
}
|
|
347
318
|
exports.getHash = getHash;
|
|
348
|
-
function mergeWithJson(targetDir, fileName, newContent) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
(0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('{}') : resolve(c)));
|
|
353
|
-
});
|
|
354
|
-
const originalContent = JSON.parse(content);
|
|
355
|
-
return (0, merge_1.deepMerge)(originalContent, newContent);
|
|
319
|
+
async function mergeWithJson(targetDir, fileName, newContent) {
|
|
320
|
+
const targetFile = (0, path_1.join)(targetDir, fileName);
|
|
321
|
+
const content = await new Promise((resolve) => {
|
|
322
|
+
(0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('{}') : resolve(c)));
|
|
356
323
|
});
|
|
324
|
+
const originalContent = JSON.parse(content);
|
|
325
|
+
return (0, merge_1.deepMerge)(originalContent, newContent);
|
|
357
326
|
}
|
|
358
327
|
exports.mergeWithJson = mergeWithJson;
|
|
359
|
-
function readJson(targetDir, fileName, defaultValue = {}) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
(0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('') : resolve(c)));
|
|
364
|
-
});
|
|
365
|
-
if (content) {
|
|
366
|
-
try {
|
|
367
|
-
return JSON.parse(content);
|
|
368
|
-
}
|
|
369
|
-
catch (ex) {
|
|
370
|
-
(0, log_1.log)('generalError_0002', `Invalid JSON found in file "${fileName}" at "${targetDir}".`);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return defaultValue;
|
|
328
|
+
async function readJson(targetDir, fileName, defaultValue = {}) {
|
|
329
|
+
const targetFile = (0, path_1.join)(targetDir, fileName);
|
|
330
|
+
const content = await new Promise((resolve) => {
|
|
331
|
+
(0, fs_3.readFile)(targetFile, 'utf8', (err, c) => (err ? resolve('') : resolve(c)));
|
|
374
332
|
});
|
|
333
|
+
if (content) {
|
|
334
|
+
try {
|
|
335
|
+
return JSON.parse(content);
|
|
336
|
+
}
|
|
337
|
+
catch (ex) {
|
|
338
|
+
(0, log_1.log)('generalError_0002', `Invalid JSON found in file "${fileName}" at "${targetDir}".`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return defaultValue;
|
|
375
342
|
}
|
|
376
343
|
exports.readJson = readJson;
|
|
377
344
|
function readBinary(targetDir, fileName) {
|
|
@@ -405,44 +372,40 @@ function writeBinary(targetDir, fileName, data) {
|
|
|
405
372
|
});
|
|
406
373
|
}
|
|
407
374
|
exports.writeBinary = writeBinary;
|
|
408
|
-
function updateExistingJson(targetDir, fileName, newContent) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
yield updateExistingFile(targetDir, fileName, JSON.stringify(content, undefined, 2));
|
|
412
|
-
});
|
|
375
|
+
async function updateExistingJson(targetDir, fileName, newContent) {
|
|
376
|
+
const content = await mergeWithJson(targetDir, fileName, newContent);
|
|
377
|
+
await updateExistingFile(targetDir, fileName, JSON.stringify(content, undefined, 2));
|
|
413
378
|
}
|
|
414
379
|
exports.updateExistingJson = updateExistingJson;
|
|
415
|
-
function copy(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return results.every(Boolean);
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
yield new Promise((resolve, reject) => {
|
|
428
|
-
(0, fs_3.copyFile)(source, target, flag, (err) => (err ? reject(err) : resolve()));
|
|
429
|
-
});
|
|
430
|
-
return true;
|
|
431
|
-
}
|
|
380
|
+
async function copy(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
|
|
381
|
+
await createDirectory((0, path_1.dirname)(target));
|
|
382
|
+
try {
|
|
383
|
+
const flag = forceOverwrite === enums_1.ForceOverwrite.yes ? 0 : fs_2.constants.COPYFILE_EXCL;
|
|
384
|
+
const isDir = await checkIsDirectory(source);
|
|
385
|
+
if (isDir) {
|
|
386
|
+
const files = await getFileNames(source);
|
|
387
|
+
const results = await Promise.all(files.map((file) => copy((0, path_1.resolve)(source, file), (0, path_1.resolve)(target, file), forceOverwrite)));
|
|
388
|
+
return results.every(Boolean);
|
|
432
389
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
390
|
+
else {
|
|
391
|
+
await new Promise((resolve, reject) => {
|
|
392
|
+
(0, fs_3.copyFile)(source, target, flag, (err) => (err ? reject(err) : resolve()));
|
|
393
|
+
});
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
catch (e) {
|
|
398
|
+
if (forceOverwrite === enums_1.ForceOverwrite.prompt) {
|
|
399
|
+
const shouldOverwrite = await promptOverwrite(target);
|
|
400
|
+
if (shouldOverwrite) {
|
|
401
|
+
return await copy(source, target, enums_1.ForceOverwrite.yes);
|
|
442
402
|
}
|
|
443
403
|
}
|
|
444
|
-
|
|
445
|
-
|
|
404
|
+
else {
|
|
405
|
+
(0, log_1.log)('didNotOverWriteFile_0045', target);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return false;
|
|
446
409
|
}
|
|
447
410
|
exports.copy = copy;
|
|
448
411
|
/**
|
|
@@ -465,59 +428,53 @@ function removeFile(target) {
|
|
|
465
428
|
});
|
|
466
429
|
}
|
|
467
430
|
exports.removeFile = removeFile;
|
|
468
|
-
function move(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return source;
|
|
481
|
-
});
|
|
431
|
+
async function move(source, target, forceOverwrite = enums_1.ForceOverwrite.no) {
|
|
432
|
+
const dir = await checkIsDirectory(target);
|
|
433
|
+
if (dir) {
|
|
434
|
+
const file = (0, path_1.basename)(source);
|
|
435
|
+
target = (0, path_1.resolve)(target, file);
|
|
436
|
+
}
|
|
437
|
+
const success = await copy(source, target, forceOverwrite);
|
|
438
|
+
if (success) {
|
|
439
|
+
await removeFile(source);
|
|
440
|
+
return target;
|
|
441
|
+
}
|
|
442
|
+
return source;
|
|
482
443
|
}
|
|
483
444
|
exports.move = move;
|
|
484
|
-
function getSourceFiles(entry) {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
});
|
|
518
|
-
},
|
|
519
|
-
};
|
|
520
|
-
});
|
|
445
|
+
async function getSourceFiles(entry) {
|
|
446
|
+
const dir = (0, path_1.dirname)(entry);
|
|
447
|
+
(0, log_1.log)('generalDebug_0003', `Trying to get source files from "${dir}" ...`);
|
|
448
|
+
const files = await matchFiles(dir, '**/*.?(jsx|tsx|js|ts)');
|
|
449
|
+
return files.map((path) => {
|
|
450
|
+
const directory = (0, path_1.dirname)(path);
|
|
451
|
+
const name = (0, path_1.basename)(path);
|
|
452
|
+
return {
|
|
453
|
+
path,
|
|
454
|
+
directory,
|
|
455
|
+
name,
|
|
456
|
+
async read() {
|
|
457
|
+
const content = await readText(directory, name);
|
|
458
|
+
if (name.endsWith('.ts') || name.endsWith('.tsx')) {
|
|
459
|
+
return (0, typescript_1.transpileModule)(content, {
|
|
460
|
+
fileName: path,
|
|
461
|
+
moduleName: name,
|
|
462
|
+
compilerOptions: {
|
|
463
|
+
allowJs: true,
|
|
464
|
+
skipLibCheck: true,
|
|
465
|
+
declaration: false,
|
|
466
|
+
sourceMap: false,
|
|
467
|
+
checkJs: false,
|
|
468
|
+
jsx: typescript_1.JsxEmit.React,
|
|
469
|
+
module: typescript_1.ModuleKind.ESNext,
|
|
470
|
+
moduleResolution: typescript_1.ModuleResolutionKind.NodeJs,
|
|
471
|
+
target: typescript_1.ScriptTarget.ESNext,
|
|
472
|
+
},
|
|
473
|
+
}).outputText;
|
|
474
|
+
}
|
|
475
|
+
return content;
|
|
476
|
+
},
|
|
477
|
+
};
|
|
521
478
|
});
|
|
522
479
|
}
|
|
523
480
|
exports.getSourceFiles = getSourceFiles;
|