swico 1.2.1-beta.2 → 1.3.0-beta-12
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 +1 -1
- package/src/command/start.js +57 -22
- package/src/template/react/$env/history.d.ts +1 -0
- package/src/template/react/$env/history.js +4 -3
- package/src/template/react/$env/index.d.ts +1 -0
- package/src/template/react/react-hooks.js +6 -5
- package/src/template/vue/$env/history.js +21 -2
- package/src/template/vue/vue-hooks.js +2 -1
- package/src/typings/global-type.d.ts +2 -0
- package/src/utils/config.d.ts +4 -0
- package/src/utils/config.js +68 -36
- package/src/utils/tools.js +3 -9
package/package.json
CHANGED
package/src/command/start.js
CHANGED
|
@@ -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,56 @@ var handleWatch = function (projectPath, devServer) {
|
|
|
87
90
|
}
|
|
88
91
|
});
|
|
89
92
|
}); });
|
|
90
|
-
var
|
|
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,
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
-
|
|
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];
|
|
122
|
+
case 2: return [4, devServer.stop()];
|
|
123
|
+
case 3:
|
|
124
|
+
_b.sent();
|
|
111
125
|
return [4, tsTypingsWatcher.close()];
|
|
112
|
-
case
|
|
113
|
-
|
|
126
|
+
case 4:
|
|
127
|
+
_b.sent();
|
|
114
128
|
restartServer();
|
|
115
|
-
|
|
116
|
-
case
|
|
129
|
+
return [3, 9];
|
|
130
|
+
case 5:
|
|
131
|
+
replaceIndexText = (0, config_1.handleGlobalStyleFile)(replaceIndexText);
|
|
132
|
+
return [4, (0, config_1.updateIndexFileText)(envPath, replaceIndexText)];
|
|
133
|
+
case 6:
|
|
134
|
+
_b.sent();
|
|
135
|
+
return [3, 9];
|
|
136
|
+
case 7:
|
|
137
|
+
replaceIndexText = (0, config_1.handleLoadingFile)(replaceIndexText, envPath);
|
|
138
|
+
return [4, (0, config_1.updateIndexFileText)(envPath, replaceIndexText)];
|
|
139
|
+
case 8:
|
|
140
|
+
_b.sent();
|
|
141
|
+
_b.label = 9;
|
|
142
|
+
case 9: return [2];
|
|
117
143
|
}
|
|
118
144
|
});
|
|
119
145
|
}); });
|
|
@@ -140,6 +166,11 @@ var getMockGetLogger = function (compiler) {
|
|
|
140
166
|
return __assign(__assign({}, logger), { log: log, debug: debug, error: error, warn: warn, info: function () { } });
|
|
141
167
|
};
|
|
142
168
|
};
|
|
169
|
+
var filterStyleFileList = [
|
|
170
|
+
"Can't resolve '../../global.less'",
|
|
171
|
+
"Can't resolve '../../global.css'",
|
|
172
|
+
"Can't resolve '../../global.scss'"
|
|
173
|
+
];
|
|
143
174
|
var createCompileListener = function (compiler) {
|
|
144
175
|
compiler.hooks.beforeCompile.tap('beforeCompile', function () {
|
|
145
176
|
tools_1.toast.info('Compiling...');
|
|
@@ -147,7 +178,8 @@ var createCompileListener = function (compiler) {
|
|
|
147
178
|
compiler.hooks.done.tap('done', function (stats) {
|
|
148
179
|
var info = stats === null || stats === void 0 ? void 0 : stats.toJson();
|
|
149
180
|
if (stats === null || stats === void 0 ? void 0 : stats.hasErrors()) {
|
|
150
|
-
|
|
181
|
+
console.log('1', info === null || info === void 0 ? void 0 : info.errors);
|
|
182
|
+
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
183
|
return;
|
|
152
184
|
}
|
|
153
185
|
if (stats === null || stats === void 0 ? void 0 : stats.hasWarnings()) {
|
|
@@ -161,13 +193,13 @@ var createCompileListener = function (compiler) {
|
|
|
161
193
|
});
|
|
162
194
|
return;
|
|
163
195
|
}
|
|
164
|
-
tools_1.toast.info("Compiled
|
|
196
|
+
tools_1.toast.info("Compiled successfully in ".concat(info === null || info === void 0 ? void 0 : info.time, "ms"));
|
|
165
197
|
});
|
|
166
198
|
};
|
|
167
199
|
function start() {
|
|
168
200
|
var _a, _b, _c, _d, _e, _f;
|
|
169
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
-
var availablePort, _g, projectConfig, projectPath, customConfig, newRouterBase, startConfig, compiler, oriLogger, devServer, e_1,
|
|
202
|
+
var availablePort, _g, projectConfig, projectPath, customConfig, env, newRouterBase, startConfig, compiler, oriLogger, devServer, e_1, strErr_1;
|
|
171
203
|
return __generator(this, function (_h) {
|
|
172
204
|
switch (_h.label) {
|
|
173
205
|
case 0:
|
|
@@ -191,7 +223,7 @@ function start() {
|
|
|
191
223
|
return [4, (0, config_1.getProjectConfig)('dev')];
|
|
192
224
|
case 5:
|
|
193
225
|
projectConfig = _h.sent();
|
|
194
|
-
projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig;
|
|
226
|
+
projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig, env = projectConfig.env;
|
|
195
227
|
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
228
|
return [4, (0, webpack_dev_1.default)(projectConfig)];
|
|
197
229
|
case 6:
|
|
@@ -209,7 +241,7 @@ function start() {
|
|
|
209
241
|
process.env.SWICO_PORT = availablePort.toString();
|
|
210
242
|
createCompileListener(compiler);
|
|
211
243
|
compiler.getInfrastructureLogger = oriLogger;
|
|
212
|
-
handleWatch(projectPath, devServer);
|
|
244
|
+
handleWatch(projectPath, devServer, env);
|
|
213
245
|
if (SWICO_RESTART !== 'true' ||
|
|
214
246
|
(SWICO_RESTART === 'true' && newRouterBase !== SWICO_ROUTER_BASE)) {
|
|
215
247
|
tools_1.toast.info("Project is running at\uFF1A".concat(chalk_1.default.hex('#29abe0')("".concat(startConfig.devServer.server, "://localhost:").concat(availablePort).concat(newRouterBase))));
|
|
@@ -219,8 +251,11 @@ function start() {
|
|
|
219
251
|
return [3, 10];
|
|
220
252
|
case 9:
|
|
221
253
|
e_1 = _h.sent();
|
|
222
|
-
|
|
223
|
-
|
|
254
|
+
strErr_1 = e_1.toString();
|
|
255
|
+
console.log('2', strErr_1);
|
|
256
|
+
if (!filterStyleFileList.find(function (item) { return strErr_1.includes(item); })) {
|
|
257
|
+
tools_1.toast.error(strErr_1);
|
|
258
|
+
}
|
|
224
259
|
return [3, 10];
|
|
225
260
|
case 10: return [2];
|
|
226
261
|
}
|
|
@@ -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) {
|
|
@@ -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
|
|
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
|
|
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
|
-
})
|
|
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: (
|
|
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:
|
|
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;
|
package/src/utils/config.d.ts
CHANGED
|
@@ -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'>;
|
package/src/utils/config.js
CHANGED
|
@@ -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,
|
|
293
|
-
return __generator(this, function (
|
|
294
|
-
switch (
|
|
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
|
-
|
|
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
|
-
|
|
357
|
+
_a.sent();
|
|
310
358
|
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
311
359
|
case 3:
|
|
312
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
324
|
-
|
|
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,
|
|
375
|
+
return [4, (0, exports.updateIndexFileText)(envPath, replaceIndexText)];
|
|
335
376
|
case 7:
|
|
336
|
-
|
|
337
|
-
return [3,
|
|
377
|
+
_a.sent();
|
|
378
|
+
return [3, 11];
|
|
338
379
|
case 8:
|
|
339
|
-
if (!(templateType === 'react')) return [3,
|
|
340
|
-
|
|
380
|
+
if (!(templateType === 'react')) return [3, 11];
|
|
381
|
+
return [4, (0, exports.handleLoadingFile)(replaceIndexText, envPath)];
|
|
341
382
|
case 9:
|
|
342
|
-
|
|
343
|
-
return [4,
|
|
383
|
+
newReplaceIndexText = _a.sent();
|
|
384
|
+
return [4, (0, exports.updateIndexFileText)(envPath, newReplaceIndexText)];
|
|
344
385
|
case 10:
|
|
345
|
-
|
|
346
|
-
|
|
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
|
}
|
package/src/utils/tools.js
CHANGED
|
@@ -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
|
|
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);
|