-
Notifications
You must be signed in to change notification settings - Fork 38
/
build.ts
53 lines (45 loc) · 1.52 KB
/
build.ts
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
import { Command } from '@oclif/command';
import { join } from 'path';
import dedent from 'dedent';
import { build } from '../../lib/deployment';
import * as flag from '../../lib/flag';
import runCommand from '../../lib/runCommand';
import defaultErrorCheck from '../../lib/defaultErrorCheck';
import TerrainCLI from '../../TerrainCLI';
export default class Build extends Command {
static description = 'Build wasm bytecode.';
static flags = {
'config-path': flag.configPath,
};
static args = [{ name: 'contract', required: true }];
async run() {
const { args } = this.parse(Build);
// Command execution path.
const execPath = join('contracts', args.contract);
// Command to be performed.
const command = async () => {
await build({
contract: args.contract,
});
};
// Message to be displayed upon successful command execution.
const successMessage = () => {
TerrainCLI.success(
dedent`
The Wasm bytecode for contract "${args.contract}" was successfully generated.\n
The next step is to optimize the Wasm bytecode:\n
"terrain contract:optimize ${args.contract}"\n
"NOTE:" Make sure that "Docker" is installed and running in the background before attempting to optimize the Wasm bytecode.
`,
'Wasm Bytecode Generated',
);
};
// Attempt to execute command while backtracking through file tree.
await runCommand(
execPath,
command,
defaultErrorCheck(args.contract),
successMessage,
);
}
}