swico 0.6.0-beta3 → 0.6.0-beta30

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.
Files changed (32) hide show
  1. package/package.json +5 -3
  2. package/src/command/build.js +7 -5
  3. package/src/command/start.js +21 -19
  4. package/src/task.js +2 -2
  5. package/src/template/react/{config.d.ts → .env/config.d.ts} +1 -1
  6. package/src/template/react/{history.d.ts → .env/history.d.ts} +1 -1
  7. package/src/template/react/{history.js → .env/history.js} +19 -3
  8. package/src/template/react/{index.d.ts → .env/index.d.ts} +1 -1
  9. package/src/template/react/{index.js → .env/index.js} +3 -3
  10. package/src/template/react/hooks.d.ts +0 -1
  11. package/src/template/react/hooks.js +3 -4
  12. package/src/template/vue/{config.d.ts → .env/config.d.ts} +1 -1
  13. package/src/template/vue/hooks.js +1 -1
  14. package/src/utils/config.d.ts +1 -1
  15. package/src/utils/config.js +56 -63
  16. package/src/utils/tools.d.ts +1 -0
  17. package/src/utils/tools.js +47 -4
  18. package/src/template/hooks/react.d.ts +0 -12
  19. package/src/template/hooks/react.js +0 -47
  20. package/src/template/hooks/vue.d.ts +0 -3
  21. package/src/template/hooks/vue.js +0 -40
  22. package/src/template/vue/Container.d.ts +0 -2
  23. package/src/template/vue/Container.js +0 -4
  24. package/src/template/vue/index.d.ts +0 -1
  25. package/src/template/vue/index.js +0 -62
  26. package/src/template/vue/routes.d.ts +0 -6
  27. package/src/template/vue/routes.js +0 -3
  28. /package/src/template/react/{config.js → .env/config.js} +0 -0
  29. /package/src/template/react/{routes.d.ts → .env/routes.d.ts} +0 -0
  30. /package/src/template/react/{routes.js → .env/routes.js} +0 -0
  31. /package/src/template/vue/{Container.vue → .env/Container.vue} +0 -0
  32. /package/src/template/vue/{config.js → .env/config.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "0.6.0-beta3",
3
+ "version": "0.6.0-beta30",
4
4
  "description": "Simple, efficient, and practical front-end framework",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -15,9 +15,11 @@
15
15
  "template",
16
16
  "webpack"
17
17
  ],
18
- "bin": {},
18
+ "bin": {
19
+ "swico": "./src/bin.js"
20
+ },
19
21
  "scripts": {
20
- "compile": "tsc && ts-node ./src/task.ts", "swico": "./src/bin.js",
22
+ "compile": "tsc && ts-node ./src/task.ts",
21
23
  "publish:offical": "npm run compile && cd ./dist && npm publish",
22
24
  "publish:beta": "npm run compile && cd ./dist && npm publish --tag=beta"
23
25
  },
@@ -54,10 +54,13 @@ 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));
58
- spinner.start('Initializing Swico production config...');
59
- return [4, (0, config_1.getProjectConfig)('prod')];
57
+ tools_1.toast.info("Swico v".concat(package_json_1.default.version));
58
+ tools_1.toast.info('Initializing Swico production config...');
59
+ return [4, (0, tools_1.initIndexFile)()];
60
60
  case 1:
61
+ _a.sent();
62
+ return [4, (0, config_1.getProjectConfig)('prod')];
63
+ case 2:
61
64
  projectConfig = _a.sent();
62
65
  entryPath = projectConfig.entryPath, templatePath = projectConfig.templatePath, projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig, templateType = projectConfig.templateType;
63
66
  return [4, (0, webpack_prod_1.default)({
@@ -67,9 +70,8 @@ function default_1() {
67
70
  customConfig: customConfig,
68
71
  templateType: templateType
69
72
  })];
70
- case 2:
73
+ case 3:
71
74
  buildConfig = _a.sent();
72
- spinner.succeed();
73
75
  compiler = (0, webpack_1.default)(buildConfig);
74
76
  compiler.run(function (err, stats) {
75
77
  if (err) {
@@ -131,41 +131,43 @@ function start() {
131
131
  switch (_b.label) {
132
132
  case 0:
133
133
  process.env.SWICO_ENV = 'dev';
134
- if (!(envPort !== null && envPort !== void 0)) return [3, 1];
134
+ tools_1.toast.info("Swico v".concat(package_json_1.default.version));
135
+ tools_1.toast.info('Initializing Swico development config...\n');
136
+ return [4, (0, tools_1.initIndexFile)()];
137
+ case 1:
138
+ _b.sent();
139
+ if (!(envPort !== null && envPort !== void 0)) return [3, 2];
135
140
  _a = envPort;
136
- return [3, 3];
137
- case 1: return [4, (0, tools_1.getPort)()];
138
- case 2:
139
- _a = (_b.sent());
140
- _b.label = 3;
141
+ return [3, 4];
142
+ case 2: return [4, (0, tools_1.getPort)()];
141
143
  case 3:
144
+ _a = (_b.sent());
145
+ _b.label = 4;
146
+ case 4:
142
147
  availablePort = _a;
143
- tools_1.toast.info("Swico V".concat(package_json_1.default.version));
144
- spinner.start('Initializing Swico development config...');
145
148
  return [4, (0, config_1.getProjectConfig)('dev')];
146
- case 4:
149
+ case 5:
147
150
  projectConfig = _b.sent();
148
151
  projectPath = projectConfig.projectPath;
149
152
  return [4, (0, webpack_dev_1.default)(projectConfig)];
150
- case 5:
153
+ case 6:
151
154
  startConfig = _b.sent();
152
- spinner.succeed();
153
155
  compiler = (0, webpack_1.default)(startConfig);
154
156
  devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
155
- _b.label = 6;
156
- case 6:
157
- _b.trys.push([6, 8, , 9]);
158
- return [4, devServer.start()];
157
+ _b.label = 7;
159
158
  case 7:
159
+ _b.trys.push([7, 9, , 10]);
160
+ return [4, devServer.start()];
161
+ case 8:
160
162
  _b.sent();
161
163
  handleWatch(projectPath, devServer);
162
- return [3, 9];
163
- case 8:
164
+ return [3, 10];
165
+ case 9:
164
166
  e_1 = _b.sent();
165
167
  strErr = e_1.toString();
166
168
  tools_1.toast.error(strErr);
167
- return [3, 9];
168
- case 9: return [2];
169
+ return [3, 10];
170
+ case 10: return [2];
169
171
  }
170
172
  });
171
173
  });
package/src/task.js CHANGED
@@ -46,8 +46,8 @@ var copyVueFiles = function () { return __awaiter(void 0, void 0, void 0, functi
46
46
  return __generator(this, function (_a) {
47
47
  switch (_a.label) {
48
48
  case 0:
49
- filePath = path_1.default.resolve(__dirname, './template/vue/Container.vue');
50
- targetPath = path_1.default.resolve(__dirname, '../dist/src/template/vue/Container.vue');
49
+ filePath = path_1.default.resolve(__dirname, './template/vue/.env/Container.vue');
50
+ targetPath = path_1.default.resolve(__dirname, '../dist/src/template/vue/.env/Container.vue');
51
51
  return [4, fs_extra_1.default.copyFile(filePath, targetPath)];
52
52
  case 1:
53
53
  _a.sent();
@@ -1,3 +1,3 @@
1
- import { ConfigRouterType } from '../../utils/config';
1
+ import { ConfigRouterType } from '../../../utils/config';
2
2
  export declare const routerType: ConfigRouterType['type'];
3
3
  export declare const routerBase: ConfigRouterType['base'];
@@ -1,4 +1,4 @@
1
- import { ConfigRouterType } from '../../utils/config';
1
+ import { ConfigRouterType } from '../../../utils/config';
2
2
  export { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom';
3
3
  export declare const formatAncPath: (ancPath: string) => string;
4
4
  export declare const pathNameList: {
@@ -8,11 +8,28 @@ var qs_1 = __importDefault(require("qs"));
8
8
  var history_1 = require("history");
9
9
  var routes_1 = __importDefault(require("./routes"));
10
10
  var config_1 = require("./config");
11
- var hooks_1 = require("./hooks");
12
11
  var react_router_dom_1 = require("react-router-dom");
13
12
  Object.defineProperty(exports, "HistoryRouter", { enumerable: true, get: function () { return react_router_dom_1.unstable_HistoryRouter; } });
14
13
  var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
15
14
  var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
15
+ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
16
+ var patternWithValuesParts = urlPatternWithValues.split('/');
17
+ var patternWithParamsParts = urlPatternWithParams.split('/');
18
+ if (patternWithValuesParts.length !== patternWithParamsParts.length) {
19
+ return false;
20
+ }
21
+ for (var i = 0; i < patternWithValuesParts.length; i++) {
22
+ var valuePart = patternWithValuesParts[i];
23
+ var paramPart = patternWithParamsParts[i];
24
+ if (paramPart.startsWith(':') && paramPart !== '') {
25
+ continue;
26
+ }
27
+ if (valuePart !== paramPart) {
28
+ return false;
29
+ }
30
+ }
31
+ return true;
32
+ };
16
33
  var interpolatePath = function (pathTemplate, params) {
17
34
  var pathParts = pathTemplate.split('/');
18
35
  var interpolatedParts = pathParts.map(function (part) {
@@ -71,8 +88,7 @@ var getLocation = function (originalHistory) {
71
88
  var _a = originalHistory.location, pathname = _a.pathname, hash = _a.hash, search = _a.search;
72
89
  var routerBaseLength = formatRouterBase.length;
73
90
  var path = pathname.slice(routerBaseLength);
74
- var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, hooks_1.compareURLPatterns)(path, item.path); });
75
- console.log('matchPathNameItem', matchPathNameItem);
91
+ var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || compareURLPatterns(path, item.path); });
76
92
  var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
77
93
  return {
78
94
  hash: hash,
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import '../global';
2
+ import '../../global';
3
3
  export type RoutesItemType = {
4
4
  component?: () => Promise<{
5
5
  default: FC;
@@ -30,11 +30,11 @@ var client_1 = require("react-dom/client");
30
30
  var react_1 = __importStar(require("react"));
31
31
  var react_router_dom_1 = require("react-router-dom");
32
32
  var routes_1 = __importDefault(require("./routes"));
33
- var loading_1 = __importDefault(require("./loading"));
33
+ var loading_1 = __importDefault(require("../loading"));
34
34
  var history_1 = require("./history");
35
35
  var config_1 = require("./config");
36
- require("../global");
37
- var layout_1 = __importDefault(require("../layout"));
36
+ require("../../global");
37
+ var layout_1 = __importDefault(require("../../layout"));
38
38
  var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
39
39
  return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
40
40
  var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
@@ -1,2 +1 @@
1
- export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
2
1
  export declare const useLocation: UseLocationType;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocation = exports.compareURLPatterns = void 0;
6
+ exports.useLocation = void 0;
7
7
  var react_router_dom_1 = require("react-router-dom");
8
- var history_1 = require("./history");
8
+ var history_1 = require("./.env/history");
9
9
  var qs_1 = __importDefault(require("qs"));
10
10
  var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
11
11
  var patternWithValuesParts = urlPatternWithValues.split('/');
@@ -25,14 +25,13 @@ var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
25
25
  }
26
26
  return true;
27
27
  };
28
- exports.compareURLPatterns = compareURLPatterns;
29
28
  var useLocation = function () {
30
29
  var _a, _b;
31
30
  var location = (0, react_router_dom_1.useLocation)();
32
31
  var params = (0, react_router_dom_1.useParams)();
33
32
  var search = location.search, hash = location.hash, pathname = location.pathname;
34
33
  var name = (_a = history_1.pathNameList.find(function (item) {
35
- return (Object.keys(params).length > 0 && (0, exports.compareURLPatterns)(pathname, item.path)) ||
34
+ return (Object.keys(params).length > 0 && compareURLPatterns(pathname, item.path)) ||
36
35
  item.path === pathname;
37
36
  })) === null || _a === void 0 ? void 0 : _a.name;
38
37
  var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
@@ -1,3 +1,3 @@
1
- import { ConfigRouterType } from '../../utils/config';
1
+ import { ConfigRouterType } from '../../../utils/config';
2
2
  export declare const routerType: ConfigRouterType['type'];
3
3
  export declare const routerBase: ConfigRouterType['base'];
@@ -7,7 +7,7 @@ exports.useLocation = exports.getFormatRouterBase = void 0;
7
7
  var vue_router_1 = require("vue-router");
8
8
  var qs_1 = __importDefault(require("qs"));
9
9
  var vue_1 = require("vue");
10
- var config_1 = require("./config");
10
+ var config_1 = require("./.env/config");
11
11
  var getFormatRouterBase = function (routerBase) {
12
12
  var lastIndexBase = routerBase[routerBase.length - 1];
13
13
  return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
@@ -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'>;
@@ -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) {
@@ -172,13 +172,14 @@ 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
+ envPath = env === 'dev' ? '.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,
@@ -226,9 +227,7 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
226
227
  case 0:
227
228
  targetPath = path_1.default.resolve(__dirname, '../index.js');
228
229
  targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
229
- return [4, fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8')];
230
- case 1:
231
- replaceFileText = _a.sent();
230
+ replaceFileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8');
232
231
  fileTypesText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".d.ts")), 'utf8');
233
232
  if (templateType === 'react') {
234
233
  formatHooksPath = path_1.default
@@ -237,17 +236,18 @@ var initCliIndexFile = function (templateType) { return __awaiter(void 0, void 0
237
236
  replaceFileText = replaceFileText.replaceAll('require("./template/react/hooks");', "require(\"".concat(formatHooksPath, "\");"));
238
237
  }
239
238
  return [4, (0, tools_1.writeFile)(targetPath, replaceFileText)];
240
- case 2:
239
+ case 1:
241
240
  _a.sent();
242
241
  return [4, (0, tools_1.writeFile)(targetTypesPath, fileTypesText)];
243
- case 3:
242
+ case 2:
244
243
  _a.sent();
245
244
  return [2];
246
245
  }
247
246
  });
248
247
  }); };
249
- var formatRouterConfig = function (_a, templateType) {
248
+ var formatRouterConfig = function (_a, templateType, env) {
250
249
  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;
250
+ var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
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;
253
253
  return __generator(this, function (_a) {
@@ -256,10 +256,10 @@ 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(envPath, "routes.js")), modifiedText)];
260
260
  case 1:
261
261
  _a.sent();
262
- configFilePath = path_1.default.resolve(projectPath, './src/.swico/config.js');
262
+ configFilePath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "config.js"));
263
263
  replaceConfigText = fs_extra_1.default.readFileSync(configFilePath, 'utf8');
264
264
  if (base) {
265
265
  replaceConfigText = replaceConfigText.replace(/exports\.routerBase\s*=\s*(.*)/gm, function (match, p1) {
@@ -280,79 +280,72 @@ 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 envPath = env === 'dev' ? '/.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, replaceHooksText, e_1, e_2;
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
- if (!fs_extra_1.default.existsSync(copyTargetPath)) return [3, 2];
291
- return [4, fs_extra_1.default.remove(copyTargetPath)];
290
+ copyTargetPath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath));
291
+ return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/.env")), copyTargetPath, function (fileName) {
292
+ return !fileName.endsWith('.d.ts') &&
293
+ (templateType === 'vue'
294
+ ? !['Container.js', 'hooks.js'].includes(fileName)
295
+ : !['hooks.js'].includes(fileName));
296
+ })];
292
297
  case 1:
293
298
  _a.sent();
294
- _a.label = 2;
295
- case 2: return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), copyTargetPath, function (fileName) {
296
- return !fileName.endsWith('.d.ts') &&
297
- (templateType === 'vue' ? fileName !== 'Container.js' : true);
298
- })];
299
+ return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, './src/.swico'), function (fileName) { return ['hooks.js'].includes(fileName); })];
300
+ case 2:
301
+ _a.sent();
302
+ return [4, formatRouterConfig(routerConfig, templateType, env)];
299
303
  case 3:
300
304
  _a.sent();
301
- return [4, formatRouterConfig(routerConfig, templateType)];
305
+ replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8');
306
+ replaceHooksText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), 'utf8');
307
+ replaceHooksText = replaceHooksText.replaceAll('.env', ".".concat(env));
308
+ _a.label = 4;
302
309
  case 4:
303
- _a.sent();
304
- replaceIndexText = fs_extra_1.default.readFileSync(path_1.default.resolve(projectPath, './src/.swico/index.js'), 'utf8');
305
- _a.label = 5;
310
+ _a.trys.push([4, 6, , 7]);
311
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
306
312
  case 5:
307
- _a.trys.push([5, 7, , 8]);
308
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.ts'), fs_extra_1.default.constants.F_OK)];
309
- case 6:
310
313
  _a.sent();
311
- replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
312
- replaceIndexText = 'require("../global");\n' + replaceIndexText;
313
- return [3, 8];
314
- case 7:
314
+ replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
315
+ replaceIndexText = 'require("../../global.less");\n' + replaceIndexText;
316
+ return [3, 7];
317
+ case 6:
315
318
  e_1 = _a.sent();
316
- replaceIndexText = replaceIndexText.replaceAll('require("../global");', '');
317
- return [3, 8];
319
+ replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
320
+ return [3, 7];
321
+ case 7:
322
+ if (!(templateType === 'vue')) return [3, 9];
323
+ replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
324
+ return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
318
325
  case 8:
319
- _a.trys.push([8, 10, , 11]);
320
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
321
- case 9:
322
326
  _a.sent();
323
- replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
324
- replaceIndexText = 'require("../global.less");\n' + replaceIndexText;
325
- return [3, 11];
327
+ return [3, 15];
328
+ case 9:
329
+ if (!(templateType === 'react')) return [3, 15];
330
+ _a.label = 10;
326
331
  case 10:
327
- e_2 = _a.sent();
328
- replaceIndexText = replaceIndexText.replaceAll('require("../global.less");', '');
329
- return [3, 11];
332
+ _a.trys.push([10, 12, 13, 15]);
333
+ return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
330
334
  case 11:
331
- if (!(templateType === 'vue')) return [3, 13];
332
- replaceIndexText = replaceIndexText.replace('"./Container"', '"./Container.vue"');
333
- return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/index.js'), replaceIndexText)];
334
- case 12:
335
335
  _a.sent();
336
- _a.label = 13;
337
- case 13:
338
- if (!(templateType === 'react')) return [3, 19];
339
- _a.label = 14;
336
+ replaceIndexText = replaceIndexText.replace('"../loading"', '"../../loading"');
337
+ return [3, 15];
338
+ case 12:
339
+ e_2 = _a.sent();
340
+ replaceIndexText = replaceIndexText.replace('"../../loading"', '"../loading"');
341
+ return [3, 15];
342
+ case 13: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
340
343
  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)];
343
- case 15:
344
344
  _a.sent();
345
- replaceIndexText = replaceIndexText.replace('"./loading"', '"../loading"');
346
- return [3, 19];
345
+ return [7];
346
+ case 15: return [4, (0, tools_1.writeFile)(path_1.default.resolve(projectPath, './src/.swico/hooks.js'), replaceHooksText)];
347
347
  case 16:
348
- e_3 = _a.sent();
349
- 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:
353
348
  _a.sent();
354
- return [7];
355
- case 19:
356
349
  resolve(null);
357
350
  return [2];
358
351
  }
@@ -6,3 +6,4 @@ export declare const toast: {
6
6
  warning: (message: string | string[]) => void;
7
7
  };
8
8
  export declare const writeFile: (sourcePath: any, text: any) => Promise<unknown>;
9
+ export declare const initIndexFile: () => Promise<void>;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,11 +62,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
62
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
63
  };
41
64
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
65
+ exports.initIndexFile = exports.writeFile = exports.toast = exports.getPort = exports.copyDirFiles = void 0;
43
66
  var portfinder_1 = __importDefault(require("portfinder"));
44
67
  var fs_extra_1 = __importDefault(require("fs-extra"));
45
68
  var path_1 = __importDefault(require("path"));
46
69
  var chalk_1 = __importDefault(require("chalk"));
70
+ var process = __importStar(require("process"));
47
71
  var copyDirFiles = function (src, dest, filter) { return __awaiter(void 0, void 0, void 0, function () {
48
72
  var _copy, e_1;
49
73
  return __generator(this, function (_a) {
@@ -102,10 +126,10 @@ var getPort = function () {
102
126
  exports.getPort = getPort;
103
127
  exports.toast = {
104
128
  info: function (message) {
105
- console.log("\n".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
129
+ console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')(message), "\n"));
106
130
  },
107
131
  error: function (message) {
108
- console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
132
+ console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some errors about Swico:'), " \n"));
109
133
  if (Array.isArray(message)) {
110
134
  message.forEach(function (item) {
111
135
  console.log(" > ".concat(chalk_1.default.red.bold(item), " \n"));
@@ -116,7 +140,7 @@ exports.toast = {
116
140
  }
117
141
  },
118
142
  warning: function (message) {
119
- console.log("\n".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about Swico:'), " \n"));
143
+ console.log("\n> ".concat(chalk_1.default.hex('#5f72f5')('There are some warnings about Swico:'), " \n"));
120
144
  if (Array.isArray(message)) {
121
145
  message.forEach(function (item) {
122
146
  console.log(" > ".concat(chalk_1.default.hex('#fb8918').bold(item), " \n"));
@@ -142,3 +166,22 @@ var writeFile = function (sourcePath, text) {
142
166
  });
143
167
  };
144
168
  exports.writeFile = writeFile;
169
+ var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, function () {
170
+ var fileText, targetPath, formatHooksPath;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0:
174
+ fileText = fs_extra_1.default.readFileSync(path_1.default.resolve(__dirname, '../index.js'), 'utf8');
175
+ targetPath = path_1.default.resolve(__dirname, '../index.js');
176
+ formatHooksPath = path_1.default
177
+ .resolve(process.cwd(), './src/.swico/hooks.js')
178
+ .replaceAll('\\', '/');
179
+ fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/hooks");');
180
+ return [4, (0, exports.writeFile)(targetPath, fileText)];
181
+ case 1:
182
+ _a.sent();
183
+ return [2];
184
+ }
185
+ });
186
+ }); };
187
+ exports.initIndexFile = initIndexFile;
@@ -1,12 +0,0 @@
1
- export interface UseLocationType {
2
- (): {
3
- name: string;
4
- path: string;
5
- pathname: string;
6
- search: string;
7
- query?: Record<string, any>;
8
- hash: string;
9
- params?: Record<string, any>;
10
- };
11
- }
12
- export declare const useLocation: UseLocationType;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocation = void 0;
7
- var react_router_dom_1 = require("react-router-dom");
8
- var qs_1 = __importDefault(require("qs"));
9
- var history_1 = require("../react/history");
10
- var routes_1 = require("../react/routes");
11
- var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
12
- var patternWithValuesParts = urlPatternWithValues.split('/');
13
- var patternWithParamsParts = urlPatternWithParams.split('/');
14
- if (patternWithValuesParts.length !== patternWithParamsParts.length) {
15
- return false;
16
- }
17
- for (var i = 0; i < patternWithValuesParts.length; i++) {
18
- var valuePart = patternWithValuesParts[i];
19
- var paramPart = patternWithParamsParts[i];
20
- if (paramPart.startsWith(':') && paramPart !== '') {
21
- continue;
22
- }
23
- if (valuePart !== paramPart) {
24
- return false;
25
- }
26
- }
27
- return true;
28
- };
29
- var useLocation = function () {
30
- var _a, _b;
31
- var location = (0, react_router_dom_1.useLocation)();
32
- var params = (0, react_router_dom_1.useParams)();
33
- var search = location.search, hash = location.hash, pathname = location.pathname;
34
- var pathNameList = (0, history_1.getPathNameList)(routes_1.routes);
35
- var name = (_a = pathNameList.find(function (item) { return (params && compareURLPatterns(pathname, item.path)) || item.path === pathname; })) === null || _a === void 0 ? void 0 : _a.name;
36
- var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
37
- return {
38
- name: name,
39
- path: pathname,
40
- pathname: (_b = window === null || window === void 0 ? void 0 : window.location) === null || _b === void 0 ? void 0 : _b.pathname,
41
- search: search,
42
- query: query,
43
- hash: hash,
44
- params: params
45
- };
46
- };
47
- exports.useLocation = useLocation;
@@ -1,3 +0,0 @@
1
- import { UseLocationType } from './react';
2
- export declare const getFormatRouterBase: (routerBase: any) => any;
3
- export declare const useLocation: UseLocationType;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useLocation = exports.getFormatRouterBase = void 0;
7
- var vue_router_1 = require("vue-router");
8
- var qs_1 = __importDefault(require("qs"));
9
- var vue_1 = require("vue");
10
- var config_1 = require("../vue/config");
11
- var getFormatRouterBase = function (routerBase) {
12
- var lastIndexBase = routerBase[routerBase.length - 1];
13
- return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
14
- };
15
- exports.getFormatRouterBase = getFormatRouterBase;
16
- var useLocation = function () {
17
- var route = (0, vue_router_1.useRoute)();
18
- var location = (0, vue_1.reactive)({
19
- name: '',
20
- path: '',
21
- search: '',
22
- hash: '',
23
- pathname: '',
24
- params: {},
25
- query: {}
26
- });
27
- (0, vue_1.watchEffect)(function () {
28
- var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name;
29
- var search = query ? qs_1.default.stringify(query) : '';
30
- location.name = name;
31
- location.path = path;
32
- location.pathname = (0, exports.getFormatRouterBase)(config_1.routerBase) + path;
33
- location.search = search;
34
- location.query = query;
35
- location.hash = hash;
36
- location.params = params;
37
- });
38
- return location;
39
- };
40
- exports.useLocation = useLocation;
@@ -1,2 +0,0 @@
1
- declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
- export default _default;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var vue_1 = require("vue");
4
- exports.default = (0, vue_1.defineComponent)({});
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- var _a;
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- var vue_1 = require("vue");
8
- var routes_1 = __importDefault(require("./routes"));
9
- var vue_router_1 = require("vue-router");
10
- var Container_1 = __importDefault(require("./Container"));
11
- var config_1 = require("./config");
12
- var Layout_1 = __importDefault(require("../layout/Layout"));
13
- var global_1 = __importDefault(require("../global"));
14
- var qs_1 = __importDefault(require("qs"));
15
- var router = (0, vue_router_1.createRouter)({
16
- history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
17
- routes: routes_1.default
18
- });
19
- var app = (0, vue_1.createApp)(Container_1.default);
20
- var Swico = { history: null };
21
- Swico.history = {
22
- push: function (options) {
23
- if (typeof options === 'string') {
24
- router.push(options);
25
- }
26
- else {
27
- var query = options.query, name_1 = options.name, hash = options.hash, params = options.params, path = options.path;
28
- router.push({ name: name_1, path: path, query: query, hash: hash, params: params });
29
- }
30
- },
31
- replace: function (options) {
32
- if (typeof options === 'string') {
33
- router.replace(options);
34
- }
35
- else {
36
- var query = options.query, name_2 = options.name, hash = options.hash, params = options.params, path = options.path;
37
- router.replace({ name: name_2, path: path, query: query, hash: hash, params: params });
38
- }
39
- },
40
- go: router.go,
41
- back: router.back,
42
- forward: router.forward,
43
- get location() {
44
- var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
45
- var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
46
- var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
47
- return {
48
- path: path,
49
- pathname: formatRouterBase + path,
50
- params: params,
51
- query: query,
52
- name: name,
53
- hash: hash,
54
- search: query ? qs_1.default.stringify(query) : ''
55
- };
56
- }
57
- };
58
- app.component('Layout', Layout_1.default);
59
- app.use(router);
60
- window.Swico = Swico;
61
- (_a = global_1.default === null || global_1.default === void 0 ? void 0 : global_1.default.onInit) === null || _a === void 0 ? void 0 : _a.call(global_1.default, app, router);
62
- app.mount('#root');
@@ -1,6 +0,0 @@
1
- import { RouteRecordRaw } from 'vue-router';
2
- type RouteItem = RouteRecordRaw & {
3
- decorator?: string;
4
- };
5
- declare const _default: RouteItem[];
6
- export default _default;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = [];
File without changes