-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.mjs
executable file
·60 lines (48 loc) · 2.11 KB
/
index.mjs
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
import fs from 'fs';
import path from 'path';
import mkdirs from './bin/mkdirs.mjs';
import compile from './built/index.js';
import { FilingError } from './built/error/errors.js';
// This function is used to export into the published npm package
// (it's basically a replacement for ./bin/index that npm understands)
// locally, always use the command line zappify as defined in package.json
export const zappify = (input, _zappName, output = './zapps', modify = false) => {
const inputFilePath = input;
const modifyAST = modify;
const inputFileName = path.parse(inputFilePath).name;
const zappName = _zappName || inputFileName;
const outputDirPath = `${output}/${zappName}`;
const configDirPath = `${outputDirPath}/config`;
const migrationsDirPath = `${outputDirPath}/migrations`;
const parseDirPath = `${outputDirPath}/parse`;
const circuitsDirPath = `${outputDirPath}/circuits`;
const contractsDirPath = `${outputDirPath}/contracts`;
const orchestrationDirPath = `${outputDirPath}/orchestration`;
const options = {
zappName,
inputFileName,
inputFilePath,
outputDirPath,
parseDirPath,
circuitsDirPath,
contractsDirPath,
orchestrationDirPath,
modifyAST,
};
if (!fs.existsSync(inputFilePath))
throw new FilingError(`inputFilePath "${inputFilePath}" does not exist.`);
if (path.parse(inputFilePath).ext !== '.zol')
if (path.parse(inputFilePath).ext === '.sol') {
console.warn(`We'd ordinarily expect a '.zol' file as input, but we'll try to compile this '.sol' file...`);
} else {
throw new FilingError(`Invalid input file extension. Expected '.zol' (a 'zappable' solidity file). Got '${path.parse(inputFilePath).ext}'.`);
}
fs.rmSync(parseDirPath, { recursive: true, force: true });
fs.rmSync(circuitsDirPath, { recursive: true, force: true });
fs.rmSync(contractsDirPath, { recursive: true, force: true });
fs.rmSync(orchestrationDirPath, { recursive: true, force: true });
fs.rmSync(configDirPath, { recursive: true, force: true });
fs.rmSync(migrationsDirPath, { recursive: true, force: true });
mkdirs(options);
compile(options)
}