swico 0.6.0-beta5 → 0.6.0-beta7

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-beta5",
3
+ "version": "0.6.0-beta7",
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,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.start('Initializing Swico development config...');
145
145
  return [4, (0, config_1.getProjectConfig)('dev')];
146
146
  case 4:
147
147
  projectConfig = _b.sent();
@@ -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,13 +172,13 @@ 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)];
179
179
  case 6:
180
180
  _e.sent();
181
- entryPath = path_1.default.resolve(projectPath, './src/.swico/index.js');
181
+ entryPath = path_1.default.resolve(projectPath, "./src/.swico/".concat(env === 'dev' ? '' : '.prod/', "index.js"));
182
182
  templatePath = path_1.default.join(projectPath, '/src/index.ejs');
183
183
  return [2, {
184
184
  projectPath: projectPath,
@@ -246,7 +246,7 @@ 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
251
  return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
252
252
  var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
@@ -256,7 +256,7 @@ var formatRouterConfig = function (_a, templateType) {
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, './src/.swico/routes.js'), modifiedText)];
259
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(env === 'dev' ? '' : '/.prod', "/routes.js")), modifiedText)];
260
260
  case 1:
261
261
  _a.sent();
262
262
  configFilePath = path_1.default.resolve(projectPath, './src/.swico/config.js');
@@ -280,13 +280,14 @@ var formatRouterConfig = function (_a, templateType) {
280
280
  });
281
281
  }); });
282
282
  };
283
- var initTemplateConfig = function (routerConfig, templateType) {
283
+ var initTemplateConfig = function (routerConfig, templateType, env) {
284
+ var swicoPath = env === 'dev' ? '' : '/.prod';
284
285
  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;
286
+ var copyTargetPath, replaceIndexText, srcPath, e_1, e_2, e_3;
286
287
  return __generator(this, function (_a) {
287
288
  switch (_a.label) {
288
289
  case 0:
289
- copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
290
+ copyTargetPath = path_1.default.resolve(projectPath, "./src/.swico".concat(swicoPath));
290
291
  if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 2];
291
292
  return [4, fs_extra_1.default.remove(copyTargetPath)];
292
293
  case 1:
@@ -298,39 +299,40 @@ var initTemplateConfig = function (routerConfig, templateType) {
298
299
  })];
299
300
  case 3:
300
301
  _a.sent();
301
- return [4, formatRouterConfig(routerConfig, templateType)];
302
+ return [4, formatRouterConfig(routerConfig, templateType, env)];
302
303
  case 4:
303
304
  _a.sent();
304
- replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
305
+ replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, "./src/.swico".concat(swicoPath, "/index.js")), 'utf8');
306
+ srcPath = env === 'dev' ? '..' : '../..';
305
307
  _a.label = 5;
306
308
  case 5:
307
309
  _a.trys.push([5, 7, , 8]);
308
310
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
309
311
  case 6:
310
312
  _a.sent();
311
- replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
312
- replaceIndexText = 'require("../global");\n' + replaceIndexText;
313
+ replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global\");"), '');
314
+ replaceIndexText = "require(\"".concat(srcPath, "/global\");\n").concat(replaceIndexText);
313
315
  return [3, 8];
314
316
  case 7:
315
317
  e_1 = _a.sent();
316
- replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
318
+ replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global\");"), '');
317
319
  return [3, 8];
318
320
  case 8:
319
321
  _a.trys.push([8, 10, , 11]);
320
322
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
321
323
  case 9:
322
324
  _a.sent();
323
- replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
324
- replaceIndexText = 'require("../global.less");\n' + replaceIndexText;
325
+ replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global.less\");"), '');
326
+ replaceIndexText = "require(\"".concat(srcPath, "/global.less\");\n").concat(replaceIndexText);
325
327
  return [3, 11];
326
328
  case 10:
327
329
  e_2 = _a.sent();
328
- replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
330
+ replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(srcPath, "/global.less\");"), '');
329
331
  return [3, 11];
330
332
  case 11:
331
333
  if (!(templateType === 'vue')) return [3, 13];
332
334
  replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
333
- return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
335
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(swicoPath, "/index.js")), replaceIndexText)];
334
336
  case 12:
335
337
  _a.sent();
336
338
  _a.label = 13;
@@ -342,13 +344,13 @@ var initTemplateConfig = function (routerConfig, templateType) {
342
344
  return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
343
345
  case 15:
344
346
  _a.sent();
345
- replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
347
+ replaceIndexText = replaceIndexText.replace('"./loading"', "\"".concat(srcPath, "/loading\""));
346
348
  return [3, 19];
347
349
  case 16:
348
350
  e_3 = _a.sent();
349
- replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
351
+ replaceIndexText = replaceIndexText.replace('"../loading"', "\"".concat(srcPath, "/loading\""));
350
352
  return [3, 19];
351
- case 17: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
353
+ case 17: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(swicoPath, "/index.js")), replaceIndexText)];
352
354
  case 18:
353
355
  _a.sent();
354
356
  return [7];
@@ -105,7 +105,7 @@ exports.toast = {
105
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"));