swico 0.5.0-beta18 → 0.5.0-beta19
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 +1 -1
- package/src/utils/config.js +13 -19
package/package.json
CHANGED
package/src/utils/config.js
CHANGED
|
@@ -241,22 +241,18 @@ var handleCliIndexFile = function (templateType) { return __awaiter(void 0, void
|
|
|
241
241
|
var formatTemplateFileText = function (_a, templateType) {
|
|
242
242
|
var _b = _a.routes, routes = _b === void 0 ? [] : _b, _c = _a.type, type = _c === void 0 ? 'browser' : _c, _d = _a.base, base = _d === void 0 ? '/' : _d;
|
|
243
243
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
244
|
-
var formatRouter, textData, modifiedText,
|
|
244
|
+
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
245
245
|
return __generator(this, function (_a) {
|
|
246
246
|
switch (_a.label) {
|
|
247
247
|
case 0:
|
|
248
248
|
formatRouter = getFormatRouter(routes, templateType);
|
|
249
249
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.routes = ".concat(JSON.stringify(formatRouter), ";");
|
|
250
250
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
251
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(
|
|
251
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/routes.js'), modifiedText)];
|
|
252
252
|
case 1:
|
|
253
253
|
_a.sent();
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
indexText = fs_extra_1.default.readFileSync(indexFilePath, 'utf8');
|
|
257
|
-
configText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
258
|
-
replaceIndexText = indexText;
|
|
259
|
-
replaceConfigText = configText;
|
|
254
|
+
configFilePath = path_1.default.resolve(projectPath, './src/.swico/config.js');
|
|
255
|
+
replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
260
256
|
if (base) {
|
|
261
257
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
262
258
|
return "exports.routerBase = '".concat(templateType === 'react' && type === 'hash' ? '/' : base, "';");
|
|
@@ -267,11 +263,8 @@ var formatTemplateFileText = function (_a, templateType) {
|
|
|
267
263
|
return "exports.routerType = '".concat(type, "';");
|
|
268
264
|
});
|
|
269
265
|
}
|
|
270
|
-
return [4, (0, tools_1.writeFile)(indexFilePath, replaceIndexText)];
|
|
271
|
-
case 2:
|
|
272
|
-
_a.sent();
|
|
273
266
|
return [4, (0, tools_1.writeFile)(configFilePath, replaceConfigText)];
|
|
274
|
-
case
|
|
267
|
+
case 2:
|
|
275
268
|
_a.sent();
|
|
276
269
|
resolve(null);
|
|
277
270
|
return [2];
|
|
@@ -284,19 +277,20 @@ var initTemplateRouterConfig = function (routerConfig, templateType) {
|
|
|
284
277
|
var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
|
|
285
278
|
return __generator(this, function (_a) {
|
|
286
279
|
switch (_a.label) {
|
|
287
|
-
case 0:
|
|
288
|
-
case 1:
|
|
289
|
-
_a.sent();
|
|
280
|
+
case 0:
|
|
290
281
|
copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
|
|
291
|
-
if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3,
|
|
282
|
+
if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 2];
|
|
292
283
|
return [4, fs_extra_1.default.remove(copyTargetPath)];
|
|
293
|
-
case
|
|
284
|
+
case 1:
|
|
294
285
|
_a.sent();
|
|
295
|
-
_a.label =
|
|
296
|
-
case
|
|
286
|
+
_a.label = 2;
|
|
287
|
+
case 2: return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
|
|
297
288
|
return !fileName.endsWith('.d.ts') &&
|
|
298
289
|
(templateType === 'vue' ? fileName !== 'Container.js' : true);
|
|
299
290
|
})];
|
|
291
|
+
case 3:
|
|
292
|
+
_a.sent();
|
|
293
|
+
return [4, formatTemplateFileText(routerConfig, templateType)];
|
|
300
294
|
case 4:
|
|
301
295
|
_a.sent();
|
|
302
296
|
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
|