-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.js
34 lines (28 loc) · 1.01 KB
/
hook.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
import execa from 'execa'
import isExist from 'path-exists'
import packageJson from './package.json'
import { dllname } from './.variables.js'
const throws = (message) => { throw new Error(message) }
const errorhandler = (err) => {
console.error(err)
process.exit(1)
}
const ignored = (target) => console.log(`ignored: ${target}`)
const done = (target) => console.log(`done: ${target}`)
const exec = (command) => execa.shell(command).then(({ cmd }) => done(cmd))
const execIf = (condition, command) => Promise.resolve(!condition ? ignored(command) : exec(command))
const hooks = {
'prestart': () =>
Promise.all([
isExist(`_local/${dllname}.manifest.json`).then(exist => execIf(!exist, 'yarn wpack:dll')),
// exec('yarn upgrade imagemin-jpegtran')
])
.catch(errorhandler),
'prebuild': () =>
Promise.all([
// exec('yarn upgrade imagemin-jpegtran')
])
.catch(errorhandler)
}
const hook = hooks[process.env.HOOK_ENV]
typeof hook === 'function' && hook()