swico 0.6.0-beta20 → 0.6.0-beta22
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 -2
- package/src/command/start.js +1 -2
- package/src/utils/config.js +35 -87
- package/src/utils/tools.js +0 -1
package/package.json
CHANGED
package/src/command/build.js
CHANGED
|
@@ -55,7 +55,7 @@ function default_1() {
|
|
|
55
55
|
case 0:
|
|
56
56
|
process.env.SWICO_ENV = 'prod';
|
|
57
57
|
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
58
|
-
spinner.
|
|
58
|
+
spinner.succeed('Initializing Swico production config...\n');
|
|
59
59
|
return [4, (0, tools_1.initIndexFile)()];
|
|
60
60
|
case 1:
|
|
61
61
|
_a.sent();
|
|
@@ -72,7 +72,6 @@ function default_1() {
|
|
|
72
72
|
})];
|
|
73
73
|
case 3:
|
|
74
74
|
buildConfig = _a.sent();
|
|
75
|
-
spinner.succeed();
|
|
76
75
|
compiler = (0, webpack_1.default)(buildConfig);
|
|
77
76
|
compiler.run(function (err, stats) {
|
|
78
77
|
if (err) {
|
package/src/command/start.js
CHANGED
|
@@ -132,7 +132,7 @@ function start() {
|
|
|
132
132
|
case 0:
|
|
133
133
|
process.env.SWICO_ENV = 'dev';
|
|
134
134
|
tools_1.toast.info("Swico v".concat(package_json_1.default.version));
|
|
135
|
-
spinner.
|
|
135
|
+
spinner.succeed('Initializing Swico development config...\n');
|
|
136
136
|
return [4, (0, tools_1.initIndexFile)()];
|
|
137
137
|
case 1:
|
|
138
138
|
_b.sent();
|
|
@@ -152,7 +152,6 @@ function start() {
|
|
|
152
152
|
return [4, (0, webpack_dev_1.default)(projectConfig)];
|
|
153
153
|
case 6:
|
|
154
154
|
startConfig = _b.sent();
|
|
155
|
-
spinner.succeed();
|
|
156
155
|
compiler = (0, webpack_1.default)(startConfig);
|
|
157
156
|
devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
|
|
158
157
|
_b.label = 7;
|
package/src/utils/config.js
CHANGED
|
@@ -80,7 +80,7 @@ var chalk_1 = __importDefault(require("chalk"));
|
|
|
80
80
|
var tools_1 = require("./tools");
|
|
81
81
|
var projectPath = process.cwd();
|
|
82
82
|
var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
|
-
var configDir, configPath, customConfig, _loop_1, _i, _a, key, templateType, routerConfig, entryPath, templatePath;
|
|
83
|
+
var configDir, configPath, customConfig, _loop_1, _i, _a, key, templateType, routerConfig, envPath, entryPath, templatePath;
|
|
84
84
|
var _b, _c, _d;
|
|
85
85
|
return __generator(this, function (_e) {
|
|
86
86
|
switch (_e.label) {
|
|
@@ -178,7 +178,8 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
178
178
|
return [4, initCliIndexFile(templateType)];
|
|
179
179
|
case 6:
|
|
180
180
|
_e.sent();
|
|
181
|
-
|
|
181
|
+
envPath = env === 'dev' ? '' : '.prod/';
|
|
182
|
+
entryPath = path_1.default.resolve(projectPath, "./src/.swico/".concat(envPath, "index.js"));
|
|
182
183
|
templatePath = path_1.default.join(projectPath, '/src/index.ejs');
|
|
183
184
|
return [2, {
|
|
184
185
|
projectPath: projectPath,
|
|
@@ -220,7 +221,7 @@ var getFormatRouter = function (routes, templateType) {
|
|
|
220
221
|
});
|
|
221
222
|
};
|
|
222
223
|
var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
223
|
-
var targetPath, targetTypesPath, replaceFileText, fileTypesText
|
|
224
|
+
var targetPath, targetTypesPath, replaceFileText, fileTypesText;
|
|
224
225
|
return __generator(this, function (_a) {
|
|
225
226
|
switch (_a.label) {
|
|
226
227
|
case 0:
|
|
@@ -228,12 +229,6 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
228
229
|
targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
229
230
|
replaceFileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8');
|
|
230
231
|
fileTypesText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8');
|
|
231
|
-
if (templateType === 'react') {
|
|
232
|
-
formatHooksPath = path_1.default
|
|
233
|
-
.resolve(projectPath, './src/.swico/hooks')
|
|
234
|
-
.replaceAll('\\', '/');
|
|
235
|
-
replaceFileText = replaceFileText.replaceAll('require("./template/react/hooks");', "require(\"".concat(formatHooksPath, "\");"));
|
|
236
|
-
}
|
|
237
232
|
return [4, (0, tools_1.writeFile)(targetPath, replaceFileText)];
|
|
238
233
|
case 1:
|
|
239
234
|
_a.sent();
|
|
@@ -246,7 +241,7 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
|
|
|
246
241
|
}); };
|
|
247
242
|
var formatRouterConfig = function (_a, templateType, env) {
|
|
248
243
|
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;
|
|
249
|
-
var
|
|
244
|
+
var envPath = env === 'dev' ? '/' : '/.prod/';
|
|
250
245
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
251
246
|
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
252
247
|
return __generator(this, function (_a) {
|
|
@@ -255,10 +250,10 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
255
250
|
formatRouter = getFormatRouter(routes, templateType);
|
|
256
251
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
257
252
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
258
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico
|
|
253
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "routes.js")), modifiedText)];
|
|
259
254
|
case 1:
|
|
260
255
|
_a.sent();
|
|
261
|
-
configFilePath = path_1.default.resolve(projectPath, "./src/.swico
|
|
256
|
+
configFilePath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "config.js"));
|
|
262
257
|
replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
|
|
263
258
|
if (base) {
|
|
264
259
|
replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
|
|
@@ -279,123 +274,76 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
279
274
|
});
|
|
280
275
|
}); });
|
|
281
276
|
};
|
|
282
|
-
var getCopyFileNameList = function (templateType, env) {
|
|
283
|
-
var list = ['hooks.js', 'index.js', 'history.js', 'loading.js'];
|
|
284
|
-
switch (true) {
|
|
285
|
-
case templateType === 'vue' && env === 'dev':
|
|
286
|
-
list.push('config.js', 'Container.vue', 'routes.js');
|
|
287
|
-
break;
|
|
288
|
-
case templateType === 'vue' && env === 'prod':
|
|
289
|
-
list.push('config.prod.js', 'Container.vue', 'routes.prod.js');
|
|
290
|
-
break;
|
|
291
|
-
case templateType === 'react' && env === 'dev':
|
|
292
|
-
list.push('config.js', 'history.js', 'routes.js');
|
|
293
|
-
break;
|
|
294
|
-
case templateType === 'react' && env === 'prod':
|
|
295
|
-
list.push('config.prod.js', 'history.js', 'routes.prod.js');
|
|
296
|
-
break;
|
|
297
|
-
default:
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
return list;
|
|
301
|
-
};
|
|
302
277
|
var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
278
|
+
var envPath = env === 'dev' ? '/' : '/.prod/';
|
|
303
279
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
304
|
-
var copyTargetPath,
|
|
280
|
+
var copyTargetPath, replaceIndexText, envAncPath, e_1, e_2, e_3;
|
|
305
281
|
return __generator(this, function (_a) {
|
|
306
282
|
switch (_a.label) {
|
|
307
283
|
case 0:
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
284
|
+
copyTargetPath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath));
|
|
285
|
+
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
|
|
286
|
+
return !fileName.endsWith('.d.ts') &&
|
|
287
|
+
(templateType === 'vue' ? fileName !== 'Container.js' : true);
|
|
288
|
+
})];
|
|
312
289
|
case 1:
|
|
313
290
|
_a.sent();
|
|
314
291
|
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
315
292
|
case 2:
|
|
316
293
|
_a.sent();
|
|
317
|
-
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath,
|
|
318
|
-
|
|
319
|
-
replaceIndexText = replaceIndexText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
320
|
-
replaceIndexText = replaceIndexText.replaceAll('require("./routes")', 'require("./routes.prod")');
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
replaceIndexText = replaceIndexText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
324
|
-
replaceIndexText = replaceIndexText.replaceAll('require("./routes.prod")', 'require("./routes")');
|
|
325
|
-
}
|
|
294
|
+
replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8');
|
|
295
|
+
envAncPath = env === 'dev' ? '..' : '../..';
|
|
326
296
|
_a.label = 3;
|
|
327
297
|
case 3:
|
|
328
298
|
_a.trys.push([3, 5, , 6]);
|
|
329
299
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
|
|
330
300
|
case 4:
|
|
331
301
|
_a.sent();
|
|
332
|
-
replaceIndexText = replaceIndexText.replaceAll(
|
|
333
|
-
replaceIndexText =
|
|
302
|
+
replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global\");"), '');
|
|
303
|
+
replaceIndexText = "require(\"".concat(envAncPath, "/global\");\n") + replaceIndexText;
|
|
334
304
|
return [3, 6];
|
|
335
305
|
case 5:
|
|
336
306
|
e_1 = _a.sent();
|
|
337
|
-
replaceIndexText = replaceIndexText.replaceAll(
|
|
307
|
+
replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global\");"), '');
|
|
338
308
|
return [3, 6];
|
|
339
309
|
case 6:
|
|
340
310
|
_a.trys.push([6, 8, , 9]);
|
|
341
311
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
|
|
342
312
|
case 7:
|
|
343
313
|
_a.sent();
|
|
344
|
-
replaceIndexText = replaceIndexText.replaceAll(
|
|
345
|
-
replaceIndexText =
|
|
314
|
+
replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global.less\");"), '');
|
|
315
|
+
replaceIndexText = "require(\"".concat(envAncPath, "/global.less\");\n") + replaceIndexText;
|
|
346
316
|
return [3, 9];
|
|
347
317
|
case 8:
|
|
348
318
|
e_2 = _a.sent();
|
|
349
|
-
replaceIndexText = replaceIndexText.replaceAll(
|
|
319
|
+
replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global.less\");"), '');
|
|
350
320
|
return [3, 9];
|
|
351
321
|
case 9:
|
|
352
|
-
if (!(templateType === 'vue')) return [3,
|
|
322
|
+
if (!(templateType === 'vue')) return [3, 11];
|
|
353
323
|
replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
|
|
354
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath,
|
|
324
|
+
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
355
325
|
case 10:
|
|
356
326
|
_a.sent();
|
|
357
|
-
|
|
358
|
-
if (env === 'prod') {
|
|
359
|
-
replaceHooksText = replaceHooksText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
replaceHooksText = replaceIndexText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
363
|
-
}
|
|
364
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), replaceHooksText)];
|
|
327
|
+
return [3, 17];
|
|
365
328
|
case 11:
|
|
366
|
-
|
|
367
|
-
|
|
329
|
+
if (!(templateType === 'react')) return [3, 17];
|
|
330
|
+
_a.label = 12;
|
|
368
331
|
case 12:
|
|
369
|
-
|
|
370
|
-
_a.label = 13;
|
|
371
|
-
case 13:
|
|
372
|
-
_a.trys.push([13, 15, 16, 19]);
|
|
332
|
+
_a.trys.push([12, 14, 15, 17]);
|
|
373
333
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
374
|
-
case
|
|
334
|
+
case 13:
|
|
375
335
|
_a.sent();
|
|
376
336
|
replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
|
|
377
|
-
return [3,
|
|
378
|
-
case
|
|
337
|
+
return [3, 17];
|
|
338
|
+
case 14:
|
|
379
339
|
e_3 = _a.sent();
|
|
380
340
|
replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
|
|
381
|
-
return [3,
|
|
382
|
-
case
|
|
383
|
-
case
|
|
384
|
-
_a.sent();
|
|
385
|
-
replaceHistoryText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/history.js'), 'utf8');
|
|
386
|
-
if (env === 'prod') {
|
|
387
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./config")', 'require("./config.prod")');
|
|
388
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./routes")', 'require("./routes.prod")');
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./config.prod")', 'require("./config")');
|
|
392
|
-
replaceHistoryText = replaceHistoryText.replaceAll('require("./routes.prod")', 'require("./routes")');
|
|
393
|
-
}
|
|
394
|
-
return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
|
|
395
|
-
case 18:
|
|
341
|
+
return [3, 17];
|
|
342
|
+
case 15: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
343
|
+
case 16:
|
|
396
344
|
_a.sent();
|
|
397
345
|
return [7];
|
|
398
|
-
case
|
|
346
|
+
case 17:
|
|
399
347
|
resolve(null);
|
|
400
348
|
return [2];
|
|
401
349
|
}
|
package/src/utils/tools.js
CHANGED
|
@@ -172,7 +172,6 @@ var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, funct
|
|
|
172
172
|
switch (_a.label) {
|
|
173
173
|
case 0:
|
|
174
174
|
fileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, '../index.js'), 'utf8');
|
|
175
|
-
console.log('fileText', fileText);
|
|
176
175
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
177
176
|
formatHooksPath = path_1.default
|
|
178
177
|
.resolve(process.cwd(), './src/.swico/hooks')
|