-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile.js
More file actions
80 lines (64 loc) · 2.58 KB
/
makefile.js
File metadata and controls
80 lines (64 loc) · 2.58 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/////////////////// Dependencies ///////////////////////////////////////////////
let {solBuild, solConcatBuild, solWatch} = require('soliditySapper')
const fs = require('fs')
/////////////////// Settings ///////////////////////////////////////////////////
// index format: "sourceRootDirectory indexFile outputDirectory"
const solIndeces = [
'src/contracts src/contracts/CryptoFormulas.sol dist/src/contracts',
'src/contracts src/contracts/StaticUpdate.sol dist/src/contracts',
'src/contracts src/contracts/FormulaValidator.sol dist/src/contracts',
'tests/contracts tests/contracts/TestingTokens.sol dist/tests/contracts',
'tests/contracts tests/contracts/FormulasDebugger.sol dist/tests/contracts',
'tests/contracts tests/contracts/FormulasFeeless.sol dist/tests/contracts',
]
/////////////////// Logic //////////////////////////////////////////////////////
const solFromDist = item => item.split(' ')
.filter((dummy, index) => index > 0) // no need for root directory now
.map((item, index) => index > 0 ? item : 'dist/' + item) // add prefix `dist/` before source file path
let commands
commands = {
// main commands
build: async () => true
&& await Promise.all(commands.concatContracts())
&& await Promise.all(commands.buildContracts()),
watch: () => commands.watchContracts(),
// build subcommands
concatContracts: () => solIndeces
.map(item => solConcatBuild(
...item.split(' ').filter((dummy, index) => index > 0)
)),
buildContracts: () => solIndeces
.map(solFromDist)
.map(item => solBuild(...item)),
// watch subcommands
watchContracts: async () => solIndeces.map((item) => {
const itemParams = item.split(' ')
// concat all files on each refresh
const refreshCallback = async () => await solConcatBuild(...itemParams.filter((dummy, index) => index > 0))
solWatch(...itemParams, refreshCallback)
})
}
/////////////////// Utils //////////////////////////////////////////////////////
function ensureFolder(folder) {
try {
fs.mkdirSync(folder)
} catch (e) {
if (!e || (e && e.code !== 'EEXIST')) {
// directory already exists
throw e
}
}
}
/////////////////// Run Command ////////////////////////////////////////////////
if (process.argv.length != 3 || !commands[process.argv[2]]) {
console.log('invalid arguments')
process.exit(1)
}
[
'./dist',
'./dist/src',
'./dist/src/contracts',
'./dist/tests',
'./dist/tests/contracts'
].map(ensureFolder)
commands[process.argv[2]]()