/
build.ts
48 lines (40 loc) · 1.21 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
import { Command } from '@oclif/command';
import { join } from 'path';
import { existsSync } from 'fs';
import { build } from '../../lib/deployment';
import * as flag from '../../lib/flag';
import CLI from '../../CLI';
import runCommand from '../../lib/runCommand';
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,
});
};
// Error check to be performed upon each backtrack iteration.
const errorCheck = () => {
if (existsSync('contracts') && !existsSync(execPath)) {
CLI.error(
`Contract "${args.contract}" not available in "contracts/" directory.`,
'Contract Unavailable',
);
}
};
// Attempt to execute command while backtracking through file tree.
await runCommand(
execPath,
command,
errorCheck,
);
}
}