-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrunScript.js
47 lines (41 loc) · 1.19 KB
/
runScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import chalk from 'chalk';
import {execSync} from './execSync.js';
/**
* @param {import('./types.js').Script} script
* @param {Promise<import('./types.js').ParsedUserConfig>} next
*/
export async function runScript(script, next) {
const {prescript, postscript, isPrescript, isPostscript, env} = script;
// prev
if (prescript) {
prescript.isPrescript = true;
await runScript(prescript, next);
}
// now
const displayName = script.desc ?? script.name;
const logRunMessage = isPrescript
? `\n${chalk.bgGrey.bold(' PREV ➤ ')} ${chalk.magenta.bold(displayName)}`
: isPostscript
? `\n${chalk.bgGrey.bold(' POST ➤ ')} ${chalk.magenta.bold(displayName)}`
: `\n${chalk.bgMagenta.bold(' RUNS ➤ ')} ${chalk.magenta.bold(
displayName
)}`;
console.log(logRunMessage);
if (script.command) {
console.log(chalk.grey(script.command));
execSync(script.command, {
env: {
...process.env,
...env
}
});
console.log();
}
if (script.scripts && next && typeof next === 'function')
await next(script.scripts);
// post
if (postscript) {
postscript.isPostscript = true;
await runScript(postscript, next);
}
}