|
1 |
| -const joi = require('joi') |
2 |
| -const chalk = require('chalk') |
3 |
| -const spinner = require('./spinner') |
4 |
| -const readline = require('readline') |
5 |
| -const { execSync } = require('child_process') |
6 |
| -const padStart = require('string.prototype.padstart') |
7 |
| - |
8 |
| -const format = (label, msg) => { |
9 |
| - return msg.split('\n').map((line, i) => { |
10 |
| - return i === 0 |
11 |
| - ? `${label} ${line}` |
12 |
| - : padStart(line, chalk.reset(label).length) |
13 |
| - }).join('\n') |
14 |
| -} |
15 |
| - |
16 |
| -Object.assign(exports, spinner) |
17 |
| - |
18 |
| -exports.log = msg => console.log(msg || '') |
19 |
| - |
20 |
| -exports.info = msg => { |
21 |
| - console.log(format(chalk.bgBlue.black(' INFO '), msg)) |
22 |
| -} |
23 |
| - |
24 |
| -exports.done = msg => { |
25 |
| - console.log(format(chalk.bgGreen.black(' DONE '), msg)) |
26 |
| -} |
27 |
| - |
28 |
| -exports.warn = msg => { |
29 |
| - console.warn(format(chalk.bgYellow.black(' WARN '), chalk.yellow(msg))) |
30 |
| -} |
31 |
| - |
32 |
| -exports.error = msg => { |
33 |
| - console.error(format(chalk.bgRed(' ERROR '), chalk.red(msg))) |
34 |
| - if (msg instanceof Error) { |
35 |
| - console.error(msg.stack) |
36 |
| - } |
37 |
| -} |
38 |
| - |
39 |
| -exports.clearConsole = title => { |
40 |
| - if (process.stdout.isTTY) { |
41 |
| - const blank = '\n'.repeat(process.stdout.rows) |
42 |
| - console.log(blank) |
43 |
| - readline.cursorTo(process.stdout, 0, 0) |
44 |
| - readline.clearScreenDown(process.stdout) |
45 |
| - if (title) { |
46 |
| - console.log(title) |
47 |
| - } |
48 |
| - } |
49 |
| -} |
50 |
| - |
51 |
| -// silent all logs except errors during tests and keep record |
52 |
| -if (process.env.VUE_CLI_TEST) { |
53 |
| - const logs = {} |
54 |
| - Object.keys(exports).forEach(key => { |
55 |
| - if (key !== 'error') { |
56 |
| - exports[key] = (...args) => { |
57 |
| - if (!logs[key]) logs[key] = [] |
58 |
| - logs[key].push(args) |
59 |
| - } |
60 |
| - } |
61 |
| - }) |
62 |
| - exports.logs = logs |
63 |
| -} |
64 |
| - |
65 |
| -// proxy to joi for option validation |
66 |
| -exports.createSchema = fn => fn(joi) |
67 |
| - |
68 |
| -exports.validate = (obj, schema, options = {}) => { |
69 |
| - joi.validate(obj, schema, options, err => { |
70 |
| - if (err) { |
71 |
| - throw err |
72 |
| - } |
73 |
| - }) |
74 |
| -} |
75 |
| - |
76 |
| -// env detection |
77 |
| -exports.hasYarn = (() => { |
78 |
| - if (process.env.VUE_CLI_TEST) { |
79 |
| - return true |
80 |
| - } |
81 |
| - try { |
82 |
| - execSync('yarnpkg --version', { stdio: 'ignore' }) |
83 |
| - return true |
84 |
| - } catch (e) { |
85 |
| - return false |
86 |
| - } |
87 |
| -})() |
88 |
| - |
89 |
| -exports.hasGit = () => { |
90 |
| - if (process.env.VUE_CLI_TEST) { |
91 |
| - return true |
92 |
| - } |
93 |
| - try { |
94 |
| - execSync('git --version', { stdio: 'ignore' }) |
95 |
| - return true |
96 |
| - } catch (e) { |
97 |
| - return false |
98 |
| - } |
99 |
| -} |
| 1 | +Object.assign(exports, require('./env')) |
| 2 | +Object.assign(exports, require('./logger')) |
| 3 | +Object.assign(exports, require('./validate')) |
| 4 | +Object.assign(exports, require('./linkBin')) |
0 commit comments