|
1 | 1 | import type { HardhatRuntimeEnvironment } from "hardhat/types/hre";
|
2 | 2 | import type { NewTaskActionFunction } from "hardhat/types/tasks";
|
3 | 3 |
|
4 |
| -// import path from "node:path"; |
| 4 | +import path from "node:path"; |
5 | 5 |
|
6 |
| -// import { HardhatError } from "@nomicfoundation/hardhat-errors"; |
7 |
| -// import { |
8 |
| -// batches, |
9 |
| -// IgnitionError, |
10 |
| -// IgnitionModuleSerializer, |
11 |
| -// } from "@nomicfoundation/ignition-core"; |
| 6 | +import { HardhatError } from "@nomicfoundation/hardhat-errors"; |
| 7 | +import { |
| 8 | + batches, |
| 9 | + IgnitionError, |
| 10 | + IgnitionModuleSerializer, |
| 11 | +} from "@nomicfoundation/ignition-core"; |
12 | 12 |
|
13 |
| -// import { loadModule } from "../utils/load-module.js"; |
14 |
| -// import { open } from "../utils/open.js"; |
15 |
| -// import { shouldBeHardhatPluginError } from "../utils/shouldBeHardhatPluginError.js"; |
16 |
| -// import { writeVisualization } from "../visualization/write-visualization.js"; |
17 |
| -import chalk from "chalk"; |
| 13 | +import { loadModule } from "../utils/load-module.js"; |
| 14 | +import { open } from "../utils/open.js"; |
| 15 | +import { shouldBeHardhatPluginError } from "../utils/shouldBeHardhatPluginError.js"; |
| 16 | +import { writeVisualization } from "../visualization/write-visualization.js"; |
18 | 17 |
|
19 | 18 | interface TaskVisualizeArguments {
|
20 | 19 | modulePath: string;
|
21 | 20 | noOpen: boolean;
|
22 | 21 | }
|
23 | 22 |
|
24 | 23 | const visualizeTask: NewTaskActionFunction<TaskVisualizeArguments> = async (
|
25 |
| - _args: { noOpen: boolean; modulePath: string }, |
26 |
| - _hre: HardhatRuntimeEnvironment, |
| 24 | + { noOpen, modulePath }: { noOpen: boolean; modulePath: string }, |
| 25 | + hre: HardhatRuntimeEnvironment, |
27 | 26 | ) => {
|
28 |
| - console.log( |
29 |
| - chalk.yellow( |
30 |
| - "This task will be implemented soon. Check back soon for more updates.", |
31 |
| - ), |
32 |
| - ); |
| 27 | + await hre.tasks.getTask("compile").run({ quiet: true }); |
33 | 28 |
|
34 |
| - return; |
| 29 | + const userModule = await loadModule(hre.config.paths.ignition, modulePath); |
35 | 30 |
|
36 |
| - // await hre.tasks.getTask("compile").run({ quiet: true }); |
| 31 | + if (userModule === undefined) { |
| 32 | + throw new HardhatError(HardhatError.ERRORS.IGNITION.NO_MODULES_FOUND); |
| 33 | + } |
37 | 34 |
|
38 |
| - // const userModule = await loadModule(hre.config.paths.ignition, modulePath); |
| 35 | + try { |
| 36 | + const serializedIgnitionModule = |
| 37 | + IgnitionModuleSerializer.serialize(userModule); |
39 | 38 |
|
40 |
| - // if (userModule === undefined) { |
41 |
| - // throw new HardhatError(HardhatError.ERRORS.IGNITION.NO_MODULES_FOUND); |
42 |
| - // } else { |
43 |
| - // try { |
44 |
| - // const serializedIgnitionModule = |
45 |
| - // IgnitionModuleSerializer.serialize(userModule); |
| 39 | + const batchInfo = batches(userModule); |
46 | 40 |
|
47 |
| - // const batchInfo = batches(userModule); |
| 41 | + await writeVisualization( |
| 42 | + { module: serializedIgnitionModule, batches: batchInfo }, |
| 43 | + { |
| 44 | + cacheDir: hre.config.paths.cache, |
| 45 | + }, |
| 46 | + ); |
| 47 | + } catch (e) { |
| 48 | + if (e instanceof IgnitionError && shouldBeHardhatPluginError(e)) { |
| 49 | + throw new HardhatError(HardhatError.ERRORS.IGNITION.INTERNAL_ERROR, e); |
| 50 | + } |
48 | 51 |
|
49 |
| - // await writeVisualization( |
50 |
| - // { module: serializedIgnitionModule, batches: batchInfo }, |
51 |
| - // { |
52 |
| - // cacheDir: hre.config.paths.cache, |
53 |
| - // }, |
54 |
| - // ); |
55 |
| - // } catch (e) { |
56 |
| - // if (e instanceof IgnitionError && shouldBeHardhatPluginError(e)) { |
57 |
| - // throw new HardhatError(HardhatError.ERRORS.IGNITION.INTERNAL_ERROR, e); |
58 |
| - // } |
| 52 | + throw e; |
| 53 | + } |
59 | 54 |
|
60 |
| - // throw e; |
61 |
| - // } |
62 |
| - // } |
| 55 | + if (!noOpen) { |
| 56 | + const indexFile = path.join( |
| 57 | + hre.config.paths.cache, |
| 58 | + "visualization", |
| 59 | + "index.html", |
| 60 | + ); |
63 | 61 |
|
64 |
| - // if (!noOpen) { |
65 |
| - // const indexFile = path.join( |
66 |
| - // hre.config.paths.cache, |
67 |
| - // "visualization", |
68 |
| - // "index.html", |
69 |
| - // ); |
| 62 | + console.log(`Deployment visualization written to ${indexFile}`); |
70 | 63 |
|
71 |
| - // console.log(`Deployment visualization written to ${indexFile}`); |
72 |
| - |
73 |
| - // open(indexFile); |
74 |
| - // } |
| 64 | + open(indexFile); |
| 65 | + } |
75 | 66 | };
|
76 | 67 |
|
77 | 68 | export default visualizeTask;
|
0 commit comments