-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
88 lines (78 loc) · 1.81 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
function defineProperty(key, from, to = exports) {
if (to[key]) throw new Error(`"${key}" already exsits!`);
// lazy
Object.defineProperty(to, key, {
get() {
return require(from[key]);
},
});
}
const internal = [
'moduleAlias',
'getPadLength',
'injectHtml',
'loadFile',
'logger',
'prompt',
'smartMerge',
'virtualFile',
'openBrowser',
'Env',
'validateSchema',
'pluginResolution',
].reduce((obj, key) => {
obj[key] = `./src/${key}`;
return obj;
}, {});
// special
internal.CONSTANTS = './src/constants';
Object.keys(internal).forEach(key => {
defineProperty(key, internal);
});
const thirdParty = {
fs: 'fs-extra',
chalk: 'chalk',
cheerio: 'cheerio',
semver: 'semver',
semverRegex: 'semver-regex',
_: 'lodash',
tryRequire: 'try-require',
ora: 'ora',
dedent: 'dedent',
globby: 'globby',
globParent: 'glob-parent',
isGlob: 'is-glob',
npa: 'npm-package-arg',
parseGitUrl: 'git-url-parse',
multimatch: 'multimatch',
stringifyObject: 'stringify-object',
LRU: 'lru-cache',
inquirer: 'inquirer',
execa: 'execa',
yParser: 'yargs-parser',
yUnParser: 'yargs-unparser',
debug: 'debug',
importFresh: 'import-fresh',
shell: 'shelljs',
onExit: 'signal-exit',
hash: 'hash-sum',
path: 'path',
isDocker: 'is-docker',
UUID: 'uuid',
};
Object.keys(thirdParty).forEach(key => {
defineProperty(key, thirdParty);
});
// ********************
const alias = {
assert: () => {
return exports.logger.assert.bind(exports.logger);
},
};
Object.keys(alias).forEach(key => {
if (exports[key]) throw new Error(`"${key}" already exsits!`);
Object.defineProperty(exports, key, {
get: alias[key],
});
});