zarro 1.165.12 → 1.165.14
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 +124 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,6 +21,8 @@ const
|
|
|
21
21
|
ZarroError = require("./gulp-tasks/modules/zarro-error"),
|
|
22
22
|
{ skip } = require("./gulp-tasks/modules/linq"),
|
|
23
23
|
gatherArgs = require("./index-modules/gather-args");
|
|
24
|
+
const { ExecStepContext } = require("exec-step");
|
|
25
|
+
const { transpileModule, ModuleKind } = require("typescript");
|
|
24
26
|
|
|
25
27
|
function requireHandler(name) {
|
|
26
28
|
const result = require(`./index-modules/handlers/${ name }`);
|
|
@@ -86,18 +88,18 @@ async function loadDefaults() {
|
|
|
86
88
|
}
|
|
87
89
|
const
|
|
88
90
|
parts = code.trim().split("="),
|
|
89
|
-
name = parts[
|
|
91
|
+
name = parts[0],
|
|
90
92
|
value = Array.from(skip(parts, 1)).join("="),
|
|
91
|
-
forced = name[
|
|
92
|
-
notYetSet = process.env[
|
|
93
|
+
forced = name[0] === '!',
|
|
94
|
+
notYetSet = process.env[name] === undefined;
|
|
93
95
|
if (notYetSet || forced) {
|
|
94
96
|
const key = name.replace(/^!/, "");
|
|
95
97
|
if (value) {
|
|
96
98
|
debug(`setting env var ${ key } to '${ value }'`);
|
|
97
|
-
process.env[
|
|
99
|
+
process.env[key] = value;
|
|
98
100
|
} else {
|
|
99
101
|
debug(`deleting env var ${ key }`);
|
|
100
|
-
delete process.env[
|
|
102
|
+
delete process.env[key];
|
|
101
103
|
}
|
|
102
104
|
} else {
|
|
103
105
|
debug(`env var ${ name } is already set, force it by setting !${ name }=${ value } in ${ defaultsFile }`)
|
|
@@ -124,6 +126,25 @@ function splitComment(line) {
|
|
|
124
126
|
return [ line.substring(0, idx), line.substring(idx + 1) ];
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
async function transpileLocalTaskModules() {
|
|
130
|
+
await Promise.all([
|
|
131
|
+
transpileModulesUnder("local-tasks"),
|
|
132
|
+
transpileModulesUnder("override-tasks")
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
const externalTaskFolders = await ls(
|
|
136
|
+
"external-tasks", {
|
|
137
|
+
entities: FsEntities.folders,
|
|
138
|
+
recurse: false,
|
|
139
|
+
fullPaths: true
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
promises = externalTaskFolders.map(
|
|
143
|
+
f => transpileModulesUnder(f)
|
|
144
|
+
);
|
|
145
|
+
await Promise.all(promises);
|
|
146
|
+
}
|
|
147
|
+
|
|
127
148
|
async function transpileLocalTasks() {
|
|
128
149
|
await Promise.all([
|
|
129
150
|
transpileTasksUnder("local-tasks"),
|
|
@@ -142,7 +163,101 @@ async function transpileLocalTasks() {
|
|
|
142
163
|
await Promise.all(promises);
|
|
143
164
|
}
|
|
144
165
|
|
|
166
|
+
async function transpileModulesUnder(folder) {
|
|
167
|
+
await transpileTypeScriptFiles(
|
|
168
|
+
path.join(folder, "modules"),
|
|
169
|
+
true,
|
|
170
|
+
s => s.replace(/\.ts$/, ".js")
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function transpileTypeScriptFiles(
|
|
175
|
+
inFolder,
|
|
176
|
+
transpileAnyTypeScript,
|
|
177
|
+
outputNameGenerator
|
|
178
|
+
) {
|
|
179
|
+
const toTranspile = [];
|
|
180
|
+
const fullPath = path.isAbsolute(inFolder)
|
|
181
|
+
? inFolder
|
|
182
|
+
: path.join(process.cwd(), inFolder);
|
|
183
|
+
const contents = await ls(fullPath, {
|
|
184
|
+
recurse: false,
|
|
185
|
+
entities: FsEntities.files,
|
|
186
|
+
match: /\.ts$/,
|
|
187
|
+
fullPaths: true
|
|
188
|
+
});
|
|
189
|
+
for (const item of contents) {
|
|
190
|
+
toTranspile.push(item);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (toTranspile.length === 0) {
|
|
194
|
+
debug(`no typescript modules found; skipping transpile phase.`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
require("typescript");
|
|
200
|
+
} catch (e) {
|
|
201
|
+
throw new Error(`TypeScript not installed, unable to transpile local tasks: \n- ${ toTranspile.join("\n -") }`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
const
|
|
206
|
+
{ ExecStepContext } = require("exec-step"),
|
|
207
|
+
ctx = new ExecStepContext(),
|
|
208
|
+
{ transpileModule, ModuleKind } = require("typescript");
|
|
209
|
+
for (const src of toTranspile) {
|
|
210
|
+
if (!transpileAnyTypeScript) {
|
|
211
|
+
const test = src.replace(/\.ts$/, ".js");
|
|
212
|
+
if (await fileExists(test)) {
|
|
213
|
+
// assume this is a compilation handled elsewhere
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const output = outputNameGenerator(src);
|
|
218
|
+
if (await fileExists(output)) {
|
|
219
|
+
const srcStat = await stat(src);
|
|
220
|
+
const outStat = await stat(output);
|
|
221
|
+
|
|
222
|
+
const srcLastModified = srcStat.mtime.getTime();
|
|
223
|
+
const outLastModified = outStat.mtime.getTime();
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
if (srcLastModified <= outLastModified) {
|
|
227
|
+
debug(`${ output } modified after ${ src }; skipping transpile`);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
debug(`will transpile: ${ src }`);
|
|
231
|
+
}
|
|
232
|
+
await ctx.exec(
|
|
233
|
+
`transpiling ${ src }`,
|
|
234
|
+
async () => {
|
|
235
|
+
const contents = await readTextFile(src);
|
|
236
|
+
const transpiled = transpileModule(contents, {
|
|
237
|
+
compilerOptions: {
|
|
238
|
+
esModuleInterop: true,
|
|
239
|
+
module: ModuleKind.CommonJS,
|
|
240
|
+
target: "es2017"
|
|
241
|
+
}
|
|
242
|
+
}).outputText;
|
|
243
|
+
await writeTextFile(output, transpiled);
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
} catch (e) {
|
|
248
|
+
log.error(`one or more typescript modules could not be transpiled:\n${ e }`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
145
252
|
async function transpileTasksUnder(folder) {
|
|
253
|
+
await transpileTypeScriptFiles(
|
|
254
|
+
folder,
|
|
255
|
+
false,
|
|
256
|
+
s => s.replace(/\.ts$/, ".generated.js")
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async function transpileTasksUnder_(folder) {
|
|
146
261
|
const toTranspile = [];
|
|
147
262
|
const fullPath = path.isAbsolute(folder)
|
|
148
263
|
? folder
|
|
@@ -236,7 +351,10 @@ async function transpileTasksUnder(folder) {
|
|
|
236
351
|
loadDefaults(),
|
|
237
352
|
init()
|
|
238
353
|
]);
|
|
239
|
-
await
|
|
354
|
+
await Promise.all([
|
|
355
|
+
transpileLocalTaskModules(),
|
|
356
|
+
transpileLocalTasks()
|
|
357
|
+
]);
|
|
240
358
|
const handler = await findHandlerFor(args);
|
|
241
359
|
if (!handler) {
|
|
242
360
|
throw new ZarroError("no handler for current args");
|