1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const debug_1 = __importDefault(require("debug"));
|
7 | const fs_extra_1 = __importDefault(require("fs-extra"));
|
8 | const config_env_1 = require("../internal/core/config/config-env");
|
9 | const errors_1 = require("../internal/core/errors");
|
10 | const errors_list_1 = require("../internal/core/errors-list");
|
11 | const scripts_runner_1 = require("../internal/util/scripts-runner");
|
12 | const task_names_1 = require("./task-names");
|
13 | function default_1() {
|
14 | const log = debug_1.default("buidler:core:tasks:run");
|
15 | config_env_1.task(task_names_1.TASK_RUN, "Runs a user-defined script after compiling the project")
|
16 | .addPositionalParam("script", "A js file to be run within buidler's environment")
|
17 | .addFlag("noCompile", "Don't compile before running this task")
|
18 | .setAction(async ({ script, noCompile }, { run, buidlerArguments }) => {
|
19 | if (!(await fs_extra_1.default.pathExists(script))) {
|
20 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.BUILTIN_TASKS.RUN_FILE_NOT_FOUND, {
|
21 | script,
|
22 | });
|
23 | }
|
24 | if (!noCompile) {
|
25 | await run(task_names_1.TASK_COMPILE);
|
26 | }
|
27 | log(`Running script ${script} in a subprocess so we can wait for it to complete`);
|
28 | try {
|
29 | process.exitCode = await scripts_runner_1.runScriptWithBuidler(buidlerArguments, script);
|
30 | }
|
31 | catch (error) {
|
32 | throw new errors_1.BuidlerError(errors_list_1.ERRORS.BUILTIN_TASKS.RUN_SCRIPT_ERROR, {
|
33 | script,
|
34 | error: error.message,
|
35 | }, error);
|
36 | }
|
37 | });
|
38 | }
|
39 | exports.default = default_1;
|
40 |
|
\ | No newline at end of file |