-
Notifications
You must be signed in to change notification settings - Fork 14
/
package-scripts.js
210 lines (202 loc) · 7.67 KB
/
package-scripts.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* eslint-disable quotes */
const fs = require("fs");
const {
series,
rimraf,
copy,
mkdirp
} = require("nps-utils");
const joinPath = require("path.join");
const cwd = require("cwd")();
const runningInRepo = fs.existsSync(".git");
const migrationsExist = fs.existsSync("migration.json");
const pathArcJsRoot = cwd;
const pathNodeModules = runningInRepo ? joinPath(".", "node_modules") : joinPath("..", "..", "node_modules");
const pathDaostackArcRepo = runningInRepo ?
joinPath(pathNodeModules, "@daostack", "arc") :
joinPath("..", "arc");
const pathDaostackMigrationsRepo = runningInRepo ?
joinPath(pathNodeModules, "@daostack", "migration") :
joinPath("..", "migration");
const pathArcJsContracts = joinPath(".", "migrated_contracts");
const pathArcTest = joinPath(".", "test");
const pathArcTestBuild = joinPath(".", "test-build");
const pathArcDist = joinPath(".", "dist");
const pathDaostackArcGanacheDb = joinPath(".", "ganacheDb");
const pathDaostackArcGanacheDbZip = joinPath(".", "ganacheDb.zip");
const pathTypeScript = joinPath(pathNodeModules, "typescript/bin/tsc");
const ganacheGasLimit = 8000000; // something reasonably close to live
const ganacheCommand = `ganache-cli -l ${ganacheGasLimit} --networkId 1512051714758 --defaultBalanceEther 999999999999999 --deterministic`;
const ganacheDbCommand = `ganache-cli --db ${pathDaostackArcGanacheDb} --networkId 1512051714758 -l ${ganacheGasLimit} --defaultBalanceEther 999999999999999 --deterministic`;
module.exports = {
scripts: {
ganache: {
default: "nps ganache.run",
run: ganacheCommand
},
ganacheDb: {
default: "nps ganacheDb.run",
run: series(
mkdirp(pathDaostackArcGanacheDb),
ganacheDbCommand,
),
clean: rimraf(pathDaostackArcGanacheDb),
zip: `node ./package-scripts/archiveGanacheDb.js ${pathDaostackArcGanacheDbZip} ${pathDaostackArcGanacheDb}`,
unzip: series(
`node ./package-scripts/unArchiveGanacheDb.js ${pathDaostackArcGanacheDbZip} ${pathArcJsRoot}`
),
restoreFromZip: series(
"nps ganacheDb.clean",
"nps ganacheDb.unzip"
)
},
lint: {
default: series(
"nps lint.code",
"nps lint.test"
),
code: {
default: `tslint ${joinPath("custom_typings", "web3.d.ts")} ${joinPath("custom_typings", "system.d.ts")} ${joinPath("lib", "**", "*.ts")}`,
andFix: `nps "lint.code --fix"`
},
test: {
default: `tslint ${joinPath("custom_typings", "web3_global.d.ts")} ${joinPath("custom_typings", "system.d.ts")} ${joinPath("test", "**", "*.ts")}`,
andFix: `nps "lint.test --fix"`
},
andFix: series(
"nps lint.code.andFix",
"nps lint.test.andFix"
),
},
test: {
default: series(
`nps test.build`,
`nps test.runAll`
),
bail: series(
`nps test.build`,
`nps "test.runAll --bail"`
),
// coming: the ability to more easily run a single test (awaiting a forthcoming release of nps).
run: `mocha --require chai --timeout 999999`,
runAll: `mocha --require chai --timeout 999999 ${joinPath(pathArcTestBuild, "test")}`,
build: {
default: series(
"nps test.build.clean",
mkdirp(joinPath(pathArcTestBuild, "config")),
copy(`${joinPath(".", "config", "**", "*")} ${joinPath(pathArcTestBuild, "config")}`),
copy(`${joinPath(pathArcJsContracts, "**", "*")} ${joinPath(pathArcTestBuild, "migrated_contracts")}`),
copy(`${joinPath(pathArcJsRoot, "migration.json")} ${pathArcTestBuild}`),
mkdirp(pathArcTestBuild),
`node ${pathTypeScript} --outDir ${pathArcTestBuild} --project ${pathArcTest}`
),
clean: rimraf(joinPath(pathArcTestBuild, "*"))
},
},
build: {
default: series(
"nps build.clean",
mkdirp(pathArcDist),
`node ${pathTypeScript} --outDir ${pathArcDist}`
),
clean: rimraf(pathArcDist)
},
deploy: {
ensureMigrations: migrationsExist ? "" : `node ${joinPath(".", "package-scripts", "fail")} "migrations.json doesn't exist"`,
pack: series(
"nps deploy.ensureMigrations",
"nps build",
"npm pack"),
publish: series(
"nps deploy.ensureMigrations",
"nps build",
"npm publish")
},
createGenesisDao: {
default: `node ${joinPath(".", "package-scripts", "createGenesisDao.js")}`
},
/**
* See README.md for how to use these scripts in a workflow to migrate contracts
*/
migrateContracts: {
/**
* Migrate contracts.
*
* Truffle will merge this migration with whatever previous ones are already present in the contract json files.
*
* Run migrateContracts.fetchContracts first if you want to start with fresh unmigrated contracts from @daostack/arc.
*
* use --reset for ganacheDb if it is crashing on re-migration.
*/
default: series(
`node ${joinPath(".", "package-scripts", "migrateContracts.js")} "${joinPath(pathArcJsRoot, "migration.json")}"`
),
andCreateGenesisDao: series(
`nps migrateContracts`,
`nps createGenesisDao`
),
/**
* Clean the output contract json files, optionally andMigrate.
*
* IMPORTANT! Only do this if you aren't worried about losing
* previously-performed migrations to other networks. By cleaning, you'll lose them, starting
* from scratch. Otherwise, truffle will merge your migrations into whatever previous
* ones exist.
*/
clean: rimraf(joinPath(pathArcJsContracts, "*")),
fetchContracts: series(
"nps migrateContracts.clean",
"nps migrateContracts.fetchFromArc",
"nps migrateContracts.fetchFromDaostack"
),
/**
* Fetch the unmigrated contract json files from DAOstack Arc.
* Run this ONLY when you want to start with fresh UNMIGRATED contracts from DAOstack Arc.
* Best to run "migrateContracts.clean" first.
* If run from the context of an application, then the application must have installed
* the proper version of Arc sibling to the Arc.js package.
*/
fetchFromArc: series(
copy(`${joinPath(pathDaostackArcRepo, "build", "contracts", "*")} ${pathArcJsContracts}`)
),
/**
* fetch contract addresses from the DAOstack migrations package.
*/
fetchFromDaostack: series(
copy(`${joinPath(pathDaostackMigrationsRepo, "migration.json")} ${pathArcJsRoot}`),
`node ${joinPath(".", "package-scripts", "cleanMigrationJson.js")}`,
),
},
docs: {
api: {
build: `node ${joinPath(".", "package-scripts", "typedoc.js")}`,
/**
* This is to create a list of all the API files for inclusion in mkdocs.yml
* Whenever the set of API objects changes, you must copy the output of this
* script and paste it into mkdocs.yml after the line:
* `- Index : "api/README.md"`
*
* Easy Powershell command: nps -s docs.api.createPagesList | ac .\mkdocs.yml
*/
createPagesList: `node ${joinPath(".", "package-scripts", "createApiPagesList.js")} ./docs api/*/**`
},
website: {
build: "mkdocs build",
preview: "mkdocs serve",
publish: "mkdocs gh-deploy --force"
},
build: {
default: series(
"nps docs.api.build",
"nps docs.website.build",
),
andPreview: series("nps docs.website.preview"),
andPublish: series("nps docs.website.publish")
},
clean: series(
rimraf(joinPath(".", "docs", "api")),
rimraf(joinPath(".", "site"))
)
}
}
};