1 | import debug from "debug";
|
2 | import fsExtra from "fs-extra";
|
3 | import * as path from "path";
|
4 | import * as semver from "semver";
|
5 |
|
6 | import { task } from "../internal/core/config/config-env";
|
7 | import { runScriptWithBuidler } from "../internal/util/scripts-runner";
|
8 |
|
9 | import { TASK_CONSOLE } from "./task-names";
|
10 |
|
11 | export default function () {
|
12 | const log = debug("buidler:core:tasks:console");
|
13 |
|
14 | task(TASK_CONSOLE, "Opens a buidler console")
|
15 | .addFlag("noCompile", "Don't compile before running this task")
|
16 | .setAction(
|
17 | async (
|
18 | { noCompile }: { noCompile: boolean },
|
19 | { config, run, buidlerArguments }
|
20 | ) => {
|
21 | if (!noCompile) {
|
22 | await run("compile");
|
23 | }
|
24 |
|
25 | await fsExtra.ensureDir(config.paths.cache);
|
26 | const historyFile = path.join(
|
27 | config.paths.cache,
|
28 | "console-history.txt"
|
29 | );
|
30 |
|
31 | const nodeArgs = [];
|
32 | if (semver.gte(process.version, "10.0.0")) {
|
33 | nodeArgs.push("--experimental-repl-await");
|
34 | }
|
35 |
|
36 | log(
|
37 | `Creating a Node REPL subprocess with Buidler's register so we can set some Node's flags`
|
38 | );
|
39 |
|
40 |
|
41 | await runScriptWithBuidler(buidlerArguments, "", [], nodeArgs, {
|
42 | NODE_REPL_HISTORY: historyFile,
|
43 | });
|
44 | }
|
45 | );
|
46 | }
|