swico 3.1.0 → 3.2.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 +1 -1
- package/src/command/build.js +1 -0
- package/src/command/start.d.ts +1 -0
- package/src/command/start.js +8 -2
- package/src/main-config/index.d.ts +0 -1
- package/src/main-config/index.js +32 -37
package/package.json
CHANGED
package/src/command/build.js
CHANGED
|
@@ -42,6 +42,7 @@ function default_1() {
|
|
|
42
42
|
}
|
|
43
43
|
const duration = Date.now() - now;
|
|
44
44
|
utils_1.toast.success(`Build complete in ${(duration / 1000).toFixed(2)}s`);
|
|
45
|
+
console.log('devServer:' + rsbuild.context.devServer);
|
|
45
46
|
});
|
|
46
47
|
utils_1.toast.info('Building...');
|
|
47
48
|
now = Date.now();
|
package/src/command/start.d.ts
CHANGED
package/src/command/start.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.updateIndexFileText = void 0;
|
|
15
16
|
exports.default = start;
|
|
16
17
|
const config_dev_1 = __importDefault(require("../rsbuild-config/config.dev"));
|
|
17
18
|
const utils_1 = require("../utils");
|
|
@@ -24,6 +25,11 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
24
25
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
25
26
|
const core_1 = require("@rsbuild/core");
|
|
26
27
|
const { SWICO_DEV_RESTART } = process.env;
|
|
28
|
+
const updateIndexFileText = (envPath, newFileText) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const projectPath = process.cwd();
|
|
30
|
+
yield fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), newFileText);
|
|
31
|
+
});
|
|
32
|
+
exports.updateIndexFileText = updateIndexFileText;
|
|
27
33
|
const handleWatch = (projectPath, devServer, env) => {
|
|
28
34
|
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
29
35
|
const configFilesWatcher = chokidar_1.default
|
|
@@ -64,11 +70,11 @@ const handleWatch = (projectPath, devServer, env) => {
|
|
|
64
70
|
break;
|
|
65
71
|
case globalStyleFilesPathList.includes(filePath):
|
|
66
72
|
replaceIndexText = (0, main_config_1.handleGlobalStyleFile)(replaceIndexText);
|
|
67
|
-
yield (0,
|
|
73
|
+
yield (0, exports.updateIndexFileText)(envPath, replaceIndexText);
|
|
68
74
|
break;
|
|
69
75
|
case filePath === loadingFilePath:
|
|
70
76
|
replaceIndexText = yield (0, main_config_1.handleLoadingFile)(projectPath, replaceIndexText);
|
|
71
|
-
yield (0,
|
|
77
|
+
yield (0, exports.updateIndexFileText)(envPath, replaceIndexText);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
}));
|
|
@@ -47,7 +47,6 @@ export interface GlobalDataType {
|
|
|
47
47
|
export declare const getProjectConfig: (env: GlobalDataType['env']) => Promise<GlobalDataType>;
|
|
48
48
|
export declare const handleLoadingFile: (projectPath: any, replaceIndexText: any) => Promise<any>;
|
|
49
49
|
export declare const handleGlobalStyleFile: (replaceIndexText: any) => any;
|
|
50
|
-
export declare const updateIndexFileText: (envPath: any, newFileText: any) => Promise<void>;
|
|
51
50
|
export declare const getFormatDefineVars: (defineVarsConfigData: any) => Promise<{}>;
|
|
52
51
|
export declare const initConfig: Omit<GlobalSwicoConfigType, 'template'>;
|
|
53
52
|
export declare const customLogger: import("@rsbuild/core").Logger;
|
package/src/main-config/index.js
CHANGED
|
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.customLogger = exports.initConfig = exports.getFormatDefineVars = exports.
|
|
48
|
+
exports.customLogger = exports.initConfig = exports.getFormatDefineVars = exports.handleGlobalStyleFile = exports.handleLoadingFile = exports.getProjectConfig = void 0;
|
|
49
49
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
50
50
|
const path_1 = __importDefault(require("path"));
|
|
51
51
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -149,7 +149,6 @@ const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
149
149
|
const templateType = customConfig['base'].template;
|
|
150
150
|
const routerConfig = Object.assign(Object.assign(Object.assign({}, exports.initConfig.router), customConfig['base'].router), customConfig[env].router);
|
|
151
151
|
yield initTemplateConfig(routerConfig, templateType, env);
|
|
152
|
-
yield initCliEntryFile(projectPath, templateType, env);
|
|
153
152
|
const envPath = env === 'dev' ? '.dev/' : '.prod/';
|
|
154
153
|
const entryPath = path_1.default.resolve(projectPath, `./.swico/${envPath}index.js`);
|
|
155
154
|
const templatePath = path_1.default.join(projectPath, '/src/index.ejs');
|
|
@@ -163,26 +162,14 @@ const getProjectConfig = (env) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
163
162
|
};
|
|
164
163
|
});
|
|
165
164
|
exports.getProjectConfig = getProjectConfig;
|
|
166
|
-
const
|
|
167
|
-
const entryFilePath = path_1.default.resolve(projectPath, './.swico/index.js');
|
|
168
|
-
let replaceEntryText = yield fs_extra_1.default.readFile(entryFilePath, 'utf8');
|
|
169
|
-
const formatHooksPath = path_1.default
|
|
170
|
-
.resolve(projectPath, './.swico/hooks')
|
|
171
|
-
.replaceAll('\\', '/');
|
|
172
|
-
replaceEntryText = replaceEntryText.replaceAll(`require("./template-root/.swico-${templateType}/hooks");`, `require("${formatHooksPath}");`);
|
|
173
|
-
const formatHistoryPath = path_1.default
|
|
174
|
-
.resolve(projectPath, `./.swico/.${env}/history`)
|
|
175
|
-
.replaceAll('\\', '/');
|
|
176
|
-
replaceEntryText = replaceEntryText.replaceAll('require("./mock-history");', `require("${formatHistoryPath}");`);
|
|
177
|
-
yield fs_extra_1.default.writeFile(entryFilePath, replaceEntryText);
|
|
178
|
-
});
|
|
179
|
-
const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templateType, env) => {
|
|
165
|
+
const handleAndCopyRouterFile = ({ routes = [], type = 'browser', base = '/' }, templateType, env) => {
|
|
180
166
|
const projectPath = process.cwd();
|
|
181
167
|
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
182
168
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
169
|
const formatRouter = getFormatRouter(projectPath, routes, templateType);
|
|
184
|
-
const
|
|
185
|
-
|
|
170
|
+
const oriRouterFilePath = path_1.default.resolve(__dirname, `../template-root/.swico-${templateType}/$env/router.js`);
|
|
171
|
+
const targetRouterFilePath = path_1.default.resolve(projectPath, `./.swico${envPath}router.js`);
|
|
172
|
+
let routerFileText = yield fs_extra_1.default.readFile(oriRouterFilePath, 'utf8');
|
|
186
173
|
let formatRoutesTextData = `exports.routes = ${JSON.stringify(formatRouter)};`;
|
|
187
174
|
formatRoutesTextData = formatRoutesTextData.replace(/"(\(\)=>import\('[^']+'\))"/g, '$1');
|
|
188
175
|
routerFileText = routerFileText.replace('exports.routes = [];', formatRoutesTextData);
|
|
@@ -196,7 +183,7 @@ const formatRouterConfig = ({ routes = [], type = 'browser', base = '/' }, templ
|
|
|
196
183
|
return `exports.routerType = '${type}';`;
|
|
197
184
|
});
|
|
198
185
|
}
|
|
199
|
-
yield fs_extra_1.default.writeFile(
|
|
186
|
+
yield fs_extra_1.default.writeFile(targetRouterFilePath, routerFileText);
|
|
200
187
|
resolve(null);
|
|
201
188
|
}));
|
|
202
189
|
};
|
|
@@ -249,31 +236,39 @@ const handleGlobalStyleFile = (replaceIndexText) => {
|
|
|
249
236
|
return newReplaceIndexText;
|
|
250
237
|
};
|
|
251
238
|
exports.handleGlobalStyleFile = handleGlobalStyleFile;
|
|
252
|
-
const updateIndexFileText = (envPath, newFileText) => __awaiter(void 0, void 0, void 0, function* () {
|
|
253
|
-
const projectPath = process.cwd();
|
|
254
|
-
yield fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, `./.swico${envPath}index.js`), newFileText);
|
|
255
|
-
});
|
|
256
|
-
exports.updateIndexFileText = updateIndexFileText;
|
|
257
239
|
const initTemplateConfig = (routerConfig, templateType, env) => {
|
|
258
|
-
const projectPath = process.cwd();
|
|
259
|
-
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
260
240
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
yield fs_extra_1.default.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
241
|
+
const projectPath = process.cwd();
|
|
242
|
+
const envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
243
|
+
const oriEntryFilePath = path_1.default.resolve(__dirname, `../index.${templateType}.js`);
|
|
244
|
+
const targetEntryFilePath = path_1.default.resolve(projectPath, './.swico/index.js');
|
|
245
|
+
let replaceEntryText = yield fs_extra_1.default.readFile(oriEntryFilePath, 'utf8');
|
|
246
|
+
const formatHooksPath = path_1.default
|
|
247
|
+
.resolve(projectPath, './.swico/hooks')
|
|
248
|
+
.replaceAll('\\', '/');
|
|
249
|
+
replaceEntryText = replaceEntryText.replaceAll(`require("./template-root/.swico-${templateType}/hooks");`, `require("${formatHooksPath}");`);
|
|
250
|
+
const formatHistoryPath = path_1.default
|
|
251
|
+
.resolve(projectPath, `./.swico/.${env}/history`)
|
|
252
|
+
.replaceAll('\\', '/');
|
|
253
|
+
replaceEntryText = replaceEntryText.replaceAll('require("./mock-history");', `require("${formatHistoryPath}");`);
|
|
254
|
+
yield fs_extra_1.default.writeFile(targetEntryFilePath, replaceEntryText);
|
|
255
|
+
yield handleAndCopyRouterFile(routerConfig, templateType, env);
|
|
256
|
+
const oriHooksFilePath = path_1.default.resolve(__dirname, `../template-root/.swico-${templateType}/$env/hooks.js`);
|
|
257
|
+
const targetHooksFilePath = path_1.default.resolve(projectPath, './.swico/hooks.js');
|
|
258
|
+
let replaceHooksText = yield fs_extra_1.default.readFile(oriHooksFilePath, 'utf8');
|
|
269
259
|
replaceHooksText = replaceHooksText.replaceAll('$env', `.${env}`);
|
|
270
|
-
yield fs_extra_1.default.writeFile(
|
|
271
|
-
|
|
260
|
+
yield fs_extra_1.default.writeFile(targetHooksFilePath, replaceHooksText);
|
|
261
|
+
const oriHistoryFilePath = path_1.default.resolve(__dirname, `../template-root/.swico-${templateType}/$env/history`);
|
|
262
|
+
const targetHistoryFilePath = path_1.default.resolve(projectPath, `./.swico${envPath}history`);
|
|
263
|
+
yield fs_extra_1.default.copyFile(oriHistoryFilePath, targetHistoryFilePath);
|
|
264
|
+
const oriIndexFilePath = path_1.default.resolve(__dirname, `../template-root/.swico-${templateType}/hooks.js`);
|
|
265
|
+
const targetIndexFilePath = path_1.default.resolve(projectPath, `./.swico${envPath}index.js`);
|
|
266
|
+
let replaceIndexText = yield fs_extra_1.default.readFile(oriIndexFilePath, 'utf8');
|
|
272
267
|
replaceIndexText = (0, exports.handleGlobalStyleFile)(replaceIndexText);
|
|
273
268
|
if (templateType === 'react') {
|
|
274
269
|
replaceIndexText = yield (0, exports.handleLoadingFile)(projectPath, replaceIndexText);
|
|
275
270
|
}
|
|
276
|
-
yield
|
|
271
|
+
yield fs_extra_1.default.writeFile(targetIndexFilePath, replaceIndexText);
|
|
277
272
|
resolve(null);
|
|
278
273
|
}));
|
|
279
274
|
};
|