swico 1.5.0 → 1.6.0-beta.1
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 +12 -10
- package/src/command/start.js +4 -4
- package/src/utils/config.d.ts +1 -2
- package/src/utils/config.js +43 -42
- package/src/utils/tools.js +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swico",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-beta.1",
|
|
4
4
|
"description": "Simple, efficient, and practical front-end framework",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -30,9 +30,6 @@
|
|
|
30
30
|
"author": "scw",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"qs": "6.13.0",
|
|
34
|
-
"react-router-dom": "6.23.0",
|
|
35
|
-
"vue-router": "^4.2.5",
|
|
36
33
|
"@babel/types": "7.23.9",
|
|
37
34
|
"@swc/core": "1.4.6",
|
|
38
35
|
"@vue/compiler-sfc": "3.4.14",
|
|
@@ -41,7 +38,7 @@
|
|
|
41
38
|
"chokidar": "3.6.0",
|
|
42
39
|
"commander": "12.0.0",
|
|
43
40
|
"copy-webpack-plugin": "12.0.2",
|
|
44
|
-
"cross-spawn": "7.0.
|
|
41
|
+
"cross-spawn": "7.0.5",
|
|
45
42
|
"css-loader": "6.3.0",
|
|
46
43
|
"esbuild-loader": "4.0.3",
|
|
47
44
|
"eslint-plugin-react": "7.33.2",
|
|
@@ -49,6 +46,7 @@
|
|
|
49
46
|
"eslint-plugin-vue": "9.19.2",
|
|
50
47
|
"eslint-webpack-plugin": "4.0.0",
|
|
51
48
|
"fork-ts-checker-webpack-plugin": "9.0.2",
|
|
49
|
+
"fs-extra": "11.3.0",
|
|
52
50
|
"html-loader": "5.0.0",
|
|
53
51
|
"html-webpack-plugin": "5.3.2",
|
|
54
52
|
"less": "4.1.2",
|
|
@@ -58,14 +56,16 @@
|
|
|
58
56
|
"portfinder": "1.0.32",
|
|
59
57
|
"postcss-loader": "8.1.0",
|
|
60
58
|
"postcss-preset-env": "9.3.0",
|
|
59
|
+
"qs": "6.13.0",
|
|
60
|
+
"react-router-dom": "6.23.0",
|
|
61
61
|
"sass": "1.77.5",
|
|
62
62
|
"sass-loader": "14.2.1",
|
|
63
63
|
"style-loader": "3.3.0",
|
|
64
64
|
"swc-loader": "0.2.6",
|
|
65
65
|
"ts-node": "10.9.1",
|
|
66
66
|
"vue-loader": "17.4.2",
|
|
67
|
+
"vue-router": "^4.2.5",
|
|
67
68
|
"vue-style-loader": "4.1.3",
|
|
68
|
-
"webpack": "5.88.2",
|
|
69
69
|
"webpack-bundle-analyzer": "4.9.1",
|
|
70
70
|
"webpack-cli": "5.1.4",
|
|
71
71
|
"webpack-dev-server": "4.15.2",
|
|
@@ -73,14 +73,16 @@
|
|
|
73
73
|
"webpackbar": "6.0.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"
|
|
77
|
-
"
|
|
76
|
+
"@types/node": "22.13.10",
|
|
77
|
+
"@types/react": "18.2.79",
|
|
78
|
+
"@types/react-dom": "18.2.25",
|
|
78
79
|
"@typescript-eslint/eslint-plugin": "6.19.0",
|
|
79
80
|
"@typescript-eslint/parser": "6.19.0",
|
|
81
|
+
"eslint": "8.48.0",
|
|
80
82
|
"react": "~18.2.0",
|
|
81
83
|
"react-dom": "~18.2.0",
|
|
84
|
+
"typescript": "5.3.3",
|
|
82
85
|
"vue": "~3.4.14",
|
|
83
|
-
"
|
|
84
|
-
"@types/react-dom": "18.2.25"
|
|
86
|
+
"webpack": "5.94.0"
|
|
85
87
|
}
|
|
86
88
|
}
|
package/src/command/start.js
CHANGED
|
@@ -106,7 +106,7 @@ var handleWatch = function (projectPath, devServer, env) {
|
|
|
106
106
|
var replaceIndexText, _a;
|
|
107
107
|
return __generator(this, function (_b) {
|
|
108
108
|
switch (_b.label) {
|
|
109
|
-
case 0: return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "
|
|
109
|
+
case 0: return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "index.js")), 'utf8')];
|
|
110
110
|
case 1:
|
|
111
111
|
replaceIndexText = _b.sent();
|
|
112
112
|
if (!['add', 'unlink'].includes(eventName)) return [3, 9];
|
|
@@ -165,9 +165,9 @@ var getMockGetLogger = function (compiler) {
|
|
|
165
165
|
};
|
|
166
166
|
};
|
|
167
167
|
var filterStyleFileList = [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
'Can\'t resolve \'../../global.less\'',
|
|
169
|
+
'Can\'t resolve \'../../global.css\'',
|
|
170
|
+
'Can\'t resolve \'../../global.scss\''
|
|
171
171
|
];
|
|
172
172
|
var createCompileListener = function (compiler) {
|
|
173
173
|
compiler.hooks.beforeCompile.tap('beforeCompile', function () {
|
package/src/utils/config.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export type ConfigRouterType = {
|
|
|
15
15
|
};
|
|
16
16
|
export interface GlobalSwicoConfigType {
|
|
17
17
|
template: 'react' | 'vue';
|
|
18
|
-
npmType?: 'npm' | 'pnpm';
|
|
19
18
|
plugins?: any[];
|
|
20
19
|
publicPath?: string;
|
|
21
20
|
console?: boolean;
|
|
@@ -38,7 +37,7 @@ export interface GlobalData {
|
|
|
38
37
|
templatePath: string;
|
|
39
38
|
env?: 'dev' | 'prod';
|
|
40
39
|
customConfig: {
|
|
41
|
-
base: Pick<GlobalSwicoConfigType, 'plugins' | 'publicPath' | 'alias' | 'define' | 'devtool' | 'externals' | '
|
|
40
|
+
base: Pick<GlobalSwicoConfigType, 'plugins' | 'publicPath' | 'alias' | 'define' | 'devtool' | 'externals' | 'router' | 'template'>;
|
|
42
41
|
dev: Pick<GlobalSwicoConfigType, 'plugins' | 'proxy' | 'https' | 'devtool' | 'router'>;
|
|
43
42
|
prod: Pick<GlobalSwicoConfigType, 'plugins' | 'console' | 'copy' | 'devtool' | 'router'>;
|
|
44
43
|
};
|
package/src/utils/config.js
CHANGED
|
@@ -78,13 +78,13 @@ var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
78
78
|
var path_1 = __importDefault(require("path"));
|
|
79
79
|
var chalk_1 = __importDefault(require("chalk"));
|
|
80
80
|
var tools_1 = require("./tools");
|
|
81
|
-
var projectPath = process.cwd();
|
|
82
81
|
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, envPath, entryPath, templatePath;
|
|
84
|
-
var _b, _c
|
|
85
|
-
return __generator(this, function (
|
|
86
|
-
switch (
|
|
82
|
+
var projectPath, configDir, configPath, customConfig, _loop_1, _i, _a, key, templateType, routerConfig, envPath, entryPath, templatePath;
|
|
83
|
+
var _b, _c;
|
|
84
|
+
return __generator(this, function (_d) {
|
|
85
|
+
switch (_d.label) {
|
|
87
86
|
case 0:
|
|
87
|
+
projectPath = process.cwd();
|
|
88
88
|
configDir = path_1.default.join(projectPath, '/config');
|
|
89
89
|
configPath = {
|
|
90
90
|
dev: path_1.default.join(configDir, '/swico.dev.ts'),
|
|
@@ -93,18 +93,18 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
93
93
|
};
|
|
94
94
|
customConfig = {};
|
|
95
95
|
_loop_1 = function (key) {
|
|
96
|
-
var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, toastTitle, unSupportedField, msgText,
|
|
97
|
-
return __generator(this, function (
|
|
98
|
-
switch (
|
|
96
|
+
var curConfigFilePath, exists, configObj, configFields, supportedFieldList_1, configFileName, toastTitle, unSupportedField, msgText, _e, _f;
|
|
97
|
+
return __generator(this, function (_g) {
|
|
98
|
+
switch (_g.label) {
|
|
99
99
|
case 0:
|
|
100
100
|
curConfigFilePath = configPath[key];
|
|
101
101
|
return [4, fs_extra_1.default.exists(curConfigFilePath)];
|
|
102
102
|
case 1:
|
|
103
|
-
exists =
|
|
103
|
+
exists = _g.sent();
|
|
104
104
|
if (!exists) return [3, 4];
|
|
105
105
|
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
106
106
|
case 2:
|
|
107
|
-
configObj = (
|
|
107
|
+
configObj = (_g.sent()).default;
|
|
108
108
|
configFields = Object.keys(configObj);
|
|
109
109
|
configFileName = void 0;
|
|
110
110
|
switch (key) {
|
|
@@ -116,7 +116,6 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
116
116
|
'define',
|
|
117
117
|
'devtool',
|
|
118
118
|
'externals',
|
|
119
|
-
'npmType',
|
|
120
119
|
'router',
|
|
121
120
|
'template'
|
|
122
121
|
];
|
|
@@ -141,34 +140,29 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
141
140
|
tools_1.toast.error("The field '".concat(chalk_1.default.blue('template'), "' does not support the value '").concat(chalk_1.default.red(configObj['template']), "',the value should be 'vue' or 'react' "), { title: toastTitle });
|
|
142
141
|
process.exit(1);
|
|
143
142
|
}
|
|
144
|
-
if (
|
|
145
|
-
!['npm', 'pnpm'].includes((_b = configObj['npmType']) !== null && _b !== void 0 ? _b : exports.initConfig.npmType)) {
|
|
146
|
-
tools_1.toast.error("The field '".concat(chalk_1.default.blue('npmType'), "' does not support the value '").concat(chalk_1.default.red(configObj['npmType']), "',the value should be 'npm' or 'pnpm' "), { title: toastTitle });
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
if (!['hash', 'browser'].includes((_d = (_c = configObj['router']) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : exports.initConfig.router.type)) {
|
|
143
|
+
if (!['hash', 'browser'].includes((_c = (_b = configObj['router']) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : exports.initConfig.router.type)) {
|
|
150
144
|
tools_1.toast.error("The field '".concat(chalk_1.default.blue('router.type'), "' does not support the value '").concat(chalk_1.default.red(configObj['router'].type), "',the value should be 'browser' or 'hash' "), { title: toastTitle });
|
|
151
145
|
process.exit(1);
|
|
152
146
|
}
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
_e = customConfig;
|
|
148
|
+
_f = key;
|
|
155
149
|
return [4, Promise.resolve("".concat(curConfigFilePath)).then(function (s) { return __importStar(require(s)); })];
|
|
156
150
|
case 3:
|
|
157
|
-
_f
|
|
158
|
-
|
|
151
|
+
_e[_f] = (_g.sent()).default;
|
|
152
|
+
_g.label = 4;
|
|
159
153
|
case 4: return [2];
|
|
160
154
|
}
|
|
161
155
|
});
|
|
162
156
|
};
|
|
163
157
|
_i = 0, _a = Object.keys(configPath);
|
|
164
|
-
|
|
158
|
+
_d.label = 1;
|
|
165
159
|
case 1:
|
|
166
160
|
if (!(_i < _a.length)) return [3, 4];
|
|
167
161
|
key = _a[_i];
|
|
168
162
|
return [5, _loop_1(key)];
|
|
169
163
|
case 2:
|
|
170
|
-
|
|
171
|
-
|
|
164
|
+
_d.sent();
|
|
165
|
+
_d.label = 3;
|
|
172
166
|
case 3:
|
|
173
167
|
_i++;
|
|
174
168
|
return [3, 1];
|
|
@@ -177,12 +171,12 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
177
171
|
routerConfig = __assign(__assign(__assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
178
172
|
return [4, initTemplateConfig(routerConfig, templateType, env)];
|
|
179
173
|
case 5:
|
|
180
|
-
|
|
174
|
+
_d.sent();
|
|
181
175
|
return [4, initCliIndexFile(templateType, env)];
|
|
182
176
|
case 6:
|
|
183
|
-
|
|
177
|
+
_d.sent();
|
|
184
178
|
envPath = env === 'dev' ? '.dev/' : '.prod/';
|
|
185
|
-
entryPath = path_1.default.resolve(projectPath, "
|
|
179
|
+
entryPath = path_1.default.resolve(projectPath, "./.swico/".concat(envPath, "index.js"));
|
|
186
180
|
templatePath = path_1.default.join(projectPath, '/src/index.ejs');
|
|
187
181
|
return [2, {
|
|
188
182
|
env: env,
|
|
@@ -197,10 +191,11 @@ var getProjectConfig = function (env) { return __awaiter(void 0, void 0, void 0,
|
|
|
197
191
|
}); };
|
|
198
192
|
exports.getProjectConfig = getProjectConfig;
|
|
199
193
|
var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
-
var targetPath, targetTypesPath, replaceFileText, fileTypesText, formatHooksPath, formatHistoryPath;
|
|
194
|
+
var projectPath, targetPath, targetTypesPath, replaceFileText, fileTypesText, formatHooksPath, formatHistoryPath;
|
|
201
195
|
return __generator(this, function (_a) {
|
|
202
196
|
switch (_a.label) {
|
|
203
197
|
case 0:
|
|
198
|
+
projectPath = process.cwd();
|
|
204
199
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
205
200
|
targetTypesPath = path_1.default.resolve(__dirname, '../index.d.ts');
|
|
206
201
|
return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, "../index.".concat(templateType, ".js")), 'utf8')];
|
|
@@ -210,11 +205,11 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
|
|
|
210
205
|
case 2:
|
|
211
206
|
fileTypesText = _a.sent();
|
|
212
207
|
formatHooksPath = path_1.default
|
|
213
|
-
.resolve(projectPath, '
|
|
208
|
+
.resolve(projectPath, './.swico/react-hooks')
|
|
214
209
|
.replaceAll('\\', '/');
|
|
215
210
|
replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
|
|
216
211
|
formatHistoryPath = path_1.default
|
|
217
|
-
.resolve(projectPath, "
|
|
212
|
+
.resolve(projectPath, "./.swico/.".concat(env, "/history"))
|
|
218
213
|
.replaceAll('\\', '/');
|
|
219
214
|
replaceFileText = replaceFileText.replaceAll('require("./mock-history");', "require(\"".concat(formatHistoryPath, "\");"));
|
|
220
215
|
return [4, fs_extra_1.default.writeFile(targetPath, replaceFileText)];
|
|
@@ -229,6 +224,7 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
|
|
|
229
224
|
}); };
|
|
230
225
|
var formatRouterConfig = function (_a, templateType, env) {
|
|
231
226
|
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;
|
|
227
|
+
var projectPath = process.cwd();
|
|
232
228
|
var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
233
229
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
234
230
|
var formatRouter, textData, modifiedText, configFilePath, replaceConfigText;
|
|
@@ -238,10 +234,10 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
238
234
|
formatRouter = (0, tools_1.getFormatRouter)(projectPath, routes, templateType);
|
|
239
235
|
textData = "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = ".concat(JSON.stringify(formatRouter), ";");
|
|
240
236
|
modifiedText = textData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
241
|
-
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "
|
|
237
|
+
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "routes.js")), modifiedText)];
|
|
242
238
|
case 1:
|
|
243
239
|
_a.sent();
|
|
244
|
-
configFilePath = path_1.default.resolve(projectPath, "
|
|
240
|
+
configFilePath = path_1.default.resolve(projectPath, "./.swico".concat(envPath, "config.js"));
|
|
245
241
|
return [4, fs_extra_1.default.readFile(configFilePath, 'utf8')];
|
|
246
242
|
case 2:
|
|
247
243
|
replaceConfigText = _a.sent();
|
|
@@ -265,6 +261,7 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
265
261
|
}); });
|
|
266
262
|
};
|
|
267
263
|
var getGlobalStyleFilePath = function () {
|
|
264
|
+
var projectPath = process.cwd();
|
|
268
265
|
var filePath, fileType;
|
|
269
266
|
var cssPath = path_1.default.resolve(projectPath, './src/global.css');
|
|
270
267
|
var lessPath = path_1.default.resolve(projectPath, './src/global.less');
|
|
@@ -288,10 +285,11 @@ var getGlobalStyleFilePath = function () {
|
|
|
288
285
|
return { filePath: filePath, fileType: fileType };
|
|
289
286
|
};
|
|
290
287
|
var handleLoadingFile = function (replaceIndexText, envPath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
291
|
-
var newReplaceIndexText, e_1;
|
|
288
|
+
var projectPath, newReplaceIndexText, e_1;
|
|
292
289
|
return __generator(this, function (_a) {
|
|
293
290
|
switch (_a.label) {
|
|
294
291
|
case 0:
|
|
292
|
+
projectPath = process.cwd();
|
|
295
293
|
newReplaceIndexText = replaceIndexText;
|
|
296
294
|
_a.label = 1;
|
|
297
295
|
case 1:
|
|
@@ -299,11 +297,11 @@ var handleLoadingFile = function (replaceIndexText, envPath) { return __awaiter(
|
|
|
299
297
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
300
298
|
case 2:
|
|
301
299
|
_a.sent();
|
|
302
|
-
newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"
|
|
300
|
+
newReplaceIndexText = newReplaceIndexText.replace('"../loading"', '"../../../src/loading"');
|
|
303
301
|
return [3, 4];
|
|
304
302
|
case 3:
|
|
305
303
|
e_1 = _a.sent();
|
|
306
|
-
newReplaceIndexText = newReplaceIndexText.replace('"
|
|
304
|
+
newReplaceIndexText = newReplaceIndexText.replace('"../../../src/loading"', '"../loading"');
|
|
307
305
|
return [3, 4];
|
|
308
306
|
case 4: return [2, newReplaceIndexText];
|
|
309
307
|
}
|
|
@@ -315,7 +313,7 @@ var handleGlobalStyleFile = function (replaceIndexText) {
|
|
|
315
313
|
var newReplaceIndexText = replaceIndexText;
|
|
316
314
|
if (styleFilePath) {
|
|
317
315
|
newReplaceIndexText = newReplaceIndexText.replaceAll("require(\"../../global.".concat(styleFileType, "\");"), '');
|
|
318
|
-
newReplaceIndexText = "require(\"
|
|
316
|
+
newReplaceIndexText = "require(\"../../../src/global.".concat(styleFileType, "\");\n").concat(replaceIndexText);
|
|
319
317
|
}
|
|
320
318
|
else {
|
|
321
319
|
newReplaceIndexText = newReplaceIndexText.replaceAll(/require\("\.\.\/\.\.\/global.(less|scss|css)"\);/g, '');
|
|
@@ -324,9 +322,12 @@ var handleGlobalStyleFile = function (replaceIndexText) {
|
|
|
324
322
|
};
|
|
325
323
|
exports.handleGlobalStyleFile = handleGlobalStyleFile;
|
|
326
324
|
var updateIndexFileText = function (envPath, newFileText) { return __awaiter(void 0, void 0, void 0, function () {
|
|
325
|
+
var projectPath;
|
|
327
326
|
return __generator(this, function (_a) {
|
|
328
327
|
switch (_a.label) {
|
|
329
|
-
case 0:
|
|
328
|
+
case 0:
|
|
329
|
+
projectPath = process.cwd();
|
|
330
|
+
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "index.js")), newFileText)];
|
|
330
331
|
case 1:
|
|
331
332
|
_a.sent();
|
|
332
333
|
return [2];
|
|
@@ -335,13 +336,14 @@ var updateIndexFileText = function (envPath, newFileText) { return __awaiter(voi
|
|
|
335
336
|
}); };
|
|
336
337
|
exports.updateIndexFileText = updateIndexFileText;
|
|
337
338
|
var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
339
|
+
var projectPath = process.cwd();
|
|
338
340
|
var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
339
341
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
340
342
|
var copyTargetPath, replaceIndexText, hooksFilePath, replaceHooksText, newReplaceIndexText;
|
|
341
343
|
return __generator(this, function (_a) {
|
|
342
344
|
switch (_a.label) {
|
|
343
345
|
case 0:
|
|
344
|
-
copyTargetPath = path_1.default.resolve(projectPath, "
|
|
346
|
+
copyTargetPath = path_1.default.resolve(projectPath, "./.swico".concat(envPath));
|
|
345
347
|
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/$env")), copyTargetPath, function (fileName) {
|
|
346
348
|
return !fileName.endsWith('.d.ts') &&
|
|
347
349
|
(templateType === 'vue'
|
|
@@ -350,7 +352,7 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
|
350
352
|
})];
|
|
351
353
|
case 1:
|
|
352
354
|
_a.sent();
|
|
353
|
-
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, '
|
|
355
|
+
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, './.swico'), function (fileName) {
|
|
354
356
|
return ['react-hooks.js', 'vue-hooks.js', 'loading.js', 'Container.vue'].includes(fileName);
|
|
355
357
|
})];
|
|
356
358
|
case 2:
|
|
@@ -358,10 +360,10 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
|
358
360
|
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
359
361
|
case 3:
|
|
360
362
|
_a.sent();
|
|
361
|
-
return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "
|
|
363
|
+
return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./.swico".concat(envPath, "index.js")), 'utf8')];
|
|
362
364
|
case 4:
|
|
363
365
|
replaceIndexText = _a.sent();
|
|
364
|
-
hooksFilePath = path_1.default.resolve(projectPath, "
|
|
366
|
+
hooksFilePath = path_1.default.resolve(projectPath, "./.swico/".concat(templateType, "-hooks.js"));
|
|
365
367
|
return [4, fs_extra_1.default.readFile(hooksFilePath, 'utf8')];
|
|
366
368
|
case 5:
|
|
367
369
|
replaceHooksText = _a.sent();
|
|
@@ -415,7 +417,6 @@ var getFormatDefineVars = function (defineVarsConfigData) { return __awaiter(voi
|
|
|
415
417
|
}); };
|
|
416
418
|
exports.getFormatDefineVars = getFormatDefineVars;
|
|
417
419
|
exports.initConfig = {
|
|
418
|
-
npmType: 'npm',
|
|
419
420
|
console: true,
|
|
420
421
|
plugins: [],
|
|
421
422
|
publicPath: '/',
|
package/src/utils/tools.js
CHANGED
|
@@ -250,15 +250,16 @@ exports.toast = {
|
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
252
|
var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
253
|
-
var fileText, targetPath, formatHooksPath, formatDevHistoryPath, formatProdHistoryPath;
|
|
253
|
+
var fileText, targetPath, projectPath, formatHooksPath, formatDevHistoryPath, formatProdHistoryPath;
|
|
254
254
|
return __generator(this, function (_a) {
|
|
255
255
|
switch (_a.label) {
|
|
256
256
|
case 0: return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, '../index.js'), 'utf8')];
|
|
257
257
|
case 1:
|
|
258
258
|
fileText = _a.sent();
|
|
259
259
|
targetPath = path_1.default.resolve(__dirname, '../index.js');
|
|
260
|
+
projectPath = process.cwd();
|
|
260
261
|
formatHooksPath = path_1.default
|
|
261
|
-
.resolve(
|
|
262
|
+
.resolve(projectPath, './.swico/react-hooks')
|
|
262
263
|
.replaceAll('\\', '/');
|
|
263
264
|
if (!fileText.includes("require(\"".concat(formatHooksPath, "\");"))) return [3, 3];
|
|
264
265
|
fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./template/react/react-hooks");');
|
|
@@ -268,10 +269,10 @@ var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, funct
|
|
|
268
269
|
_a.label = 3;
|
|
269
270
|
case 3:
|
|
270
271
|
formatDevHistoryPath = path_1.default
|
|
271
|
-
.resolve(
|
|
272
|
+
.resolve(projectPath, './.swico/.dev/history')
|
|
272
273
|
.replaceAll('\\', '/');
|
|
273
274
|
formatProdHistoryPath = path_1.default
|
|
274
|
-
.resolve(
|
|
275
|
+
.resolve(projectPath, './.swico/.prod/history')
|
|
275
276
|
.replaceAll('\\', '/');
|
|
276
277
|
if (!fileText.includes("require(\"".concat(formatDevHistoryPath, "\");"))) return [3, 5];
|
|
277
278
|
fileText = fileText.replaceAll("require(\"".concat(formatDevHistoryPath, "\");"), 'require("./mock-history");');
|