-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathutils.js
34 lines (30 loc) · 991 Bytes
/
utils.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 chalk from 'chalk'
import execa from 'execa'
export const main = async (name, cmd) => {
log(`Running ${name} script`)
try {
await cmd()
} catch (err) {
fail(err)
}
success(`${name} execution done`)
}
export const log = console.log
export const info = (...args) => console.log(chalk.blue('info'), ...args)
export const error = (...args) => console.log(chalk.red('error'), ...args)
export const fail = (...args) => {
error(...args)
process.exit(1)
}
export const success = (...args) => console.log(chalk.green('success'), ...args)
export const execaOptions = { reject: false }
export const cleanDir = dir => {
// log('Cleaning', EXTERNAL_FILES_DIR)
const { failed } = execa.sync('rm', ['-rf', dir], execaOptions)
if (failed) throw new Error(`Couldn't clean ${dir}`)
}
export const createDir = dir => {
// log('Creating', dir)
const { failed } = execa.sync('mkdir', ['-p', dir], execaOptions)
if (failed) throw new Error(`Couldn't create ${dir}`)
}