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