-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtasksfile.js
53 lines (43 loc) · 1.34 KB
/
tasksfile.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
const { sh: _sh, cli } = require('tasksfile')
const glob = require('glob')
const fs = require('fs')
function sh (command, options = {}) {
return _sh(command, { nopipe: true, ...options })
}
function generate () {
sh('./refresh-cache.sh')
const generators = glob.sync(`src/**/generate.ts`).filter((path) => !path.includes('_helpers'))
for (const generator of generators) {
sh(`ts-node ${generator}`)
}
}
function build () {
// Build TypeScript
sh('rm -rf build/')
sh('tsc')
sh('rm -rf build/_helpers/')
// Remove build time dependencies
const deleteFiles = [].concat(
glob.sync(`build/**/{generate,test}.js`),
glob.sync(`build/**/{generate,test}.d.ts`)
)
deleteFiles.map(fs.unlinkSync)
// Rename "data" to "index" for easier import
const dataFiles = [].concat(glob.sync(`build/**/data.js`), glob.sync(`build/**/data.d.ts`))
dataFiles.map((path) => {
fs.renameSync(path, path.replace('data', 'index'))
})
// Add commonjs export
const indexFiles = glob.sync(`build/**/index.js`)
indexFiles.map((path) => {
const content = fs.readFileSync(path, 'utf-8')
fs.writeFileSync(path, content + 'module.exports = exports.default;\n', 'utf-8')
})
// Add package.json and README into build directory
sh('cp package.json build/package.json')
sh('cp README.md build/README.md')
}
cli({
generate,
build
})