swico 2.6.0-beta.7 → 2.6.0-beta.8
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/main-config/index.js +28 -3
- package/src/utils.d.ts +0 -2
- package/src/utils.js +1 -25
package/package.json
CHANGED
package/src/main-config/index.js
CHANGED
|
@@ -50,6 +50,29 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
50
50
|
const path_1 = __importDefault(require("path"));
|
|
51
51
|
const chalk_1 = __importDefault(require("chalk"));
|
|
52
52
|
const utils_1 = require("../utils");
|
|
53
|
+
const getFormatRouter = (projectPath, routes, templateType) => {
|
|
54
|
+
const _main = (item) => {
|
|
55
|
+
const { component, name, children, redirect, decorator } = item;
|
|
56
|
+
return decorator
|
|
57
|
+
? Object.assign(Object.assign({}, item), { component: `()=>import('${projectPath}/src/pages/${decorator}${templateType === 'vue' ? '.vue' : ''}')`, children: [
|
|
58
|
+
{
|
|
59
|
+
path: '',
|
|
60
|
+
component: component
|
|
61
|
+
? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
|
|
62
|
+
: undefined,
|
|
63
|
+
name,
|
|
64
|
+
redirect,
|
|
65
|
+
children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined
|
|
66
|
+
}
|
|
67
|
+
] }) : Object.assign(Object.assign({}, item), { component: component
|
|
68
|
+
? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
|
|
69
|
+
: undefined, name,
|
|
70
|
+
redirect, children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined });
|
|
71
|
+
};
|
|
72
|
+
return routes.map((item) => {
|
|
73
|
+
return _main(item);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
53
76
|
const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
77
|
var _a, _b;
|
|
55
78
|
const projectPath = process.cwd();
|
|
@@ -152,7 +175,7 @@ const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templ
|
|
|
152
175
|
const projectPath = process.cwd();
|
|
153
176
|
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
154
177
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
-
const formatRouter =
|
|
178
|
+
const formatRouter = getFormatRouter(projectPath, routes, templateType);
|
|
156
179
|
const textData = `"use strict";
|
|
157
180
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
158
181
|
exports.default = ${JSON.stringify(formatRouter)};`;
|
|
@@ -244,8 +267,10 @@ const initTemplateConfig = (routerConfig, templateType, env) => {
|
|
|
244
267
|
yield fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText);
|
|
245
268
|
let replaceIndexText = yield fs_extra_1.default.readFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), 'utf8');
|
|
246
269
|
replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
|
|
247
|
-
|
|
248
|
-
|
|
270
|
+
if (templateType === 'react') {
|
|
271
|
+
replaceIndexText = yield (0, exports.handleLoadingFile)(projectPath, templateType, replaceIndexText);
|
|
272
|
+
}
|
|
273
|
+
yield (0, exports.updateIndexFileText)(envPath, replaceIndexText);
|
|
249
274
|
resolve(null);
|
|
250
275
|
}));
|
|
251
276
|
};
|
package/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ConfigRouterType } from './main-config';
|
|
2
1
|
export declare const copyDirFiles: (src: any, dest: any, filter?: (fileName: any) => boolean) => Promise<void>;
|
|
3
|
-
export declare const getFormatRouter: (projectPath: string, routes: ConfigRouterType["routes"], templateType: any) => any[];
|
|
4
2
|
export declare const getPort: () => Promise<number>;
|
|
5
3
|
export declare const colorConfig: {
|
|
6
4
|
theme: string;
|
package/src/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.toast = exports.colorConfig = exports.getPort = exports.
|
|
22
|
+
exports.toast = exports.colorConfig = exports.getPort = exports.copyDirFiles = void 0;
|
|
23
23
|
const portfinder_1 = __importDefault(require("portfinder"));
|
|
24
24
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
25
25
|
const path_1 = __importDefault(require("path"));
|
|
@@ -63,30 +63,6 @@ const copyDirFiles = (src, dest, filter) => __awaiter(void 0, void 0, void 0, fu
|
|
|
63
63
|
yield _copy(src, dest);
|
|
64
64
|
});
|
|
65
65
|
exports.copyDirFiles = copyDirFiles;
|
|
66
|
-
const getFormatRouter = (projectPath, routes, templateType) => {
|
|
67
|
-
const _main = (item) => {
|
|
68
|
-
const { component, name, children, redirect, decorator } = item;
|
|
69
|
-
return decorator
|
|
70
|
-
? Object.assign(Object.assign({}, item), { component: `()=>import('${projectPath}/src/pages/${decorator}${templateType === 'vue' ? '.vue' : ''}')`, children: [
|
|
71
|
-
{
|
|
72
|
-
path: '',
|
|
73
|
-
component: component
|
|
74
|
-
? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
|
|
75
|
-
: undefined,
|
|
76
|
-
name,
|
|
77
|
-
redirect,
|
|
78
|
-
children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined
|
|
79
|
-
}
|
|
80
|
-
] }) : Object.assign(Object.assign({}, item), { component: component
|
|
81
|
-
? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
|
|
82
|
-
: undefined, name,
|
|
83
|
-
redirect, children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined });
|
|
84
|
-
};
|
|
85
|
-
return routes.map((item) => {
|
|
86
|
-
return _main(item);
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
exports.getFormatRouter = getFormatRouter;
|
|
90
66
|
const getPort = () => {
|
|
91
67
|
return portfinder_1.default.getPortPromise({
|
|
92
68
|
port: 3000,
|