swico 1.2.1-beta.2 → 1.3.0-beta-9

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": "1.2.1-beta.2",
3
+ "version": "1.3.0-beta-9",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -61,13 +61,16 @@ var path_1 = __importDefault(require("path"));
61
61
  var _a = process.env, SWICO_PORT = _a.SWICO_PORT, SWICO_RESTART = _a.SWICO_RESTART, SWICO_ROUTER_BASE = _a.SWICO_ROUTER_BASE;
62
62
  var package_json_1 = __importDefault(require("../../package.json"));
63
63
  var chalk_1 = __importDefault(require("chalk"));
64
+ var fs_extra_1 = __importDefault(require("fs-extra"));
64
65
  var currentPort, currentRouterBase = '/';
65
- var handleWatch = function (projectPath, devServer) {
66
+ var handleWatch = function (projectPath, devServer, env) {
67
+ var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
66
68
  var configFilesWatcher = chokidar_1.default
67
69
  .watch([path_1.default.join(projectPath, '/config/*.ts'), path_1.default.join(projectPath, '/.eslintrc')], {
68
70
  interval: 500,
69
71
  binaryInterval: 500,
70
- ignoreInitial: true
72
+ ignoreInitial: true,
73
+ ignored: [path_1.default.join(projectPath, '/config/swico.prod.ts')]
71
74
  })
72
75
  .on('all', function (path, stats) { return __awaiter(void 0, void 0, void 0, function () {
73
76
  return __generator(this, function (_a) {
@@ -87,33 +90,60 @@ var handleWatch = function (projectPath, devServer) {
87
90
  }
88
91
  });
89
92
  }); });
90
- var watchFiles = [
91
- path_1.default.join(projectPath, '/src/loading/index.tsx'),
93
+ var globalStyleFilesPathList = [
92
94
  path_1.default.join(projectPath, '/src/global.css'),
93
95
  path_1.default.join(projectPath, '/src/global.less'),
94
96
  path_1.default.join(projectPath, '/src/global.scss')
95
97
  ];
98
+ var loadingFilePath = path_1.default.join(projectPath, '/src/loading/index.tsx');
96
99
  var tsTypingsWatcher = chokidar_1.default
97
100
  .watch([path_1.default.join(projectPath, '/src/**/*')], {
98
101
  interval: 500,
99
102
  binaryInterval: 500,
100
103
  ignoreInitial: true
101
104
  })
102
- .on('all', function (eventName, path, stats) { return __awaiter(void 0, void 0, void 0, function () {
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
+ .on('all', function (eventName, filePath, stats) { return __awaiter(void 0, void 0, void 0, function () {
106
+ var replaceIndexText, _a;
107
+ return __generator(this, function (_b) {
108
+ switch (_b.label) {
105
109
  case 0:
106
- if (!((watchFiles.includes(path) || path.endsWith('.d.ts')) &&
107
- ['add'].includes(eventName))) return [3, 3];
108
- return [4, devServer.stop()];
110
+ console.log('eventName', eventName, filePath);
111
+ return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8')];
109
112
  case 1:
110
- _a.sent();
111
- return [4, tsTypingsWatcher.close()];
113
+ replaceIndexText = _b.sent();
114
+ if (!['add', 'unlink'].includes(eventName)) return [3, 9];
115
+ _a = true;
116
+ switch (_a) {
117
+ case filePath.endsWith('.d.ts'): return [3, 2];
118
+ case globalStyleFilesPathList.includes(filePath): return [3, 5];
119
+ case filePath === loadingFilePath: return [3, 7];
120
+ }
121
+ return [3, 9];
112
122
  case 2:
113
- _a.sent();
123
+ console.log('1');
124
+ return [4, devServer.stop()];
125
+ case 3:
126
+ _b.sent();
127
+ return [4, tsTypingsWatcher.close()];
128
+ case 4:
129
+ _b.sent();
114
130
  restartServer();
115
- _a.label = 3;
116
- case 3: return [2];
131
+ return [3, 9];
132
+ case 5:
133
+ console.log('2');
134
+ replaceIndexText = (0, config_1.handleGlobalStyleFile)(replaceIndexText);
135
+ return [4, (0, config_1.updateIndexFileText)(envPath, replaceIndexText)];
136
+ case 6:
137
+ _b.sent();
138
+ return [3, 9];
139
+ case 7:
140
+ console.log('3');
141
+ replaceIndexText = (0, config_1.handleLoadingFile)(replaceIndexText, envPath);
142
+ return [4, (0, config_1.updateIndexFileText)(envPath, replaceIndexText)];
143
+ case 8:
144
+ _b.sent();
145
+ _b.label = 9;
146
+ case 9: return [2];
117
147
  }
118
148
  });
119
149
  }); });
@@ -140,6 +170,11 @@ var getMockGetLogger = function (compiler) {
140
170
  return __assign(__assign({}, logger), { log: log, debug: debug, error: error, warn: warn, info: function () { } });
141
171
  };
142
172
  };
173
+ var filterStyleFileList = [
174
+ "Can't resolve '../../global.less'",
175
+ "Can't resolve '../../global.css'",
176
+ "Can't resolve '../../global.scss'"
177
+ ];
143
178
  var createCompileListener = function (compiler) {
144
179
  compiler.hooks.beforeCompile.tap('beforeCompile', function () {
145
180
  tools_1.toast.info('Compiling...');
@@ -147,7 +182,7 @@ var createCompileListener = function (compiler) {
147
182
  compiler.hooks.done.tap('done', function (stats) {
148
183
  var info = stats === null || stats === void 0 ? void 0 : stats.toJson();
149
184
  if (stats === null || stats === void 0 ? void 0 : stats.hasErrors()) {
150
- tools_1.toast.error(info === null || info === void 0 ? void 0 : info.errors.map(function (item) { return item.message || item.stack; }));
185
+ tools_1.toast.error(info === null || info === void 0 ? void 0 : info.errors.map(function (item) { return item.message || item.stack; }).filter(function (item1) { return !filterStyleFileList.find(function (item2) { return item1.includes(item2); }); }));
151
186
  return;
152
187
  }
153
188
  if (stats === null || stats === void 0 ? void 0 : stats.hasWarnings()) {
@@ -161,13 +196,13 @@ var createCompileListener = function (compiler) {
161
196
  });
162
197
  return;
163
198
  }
164
- tools_1.toast.info("Compiled complete in ".concat(info === null || info === void 0 ? void 0 : info.time, "ms"));
199
+ tools_1.toast.info("Compiled successfully in ".concat(info === null || info === void 0 ? void 0 : info.time, "ms"));
165
200
  });
166
201
  };
167
202
  function start() {
168
203
  var _a, _b, _c, _d, _e, _f;
169
204
  return __awaiter(this, void 0, void 0, function () {
170
- var availablePort, _g, projectConfig, projectPath, customConfig, newRouterBase, startConfig, compiler, oriLogger, devServer, e_1, strErr;
205
+ var availablePort, _g, projectConfig, projectPath, customConfig, env, newRouterBase, startConfig, compiler, oriLogger, devServer, e_1, strErr;
171
206
  return __generator(this, function (_h) {
172
207
  switch (_h.label) {
173
208
  case 0:
@@ -191,7 +226,7 @@ function start() {
191
226
  return [4, (0, config_1.getProjectConfig)('dev')];
192
227
  case 5:
193
228
  projectConfig = _h.sent();
194
- projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig;
229
+ projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig, env = projectConfig.env;
195
230
  newRouterBase = (_f = (_c = (_b = (_a = customConfig['dev']) === null || _a === void 0 ? void 0 : _a.router) === null || _b === void 0 ? void 0 : _b.base) !== null && _c !== void 0 ? _c : (_e = (_d = customConfig['base']) === null || _d === void 0 ? void 0 : _d.router) === null || _e === void 0 ? void 0 : _e.base) !== null && _f !== void 0 ? _f : '/';
196
231
  return [4, (0, webpack_dev_1.default)(projectConfig)];
197
232
  case 6:
@@ -209,7 +244,7 @@ function start() {
209
244
  process.env.SWICO_PORT = availablePort.toString();
210
245
  createCompileListener(compiler);
211
246
  compiler.getInfrastructureLogger = oriLogger;
212
- handleWatch(projectPath, devServer);
247
+ handleWatch(projectPath, devServer, env);
213
248
  if (SWICO_RESTART !== 'true' ||
214
249
  (SWICO_RESTART === 'true' && newRouterBase !== SWICO_ROUTER_BASE)) {
215
250
  tools_1.toast.info("Project is running at\uFF1A".concat(chalk_1.default.hex('#29abe0')("".concat(startConfig.devServer.server, "://localhost:").concat(availablePort).concat(newRouterBase))));
@@ -5,6 +5,7 @@ export declare const formatAncPath: (ancPath: string) => string;
5
5
  export declare const pathNameList: {
6
6
  path: string;
7
7
  name: string;
8
+ custom?: any;
8
9
  }[];
9
10
  export declare const getHistory: (router: any) => {
10
11
  go: (delta: any) => void;
@@ -72,9 +72,9 @@ exports.formatAncPath = formatAncPath;
72
72
  var getPathNameList = function (routes) {
73
73
  var list = [];
74
74
  var checkRouteItem = function (item, ancPath) {
75
- var path = item.path, name = item.name, children = item.children;
75
+ var path = item.path, name = item.name, children = item.children, custom = item.custom;
76
76
  var newAncPath = "".concat((0, exports.formatAncPath)(ancPath)).concat(path.startsWith('/') ? path : '/' + path);
77
- list.push({ path: newAncPath, name: name });
77
+ list.push({ path: newAncPath, name: name, custom: custom });
78
78
  if (children) {
79
79
  children.some(function (item) { return checkRouteItem(item, newAncPath); });
80
80
  }
@@ -97,7 +97,8 @@ var getLocation = function (historyLocation) {
97
97
  query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
98
98
  name: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.name,
99
99
  params: params,
100
- path: path
100
+ path: path,
101
+ custom: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.custom
101
102
  };
102
103
  };
103
104
  var getFormatHistoryOption = function (to, pathList, type) {
@@ -8,5 +8,6 @@ export type RoutesItemType = {
8
8
  path: string;
9
9
  redirect?: string;
10
10
  name?: string;
11
+ custom?: any;
11
12
  };
12
13
  export declare const getChildrenRouteList: (childrenRoutes: RoutesItemType[], ancPathKey: string) => any;
@@ -19,20 +19,21 @@ var react_router_dom_1 = require("react-router-dom");
19
19
  var history_1 = require("./$env/history");
20
20
  var qs_1 = __importDefault(require("qs"));
21
21
  var useLocation = function () {
22
- var _a, _b;
22
+ var _a;
23
23
  var location = (0, react_router_dom_1.useLocation)();
24
24
  var params = (0, react_router_dom_1.useParams)();
25
25
  var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
26
- var name = (_a = history_1.pathNameList.find(function (item) {
26
+ var matchItem = history_1.pathNameList.find(function (item) {
27
27
  return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
28
28
  item.path === pathname;
29
- })) === null || _a === void 0 ? void 0 : _a.name;
29
+ });
30
30
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
31
31
  return {
32
- name: name,
32
+ name: matchItem === null || matchItem === void 0 ? void 0 : matchItem.name,
33
+ custom: matchItem === null || matchItem === void 0 ? void 0 : matchItem.custom,
33
34
  state: state !== null && state !== void 0 ? state : {},
34
35
  path: pathname,
35
- pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
36
+ pathname: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname,
36
37
  search: '',
37
38
  query: query,
38
39
  hash: hash,
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -8,10 +19,17 @@ var vue_router_1 = require("vue-router");
8
19
  var config_1 = require("./config");
9
20
  var routes_1 = __importDefault(require("./routes"));
10
21
  var qs_1 = __importDefault(require("qs"));
22
+ var transformRouteItemCustomToMeta = function (routeItem) {
23
+ var newRouteItem = __assign({}, routeItem);
24
+ var custom = routeItem.custom, children = routeItem.children;
25
+ newRouteItem.meta = custom;
26
+ return __assign(__assign({}, newRouteItem), { children: children === null || children === void 0 ? void 0 : children.map(function (item) { return transformRouteItemCustomToMeta(item); }) });
27
+ };
28
+ var formatRoutes = routes_1.default.map(function (routeItem) { return transformRouteItemCustomToMeta(routeItem); });
11
29
  var getRouter = function () {
12
30
  var router = (0, vue_router_1.createRouter)({
13
31
  history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
14
- routes: routes_1.default
32
+ routes: formatRoutes
15
33
  });
16
34
  exports.history = {
17
35
  push: function (options) {
@@ -39,9 +57,10 @@ var getRouter = function () {
39
57
  var _a, _b;
40
58
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
41
59
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
42
- var _c = router.currentRoute.value, path = _c.path, params = _c.params, query = _c.query, name = _c.name, hash = _c.hash, fullPath = _c.fullPath;
60
+ var _c = router.currentRoute.value, path = _c.path, params = _c.params, query = _c.query, name = _c.name, hash = _c.hash, fullPath = _c.fullPath, meta = _c.meta;
43
61
  return {
44
62
  path: path,
63
+ custom: meta,
45
64
  pathname: formatRouterBase + path,
46
65
  params: params,
47
66
  query: query,
@@ -38,7 +38,7 @@ var useLocation = function () {
38
38
  });
39
39
  (0, vue_1.watchEffect)(function () {
40
40
  var _a;
41
- var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name;
41
+ var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name, meta = route.meta;
42
42
  var search = query ? qs_1.default.stringify(query) : '';
43
43
  location.name = name;
44
44
  location.path = path;
@@ -48,6 +48,7 @@ var useLocation = function () {
48
48
  location.hash = hash;
49
49
  location.params = params;
50
50
  location.state = ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.swicoState) || {};
51
+ location.custom = meta;
51
52
  });
52
53
  return location;
53
54
  };
@@ -7,6 +7,7 @@ export type SwicoLocationType = {
7
7
  pathname: string;
8
8
  search: string;
9
9
  state?: Record<string, any>;
10
+ custom?: any;
10
11
  };
11
12
  export type SwicoHistoryOptionType = {
12
13
  query?: Record<string, any>;
@@ -15,6 +16,7 @@ export type SwicoHistoryOptionType = {
15
16
  path?: string;
16
17
  name?: string;
17
18
  state?: Record<string, any>;
19
+ custom?: any;
18
20
  };
19
21
  export type SwicoHistoryType = {
20
22
  push: (to: string | SwicoHistoryOptionType) => void;
@@ -5,6 +5,7 @@ export type ConfigRoutesItemType = {
5
5
  redirect?: string;
6
6
  name?: string;
7
7
  decorator?: string;
8
+ custom?: any;
8
9
  [key: string]: any;
9
10
  };
10
11
  export type ConfigRouterType = {
@@ -43,5 +44,8 @@ export interface GlobalData {
43
44
  };
44
45
  }
45
46
  export declare const getProjectConfig: (env: GlobalData['env']) => Promise<GlobalData>;
47
+ export declare const handleLoadingFile: (replaceIndexText: any, envPath: any) => Promise<any>;
48
+ export declare const handleGlobalStyleFile: (replaceIndexText: any) => any;
49
+ export declare const updateIndexFileText: (envPath: any, newFileText: any) => Promise<void>;
46
50
  export declare const getFormatDefineVars: (defineVarsConfigData: any) => Promise<{}>;
47
51
  export declare const initConfig: Omit<GlobalSwicoConfigType, 'template'>;
@@ -73,7 +73,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
73
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
74
  };
75
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
- exports.initConfig = exports.getFormatDefineVars = exports.getProjectConfig = void 0;
76
+ exports.initConfig = exports.getFormatDefineVars = exports.updateIndexFileText = exports.handleGlobalStyleFile = exports.handleLoadingFile = exports.getProjectConfig = void 0;
77
77
  var fs_extra_1 = __importDefault(require("fs-extra"));
78
78
  var path_1 = __importDefault(require("path"));
79
79
  var chalk_1 = __importDefault(require("chalk"));
@@ -185,6 +185,7 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
185
185
  entryPath = path_1.default.resolve(projectPath, "./src/.swico/".concat(envPath, "index.js"));
186
186
  templatePath = path_1.default.join(projectPath, '/src/index.ejs');
187
187
  return [2, {
188
+ env: env,
188
189
  projectPath: projectPath,
189
190
  entryPath: entryPath,
190
191
  templatePath: templatePath,
@@ -286,12 +287,59 @@ var getGlobalStyleFilePath = function () {
286
287
  }
287
288
  return { filePath: filePath, fileType: fileType };
288
289
  };
290
+ var handleLoadingFile = function (replaceIndexText, envPath) { return __awaiter(void 0, void 0, void 0, function () {
291
+ var newReplaceIndexText, e_1;
292
+ return __generator(this, function (_a) {
293
+ switch (_a.label) {
294
+ case 0:
295
+ newReplaceIndexText = replaceIndexText;
296
+ _a.label = 1;
297
+ case 1:
298
+ _a.trys.push([1, 3, , 4]);
299
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
300
+ case 2:
301
+ _a.sent();
302
+ newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../loading"');
303
+ return [3, 4];
304
+ case 3:
305
+ e_1 = _a.sent();
306
+ newReplaceIndexText = newReplaceIndexText.replace('"../../loading"', '"../loading"');
307
+ return [3, 4];
308
+ case 4: return [2, newReplaceIndexText];
309
+ }
310
+ });
311
+ }); };
312
+ exports.handleLoadingFile = handleLoadingFile;
313
+ var handleGlobalStyleFile = function (replaceIndexText) {
314
+ var _a = getGlobalStyleFilePath(), styleFilePath = _a.filePath, styleFileType = _a.fileType;
315
+ var newReplaceIndexText = replaceIndexText;
316
+ if (styleFilePath) {
317
+ newReplaceIndexText = newReplaceIndexText.replaceAll("require(\"../../global.".concat(styleFileType, "\");"), '');
318
+ newReplaceIndexText = "require(\"../../global.".concat(styleFileType, "\");\n").concat(replaceIndexText);
319
+ }
320
+ else {
321
+ newReplaceIndexText = newReplaceIndexText.replaceAll(/require\("\.\.\/\.\.\/global.(less|scss|css)"\);/g, '');
322
+ }
323
+ return newReplaceIndexText;
324
+ };
325
+ exports.handleGlobalStyleFile = handleGlobalStyleFile;
326
+ var updateIndexFileText = function (envPath, newFileText) { return __awaiter(void 0, void 0, void 0, function () {
327
+ return __generator(this, function (_a) {
328
+ switch (_a.label) {
329
+ case 0: return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), newFileText)];
330
+ case 1:
331
+ _a.sent();
332
+ return [2];
333
+ }
334
+ });
335
+ }); };
336
+ exports.updateIndexFileText = updateIndexFileText;
289
337
  var initTemplateConfig = function (routerConfig, templateType, env) {
290
338
  var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
291
339
  return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
292
- var copyTargetPath, replaceIndexText, hooksFilePath, replaceHooksText, _a, styleFilePath, styleFileType, e_1;
293
- return __generator(this, function (_b) {
294
- switch (_b.label) {
340
+ var copyTargetPath, replaceIndexText, hooksFilePath, replaceHooksText, newReplaceIndexText;
341
+ return __generator(this, function (_a) {
342
+ switch (_a.label) {
295
343
  case 0:
296
344
  copyTargetPath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath));
297
345
  return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/$env")), copyTargetPath, function (fileName) {
@@ -301,59 +349,43 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
301
349
  : !['react-hooks.js'].includes(fileName));
302
350
  })];
303
351
  case 1:
304
- _b.sent();
352
+ _a.sent();
305
353
  return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, './src/.swico'), function (fileName) {
306
354
  return ['react-hooks.js', 'vue-hooks.js', 'loading.js', 'Container.vue'].includes(fileName);
307
355
  })];
308
356
  case 2:
309
- _b.sent();
357
+ _a.sent();
310
358
  return [4, formatRouterConfig(routerConfig, templateType, env)];
311
359
  case 3:
312
- _b.sent();
360
+ _a.sent();
313
361
  return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8')];
314
362
  case 4:
315
- replaceIndexText = _b.sent();
363
+ replaceIndexText = _a.sent();
316
364
  hooksFilePath = path_1.default.resolve(projectPath, "./src/.swico/".concat(templateType, "-hooks.js"));
317
365
  return [4, fs_extra_1.default.readFile(hooksFilePath, 'utf8')];
318
366
  case 5:
319
- replaceHooksText = _b.sent();
367
+ replaceHooksText = _a.sent();
320
368
  replaceHooksText = replaceHooksText.replaceAll('$env', ".".concat(env));
321
369
  return [4, fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText)];
322
370
  case 6:
323
- _b.sent();
324
- _a = getGlobalStyleFilePath(), styleFilePath = _a.filePath, styleFileType = _a.fileType;
325
- if (styleFilePath) {
326
- replaceIndexText = replaceIndexText.replaceAll("require(\"../../global.".concat(styleFileType, "\");"), '');
327
- replaceIndexText = "require(\"../../global.".concat(styleFileType, "\");\n").concat(replaceIndexText);
328
- }
329
- else {
330
- replaceIndexText = replaceIndexText.replaceAll(/require\("\.\.\/\.\.\/global.(less|scss|css)"\);/g, '');
331
- }
371
+ _a.sent();
372
+ replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
332
373
  if (!(templateType === 'vue')) return [3, 8];
333
374
  replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
334
- return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
375
+ return [4, (0, exports.updateIndexFileText)(envPath, replaceIndexText)];
335
376
  case 7:
336
- _b.sent();
337
- return [3, 14];
377
+ _a.sent();
378
+ return [3, 11];
338
379
  case 8:
339
- if (!(templateType === 'react')) return [3, 14];
340
- _b.label = 9;
380
+ if (!(templateType === 'react')) return [3, 11];
381
+ return [4, (0, exports.handleLoadingFile)(replaceIndexText, envPath)];
341
382
  case 9:
342
- _b.trys.push([9, 11, 12, 14]);
343
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
383
+ newReplaceIndexText = _a.sent();
384
+ return [4, (0, exports.updateIndexFileText)(envPath, newReplaceIndexText)];
344
385
  case 10:
345
- _b.sent();
346
- replaceIndexText = replaceIndexText.replace('"../loading"', '"../../loading"');
347
- return [3, 14];
386
+ _a.sent();
387
+ _a.label = 11;
348
388
  case 11:
349
- e_1 = _b.sent();
350
- replaceIndexText = replaceIndexText.replace('"../../loading"', '"../loading"');
351
- return [3, 14];
352
- case 12: return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
353
- case 13:
354
- _b.sent();
355
- return [7];
356
- case 14:
357
389
  resolve(null);
358
390
  return [2];
359
391
  }
@@ -170,7 +170,7 @@ var copyDirFiles = function (src, dest, filter) { return __awaiter(void 0, void
170
170
  exports.copyDirFiles = copyDirFiles;
171
171
  var getFormatRouter = function (projectPath, routes, templateType) {
172
172
  var _main = function (item) {
173
- var path = item.path, component = item.component, name = item.name, children = item.children, redirect = item.redirect, decorator = item.decorator;
173
+ var component = item.component, name = item.name, children = item.children, redirect = item.redirect, decorator = item.decorator;
174
174
  return decorator
175
175
  ? __assign(__assign({}, item), { component: "()=>import('".concat(projectPath, "/src/pages/").concat(decorator).concat(templateType === 'vue' ? '.vue' : '', "')"), children: [
176
176
  {
@@ -182,15 +182,9 @@ var getFormatRouter = function (projectPath, routes, templateType) {
182
182
  redirect: redirect,
183
183
  children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined
184
184
  }
185
- ] }) : {
186
- path: path,
187
- component: component
185
+ ] }) : __assign(__assign({}, item), { component: component
188
186
  ? "()=>import('".concat(projectPath, "/src/pages/").concat(component).concat(templateType === 'vue' ? '.vue' : '', "')")
189
- : undefined,
190
- name: name,
191
- redirect: redirect,
192
- children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined
193
- };
187
+ : undefined, name: name, redirect: redirect, children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined });
194
188
  };
195
189
  return routes.map(function (item) {
196
190
  return _main(item);