swico 0.6.0-beta6 → 0.6.0-beta8
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/command/build.js +1 -1
- package/src/command/start.js +1 -1
- package/src/utils/config.js +37 -18
- package/src/utils/tools.js +3 -3
package/package.json
CHANGED
package/src/command/build.js
CHANGED
|
@@ -54,7 +54,7 @@ function default_1() {
|
|
|
54
54
|
switch (_a.label) {
|
|
55
55
|
case 0:
|
|
56
56
|
process.env.SWICO_ENV = 'prod';
|
|
57
|
-
tools_1.toast.info("Swico
|
|
57
|
+
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
58
58
|
spinner.start('Initializing Swico production config...');
|
|
59
59
|
return [4, (0, config_1.getProjectConfig)('prod')];
|
|
60
60
|
case 1:
|
package/src/command/start.js
CHANGED
|
@@ -131,7 +131,7 @@ function start() {
|
|
|
131
131
|
switch (_b.label) {
|
|
132
132
|
case 0:
|
|
133
133
|
process.env.SWICO_ENV = 'dev';
|
|
134
|
-
tools_1.toast.info("Swico
|
|
134
|
+
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
135
135
|
spinner.start('Initializing Swico development config...');
|
|
136
136
|
if (!(envPort !== null && envPort !== void 0)) return [3, 1];
|
|
137
137
|
_a = envPort;
|
package/src/utils/config.js
CHANGED
|
@@ -248,18 +248,23 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
248
248
|
}); };
|
|
249
249
|
var formatRouterConfig = function (_a, templateType, env) {
|
|
250
250
|
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;
|
|
251
|
+
var envPathSuffix = env === 'dev' ? '' : '.prod.';
|
|
251
252
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
252
253
|
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
253
254
|
return __generator(this, function (_a) {
|
|
254
255
|
switch (_a.label) {
|
|
255
256
|
case 0:
|
|
257
|
+
if (env === 'prod') {
|
|
258
|
+
fs_extra_1.default.copyFileSync(path_1.default.resolve(projectPath, './src/.swico/routes.js'), path_1.default.resolve(projectPath, './src/.swico/routes.prod.js'));
|
|
259
|
+
fs_extra_1.default.copyFileSync(path_1.default.resolve(projectPath, './src/.swico/config.js'), path_1.default.resolve(projectPath, './src/.swico/routes.config.js'));
|
|
260
|
+
}
|
|
256
261
|
formatRouter = getFormatRouter(routes, templateType);
|
|
257
262
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
258
263
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
259
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(
|
|
264
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico/routes.".concat(envPathSuffix, "js")), modifiedText)];
|
|
260
265
|
case 1:
|
|
261
266
|
_a.sent();
|
|
262
|
-
configFilePath = path_1.default.resolve(projectPath,
|
|
267
|
+
configFilePath = path_1.default.resolve(projectPath, "./src/.swico/config.".concat(envPathSuffix, "js"));
|
|
263
268
|
replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
264
269
|
if (base) {
|
|
265
270
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
@@ -281,13 +286,12 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
281
286
|
}); });
|
|
282
287
|
};
|
|
283
288
|
var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
284
|
-
var swicoPath = env === 'dev' ? '' : '/.prod';
|
|
285
289
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
286
|
-
var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
|
|
290
|
+
var copyTargetPath, replaceIndexText, replaceHistoryText, e_1, e_2, e_3;
|
|
287
291
|
return __generator(this, function (_a) {
|
|
288
292
|
switch (_a.label) {
|
|
289
293
|
case 0:
|
|
290
|
-
copyTargetPath = path_1.default.resolve(projectPath,
|
|
294
|
+
copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
|
|
291
295
|
if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 2];
|
|
292
296
|
return [4, fs_extra_1.default.remove(copyTargetPath)];
|
|
293
297
|
case 1:
|
|
@@ -302,7 +306,16 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
|
302
306
|
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
303
307
|
case 4:
|
|
304
308
|
_a.sent();
|
|
305
|
-
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath,
|
|
309
|
+
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
|
|
310
|
+
replaceHistoryText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/history.js'), 'utf8');
|
|
311
|
+
if (env === 'prod') {
|
|
312
|
+
replaceIndexText = replaceIndexText.replaceAll('require("./config");', 'require("./config.prod");');
|
|
313
|
+
replaceHistoryText = replaceHistoryText.replaceAll('require("./config");', 'require("./config.prod");');
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
replaceIndexText = replaceIndexText.replaceAll('require("./config.prod");', 'require("./config");');
|
|
317
|
+
replaceHistoryText = replaceHistoryText.replaceAll('require("./config.prod");', 'require("./config");');
|
|
318
|
+
}
|
|
306
319
|
_a.label = 5;
|
|
307
320
|
case 5:
|
|
308
321
|
_a.trys.push([5, 7, , 8]);
|
|
@@ -329,31 +342,37 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
|
329
342
|
replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
|
|
330
343
|
return [3, 11];
|
|
331
344
|
case 11:
|
|
332
|
-
if (!(templateType === 'vue')) return [3,
|
|
345
|
+
if (!(templateType === 'vue')) return [3, 14];
|
|
333
346
|
replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
|
|
334
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath,
|
|
347
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
|
|
335
348
|
case 12:
|
|
336
349
|
_a.sent();
|
|
337
|
-
|
|
350
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
|
|
338
351
|
case 13:
|
|
339
|
-
|
|
352
|
+
_a.sent();
|
|
340
353
|
_a.label = 14;
|
|
341
354
|
case 14:
|
|
342
|
-
|
|
343
|
-
|
|
355
|
+
if (!(templateType === 'react')) return [3, 21];
|
|
356
|
+
_a.label = 15;
|
|
344
357
|
case 15:
|
|
358
|
+
_a.trys.push([15, 17, 18, 21]);
|
|
359
|
+
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
360
|
+
case 16:
|
|
345
361
|
_a.sent();
|
|
346
362
|
replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
|
|
347
|
-
return [3,
|
|
348
|
-
case
|
|
363
|
+
return [3, 21];
|
|
364
|
+
case 17:
|
|
349
365
|
e_3 = _a.sent();
|
|
350
366
|
replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
|
|
351
|
-
return [3,
|
|
352
|
-
case
|
|
353
|
-
case
|
|
367
|
+
return [3, 21];
|
|
368
|
+
case 18: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
|
|
369
|
+
case 19:
|
|
370
|
+
_a.sent();
|
|
371
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
|
|
372
|
+
case 20:
|
|
354
373
|
_a.sent();
|
|
355
374
|
return [7];
|
|
356
|
-
case
|
|
375
|
+
case 21:
|
|
357
376
|
resolve(null);
|
|
358
377
|
return [2];
|
|
359
378
|
}
|
package/src/utils/tools.js
CHANGED
|
@@ -102,10 +102,10 @@ var getPort = function () {
|
|
|
102
102
|
exports.getPort = getPort;
|
|
103
103
|
exports.toast = {
|
|
104
104
|
info: function (message) {
|
|
105
|
-
console.log("\n".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
|
|
105
|
+
console.log("\n".concat(chalk_1.default.hex('#5f72f5')("> ".concat(message)), "\n"));
|
|
106
106
|
},
|
|
107
107
|
error: function (message) {
|
|
108
|
-
console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
|
|
108
|
+
console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
|
|
109
109
|
if (Array.isArray(message)) {
|
|
110
110
|
message.forEach(function (item) {
|
|
111
111
|
console.log(" > ".concat(chalk_1.default.red.bold(item), " \n"));
|
|
@@ -116,7 +116,7 @@ exports.toast = {
|
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
118
|
warning: function (message) {
|
|
119
|
-
console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about Swico:'), " \n"));
|
|
119
|
+
console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about Swico:'), " \n"));
|
|
120
120
|
if (Array.isArray(message)) {
|
|
121
121
|
message.forEach(function (item) {
|
|
122
122
|
console.log(" > ".concat(chalk_1.default.hex('#fb8918').bold(item), " \n"));
|