-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
47 lines (39 loc) · 1.44 KB
/
gulpfile.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 { series } = require('gulp')
const { spawn } = require('child_process')
const fs = require('fs')
const fse = require('fs-extra')
const rimraf = require('rimraf')
const { waitForProcess, defaultSpawnOptions } = require('@mikeyt23/node-cli-utils')
const util = require('util')
const path = require('path')
const readdir = util.promisify(fs.readdir)
async function clean() {
console.log('deleting dist and coverage directory contents...')
await Promise.all([
new Promise(resolve => rimraf('dist/*', resolve)),
new Promise(resolve => rimraf('coverage/*', resolve))
])
}
async function tsc() {
await waitForProcess(spawn('npm run tsc', [], defaultSpawnOptions))
}
async function pack() {
console.log('packing...')
await fse.mkdirp('packed')
await new Promise(resolve => rimraf('packed/*', resolve))
await waitForProcess(spawn('npm pack', [], defaultSpawnOptions))
const fileNames = await readdir('./')
const tarballs = fileNames.filter(f => f.endsWith('.tgz'))
console.log('tarballs: ', tarballs)
if (tarballs.length == 0) {
throw new Error('no tarball was created - cannot move to packed dir')
}
if (tarballs.length > 1) {
throw new Error('multiple packed modules - delete them all and re-run')
}
console.log('moving tarball to packed dir')
await fse.move(tarballs[0], path.join('packed', tarballs[0]))
}
exports.clean = clean
exports.build = series(clean, tsc)
exports.pack = series(clean, tsc, pack)