swico 0.6.0-beta18 → 0.6.0-beta2
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 +2 -3
- package/src/command/start.js +2 -3
- package/src/template/react/history.js +1 -2
- package/src/utils/config.d.ts +1 -1
- package/src/utils/config.js +45 -89
- package/src/utils/tools.d.ts +0 -1
- package/src/utils/tools.js +4 -21
- package/src/template/react/config.prod.d.ts +0 -3
- package/src/template/react/config.prod.js +0 -5
- package/src/template/react/routes.prod.d.ts +0 -3
- package/src/template/react/routes.prod.js +0 -3
- package/src/template/vue/config.prod.d.ts +0 -3
- package/src/template/vue/config.prod.js +0 -5
- package/src/template/vue/routes.prod.d.ts +0 -6
- package/src/template/vue/routes.prod.js +0 -3
package/package.json
CHANGED
package/src/command/build.js
CHANGED
|
@@ -54,8 +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
|
|
58
|
-
spinner.start('Initializing Swico production config...');
|
|
57
|
+
tools_1.toast.info("Swico V".concat(package_json_1.default.version));
|
|
59
58
|
return [4, (0, config_1.getProjectConfig)('prod')];
|
|
60
59
|
case 1:
|
|
61
60
|
projectConfig = _a.sent();
|
|
@@ -69,8 +68,8 @@ function default_1() {
|
|
|
69
68
|
})];
|
|
70
69
|
case 2:
|
|
71
70
|
buildConfig = _a.sent();
|
|
72
|
-
spinner.succeed();
|
|
73
71
|
compiler = (0, webpack_1.default)(buildConfig);
|
|
72
|
+
console.log("".concat(chalk_1.default.hex('#5f72f5')('Starts building....'), " \n"));
|
|
74
73
|
compiler.run(function (err, stats) {
|
|
75
74
|
if (err) {
|
|
76
75
|
tools_1.toast.error(err.stack || err.toString());
|
package/src/command/start.js
CHANGED
|
@@ -131,8 +131,6 @@ function start() {
|
|
|
131
131
|
switch (_b.label) {
|
|
132
132
|
case 0:
|
|
133
133
|
process.env.SWICO_ENV = 'dev';
|
|
134
|
-
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
135
|
-
spinner.start('Initializing Swico development config...');
|
|
136
134
|
if (!(envPort !== null && envPort !== void 0)) return [3, 1];
|
|
137
135
|
_a = envPort;
|
|
138
136
|
return [3, 3];
|
|
@@ -142,6 +140,8 @@ function start() {
|
|
|
142
140
|
_b.label = 3;
|
|
143
141
|
case 3:
|
|
144
142
|
availablePort = _a;
|
|
143
|
+
tools_1.toast.info("Swico V".concat(package_json_1.default.version));
|
|
144
|
+
tools_1.toast.info('Initializing Swico config...');
|
|
145
145
|
return [4, (0, config_1.getProjectConfig)('dev')];
|
|
146
146
|
case 4:
|
|
147
147
|
projectConfig = _b.sent();
|
|
@@ -149,7 +149,6 @@ function start() {
|
|
|
149
149
|
return [4, (0, webpack_dev_1.default)(projectConfig)];
|
|
150
150
|
case 5:
|
|
151
151
|
startConfig = _b.sent();
|
|
152
|
-
spinner.succeed();
|
|
153
152
|
compiler = (0, webpack_1.default)(startConfig);
|
|
154
153
|
devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
|
|
155
154
|
_b.label = 6;
|
|
@@ -31,14 +31,13 @@ var interpolatePath = function (pathTemplate, params) {
|
|
|
31
31
|
return interpolatedParts.join('/');
|
|
32
32
|
};
|
|
33
33
|
var interpolatePathParams = function (pathTemplate, path) {
|
|
34
|
-
var _a;
|
|
35
34
|
if (pathTemplate === void 0) { pathTemplate = ''; }
|
|
36
35
|
var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
|
|
37
36
|
var regex = new RegExp("^".concat(regexPattern, "$"));
|
|
38
37
|
var match = path.match(regex);
|
|
39
38
|
if (match) {
|
|
40
39
|
var params_1 = match.slice(1);
|
|
41
|
-
var paramNames =
|
|
40
|
+
var paramNames = pathTemplate.match(/:(\w+)/g).map(function (name) { return name.slice(1); });
|
|
42
41
|
var result_1 = {};
|
|
43
42
|
paramNames.forEach(function (name, index) {
|
|
44
43
|
result_1[name] = params_1[index];
|
package/src/utils/config.d.ts
CHANGED
|
@@ -42,6 +42,6 @@ export interface GlobalData {
|
|
|
42
42
|
prod: Pick<GlobalSwicoConfigType, 'plugins' | 'console' | 'copy' | 'devtool' | 'router'>;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
export declare const getProjectConfig: (env
|
|
45
|
+
export declare const getProjectConfig: (env?: GlobalData['env']) => Promise<GlobalData>;
|
|
46
46
|
export declare const getFormatDefineVars: (defineVarsConfigData: any) => Promise<{}>;
|
|
47
47
|
export declare const initConfig: Omit<GlobalSwicoConfigType, 'template'>;
|
package/src/utils/config.js
CHANGED
|
@@ -171,9 +171,8 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
171
171
|
return [3, 1];
|
|
172
172
|
case 4:
|
|
173
173
|
templateType = customConfig['base'].template;
|
|
174
|
-
(0, tools_1.initIndexFile)(templateType);
|
|
175
174
|
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
176
|
-
return [4, initTemplateConfig(routerConfig, templateType
|
|
175
|
+
return [4, initTemplateConfig(routerConfig, templateType)];
|
|
177
176
|
case 5:
|
|
178
177
|
_e.sent();
|
|
179
178
|
return [4, initCliIndexFile(templateType)];
|
|
@@ -227,7 +226,9 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
227
226
|
case 0:
|
|
228
227
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
229
228
|
targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
230
|
-
|
|
229
|
+
return [4, fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8')];
|
|
230
|
+
case 1:
|
|
231
|
+
replaceFileText = _a.sent();
|
|
231
232
|
fileTypesText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8');
|
|
232
233
|
if (templateType === 'react') {
|
|
233
234
|
formatHooksPath = path_1.default
|
|
@@ -236,18 +237,17 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
236
237
|
replaceFileText = replaceFileText.replaceAll('require("./template/react/hooks");', "require(\"".concat(formatHooksPath, "\");"));
|
|
237
238
|
}
|
|
238
239
|
return [4, (0, tools_1.writeFile)(targetPath, replaceFileText)];
|
|
239
|
-
case
|
|
240
|
+
case 2:
|
|
240
241
|
_a.sent();
|
|
241
242
|
return [4, (0, tools_1.writeFile)(targetTypesPath, fileTypesText)];
|
|
242
|
-
case
|
|
243
|
+
case 3:
|
|
243
244
|
_a.sent();
|
|
244
245
|
return [2];
|
|
245
246
|
}
|
|
246
247
|
});
|
|
247
248
|
}); };
|
|
248
|
-
var formatRouterConfig = function (_a, templateType
|
|
249
|
+
var formatRouterConfig = function (_a, templateType) {
|
|
249
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;
|
|
250
|
-
var envPathSuffix = env === 'dev' ? '' : 'prod.';
|
|
251
251
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
252
252
|
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
253
253
|
return __generator(this, function (_a) {
|
|
@@ -256,10 +256,10 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
256
256
|
formatRouter = getFormatRouter(routes, templateType);
|
|
257
257
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
258
258
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
259
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath,
|
|
259
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/routes.js'), modifiedText)];
|
|
260
260
|
case 1:
|
|
261
261
|
_a.sent();
|
|
262
|
-
configFilePath = path_1.default.resolve(projectPath,
|
|
262
|
+
configFilePath = path_1.default.resolve(projectPath, './src/.swico/config.js');
|
|
263
263
|
replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
264
264
|
if (base) {
|
|
265
265
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
@@ -280,119 +280,75 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
280
280
|
});
|
|
281
281
|
}); });
|
|
282
282
|
};
|
|
283
|
-
var
|
|
284
|
-
var list = ['hooks.js', 'index.js', 'history.js', 'loading.js'];
|
|
285
|
-
switch (true) {
|
|
286
|
-
case templateType === 'vue' && env === 'dev':
|
|
287
|
-
list.push('config.js', 'Container.vue', 'routes.js');
|
|
288
|
-
break;
|
|
289
|
-
case templateType === 'vue' && env === 'prod':
|
|
290
|
-
list.push('config.prod.js', 'Container.vue', 'routes.prod.js');
|
|
291
|
-
break;
|
|
292
|
-
case templateType === 'react' && env === 'dev':
|
|
293
|
-
list.push('config.js', 'history.js', 'routes.js');
|
|
294
|
-
break;
|
|
295
|
-
case templateType === 'react' && env === 'prod':
|
|
296
|
-
list.push('config.prod.js', 'history.js', 'routes.prod.js');
|
|
297
|
-
break;
|
|
298
|
-
default:
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
return list;
|
|
302
|
-
};
|
|
303
|
-
var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
283
|
+
var initTemplateConfig = function (routerConfig, templateType) {
|
|
304
284
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
305
|
-
var copyTargetPath,
|
|
285
|
+
var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
|
|
306
286
|
return __generator(this, function (_a) {
|
|
307
287
|
switch (_a.label) {
|
|
308
288
|
case 0:
|
|
309
|
-
console.log('0');
|
|
310
289
|
copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
|
|
311
|
-
|
|
312
|
-
return [4,
|
|
290
|
+
if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 2];
|
|
291
|
+
return [4, fs_extra_1.default.remove(copyTargetPath)];
|
|
313
292
|
case 1:
|
|
314
293
|
_a.sent();
|
|
315
|
-
|
|
316
|
-
case 2:
|
|
294
|
+
_a.label = 2;
|
|
295
|
+
case 2: return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
|
|
296
|
+
return !fileName.endsWith('.d.ts') &&
|
|
297
|
+
(templateType === 'vue' ? fileName !== 'Container.js' : true);
|
|
298
|
+
})];
|
|
299
|
+
case 3:
|
|
300
|
+
_a.sent();
|
|
301
|
+
return [4, formatRouterConfig(routerConfig, templateType)];
|
|
302
|
+
case 4:
|
|
317
303
|
_a.sent();
|
|
318
304
|
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
replaceIndexText = replaceIndexText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
325
|
-
replaceIndexText = replaceIndexText.replaceAll('require("./routes.prod")', 'require("./routes")');
|
|
326
|
-
}
|
|
327
|
-
_a.label = 3;
|
|
328
|
-
case 3:
|
|
329
|
-
_a.trys.push([3, 5, , 6]);
|
|
305
|
+
_a.label = 5;
|
|
306
|
+
case 5:
|
|
307
|
+
_a.trys.push([5, 7, , 8]);
|
|
330
308
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
|
|
331
|
-
case
|
|
309
|
+
case 6:
|
|
332
310
|
_a.sent();
|
|
333
311
|
replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
|
|
334
312
|
replaceIndexText = 'require("../global");\n' + replaceIndexText;
|
|
335
|
-
return [3,
|
|
336
|
-
case
|
|
313
|
+
return [3, 8];
|
|
314
|
+
case 7:
|
|
337
315
|
e_1 = _a.sent();
|
|
338
316
|
replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
|
|
339
|
-
return [3,
|
|
340
|
-
case
|
|
341
|
-
_a.trys.push([
|
|
317
|
+
return [3, 8];
|
|
318
|
+
case 8:
|
|
319
|
+
_a.trys.push([8, 10, , 11]);
|
|
342
320
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
|
|
343
|
-
case
|
|
321
|
+
case 9:
|
|
344
322
|
_a.sent();
|
|
345
323
|
replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
|
|
346
324
|
replaceIndexText = 'require("../global.less");\n' + replaceIndexText;
|
|
347
|
-
return [3,
|
|
348
|
-
case
|
|
325
|
+
return [3, 11];
|
|
326
|
+
case 10:
|
|
349
327
|
e_2 = _a.sent();
|
|
350
328
|
replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
|
|
351
|
-
return [3,
|
|
352
|
-
case
|
|
353
|
-
if (!(templateType === 'vue')) return [3,
|
|
329
|
+
return [3, 11];
|
|
330
|
+
case 11:
|
|
331
|
+
if (!(templateType === 'vue')) return [3, 13];
|
|
354
332
|
replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
|
|
355
333
|
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
|
|
356
|
-
case 10:
|
|
357
|
-
_a.sent();
|
|
358
|
-
replaceHooksText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), 'utf8');
|
|
359
|
-
if (env === 'prod') {
|
|
360
|
-
replaceHooksText = replaceHooksText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
replaceHooksText = replaceIndexText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
364
|
-
}
|
|
365
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), replaceHooksText)];
|
|
366
|
-
case 11:
|
|
367
|
-
_a.sent();
|
|
368
|
-
return [3, 19];
|
|
369
334
|
case 12:
|
|
370
|
-
|
|
335
|
+
_a.sent();
|
|
371
336
|
_a.label = 13;
|
|
372
337
|
case 13:
|
|
373
|
-
|
|
374
|
-
|
|
338
|
+
if (!(templateType === 'react')) return [3, 19];
|
|
339
|
+
_a.label = 14;
|
|
375
340
|
case 14:
|
|
341
|
+
_a.trys.push([14, 16, 17, 19]);
|
|
342
|
+
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
343
|
+
case 15:
|
|
376
344
|
_a.sent();
|
|
377
345
|
replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
|
|
378
346
|
return [3, 19];
|
|
379
|
-
case
|
|
347
|
+
case 16:
|
|
380
348
|
e_3 = _a.sent();
|
|
381
349
|
replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
|
|
382
350
|
return [3, 19];
|
|
383
|
-
case
|
|
384
|
-
case 17:
|
|
385
|
-
_a.sent();
|
|
386
|
-
replaceHistoryText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/history.js'), 'utf8');
|
|
387
|
-
if (env === 'prod') {
|
|
388
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
389
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./routes")', 'require("./routes.prod")');
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
393
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./routes.prod")', 'require("./routes")');
|
|
394
|
-
}
|
|
395
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
|
|
351
|
+
case 17: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
|
|
396
352
|
case 18:
|
|
397
353
|
_a.sent();
|
|
398
354
|
return [7];
|
package/src/utils/tools.d.ts
CHANGED
package/src/utils/tools.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.
|
|
42
|
+
exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
|
|
43
43
|
var portfinder_1 = __importDefault(require("portfinder"));
|
|
44
44
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
45
45
|
var path_1 = __importDefault(require("path"));
|
|
@@ -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
|
|
105
|
+
console.log("\n".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
|
|
106
106
|
},
|
|
107
107
|
error: function (message) {
|
|
108
|
-
console.log("\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
|
|
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"));
|
|
@@ -142,20 +142,3 @@ var writeFile = function (sourcePath, text) {
|
|
|
142
142
|
});
|
|
143
143
|
};
|
|
144
144
|
exports.writeFile = writeFile;
|
|
145
|
-
var initIndexFile = function (tempalteType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
146
|
-
var fileText, targetPath;
|
|
147
|
-
return __generator(this, function (_a) {
|
|
148
|
-
switch (_a.label) {
|
|
149
|
-
case 0:
|
|
150
|
-
if (!(tempalteType === 'react')) return [3, 2];
|
|
151
|
-
fileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, '../index.react.js'), 'utf8');
|
|
152
|
-
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
153
|
-
return [4, (0, exports.writeFile)(targetPath, fileText)];
|
|
154
|
-
case 1:
|
|
155
|
-
_a.sent();
|
|
156
|
-
_a.label = 2;
|
|
157
|
-
case 2: return [2];
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}); };
|
|
161
|
-
exports.initIndexFile = initIndexFile;
|