1 | "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.initGenerate = exports.onBeforeCompile = exports.initOptions = exports.initClientConf = exports.initServerConf = exports.initDllConf = exports.initCommand = void 0;
|
2 |
|
3 | var _joi = _interopRequireDefault(require("@hapi/joi"));
|
4 |
|
5 |
|
6 | var _env = require("./utils/env");
|
7 | var _extend = _interopRequireDefault(require("./utils/extend"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}const cwd = process.cwd();const fs = require('fs');const path = require('path');
|
8 | const colors = require('colors');
|
9 | let tuarcPath = path.resolve(cwd, './.tuarc');
|
10 | let tuarcConf = {
|
11 | plugins: [] };
|
12 |
|
13 |
|
14 | try {
|
15 | tuarcConf = require(tuarcPath);
|
16 | } catch (err) {
|
17 | }
|
18 |
|
19 | const defaultPlugins = [
|
20 | '@tuax/cli',
|
21 | '@tuax/plugin-babel'
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | ];
|
30 |
|
31 | let pluginList = defaultPlugins.concat(tuarcConf.plugins || []);
|
32 |
|
33 | const resolveModule = plugin => {
|
34 | let [pluginModule, ...options] = Array.isArray(plugin) ? plugin : [plugin];
|
35 | if (typeof pluginModule === 'string') {
|
36 | pluginModule = require(pluginModule);
|
37 | }
|
38 | return { pluginModule, options };
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | const initCommand = yargv => {
|
48 | pluginList.forEach(plugin => {
|
49 | let { pluginModule, options } = resolveModule(plugin);
|
50 | if (typeof pluginModule.command === 'function')
|
51 | pluginModule.command(yargv, options);
|
52 | });
|
53 | };
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | exports.initCommand = initCommand;
|
59 | const initServerConf = chainedConf => {
|
60 | let { config } = require('./options');
|
61 | pluginList.forEach(plugin => {
|
62 | let { pluginModule, options } = resolveModule(plugin);
|
63 | if (typeof pluginModule.serverConf === 'function')
|
64 | pluginModule.serverConf(chainedConf, _env.env, config, ...options);
|
65 | });
|
66 | };
|
67 |
|
68 |
|
69 |
|
70 | exports.initServerConf = initServerConf;
|
71 | const initClientConf = chainedConf => {
|
72 | let { config } = require('./options');
|
73 | pluginList.forEach(plugin => {
|
74 | let { pluginModule, options } = resolveModule(plugin);
|
75 | if (typeof pluginModule.clientConf === 'function')
|
76 | pluginModule.clientConf(chainedConf, _env.env, config, ...options);
|
77 | });
|
78 | };
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | exports.initClientConf = initClientConf;
|
84 | const initDllConf = chainedConf => {
|
85 | let { config } = require('./options');
|
86 | pluginList.forEach(plugin => {
|
87 | let { pluginModule, options } = resolveModule(plugin);
|
88 | if (typeof pluginModule.dllConf === 'function')
|
89 | pluginModule.dllConf(chainedConf, _env.env, config, ...options);
|
90 | });
|
91 | };
|
92 |
|
93 |
|
94 |
|
95 | exports.initDllConf = initDllConf;
|
96 | const onBeforeCompile = () => {
|
97 | let { config } = require('./options');
|
98 | pluginList.forEach(plugin => {
|
99 | let { pluginModule, options } = resolveModule(plugin);
|
100 | if (typeof pluginModule.beforeCompile === 'function')
|
101 | pluginModule.beforeCompile(_env.env, config, ...options);
|
102 | });
|
103 | };
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | exports.onBeforeCompile = onBeforeCompile;
|
113 | const initOptions = () => {
|
114 | let pluginConfigs = {
|
115 | pluginScheme: {},
|
116 | pluginDefaultOptions: {} };
|
117 |
|
118 | pluginList.forEach(plugin => {
|
119 | let { pluginModule, options } = resolveModule(plugin);
|
120 | if (typeof pluginModule.options === 'function') {
|
121 | let pluginOption = pluginModule.options(_joi.default, ...options) || {};
|
122 | let { pluginScheme, pluginDefaultOptions } = pluginOption;
|
123 | if (typeof pluginScheme === 'undefined') {
|
124 |
|
125 | } else {
|
126 | (0, _extend.default)(true, pluginConfigs.pluginScheme, pluginScheme);
|
127 | }
|
128 | if (typeof pluginDefaultOptions === 'undefined') {
|
129 |
|
130 | } else {
|
131 | (0, _extend.default)(true, pluginConfigs.pluginDefaultOptions, pluginDefaultOptions);
|
132 | }
|
133 | }
|
134 | });
|
135 | return pluginConfigs;
|
136 | };exports.initOptions = initOptions;
|
137 |
|
138 | const initGenerate = () => {
|
139 | if (!fs.existsSync(path.resolve(cwd, 'package.json'))) {
|
140 | throw new Error('请执行 npm init 创建 package.json');
|
141 | return;
|
142 | }
|
143 | let installPkg = require('./utils/installPkg');
|
144 | pluginList.forEach(plugin => {
|
145 | let { pluginModule, options } = resolveModule(plugin);
|
146 | if (typeof pluginModule.generate === 'function')
|
147 | installPkg.addPkg(pluginModule.generate(options));
|
148 | });
|
149 | installPkg.run();
|
150 | };exports.initGenerate = initGenerate; |
\ | No newline at end of file |