1 | const chalk = require("chalk");
|
2 | const path = require("path");
|
3 | const moment = require("moment");
|
4 | const spawn = require("cross-spawn");
|
5 |
|
6 | module.exports = async ({ script, task, type = script.type }, quiet = false) => {
|
7 | if (!quiet) {
|
8 | console.log(
|
9 | `${chalk.green
|
10 | .bgHex("#181c24")
|
11 | .bold("[" + moment().format("HH:MM:SS") + "]")}${chalk
|
12 | .bgHex("#181c24")
|
13 | .bold.hex("#8c91a7")(" " + task.name + ": ")}`
|
14 | );
|
15 | }
|
16 | return new Promise(resolve => {
|
17 | const cmd = spawn(type, [...script.rest], {
|
18 | stdio: "inherit",
|
19 | env: Object.assign({}, process.env, {
|
20 | FORCE_COLOR: true,
|
21 | PATH: `${path.resolve("node_modules/.bin")}:${process.env.PATH}`
|
22 | })
|
23 | });
|
24 |
|
25 | cmd.on("close", code => {
|
26 | if (code === 0) {
|
27 | resolve();
|
28 | } else {
|
29 | console.error(`${chalk.red("ERROR")} ${code}`);
|
30 | }
|
31 | });
|
32 | });
|
33 | };
|