swico 1.7.3 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -13
- package/src/bin.js +6 -6
- package/src/command/build.js +33 -73
- package/src/command/start.js +99 -191
- package/src/config/rsbpack.dev.js +104 -0
- package/src/config/{webpack.base.react.d.ts → rspack.base.react.d.ts} +13 -3
- package/src/config/rspack.base.react.js +193 -0
- package/src/config/{webpack.base.vue.d.ts → rspack.base.vue.d.ts} +13 -1
- package/src/config/rspack.base.vue.js +282 -0
- package/src/config/rspack.prod.js +123 -0
- package/src/index.js +3 -5
- package/src/index.react.js +5 -10
- package/src/index.vue.js +4 -6
- package/src/project-path/.swico-react/$env/history.js +65 -66
- package/src/project-path/.swico-react/$env/index.js +29 -47
- package/src/project-path/.swico-react/loading.js +1 -1
- package/src/project-path/.swico-react/react-hooks.js +24 -37
- package/src/project-path/.swico-vue/$env/history.js +25 -36
- package/src/project-path/.swico-vue/$env/index.js +7 -7
- package/src/project-path/.swico-vue/Container.js +1 -1
- package/src/project-path/.swico-vue/vue-hooks.js +17 -28
- package/src/project-path/src/layout/Layout.js +1 -1
- package/src/project-path/src/layout/index.js +3 -3
- package/src/task.js +13 -58
- package/src/utils/config.js +185 -349
- package/src/utils/tools.js +103 -199
- package/src/config/webpack.base.react.js +0 -315
- package/src/config/webpack.base.vue.js +0 -338
- package/src/config/webpack.dev.js +0 -159
- package/src/config/webpack.prod.js +0 -193
- /package/src/config/{webpack.dev.d.ts → rsbpack.dev.d.ts} +0 -0
- /package/src/config/{webpack.prod.d.ts → rspack.prod.d.ts} +0 -0
package/src/utils/config.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -42,232 +31,140 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
32
|
});
|
|
44
33
|
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
34
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
36
|
};
|
|
75
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
38
|
exports.initConfig = exports.getFormatDefineVars = exports.updateIndexFileText = exports.handleGlobalStyleFile = exports.handleLoadingFile = exports.getProjectConfig = void 0;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
tools_1.toast.error(msgText);
|
|
137
|
-
process.exit(1);
|
|
138
|
-
}
|
|
139
|
-
if (key === 'base' && !['vue', 'react'].includes(configObj['template'])) {
|
|
140
|
-
tools_1.toast.error("The field '".concat(chalk_1.default.blue('template'), "' does not support the value '").concat(chalk_1.default.red(configObj['template']), "',the value should be 'vue' or 'react' "), { title: toastTitle });
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
if (!['hash', 'browser'].includes((_c = (_b = configObj['router']) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : exports.initConfig.router.type)) {
|
|
144
|
-
tools_1.toast.error("The field '".concat(chalk_1.default.blue('router.type'), "' does not support the value '").concat(chalk_1.default.red(configObj['router'].type), "',the value should be 'browser' or 'hash' "), { title: toastTitle });
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
_e = customConfig;
|
|
148
|
-
_f = key;
|
|
149
|
-
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
150
|
-
case 3:
|
|
151
|
-
_e[_f] = (_g.sent()).default;
|
|
152
|
-
_g.label = 4;
|
|
153
|
-
case 4: return [2];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
_i = 0, _a = Object.keys(configPath);
|
|
158
|
-
_d.label = 1;
|
|
159
|
-
case 1:
|
|
160
|
-
if (!(_i < _a.length)) return [3, 4];
|
|
161
|
-
key = _a[_i];
|
|
162
|
-
return [5, _loop_1(key)];
|
|
163
|
-
case 2:
|
|
164
|
-
_d.sent();
|
|
165
|
-
_d.label = 3;
|
|
166
|
-
case 3:
|
|
167
|
-
_i++;
|
|
168
|
-
return [3, 1];
|
|
169
|
-
case 4:
|
|
170
|
-
templateType = customConfig['base'].template;
|
|
171
|
-
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
172
|
-
return [4, initTemplateConfig(routerConfig, templateType, env)];
|
|
173
|
-
case 5:
|
|
174
|
-
_d.sent();
|
|
175
|
-
return [4, initCliIndexFile(templateType, env)];
|
|
176
|
-
case 6:
|
|
177
|
-
_d.sent();
|
|
178
|
-
envPath = env === 'dev' ? '.dev/' : '.prod/';
|
|
179
|
-
entryPath = path_1.default.resolve(projectPath, "./.swico/".concat(envPath, "index.js"));
|
|
180
|
-
templatePath = path_1.default.join(projectPath, '/src/index.ejs');
|
|
181
|
-
return [2, {
|
|
182
|
-
env: env,
|
|
183
|
-
projectPath: projectPath,
|
|
184
|
-
entryPath: entryPath,
|
|
185
|
-
templatePath: templatePath,
|
|
186
|
-
customConfig: customConfig,
|
|
187
|
-
templateType: templateType
|
|
188
|
-
}];
|
|
39
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const tools_1 = require("./tools");
|
|
43
|
+
const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const projectPath = process.cwd();
|
|
46
|
+
const configDir = path_1.default.join(projectPath, '/config');
|
|
47
|
+
const configPath = {
|
|
48
|
+
dev: path_1.default.join(configDir, '/swico.dev.ts'),
|
|
49
|
+
prod: path_1.default.join(configDir, '/swico.prod.ts'),
|
|
50
|
+
base: path_1.default.join(configDir, '/swico.ts')
|
|
51
|
+
};
|
|
52
|
+
const customConfig = {};
|
|
53
|
+
for (const key of Object.keys(configPath)) {
|
|
54
|
+
const curConfigFilePath = configPath[key];
|
|
55
|
+
const exists = yield fs_extra_1.default.exists(curConfigFilePath);
|
|
56
|
+
if (exists) {
|
|
57
|
+
const configObj = (yield Promise.resolve(`${curConfigFilePath}`).then(s => __importStar(require(s)))).default;
|
|
58
|
+
const configFields = Object.keys(configObj);
|
|
59
|
+
let supportedFieldList, configFileName;
|
|
60
|
+
switch (key) {
|
|
61
|
+
case 'base':
|
|
62
|
+
supportedFieldList = [
|
|
63
|
+
'plugins',
|
|
64
|
+
'publicPath',
|
|
65
|
+
'alias',
|
|
66
|
+
'define',
|
|
67
|
+
'devtool',
|
|
68
|
+
'externals',
|
|
69
|
+
'router',
|
|
70
|
+
'template'
|
|
71
|
+
];
|
|
72
|
+
configFileName = 'swico.ts';
|
|
73
|
+
break;
|
|
74
|
+
case 'dev':
|
|
75
|
+
supportedFieldList = ['plugins', 'proxy', 'https', 'devtool', 'router'];
|
|
76
|
+
configFileName = 'swico.dev.ts';
|
|
77
|
+
break;
|
|
78
|
+
case 'prod':
|
|
79
|
+
supportedFieldList = ['plugins', 'console', 'copy', 'devtool', 'router'];
|
|
80
|
+
configFileName = 'swico.prod.ts';
|
|
81
|
+
}
|
|
82
|
+
const toastTitle = `Swico config file => ${chalk_1.default.hex(tools_1.colorConfig.theme)(configFileName)}`;
|
|
83
|
+
const unSupportedField = configFields.find((field) => !supportedFieldList.includes(field));
|
|
84
|
+
if (configFields.length > 0 && unSupportedField) {
|
|
85
|
+
const msgText = `The Swico configuration file '${chalk_1.default.blue(configFileName)}' does not support the field '${chalk_1.default.red(unSupportedField)}' `;
|
|
86
|
+
tools_1.toast.error(msgText);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
if (key === 'base' && !['vue', 'react'].includes(configObj['template'])) {
|
|
90
|
+
tools_1.toast.error(`The field '${chalk_1.default.blue('template')}' does not support the value '${chalk_1.default.red(configObj['template'])}',the value should be 'vue' or 'react' `, { title: toastTitle });
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
if (!['hash', 'browser'].includes((_b = (_a = configObj['router']) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : exports.initConfig.router.type)) {
|
|
94
|
+
tools_1.toast.error(`The field '${chalk_1.default.blue('router.type')}' does not support the value '${chalk_1.default.red(configObj['router'].type)}',the value should be 'browser' or 'hash' `, { title: toastTitle });
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
customConfig[key] = (yield Promise.resolve(`${curConfigFilePath}`).then(s => __importStar(require(s)))).default;
|
|
189
98
|
}
|
|
190
|
-
}
|
|
191
|
-
|
|
99
|
+
}
|
|
100
|
+
const templateType = customConfig['base'].template;
|
|
101
|
+
const routerConfig = Object.assign(Object.assign(Object.assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
102
|
+
yield initTemplateConfig(routerConfig, templateType, env);
|
|
103
|
+
yield initCliIndexFile(templateType, env);
|
|
104
|
+
const envPath = env === 'dev' ? '.dev/' : '.prod/';
|
|
105
|
+
const entryPath = path_1.default.resolve(projectPath, `./.swico/${envPath}index.js`);
|
|
106
|
+
const templatePath = path_1.default.join(projectPath, '/src/index.ejs');
|
|
107
|
+
return {
|
|
108
|
+
env,
|
|
109
|
+
projectPath,
|
|
110
|
+
entryPath,
|
|
111
|
+
templatePath,
|
|
112
|
+
customConfig,
|
|
113
|
+
templateType
|
|
114
|
+
};
|
|
115
|
+
});
|
|
192
116
|
exports.getProjectConfig = getProjectConfig;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
117
|
+
const initCliIndexFile = (templateType, env) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const projectPath = process.cwd();
|
|
119
|
+
const targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
120
|
+
const targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
121
|
+
let replaceFileText = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, `../index.${templateType}.js`), 'utf8');
|
|
122
|
+
const fileTypesText = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, `../index.${templateType}.d.ts`), 'utf8');
|
|
123
|
+
if (templateType === 'react') {
|
|
124
|
+
const formatHooksPath = path_1.default
|
|
125
|
+
.resolve(projectPath, './.swico/react-hooks')
|
|
126
|
+
.replaceAll('\\', '/');
|
|
127
|
+
replaceFileText = replaceFileText.replaceAll('require("./project-path/.swico-react/react-hooks");', `require("${formatHooksPath}");`);
|
|
128
|
+
}
|
|
129
|
+
const formatHistoryPath = path_1.default
|
|
130
|
+
.resolve(projectPath, `./.swico/.${env}/history`)
|
|
131
|
+
.replaceAll('\\', '/');
|
|
132
|
+
replaceFileText = replaceFileText.replaceAll('require("./mock-history");', `require("${formatHistoryPath}");`);
|
|
133
|
+
yield fs_extra_1.default.writeFile(targetPath, replaceFileText);
|
|
134
|
+
yield fs_extra_1.default.writeFile(targetTypesPath, fileTypesText);
|
|
135
|
+
});
|
|
136
|
+
const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templateType, env) => {
|
|
137
|
+
const projectPath = process.cwd();
|
|
138
|
+
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
139
|
+
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const formatRouter = (0, tools_1.getFormatRouter)(projectPath, routes, templateType);
|
|
141
|
+
const textData = `"use strict";
|
|
142
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
143
|
+
exports.default = ${JSON.stringify(formatRouter)};`;
|
|
144
|
+
let modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
145
|
+
yield fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, `./.swico${envPath}routes.js`), modifiedText);
|
|
146
|
+
const configFilePath = path_1.default.resolve(projectPath, `./.swico${envPath}config.js`);
|
|
147
|
+
let replaceConfigText = yield fs_extra_1.default.readFile(configFilePath, 'utf8');
|
|
148
|
+
if (base) {
|
|
149
|
+
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
150
|
+
return `exports.routerBase = '${templateType === 'react' && type === 'hash' ? '/' : base}';`;
|
|
151
|
+
});
|
|
224
152
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return __generator(this, function (_a) {
|
|
234
|
-
switch (_a.label) {
|
|
235
|
-
case 0:
|
|
236
|
-
formatRouter = (0, tools_1.getFormatRouter)(projectPath, routes, templateType);
|
|
237
|
-
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
238
|
-
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
239
|
-
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "routes.js")), modifiedText)];
|
|
240
|
-
case 1:
|
|
241
|
-
_a.sent();
|
|
242
|
-
configFilePath = path_1.default.resolve(projectPath, "./.swico".concat(envPath, "config.js"));
|
|
243
|
-
return [4, fs_extra_1.default.readFile(configFilePath, 'utf8')];
|
|
244
|
-
case 2:
|
|
245
|
-
replaceConfigText = _a.sent();
|
|
246
|
-
if (base) {
|
|
247
|
-
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
248
|
-
return "exports.routerBase = '".concat(templateType === 'react' && type === 'hash' ? '/' : base, "';");
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
if (type) {
|
|
252
|
-
replaceConfigText = replaceConfigText.replace(/exports\.routerType\s*=\s*(.*)/gm, function (match, p1) {
|
|
253
|
-
return "exports.routerType = '".concat(type, "';");
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
return [4, fs_extra_1.default.writeFile(configFilePath, replaceConfigText)];
|
|
257
|
-
case 3:
|
|
258
|
-
_a.sent();
|
|
259
|
-
resolve(null);
|
|
260
|
-
return [2];
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}); });
|
|
153
|
+
if (type) {
|
|
154
|
+
replaceConfigText = replaceConfigText.replace(/exports\.routerType\s*=\s*(.*)/gm, function (match, p1) {
|
|
155
|
+
return `exports.routerType = '${type}';`;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
yield fs_extra_1.default.writeFile(configFilePath, replaceConfigText);
|
|
159
|
+
resolve(null);
|
|
160
|
+
}));
|
|
264
161
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
162
|
+
const getGlobalStyleFilePath = () => {
|
|
163
|
+
const projectPath = process.cwd();
|
|
164
|
+
let filePath, fileType;
|
|
165
|
+
const cssPath = path_1.default.resolve(projectPath, './src/global.css');
|
|
166
|
+
const lessPath = path_1.default.resolve(projectPath, './src/global.less');
|
|
167
|
+
const scssPath = path_1.default.resolve(projectPath, './src/global.scss');
|
|
271
168
|
switch (true) {
|
|
272
169
|
case fs_extra_1.default.existsSync(cssPath):
|
|
273
170
|
filePath = cssPath;
|
|
@@ -284,38 +181,27 @@ var getGlobalStyleFilePath = function () {
|
|
|
284
181
|
default:
|
|
285
182
|
break;
|
|
286
183
|
}
|
|
287
|
-
return { filePath
|
|
184
|
+
return { filePath, fileType };
|
|
288
185
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
_a.sent();
|
|
302
|
-
newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../src/loading"');
|
|
303
|
-
return [3, 4];
|
|
304
|
-
case 3:
|
|
305
|
-
e_1 = _a.sent();
|
|
306
|
-
newReplaceIndexText = newReplaceIndexText.replace('"../../src/loading"', '"../loading"');
|
|
307
|
-
return [3, 4];
|
|
308
|
-
case 4: return [2, newReplaceIndexText];
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
}); };
|
|
186
|
+
const handleLoadingFile = (replaceIndexText, envPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
const projectPath = process.cwd();
|
|
188
|
+
let newReplaceIndexText = replaceIndexText;
|
|
189
|
+
try {
|
|
190
|
+
yield fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK);
|
|
191
|
+
newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../src/loading"');
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
newReplaceIndexText = newReplaceIndexText.replace('"../../src/loading"', '"../loading"');
|
|
195
|
+
}
|
|
196
|
+
return newReplaceIndexText;
|
|
197
|
+
});
|
|
312
198
|
exports.handleLoadingFile = handleLoadingFile;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
199
|
+
const handleGlobalStyleFile = (replaceIndexText) => {
|
|
200
|
+
const { filePath: styleFilePath, fileType: styleFileType } = getGlobalStyleFilePath();
|
|
201
|
+
let newReplaceIndexText = replaceIndexText;
|
|
316
202
|
if (styleFilePath) {
|
|
317
|
-
newReplaceIndexText = newReplaceIndexText.replaceAll(
|
|
318
|
-
newReplaceIndexText =
|
|
203
|
+
newReplaceIndexText = newReplaceIndexText.replaceAll(`require("../../src/global.${styleFileType}");`, '');
|
|
204
|
+
newReplaceIndexText = `require("../../src/global.${styleFileType}");\n${replaceIndexText}`;
|
|
319
205
|
}
|
|
320
206
|
else {
|
|
321
207
|
newReplaceIndexText = newReplaceIndexText.replaceAll(/require\("\.\.\/\.\.\/src\/global.(less|scss|css)"\);/g, '');
|
|
@@ -323,100 +209,50 @@ var handleGlobalStyleFile = function (replaceIndexText) {
|
|
|
323
209
|
return newReplaceIndexText;
|
|
324
210
|
};
|
|
325
211
|
exports.handleGlobalStyleFile = handleGlobalStyleFile;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
case 0:
|
|
331
|
-
projectPath = process.cwd();
|
|
332
|
-
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "index.js")), newFileText)];
|
|
333
|
-
case 1:
|
|
334
|
-
_a.sent();
|
|
335
|
-
return [2];
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}); };
|
|
212
|
+
const updateIndexFileText = (envPath, newFileText) => __awaiter(void 0, void 0, void 0, function* () {
|
|
213
|
+
const projectPath = process.cwd();
|
|
214
|
+
yield fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), newFileText);
|
|
215
|
+
});
|
|
339
216
|
exports.updateIndexFileText = updateIndexFileText;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return new Promise(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
case 2:
|
|
361
|
-
_a.sent();
|
|
362
|
-
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
363
|
-
case 3:
|
|
364
|
-
_a.sent();
|
|
365
|
-
return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "index.js")), 'utf8')];
|
|
366
|
-
case 4:
|
|
367
|
-
replaceIndexText = _a.sent();
|
|
368
|
-
hooksFilePath = path_1.default.resolve(projectPath, "./.swico/".concat(templateType, "-hooks.js"));
|
|
369
|
-
return [4, fs_extra_1.default.readFile(hooksFilePath, 'utf8')];
|
|
370
|
-
case 5:
|
|
371
|
-
replaceHooksText = _a.sent();
|
|
372
|
-
replaceHooksText = replaceHooksText.replaceAll('$env', ".".concat(env));
|
|
373
|
-
return [4, fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText)];
|
|
374
|
-
case 6:
|
|
375
|
-
_a.sent();
|
|
376
|
-
replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
|
|
377
|
-
if (!(templateType === 'vue')) return [3, 8];
|
|
378
|
-
replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
|
|
379
|
-
return [4, (0, exports.updateIndexFileText)(envPath, replaceIndexText)];
|
|
380
|
-
case 7:
|
|
381
|
-
_a.sent();
|
|
382
|
-
return [3, 11];
|
|
383
|
-
case 8:
|
|
384
|
-
if (!(templateType === 'react')) return [3, 11];
|
|
385
|
-
return [4, (0, exports.handleLoadingFile)(replaceIndexText, envPath)];
|
|
386
|
-
case 9:
|
|
387
|
-
newReplaceIndexText = _a.sent();
|
|
388
|
-
return [4, (0, exports.updateIndexFileText)(envPath, newReplaceIndexText)];
|
|
389
|
-
case 10:
|
|
390
|
-
_a.sent();
|
|
391
|
-
_a.label = 11;
|
|
392
|
-
case 11:
|
|
393
|
-
resolve(null);
|
|
394
|
-
return [2];
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}); });
|
|
398
|
-
};
|
|
399
|
-
var getFormatDefineVars = function (defineVarsConfigData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
400
|
-
var formatObj, obj, _i, _a, _b, key, value;
|
|
401
|
-
return __generator(this, function (_c) {
|
|
402
|
-
switch (_c.label) {
|
|
403
|
-
case 0:
|
|
404
|
-
formatObj = {};
|
|
405
|
-
obj = defineVarsConfigData;
|
|
406
|
-
if (!(typeof defineVarsConfigData === 'function')) return [3, 2];
|
|
407
|
-
return [4, Promise.resolve(defineVarsConfigData())];
|
|
408
|
-
case 1:
|
|
409
|
-
obj = _c.sent();
|
|
410
|
-
_c.label = 2;
|
|
411
|
-
case 2:
|
|
412
|
-
for (_i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
|
|
413
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
414
|
-
formatObj[key] = JSON.stringify(value);
|
|
415
|
-
}
|
|
416
|
-
return [2, formatObj];
|
|
217
|
+
const initTemplateConfig = (routerConfig, templateType, env) => {
|
|
218
|
+
const projectPath = process.cwd();
|
|
219
|
+
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
220
|
+
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
221
|
+
const copyTargetPath = path_1.default.resolve(projectPath, `./.swico${envPath}`);
|
|
222
|
+
yield (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, `../project-path/.swico-${templateType}/$env`), copyTargetPath, (fileName) => !fileName.endsWith('.d.ts') &&
|
|
223
|
+
(templateType === 'vue'
|
|
224
|
+
? !['Container.js', 'vue-hooks.js'].includes(fileName)
|
|
225
|
+
: !['react-hooks.js'].includes(fileName)));
|
|
226
|
+
yield (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, `../project-path/.swico-${templateType}`), path_1.default.resolve(projectPath, './.swico'), (fileName) => ['react-hooks.js', 'vue-hooks.js', 'loading.js', 'Container.vue'].includes(fileName));
|
|
227
|
+
yield formatRouterConfig(routerConfig, templateType, env);
|
|
228
|
+
let replaceIndexText = yield fs_extra_1.default.readFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), 'utf8');
|
|
229
|
+
const hooksFilePath = path_1.default.resolve(projectPath, `./.swico/${templateType}-hooks.js`);
|
|
230
|
+
let replaceHooksText = yield fs_extra_1.default.readFile(hooksFilePath, 'utf8');
|
|
231
|
+
replaceHooksText = replaceHooksText.replaceAll('$env', `.${env}`);
|
|
232
|
+
yield fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText);
|
|
233
|
+
replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
|
|
234
|
+
if (templateType === 'vue') {
|
|
235
|
+
replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
|
|
236
|
+
yield (0, exports.updateIndexFileText)(envPath, replaceIndexText);
|
|
417
237
|
}
|
|
418
|
-
|
|
419
|
-
|
|
238
|
+
else if (templateType === 'react') {
|
|
239
|
+
const newReplaceIndexText = yield (0, exports.handleLoadingFile)(replaceIndexText, envPath);
|
|
240
|
+
yield (0, exports.updateIndexFileText)(envPath, newReplaceIndexText);
|
|
241
|
+
}
|
|
242
|
+
resolve(null);
|
|
243
|
+
}));
|
|
244
|
+
};
|
|
245
|
+
const getFormatDefineVars = (defineVarsConfigData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
246
|
+
const formatObj = {};
|
|
247
|
+
let obj = defineVarsConfigData;
|
|
248
|
+
if (typeof defineVarsConfigData === 'function') {
|
|
249
|
+
obj = yield Promise.resolve(defineVarsConfigData());
|
|
250
|
+
}
|
|
251
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
252
|
+
formatObj[key] = JSON.stringify(value);
|
|
253
|
+
}
|
|
254
|
+
return formatObj;
|
|
255
|
+
});
|
|
420
256
|
exports.getFormatDefineVars = getFormatDefineVars;
|
|
421
257
|
exports.initConfig = {
|
|
422
258
|
console: true,
|