swico 0.6.0-beta7 → 0.6.0-beta9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "0.6.0-beta7",
3
+ "version": "0.6.0-beta9",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -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 V".concat(package_json_1.default.version));
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:
@@ -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 V".concat(package_json_1.default.version));
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;
@@ -178,7 +178,7 @@ 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
- entryPath = path_1.default.resolve(projectPath, "./src/.swico/".concat(env === 'dev' ? '' : '.prod/', "index.js"));
181
+ entryPath = path_1.default.resolve(projectPath, './src/.swico/index.js');
182
182
  templatePath = path_1.default.join(projectPath, '/src/index.ejs');
183
183
  return [2, {
184
184
  projectPath: projectPath,
@@ -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(env === 'dev' ? '' : '/.prod', "/routes.js")), modifiedText)];
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, './src/.swico/config.js');
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, srcPath, 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, "./src/.swico".concat(swicoPath));
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,59 +306,73 @@ 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, "./src/.swico".concat(swicoPath, "/index.js")), 'utf8');
306
- srcPath = env === 'dev' ? '..' : '../..';
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
+ }
307
319
  _a.label = 5;
308
320
  case 5:
309
321
  _a.trys.push([5, 7, , 8]);
310
322
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
311
323
  case 6:
312
324
  _a.sent();
313
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global\");"), '');
314
- replaceIndexText = "require(\"".concat(srcPath, "/global\");\n").concat(replaceIndexText);
325
+ replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
326
+ replaceIndexText = 'require("../global");\n' + replaceIndexText;
315
327
  return [3, 8];
316
328
  case 7:
317
329
  e_1 = _a.sent();
318
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global\");"), '');
330
+ replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
319
331
  return [3, 8];
320
332
  case 8:
321
333
  _a.trys.push([8, 10, , 11]);
322
334
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
323
335
  case 9:
324
336
  _a.sent();
325
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global.less\");"), '');
326
- replaceIndexText = "require(\"".concat(srcPath, "/global.less\");\n").concat(replaceIndexText);
337
+ replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
338
+ replaceIndexText = 'require("../global.less");\n' + replaceIndexText;
327
339
  return [3, 11];
328
340
  case 10:
329
341
  e_2 = _a.sent();
330
- replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global.less\");"), '');
342
+ replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
331
343
  return [3, 11];
332
344
  case 11:
333
- if (!(templateType === 'vue')) return [3, 13];
345
+ if (!(templateType === 'vue')) return [3, 14];
334
346
  replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
335
- return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(swicoPath, "/index.js")), replaceIndexText)];
347
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
336
348
  case 12:
337
349
  _a.sent();
338
- _a.label = 13;
350
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
339
351
  case 13:
340
- if (!(templateType === 'react')) return [3, 19];
352
+ _a.sent();
341
353
  _a.label = 14;
342
354
  case 14:
343
- _a.trys.push([14, 16, 17, 19]);
344
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
355
+ if (!(templateType === 'react')) return [3, 21];
356
+ _a.label = 15;
345
357
  case 15:
346
- _a.sent();
347
- replaceIndexText = replaceIndexText.replace('"./loading"', "\"".concat(srcPath, "/loading\""));
348
- return [3, 19];
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)];
349
360
  case 16:
361
+ _a.sent();
362
+ replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
363
+ return [3, 21];
364
+ case 17:
350
365
  e_3 = _a.sent();
351
- replaceIndexText = replaceIndexText.replace('"../loading"', "\"".concat(srcPath, "/loading\""));
352
- return [3, 19];
353
- case 17: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(swicoPath, "/index.js")), replaceIndexText)];
354
- case 18:
366
+ replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
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:
355
373
  _a.sent();
356
374
  return [7];
357
- case 19:
375
+ case 21:
358
376
  resolve(null);
359
377
  return [2];
360
378
  }
@@ -102,7 +102,7 @@ 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')(message), "\n"));
106
106
  },
107
107
  error: function (message) {
108
108
  console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));