-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathask-cli-compile.js
45 lines (38 loc) · 1.17 KB
/
ask-cli-compile.js
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
#!/usr/bin/env node
const program = require('commander');
// const glob = require('glob');
const chalk = require('chalk');
const fs = require('fs-extra');
const path = require('path');
const {execute} = require('./utils/executor');
program
.argument('<contract>', "Contract file to be compiled.")
.option('--debug', 'Compiled to debug code')
.option('--release', 'Compiled to release code, default');
program.parse(process.argv);
const options = program.opts();
const contract = path.join(process.cwd(), program.args[0]);
const releaseMode = options.debug === undefined;
// console.log("compiled mode: ", releaseMode);
// console.log('contract: ', contract);
// to check if `contract` existed or not
if (!fs.existsSync(contract)) {
console.log(chalk.red(`Error: '${contract}' is not exist.`));
process.exit(1);
}
// clean build folder
const buildDir = path.join(process.cwd(), 'build');
if (fs.existsSync(buildDir)) {
fs.emptyDirSync(buildDir);
fs.rmdirSync(buildDir);
}
fs.mkdirSync(buildDir);
// prepare compile arguments
const contractName = path.parse(contract).name;
const cmdArgs = [
contract,
releaseMode,
buildDir,
contractName
];
execute('ask', cmdArgs);