-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
47 lines (41 loc) · 1.38 KB
/
build.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
46
47
const { exec } = require('child_process');
const { existsSync } = require('fs');
const { join } = require('path');
const contractName = process.argv[2];
let subdirName;
switch(contractName) {
case 'auction':
case 'escrow':
subdirName = 'dynamic';
break;
default:
throw new Error('Contract name must be one of: auction, escrow');
}
const basePath = join(__dirname, subdirName, contractName);
const inputPath = join(basePath, `${contractName}.arl`);
const metadataPath = join(basePath, `${contractName}.json`);
if (!existsSync(inputPath)) throw new Error(`${contractName}.arl does not exist`);
async function compile(targetName, targetExt) {
try {
await new Promise((resolve, reject) => {
const outputPath = join(basePath, `${contractName}.${targetExt}`);
const command = `archetype -t ${targetName} ${inputPath} --metadata-storage ${metadataPath} > ${outputPath}`;
exec(command, (error, stdout) => {
if (error) reject(error);
else resolve(stdout);
});
});
} catch(e) {
console.error(e);
}
}
const targets = {
'michelson': 'tz',
'michelson-storage': 'storage.tz',
'markdown': 'md',
'whyml': 'mlw'
};
Promise.all(Object.keys(targets).map(targetName => {
const targetExt = targets[targetName];
return compile(targetName, targetExt);
}));