1 | const fs = require('fs')
|
2 | const path = require('path')
|
3 | const pkgConf = require('pkg-conf')
|
4 | const execa = require('execa')
|
5 | const symbols = require('log-symbols')
|
6 | const consts = require('./consts')
|
7 |
|
8 | const pkg = require('../package.json')
|
9 | const debug = require('debug')(pkg.name)
|
10 |
|
11 | const info = message => exports.debug(`${symbols.info} ${message}`)
|
12 | const success = message => exports.debug(`${symbols.success} ${message}`)
|
13 | const warning = message => exports.debug(`${symbols.warning} ${message}`)
|
14 | const error = message => exports.debug(`${symbols.error} ${message}`)
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | const execute = (cmd, ...args) =>
|
24 | execa.sync(cmd, [...args], Object.assign({ stdio: 'inherit' }))
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | const readSettings = async (options = {}) => {
|
35 | let settings = {}
|
36 | const cwd = options.cwd || consts.cwd
|
37 | const { filename, namespace } = options
|
38 | const config = filename ? path.resolve(cwd, filename) : null
|
39 |
|
40 | if (config && fs.existsSync(config)) {
|
41 | settings = require(config)
|
42 | } else if (namespace) {
|
43 | settings = await pkgConf(namespace)
|
44 | }
|
45 |
|
46 | return settings
|
47 | }
|
48 |
|
49 | module.exports = {
|
50 | pkg,
|
51 | debug,
|
52 | info,
|
53 | success,
|
54 | warning,
|
55 | error,
|
56 | execute,
|
57 | readSettings
|
58 | }
|