-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathvisualize.ts
More file actions
72 lines (57 loc) · 1.8 KB
/
visualize.ts
File metadata and controls
72 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import type { HardhatRuntimeEnvironment } from "hardhat/types/hre";
import type { NewTaskActionFunction } from "hardhat/types/tasks";
import path from "node:path";
import { HardhatError } from "@nomicfoundation/hardhat-errors";
import {
batches,
IgnitionModuleSerializer,
} from "@nomicfoundation/ignition-core";
import { loadModule } from "../utils/load-module.js";
import { open } from "../utils/open.js";
import { writeVisualization } from "../visualization/write-visualization.js";
interface TaskVisualizeArguments {
modulePath: string;
noOpen: boolean;
}
const visualizeTask: NewTaskActionFunction<TaskVisualizeArguments> = async (
{ noOpen, modulePath }: { noOpen: boolean; modulePath: string },
hre: HardhatRuntimeEnvironment,
) => {
const noTests = hre.config.solidity.splitTestsCompilation;
await hre.tasks.getTask("build").run({ noTests, quiet: true });
const userModule = await loadModule(hre.config.paths.ignition, modulePath);
if (userModule === undefined) {
throw new HardhatError(
HardhatError.ERRORS.IGNITION.INTERNAL.NO_MODULES_FOUND,
);
}
try {
const serializedIgnitionModule =
IgnitionModuleSerializer.serialize(userModule);
const batchInfo = batches(userModule);
await writeVisualization(
{ module: serializedIgnitionModule, batches: batchInfo },
{
cacheDir: hre.config.paths.cache,
},
);
} catch (e) {
if (e instanceof Error) {
throw new HardhatError(
HardhatError.ERRORS.IGNITION.INTERNAL.INTERNAL_ERROR,
e,
);
}
throw e;
}
if (!noOpen) {
const indexFile = path.join(
hre.config.paths.cache,
"visualization",
"index.html",
);
console.log(`Deployment visualization written to ${indexFile}`);
open(indexFile);
}
};
export default visualizeTask;