zarro 1.190.0 → 1.190.2
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 +43 -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,45 @@ function looksLikeAnonymousTaskMessage(str) {
|
|
|
393
326
|
return anonymousPos > -1;
|
|
394
327
|
}
|
|
395
328
|
|
|
329
|
+
const generatedFileMatcher = /\.generated\.js$/;
|
|
330
|
+
|
|
331
|
+
async function removeOrphanedGeneratedFilesUnder(dir) {
|
|
332
|
+
const allFiles = await ls(dir, {
|
|
333
|
+
recurse: true,
|
|
334
|
+
entities: FsEntities.files,
|
|
335
|
+
fullPaths: true
|
|
336
|
+
});
|
|
337
|
+
const lookup = new Set(allFiles);
|
|
338
|
+
for (let i = 0; i < allFiles.length; i++) {
|
|
339
|
+
const current = allFiles[i];
|
|
340
|
+
if (current.match(generatedFileMatcher)) {
|
|
341
|
+
const seek = current.replace(generatedFileMatcher, ".ts");
|
|
342
|
+
if (!lookup.has(seek)) {
|
|
343
|
+
await rm(current);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function removeOrphanedGeneratedFiles() {
|
|
350
|
+
await Promise.all([
|
|
351
|
+
removeOrphanedGeneratedFilesUnder("local-tasks"),
|
|
352
|
+
removeOrphanedGeneratedFilesUnder("override-tasks")
|
|
353
|
+
]);
|
|
354
|
+
const externalTaskFolders = await ls(
|
|
355
|
+
"external-tasks", {
|
|
356
|
+
entities: FsEntities.folders,
|
|
357
|
+
recurse: false,
|
|
358
|
+
fullPaths: true
|
|
359
|
+
}
|
|
360
|
+
),
|
|
361
|
+
promises = externalTaskFolders.map(
|
|
362
|
+
f => removeOrphanedGeneratedFilesUnder(f)
|
|
363
|
+
);
|
|
364
|
+
await Promise.all(promises);
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
|
|
396
368
|
(async function () {
|
|
397
369
|
patchConsoleOutputToSuppressIntermediateTasks();
|
|
398
370
|
try {
|
|
@@ -418,7 +390,8 @@ function looksLikeAnonymousTaskMessage(str) {
|
|
|
418
390
|
]);
|
|
419
391
|
await Promise.all([
|
|
420
392
|
transpileLocalTaskModules(),
|
|
421
|
-
transpileLocalTasks()
|
|
393
|
+
transpileLocalTasks(),
|
|
394
|
+
removeOrphanedGeneratedFiles()
|
|
422
395
|
]);
|
|
423
396
|
const handler = await findHandlerFor(args);
|
|
424
397
|
if (!handler) {
|