swico 0.6.0-beta1 → 0.6.0-beta11

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-beta1",
3
+ "version": "0.6.0-beta11",
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,8 @@ 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
+ spinner.start('Initializing Swico production config...');
58
59
  return [4, (0, config_1.getProjectConfig)('prod')];
59
60
  case 1:
60
61
  projectConfig = _a.sent();
@@ -68,8 +69,8 @@ function default_1() {
68
69
  })];
69
70
  case 2:
70
71
  buildConfig = _a.sent();
72
+ spinner.succeed();
71
73
  compiler = (0, webpack_1.default)(buildConfig);
72
- console.log("".concat(chalk_1.default.hex('#5f72f5')('Swico starts building....'), " \n"));
73
74
  compiler.run(function (err, stats) {
74
75
  if (err) {
75
76
  tools_1.toast.error(err.stack || err.toString());
@@ -131,6 +131,8 @@ 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...');
134
136
  if (!(envPort !== null && envPort !== void 0)) return [3, 1];
135
137
  _a = envPort;
136
138
  return [3, 3];
@@ -140,8 +142,6 @@ function start() {
140
142
  _b.label = 3;
141
143
  case 3:
142
144
  availablePort = _a;
143
- tools_1.toast.info("Swico V".concat(package_json_1.default.version));
144
- spinner.info('initializing Swico config...\n');
145
145
  return [4, (0, config_1.getProjectConfig)('dev')];
146
146
  case 4:
147
147
  projectConfig = _b.sent();
@@ -149,6 +149,7 @@ function start() {
149
149
  return [4, (0, webpack_dev_1.default)(projectConfig)];
150
150
  case 5:
151
151
  startConfig = _b.sent();
152
+ spinner.succeed();
152
153
  compiler = (0, webpack_1.default)(startConfig);
153
154
  devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
154
155
  _b.label = 6;
@@ -11,6 +11,8 @@ var config_1 = require("./config");
11
11
  var hooks_1 = require("./hooks");
12
12
  var react_router_dom_1 = require("react-router-dom");
13
13
  Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
14
+ var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
15
+ var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
14
16
  var interpolatePath = function (pathTemplate, params) {
15
17
  var pathParts = pathTemplate.split('/');
16
18
  var interpolatedParts = pathParts.map(function (part) {
@@ -29,13 +31,14 @@ var interpolatePath = function (pathTemplate, params) {
29
31
  return interpolatedParts.join('/');
30
32
  };
31
33
  var interpolatePathParams = function (pathTemplate, path) {
34
+ var _a;
32
35
  if (pathTemplate === void 0) { pathTemplate = ''; }
33
36
  var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
34
37
  var regex = new RegExp("^".concat(regexPattern, "$"));
35
38
  var match = path.match(regex);
36
39
  if (match) {
37
40
  var params_1 = match.slice(1);
38
- var paramNames = pathTemplate.match(/:(\w+)/g).map(function (name) { return name.slice(1); });
41
+ var paramNames = ((_a = pathTemplate.match(/:(\w+)/g)) === null || _a === void 0 ? void 0 : _a.map(function (name) { return name.slice(1); })) || [];
39
42
  var result_1 = {};
40
43
  paramNames.forEach(function (name, index) {
41
44
  result_1[name] = params_1[index];
@@ -66,7 +69,7 @@ var getPathNameList = function (routes) {
66
69
  exports.pathNameList = getPathNameList(routes_1.default);
67
70
  var getLocation = function (originalHistory) {
68
71
  var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
69
- var routerBaseLength = config_1.routerBase.length;
72
+ var routerBaseLength = formatRouterBase.length;
70
73
  var path = pathname.slice(routerBaseLength);
71
74
  var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, hooks_1.compareURLPatterns)(path, item.path); });
72
75
  console.log('matchPathNameItem', matchPathNameItem);
@@ -107,8 +110,6 @@ var getHistory = function (routerBase, routerType) {
107
110
  var _a;
108
111
  var history;
109
112
  var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
110
- var lastIndexBase = routerBase[routerBase.length - 1];
111
- var formatRouterBase = lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
112
113
  history = {
113
114
  go: originalHistory.go,
114
115
  forward: originalHistory.forward,
@@ -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?: GlobalData['env']) => Promise<GlobalData>;
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'>;
@@ -172,7 +172,7 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
172
172
  case 4:
173
173
  templateType = customConfig['base'].template;
174
174
  routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
175
- return [4, initTemplateConfig(routerConfig, templateType)];
175
+ return [4, initTemplateConfig(routerConfig, templateType, env)];
176
176
  case 5:
177
177
  _e.sent();
178
178
  return [4, initCliIndexFile(templateType)];
@@ -246,20 +246,25 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
246
246
  }
247
247
  });
248
248
  }); };
249
- var formatRouterConfig = function (_a, templateType) {
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/config.prod.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/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) {
@@ -280,9 +285,9 @@ var formatRouterConfig = function (_a, templateType) {
280
285
  });
281
286
  }); });
282
287
  };
283
- var initTemplateConfig = function (routerConfig, templateType) {
288
+ var initTemplateConfig = function (routerConfig, templateType, env) {
284
289
  return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
285
- var copyTargetPath, replaceIndexText, e_1, e_2, e_3;
290
+ var copyTargetPath, replaceIndexText, replaceHistoryText, e_1, e_2, e_3;
286
291
  return __generator(this, function (_a) {
287
292
  switch (_a.label) {
288
293
  case 0:
@@ -298,10 +303,19 @@ var initTemplateConfig = function (routerConfig, templateType) {
298
303
  })];
299
304
  case 3:
300
305
  _a.sent();
301
- return [4, formatRouterConfig(routerConfig, templateType)];
306
+ return [4, formatRouterConfig(routerConfig, templateType, env)];
302
307
  case 4:
303
308
  _a.sent();
304
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
+ }
305
319
  _a.label = 5;
306
320
  case 5:
307
321
  _a.trys.push([5, 7, , 8]);
@@ -328,31 +342,37 @@ var initTemplateConfig = function (routerConfig, templateType) {
328
342
  replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
329
343
  return [3, 11];
330
344
  case 11:
331
- if (!(templateType === 'vue')) return [3, 13];
345
+ if (!(templateType === 'vue')) return [3, 14];
332
346
  replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
333
347
  return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
334
348
  case 12:
335
349
  _a.sent();
336
- _a.label = 13;
350
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/history.js'), replaceHistoryText)];
337
351
  case 13:
338
- if (!(templateType === 'react')) return [3, 19];
352
+ _a.sent();
339
353
  _a.label = 14;
340
354
  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)];
355
+ if (!(templateType === 'react')) return [3, 21];
356
+ _a.label = 15;
343
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:
344
361
  _a.sent();
345
362
  replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
346
- return [3, 19];
347
- case 16:
363
+ return [3, 21];
364
+ case 17:
348
365
  e_3 = _a.sent();
349
366
  replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
350
- return [3, 19];
351
- case 17: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
352
- case 18:
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:
353
373
  _a.sent();
354
374
  return [7];
355
- case 19:
375
+ case 21:
356
376
  resolve(null);
357
377
  return [2];
358
378
  }
@@ -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')(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"));