zarro 1.190.0 → 1.190.1
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/index.js +41 -70
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12,7 +12,8 @@ const
|
|
|
12
12
|
readTextFile,
|
|
13
13
|
fileExists,
|
|
14
14
|
readTextFileLines,
|
|
15
|
-
writeTextFile
|
|
15
|
+
writeTextFile,
|
|
16
|
+
rm
|
|
16
17
|
} = require("yafs"),
|
|
17
18
|
log = require("./gulp-tasks/modules/log"),
|
|
18
19
|
path = require("path"),
|
|
@@ -261,74 +262,6 @@ function importTypeScript() {
|
|
|
261
262
|
}
|
|
262
263
|
|
|
263
264
|
|
|
264
|
-
async function transpileTasksUnder_(folder) {
|
|
265
|
-
const toTranspile = [];
|
|
266
|
-
const fullPath = path.isAbsolute(folder)
|
|
267
|
-
? folder
|
|
268
|
-
: path.join(process.cwd(), folder);
|
|
269
|
-
const contents = await ls(fullPath, {
|
|
270
|
-
recurse: false,
|
|
271
|
-
entities: FsEntities.files,
|
|
272
|
-
match: /\.ts$/,
|
|
273
|
-
fullPaths: true
|
|
274
|
-
});
|
|
275
|
-
for (const item of contents) {
|
|
276
|
-
toTranspile.push(item);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (toTranspile.length === 0) {
|
|
280
|
-
debug(`no typescript modules found; skipping transpile phase.`);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
importTypeScript();
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
const
|
|
288
|
-
{ ExecStepContext } = require("exec-step"),
|
|
289
|
-
ctx = new ExecStepContext(),
|
|
290
|
-
{ transpileModule, ModuleKind } = require("typescript");
|
|
291
|
-
for (const src of toTranspile) {
|
|
292
|
-
const test = src.replace(/\.ts$/, ".js");
|
|
293
|
-
if (await fileExists(test)) {
|
|
294
|
-
// assume this is a compilation handled elsewhere
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
const output = src.replace(/\.ts$/, ".generated.js");
|
|
298
|
-
if (await fileExists(output)) {
|
|
299
|
-
const srcStat = await stat(src);
|
|
300
|
-
const outStat = await stat(output);
|
|
301
|
-
|
|
302
|
-
const srcLastModified = srcStat.mtime.getTime();
|
|
303
|
-
const outLastModified = outStat.mtime.getTime();
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (srcLastModified <= outLastModified) {
|
|
307
|
-
debug(`${ output } modified after ${ src }; skipping transpile`);
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
debug(`will transpile: ${ src }`);
|
|
311
|
-
}
|
|
312
|
-
await ctx.exec(
|
|
313
|
-
`transpiling ${ src }`,
|
|
314
|
-
async () => {
|
|
315
|
-
const contents = await readTextFile(src);
|
|
316
|
-
const transpiled = transpileModule(contents, {
|
|
317
|
-
compilerOptions: {
|
|
318
|
-
esModuleInterop: true,
|
|
319
|
-
module: ModuleKind.CommonJS,
|
|
320
|
-
target: "es2017"
|
|
321
|
-
}
|
|
322
|
-
}).outputText;
|
|
323
|
-
await writeTextFile(output, transpiled);
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
} catch (e) {
|
|
328
|
-
log.error(`one or more typescript modules could not be transpiled:\n${ e }`);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
265
|
const timestampMatcher = /\[\d\d:\d\d:\d\d]/;
|
|
333
266
|
|
|
334
267
|
function patchConsoleOutputToSuppressIntermediateTasks() {
|
|
@@ -393,6 +326,43 @@ function looksLikeAnonymousTaskMessage(str) {
|
|
|
393
326
|
return anonymousPos > -1;
|
|
394
327
|
}
|
|
395
328
|
|
|
329
|
+
async function removeOrphanedGeneratedFilesUnder(dir) {
|
|
330
|
+
const allFiles = await ls(dir, {
|
|
331
|
+
recurse: true,
|
|
332
|
+
entities: FsEntities.files,
|
|
333
|
+
fullPaths: true
|
|
334
|
+
});
|
|
335
|
+
const lookup = new Set(allFiles);
|
|
336
|
+
for (let i = 0; i < allFiles.length; i++) {
|
|
337
|
+
const current = allFiles[i];
|
|
338
|
+
if (current.match(/\.generated\.js$/)) {
|
|
339
|
+
const seek = current.replace(".generated", "");
|
|
340
|
+
if (!lookup.has(seek)) {
|
|
341
|
+
await rm(current);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function removeOrphanedGeneratedFiles() {
|
|
348
|
+
await Promise.all([
|
|
349
|
+
removeOrphanedGeneratedFilesUnder("local-tasks"),
|
|
350
|
+
removeOrphanedGeneratedFilesUnder("override-tasks")
|
|
351
|
+
]);
|
|
352
|
+
const externalTaskFolders = await ls(
|
|
353
|
+
"external-tasks", {
|
|
354
|
+
entities: FsEntities.folders,
|
|
355
|
+
recurse: false,
|
|
356
|
+
fullPaths: true
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
promises = externalTaskFolders.map(
|
|
360
|
+
f => removeOrphanedGeneratedFilesUnder(f)
|
|
361
|
+
);
|
|
362
|
+
await Promise.all(promises);
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
396
366
|
(async function () {
|
|
397
367
|
patchConsoleOutputToSuppressIntermediateTasks();
|
|
398
368
|
try {
|
|
@@ -418,7 +388,8 @@ function looksLikeAnonymousTaskMessage(str) {
|
|
|
418
388
|
]);
|
|
419
389
|
await Promise.all([
|
|
420
390
|
transpileLocalTaskModules(),
|
|
421
|
-
transpileLocalTasks()
|
|
391
|
+
transpileLocalTasks(),
|
|
392
|
+
removeOrphanedGeneratedFiles()
|
|
422
393
|
]);
|
|
423
394
|
const handler = await findHandlerFor(args);
|
|
424
395
|
if (!handler) {
|