swico 1.0.1-beta.1 → 1.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swico",
3
- "version": "1.0.1-beta.1",
3
+ "version": "1.1.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",
@@ -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",
@@ -158,10 +158,11 @@ var createCompileListener = function (compiler) {
158
158
  });
159
159
  };
160
160
  function start() {
161
+ var _a, _b, _c, _d, _e, _f;
161
162
  return __awaiter(this, void 0, void 0, function () {
162
- var _a, projectConfig, projectPath, startConfig, compiler, oriLogger, devServer, e_1, strErr;
163
- return __generator(this, function (_b) {
164
- switch (_b.label) {
163
+ var _g, projectConfig, projectPath, customConfig, routerBase, startConfig, compiler, oriLogger, devServer, e_1, strErr;
164
+ return __generator(this, function (_h) {
165
+ switch (_h.label) {
165
166
  case 0:
166
167
  process.env.SWICO_ENV = 'dev';
167
168
  if (RESTART !== 'true') {
@@ -170,42 +171,43 @@ function start() {
170
171
  }
171
172
  return [4, (0, tools_1.initIndexFile)()];
172
173
  case 1:
173
- _b.sent();
174
+ _h.sent();
174
175
  if (!(envPort !== null && envPort !== void 0)) return [3, 2];
175
- _a = envPort;
176
+ _g = envPort;
176
177
  return [3, 4];
177
178
  case 2: return [4, (0, tools_1.getPort)()];
178
179
  case 3:
179
- _a = (_b.sent());
180
- _b.label = 4;
180
+ _g = (_h.sent());
181
+ _h.label = 4;
181
182
  case 4:
182
- availablePort = _a;
183
+ availablePort = _g;
183
184
  return [4, (0, config_1.getProjectConfig)('dev')];
184
185
  case 5:
185
- projectConfig = _b.sent();
186
- projectPath = projectConfig.projectPath;
186
+ projectConfig = _h.sent();
187
+ projectPath = projectConfig.projectPath, customConfig = projectConfig.customConfig;
188
+ routerBase = (_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
189
  return [4, (0, webpack_dev_1.default)(projectConfig)];
188
190
  case 6:
189
- startConfig = _b.sent();
191
+ startConfig = _h.sent();
190
192
  compiler = (0, webpack_1.default)(startConfig);
191
193
  oriLogger = compiler.getInfrastructureLogger;
192
194
  compiler.getInfrastructureLogger = getMockGetLogger(compiler);
193
195
  devServer = new webpack_dev_server_1.default(__assign(__assign({}, startConfig.devServer), { port: availablePort }), compiler);
194
- _b.label = 7;
196
+ _h.label = 7;
195
197
  case 7:
196
- _b.trys.push([7, 9, , 10]);
198
+ _h.trys.push([7, 9, , 10]);
197
199
  return [4, devServer.start()];
198
200
  case 8:
199
- _b.sent();
201
+ _h.sent();
200
202
  createCompileListener(compiler);
201
203
  compiler.getInfrastructureLogger = oriLogger;
202
204
  handleWatch(projectPath, devServer);
203
205
  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, "/"))));
206
+ tools_1.toast.info("Project is running at\uFF1A".concat(chalk_1.default.hex('#29abe0')("".concat(startConfig.devServer.server, "://localhost:").concat(availablePort).concat(routerBase))));
205
207
  }
206
208
  return [3, 10];
207
209
  case 9:
208
- e_1 = _b.sent();
210
+ e_1 = _h.sent();
209
211
  strErr = e_1.toString();
210
212
  tools_1.toast.error(strErr);
211
213
  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',
@@ -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, e_1, e_2;
270
- return __generator(this, function (_a) {
271
- switch (_a.label) {
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
- _a.sent();
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
- _a.sent();
309
+ _b.sent();
287
310
  return [4, formatRouterConfig(routerConfig, templateType, env)];
288
311
  case 3:
289
- _a.sent();
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 = _a.sent();
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 = _a.sent();
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
- _a.sent();
301
- _a.label = 7;
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
- _a.trys.push([7, 9, , 10]);
304
- return [4, fs_extra_1.default.access(path_1.default.resolve(projectPath, './src/global.less'), fs_extra_1.default.constants.F_OK)];
336
+ _b.sent();
337
+ return [3, 14];
305
338
  case 8:
306
- _a.sent();
307
- replaceIndexText = replaceIndexText.replaceAll('require("../../global.less");', '');
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
- e_1 = _a.sent();
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 14:
328
- _a.sent();
344
+ case 10:
345
+ _b.sent();
329
346
  replaceIndexText = replaceIndexText.replace('"../loading"', '"../../loading"');
330
- return [3, 18];
331
- case 15:
332
- e_2 = _a.sent();
347
+ return [3, 14];
348
+ case 11:
349
+ e_1 = _b.sent();
333
350
  replaceIndexText = replaceIndexText.replace('"../../loading"', '"../loading"');
334
- return [3, 18];
335
- case 16: return [4, fs_extra_1.default.writeFile(path_1.default.resolve(projectPath, "./src/.swico".concat(envPath, "index.js")), replaceIndexText)];
336
- case 17:
337
- _a.sent();
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 18:
356
+ case 14:
340
357
  resolve(null);
341
358
  return [2];
342
359
  }