swico 0.6.0-beta21 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "0.6.0-beta21",
3
+ "version": "0.6.0-beta22",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -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
- entryPath = path_1.default.resolve(projectPath, './src/.swico/index.js');
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, formatHooksPath;
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 envPathSuffix = env === 'dev' ? '' : 'prod.';
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/routes.".concat(envPathSuffix, "js")), modifiedText)];
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/config.".concat(envPathSuffix, "js"));
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, copyFileNameList, replaceIndexText, e_1, e_2, replaceHooksText, e_3, replaceHistoryText;
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
- console.log('0');
309
- copyTargetPath = path_1.default.resolve(projectPath, './src/.swico');
310
- copyFileNameList = getCopyFileNameList(templateType, env);
311
- return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) { return copyFileNameList.includes(fileName); })];
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, './src/.swico/index.js'), 'utf8');
318
- if (env === 'prod') {
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('require("../global");', '');
333
- replaceIndexText = 'require("../global");\n' + 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('require("../global");', '');
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('require("../global.less");', '');
345
- replaceIndexText = 'require("../global.less");\n' + 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('require("../global.less");', '');
319
+ replaceIndexText = replaceIndexText.replaceAll("require(\"".concat(envAncPath, "/global.less\");"), '');
350
320
  return [3, 9];
351
321
  case 9:
352
- if (!(templateType === 'vue')) return [3, 12];
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, './src/.swico/index.js'), replaceIndexText)];
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
- replaceHooksText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), 'utf8');
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
- _a.sent();
367
- return [3, 19];
329
+ if (!(templateType === 'react')) return [3, 17];
330
+ _a.label = 12;
368
331
  case 12:
369
- if (!(templateType === 'react')) return [3, 19];
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 14:
334
+ case 13:
375
335
  _a.sent();
376
336
  replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
377
- return [3, 19];
378
- case 15:
337
+ return [3, 17];
338
+ case 14:
379
339
  e_3 = _a.sent();
380
340
  replaceIndexText = replaceIndexText.replace('"../loading"', '"./loading"');
381
- return [3, 19];
382
- case 16: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
383
- case 17:
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 19:
346
+ case 17:
399
347
  resolve(null);
400
348
  return [2];
401
349
  }
@@ -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')