UNPKG

1.36 kBPlain TextView Raw
1import debug from "debug";
2import fsExtra from "fs-extra";
3import * as path from "path";
4import * as semver from "semver";
5
6import { task } from "../internal/core/config/config-env";
7import { runScriptWithBuidler } from "../internal/util/scripts-runner";
8
9import { TASK_CONSOLE } from "./task-names";
10
11export 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 // Running the script "" is like running `node`, so this starts the repl
41 await runScriptWithBuidler(buidlerArguments, "", [], nodeArgs, {
42 NODE_REPL_HISTORY: historyFile,
43 });
44 }
45 );
46}