swico 1.0.1 → 1.1.0-beta.2
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 +3 -1
- package/src/command/start.js +48 -21
- package/src/config/webpack.base.react.js +39 -0
- package/src/config/webpack.base.vue.js +45 -0
- package/src/utils/config.js +58 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swico",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-beta.2",
|
|
4
4
|
"description": "Simple, efficient, and practical front-end framework",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -73,6 +73,8 @@
|
|
|
73
73
|
"postcss-loader": "8.1.0",
|
|
74
74
|
"postcss-preset-env": "9.3.0",
|
|
75
75
|
"prettier": "3.2.5",
|
|
76
|
+
"sass": "^1.77.5",
|
|
77
|
+
"sass-loader": "^14.2.1",
|
|
76
78
|
"style-loader": "3.3.0",
|
|
77
79
|
"swc-loader": "0.2.6",
|
|
78
80
|
"ts-node": "10.9.1",
|
package/src/command/start.js
CHANGED
|
@@ -57,18 +57,15 @@ var tools_1 = require("../utils/tools");
|
|
|
57
57
|
var config_1 = require("../utils/config");
|
|
58
58
|
var chokidar_1 = __importDefault(require("chokidar"));
|
|
59
59
|
var path_1 = __importDefault(require("path"));
|
|
60
|
-
var ora_1 = __importDefault(require("ora"));
|
|
61
60
|
var cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
62
61
|
var _a = process.env, envPort = _a.PORT, RESTART = _a.RESTART;
|
|
63
62
|
var package_json_1 = __importDefault(require("../../package.json"));
|
|
64
63
|
var chalk_1 = __importDefault(require("chalk"));
|
|
65
|
-
var spinner = (0, ora_1.default)();
|
|
66
64
|
var handleWatch = function (projectPath, devServer) {
|
|
67
65
|
var configFilesWatcher = chokidar_1.default
|
|
68
66
|
.watch([
|
|
69
67
|
path_1.default.join(projectPath, '/config/*.ts'),
|
|
70
|
-
path_1.default.join(projectPath, '/.eslintrc')
|
|
71
|
-
path_1.default.join(projectPath, '/src/loading/index.tsx')
|
|
68
|
+
path_1.default.join(projectPath, '/.eslintrc')
|
|
72
69
|
], {
|
|
73
70
|
interval: 500,
|
|
74
71
|
binaryInterval: 500,
|
|
@@ -115,8 +112,34 @@ var handleWatch = function (projectPath, devServer) {
|
|
|
115
112
|
}
|
|
116
113
|
});
|
|
117
114
|
}); });
|
|
115
|
+
var otherWatcher = chokidar_1.default
|
|
116
|
+
.watch([
|
|
117
|
+
path_1.default.join(projectPath, '/src/loading/index.tsx'),
|
|
118
|
+
path_1.default.join(projectPath, '/src/global.css'),
|
|
119
|
+
path_1.default.join(projectPath, '/src/global.less'),
|
|
120
|
+
path_1.default.join(projectPath, '/src/global.scss')
|
|
121
|
+
], {
|
|
122
|
+
interval: 500,
|
|
123
|
+
binaryInterval: 500,
|
|
124
|
+
ignoreInitial: true
|
|
125
|
+
})
|
|
126
|
+
.on('add', function (eventName, path) { return __awaiter(void 0, void 0, void 0, function () {
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
switch (_a.label) {
|
|
129
|
+
case 0: return [4, devServer.stop()];
|
|
130
|
+
case 1:
|
|
131
|
+
_a.sent();
|
|
132
|
+
return [4, otherWatcher.close()];
|
|
133
|
+
case 2:
|
|
134
|
+
_a.sent();
|
|
135
|
+
restartServer();
|
|
136
|
+
return [2];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}); });
|
|
118
140
|
};
|
|
119
141
|
var availablePort;
|
|
142
|
+
var routerBase = '/';
|
|
120
143
|
var restartServer = function () {
|
|
121
144
|
var result = cross_spawn_1.default.sync('cross-env', ["PORT=".concat(availablePort), 'RESTART=true', 'swico', 'start'], {
|
|
122
145
|
stdio: 'inherit'
|
|
@@ -158,10 +181,11 @@ var createCompileListener = function (compiler) {
|
|
|
158
181
|
});
|
|
159
182
|
};
|
|
160
183
|
function start() {
|
|
184
|
+
var _a, _b, _c, _d, _e, _f;
|
|
161
185
|
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
-
var
|
|
163
|
-
return __generator(this, function (
|
|
164
|
-
switch (
|
|
186
|
+
var _g, projectConfig, projectPath, customConfig, newRouterBase, startConfig, compiler, oriLogger, devServer, e_1, strErr;
|
|
187
|
+
return __generator(this, function (_h) {
|
|
188
|
+
switch (_h.label) {
|
|
165
189
|
case 0:
|
|
166
190
|
process.env.SWICO_ENV = 'dev';
|
|
167
191
|
if (RESTART !== 'true') {
|
|
@@ -170,42 +194,45 @@ function start() {
|
|
|
170
194
|
}
|
|
171
195
|
return [4, (0, tools_1.initIndexFile)()];
|
|
172
196
|
case 1:
|
|
173
|
-
|
|
197
|
+
_h.sent();
|
|
174
198
|
if (!(envPort !== null && envPort !== void 0)) return [3, 2];
|
|
175
|
-
|
|
199
|
+
_g = envPort;
|
|
176
200
|
return [3, 4];
|
|
177
201
|
case 2: return [4, (0, tools_1.getPort)()];
|
|
178
202
|
case 3:
|
|
179
|
-
|
|
180
|
-
|
|
203
|
+
_g = (_h.sent());
|
|
204
|
+
_h.label = 4;
|
|
181
205
|
case 4:
|
|
182
|
-
availablePort =
|
|
206
|
+
availablePort = _g;
|
|
183
207
|
return [4, (0, config_1.getProjectConfig)('dev')];
|
|
184
208
|
case 5:
|
|
185
|
-
projectConfig =
|
|
186
|
-
projectPath = projectConfig.projectPath;
|
|
209
|
+
projectConfig = _h.sent();
|
|
210
|
+
projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig;
|
|
211
|
+
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 : '/';
|
|
187
212
|
return [4, (0, webpack_dev_1.default)(projectConfig)];
|
|
188
213
|
case 6:
|
|
189
|
-
startConfig =
|
|
214
|
+
startConfig = _h.sent();
|
|
190
215
|
compiler = (0, webpack_1.default)(startConfig);
|
|
191
216
|
oriLogger = compiler.getInfrastructureLogger;
|
|
192
217
|
compiler.getInfrastructureLogger = getMockGetLogger(compiler);
|
|
193
218
|
devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
|
|
194
|
-
|
|
219
|
+
devServer.watchFiles([], {});
|
|
220
|
+
_h.label = 7;
|
|
195
221
|
case 7:
|
|
196
|
-
|
|
222
|
+
_h.trys.push([7, 9, , 10]);
|
|
197
223
|
return [4, devServer.start()];
|
|
198
224
|
case 8:
|
|
199
|
-
|
|
225
|
+
_h.sent();
|
|
200
226
|
createCompileListener(compiler);
|
|
201
227
|
compiler.getInfrastructureLogger = oriLogger;
|
|
202
228
|
handleWatch(projectPath, devServer);
|
|
203
|
-
if (RESTART !== 'true') {
|
|
204
|
-
tools_1.toast.info("Project is running at\uFF1A".concat(chalk_1.default.hex('#29abe0')("".concat(startConfig.devServer.server, "://localhost:").concat(availablePort
|
|
229
|
+
if (RESTART !== 'true' || newRouterBase !== routerBase) {
|
|
230
|
+
tools_1.toast.info("Project is running at\uFF1A".concat(chalk_1.default.hex('#29abe0')("".concat(startConfig.devServer.server, "://localhost:").concat(availablePort).concat(newRouterBase))));
|
|
205
231
|
}
|
|
232
|
+
routerBase = newRouterBase;
|
|
206
233
|
return [3, 10];
|
|
207
234
|
case 9:
|
|
208
|
-
e_1 =
|
|
235
|
+
e_1 = _h.sent();
|
|
209
236
|
strErr = e_1.toString();
|
|
210
237
|
tools_1.toast.error(strErr);
|
|
211
238
|
return [3, 10];
|
|
@@ -213,6 +213,45 @@ function default_1(_a) {
|
|
|
213
213
|
'less-loader'
|
|
214
214
|
]
|
|
215
215
|
},
|
|
216
|
+
{
|
|
217
|
+
test: /\.module\.scss$/,
|
|
218
|
+
use: [
|
|
219
|
+
env === 'dev' ? 'style-loader' : mini_css_extract_plugin_1.default.loader,
|
|
220
|
+
{
|
|
221
|
+
loader: 'css-loader',
|
|
222
|
+
options: {
|
|
223
|
+
modules: {
|
|
224
|
+
localIdentName: 'moduleStyle_[local]_[contenthash:8]'
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
loader: 'postcss-loader',
|
|
230
|
+
options: {
|
|
231
|
+
postcssOptions: {
|
|
232
|
+
plugins: [['postcss-preset-env', 'autoprefixer']]
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
'sass-loader'
|
|
237
|
+
]
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
test: /\.scss$/,
|
|
241
|
+
use: [
|
|
242
|
+
env === 'dev' ? 'style-loader' : mini_css_extract_plugin_1.default.loader,
|
|
243
|
+
'css-loader',
|
|
244
|
+
{
|
|
245
|
+
loader: 'postcss-loader',
|
|
246
|
+
options: {
|
|
247
|
+
postcssOptions: {
|
|
248
|
+
plugins: [['autoprefixer']]
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
'sass-loader'
|
|
253
|
+
]
|
|
254
|
+
},
|
|
216
255
|
{
|
|
217
256
|
test: /\.(jpg|png|gif|webp|bmp|jpeg|svg)$/,
|
|
218
257
|
type: 'asset',
|
|
@@ -224,6 +224,51 @@ function default_1(_a) {
|
|
|
224
224
|
}
|
|
225
225
|
]
|
|
226
226
|
},
|
|
227
|
+
{
|
|
228
|
+
test: /\.less$/,
|
|
229
|
+
oneOf: [
|
|
230
|
+
{
|
|
231
|
+
resourceQuery: /module/,
|
|
232
|
+
use: [
|
|
233
|
+
'vue-style-loader',
|
|
234
|
+
{
|
|
235
|
+
loader: 'css-loader',
|
|
236
|
+
options: {
|
|
237
|
+
modules: {
|
|
238
|
+
localIdentName: 'moduleStyle_[local]_[contenthash:8]'
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
loader: 'postcss-loader',
|
|
244
|
+
options: {
|
|
245
|
+
postcssOptions: {
|
|
246
|
+
plugins: [['autoprefixer']]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
'sass-loader'
|
|
251
|
+
]
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
use: [
|
|
255
|
+
env === 'dev'
|
|
256
|
+
? 'vue-style-loader'
|
|
257
|
+
: mini_css_extract_plugin_1.default.loader,
|
|
258
|
+
'css-loader',
|
|
259
|
+
{
|
|
260
|
+
loader: 'postcss-loader',
|
|
261
|
+
options: {
|
|
262
|
+
postcssOptions: {
|
|
263
|
+
plugins: [['autoprefixer']]
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
'sass-loader'
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
},
|
|
227
272
|
{
|
|
228
273
|
test: /\.(jpg|png|gif|webp|bmp|jpeg|svg)$/,
|
|
229
274
|
type: 'asset',
|
package/src/utils/config.js
CHANGED
|
@@ -263,12 +263,35 @@ var formatRouterConfig = function (_a, templateType, env) {
|
|
|
263
263
|
});
|
|
264
264
|
}); });
|
|
265
265
|
};
|
|
266
|
+
var getGlobalStyleFilePath = function () {
|
|
267
|
+
var filePath, fileType;
|
|
268
|
+
var cssPath = path_1.default.resolve(projectPath, './src/global.css');
|
|
269
|
+
var lessPath = path_1.default.resolve(projectPath, './src/global.less');
|
|
270
|
+
var scssPath = path_1.default.resolve(projectPath, './src/global.scss');
|
|
271
|
+
switch (true) {
|
|
272
|
+
case fs_extra_1.default.existsSync(cssPath):
|
|
273
|
+
filePath = cssPath;
|
|
274
|
+
fileType = 'css';
|
|
275
|
+
break;
|
|
276
|
+
case fs_extra_1.default.existsSync(lessPath):
|
|
277
|
+
filePath = lessPath;
|
|
278
|
+
fileType = 'less';
|
|
279
|
+
break;
|
|
280
|
+
case fs_extra_1.default.existsSync(scssPath):
|
|
281
|
+
filePath = scssPath;
|
|
282
|
+
fileType = 'scss';
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
return { filePath: filePath, fileType: fileType };
|
|
288
|
+
};
|
|
266
289
|
var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
267
290
|
var envPath = env === 'dev' ? '/.dev/' : '/.prod/';
|
|
268
291
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
269
|
-
var copyTargetPath, replaceIndexText, hooksFilePath, replaceHooksText,
|
|
270
|
-
return __generator(this, function (
|
|
271
|
-
switch (
|
|
292
|
+
var copyTargetPath, replaceIndexText, hooksFilePath, replaceHooksText, _a, styleFilePath, styleFileType, e_1;
|
|
293
|
+
return __generator(this, function (_b) {
|
|
294
|
+
switch (_b.label) {
|
|
272
295
|
case 0:
|
|
273
296
|
copyTargetPath = path_1.default.resolve(projectPath, "./src/.swico".concat(envPath));
|
|
274
297
|
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType, "/$env")), copyTargetPath, function (fileName) {
|
|
@@ -278,65 +301,59 @@ var initTemplateConfig = function (routerConfig, templateType, env) {
|
|
|
278
301
|
: !['react-hooks.js'].includes(fileName));
|
|
279
302
|
})];
|
|
280
303
|
case 1:
|
|
281
|
-
|
|
304
|
+
_b.sent();
|
|
282
305
|
return [4, (0, tools_1.copyDirFiles)(path_1.default.resolve(__dirname, "../template/".concat(templateType)), path_1.default.resolve(projectPath, './src/.swico'), function (fileName) {
|
|
283
306
|
return ['react-hooks.js', 'vue-hooks.js', 'loading.js', 'Container.vue'].includes(fileName);
|
|
284
307
|
})];
|
|
285
308
|
case 2:
|
|
286
|
-
|
|
309
|
+
_b.sent();
|
|
287
310
|
return [4, formatRouterConfig(routerConfig, templateType, env)];
|
|
288
311
|
case 3:
|
|
289
|
-
|
|
312
|
+
_b.sent();
|
|
290
313
|
return [4, fs_extra_1.default.readFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), 'utf8')];
|
|
291
314
|
case 4:
|
|
292
|
-
replaceIndexText =
|
|
315
|
+
replaceIndexText = _b.sent();
|
|
293
316
|
hooksFilePath = path_1.default.resolve(projectPath, "./src/.swico/".concat(templateType, "-hooks.js"));
|
|
294
317
|
return [4, fs_extra_1.default.readFile(hooksFilePath, 'utf8')];
|
|
295
318
|
case 5:
|
|
296
|
-
replaceHooksText =
|
|
319
|
+
replaceHooksText = _b.sent();
|
|
297
320
|
replaceHooksText = replaceHooksText.replaceAll('$env', ".".concat(env));
|
|
298
321
|
return [4, fs_extra_1.default.writeFile(hooksFilePath, replaceHooksText)];
|
|
299
322
|
case 6:
|
|
300
|
-
|
|
301
|
-
_a.
|
|
323
|
+
_b.sent();
|
|
324
|
+
_a = getGlobalStyleFilePath(), styleFilePath = _a.filePath, styleFileType = _a.fileType;
|
|
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
|
+
}
|
|
332
|
+
if (!(templateType === 'vue')) return [3, 8];
|
|
333
|
+
replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
|
|
334
|
+
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
302
335
|
case 7:
|
|
303
|
-
|
|
304
|
-
return [
|
|
336
|
+
_b.sent();
|
|
337
|
+
return [3, 14];
|
|
305
338
|
case 8:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
replaceIndexText = 'require("../../global.less");\n' + replaceIndexText;
|
|
309
|
-
return [3, 10];
|
|
339
|
+
if (!(templateType === 'react')) return [3, 14];
|
|
340
|
+
_b.label = 9;
|
|
310
341
|
case 9:
|
|
311
|
-
|
|
312
|
-
replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
|
|
313
|
-
return [3, 10];
|
|
314
|
-
case 10:
|
|
315
|
-
if (!(templateType === 'vue')) return [3, 12];
|
|
316
|
-
replaceIndexText = replaceIndexText.replace('"../Container"', '"../Container.vue"');
|
|
317
|
-
return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
|
|
318
|
-
case 11:
|
|
319
|
-
_a.sent();
|
|
320
|
-
return [3, 18];
|
|
321
|
-
case 12:
|
|
322
|
-
if (!(templateType === 'react')) return [3, 18];
|
|
323
|
-
_a.label = 13;
|
|
324
|
-
case 13:
|
|
325
|
-
_a.trys.push([13, 15, 16, 18]);
|
|
342
|
+
_b.trys.push([9, 11, 12, 14]);
|
|
326
343
|
return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/loading/index.tsx'), fs_extra_1.default.constants.F_OK)];
|
|
327
|
-
case
|
|
328
|
-
|
|
344
|
+
case 10:
|
|
345
|
+
_b.sent();
|
|
329
346
|
replaceIndexText = replaceIndexText.replace('"../loading"', '"../../loading"');
|
|
330
|
-
return [3,
|
|
331
|
-
case
|
|
332
|
-
|
|
347
|
+
return [3, 14];
|
|
348
|
+
case 11:
|
|
349
|
+
e_1 = _b.sent();
|
|
333
350
|
replaceIndexText = replaceIndexText.replace('"../../loading"', '"../loading"');
|
|
334
|
-
return [3,
|
|
335
|
-
case
|
|
336
|
-
case
|
|
337
|
-
|
|
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();
|
|
338
355
|
return [7];
|
|
339
|
-
case
|
|
356
|
+
case 14:
|
|
340
357
|
resolve(null);
|
|
341
358
|
return [2];
|
|
342
359
|
}
|