swico 1.7.3 → 2.0.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.
Files changed (32) hide show
  1. package/package.json +7 -13
  2. package/src/bin.js +6 -6
  3. package/src/command/build.js +33 -73
  4. package/src/command/start.js +99 -191
  5. package/src/config/rsbpack.dev.js +104 -0
  6. package/src/config/{webpack.base.react.d.ts → rspack.base.react.d.ts} +13 -3
  7. package/src/config/rspack.base.react.js +193 -0
  8. package/src/config/{webpack.base.vue.d.ts → rspack.base.vue.d.ts} +13 -1
  9. package/src/config/rspack.base.vue.js +282 -0
  10. package/src/config/rspack.prod.js +123 -0
  11. package/src/index.js +3 -5
  12. package/src/index.react.js +5 -10
  13. package/src/index.vue.js +4 -6
  14. package/src/project-path/.swico-react/$env/history.js +65 -66
  15. package/src/project-path/.swico-react/$env/index.js +29 -47
  16. package/src/project-path/.swico-react/loading.js +1 -1
  17. package/src/project-path/.swico-react/react-hooks.js +24 -37
  18. package/src/project-path/.swico-vue/$env/history.js +25 -36
  19. package/src/project-path/.swico-vue/$env/index.js +7 -7
  20. package/src/project-path/.swico-vue/Container.js +1 -1
  21. package/src/project-path/.swico-vue/vue-hooks.js +17 -28
  22. package/src/project-path/src/layout/Layout.js +1 -1
  23. package/src/project-path/src/layout/index.js +3 -3
  24. package/src/task.js +13 -58
  25. package/src/utils/config.js +185 -349
  26. package/src/utils/tools.js +103 -199
  27. package/src/config/webpack.base.react.js +0 -315
  28. package/src/config/webpack.base.vue.js +0 -338
  29. package/src/config/webpack.dev.js +0 -159
  30. package/src/config/webpack.prod.js +0 -193
  31. /package/src/config/{webpack.dev.d.ts → rsbpack.dev.d.ts} +0 -0
  32. /package/src/config/{webpack.prod.d.ts → rspack.prod.d.ts} +0 -0
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -42,33 +31,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
43
32
  });
44
33
  };
45
- var __generator = (this && this.__generator) || function (thisArg, body) {
46
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
- function verb(n) { return function (v) { return step([n, v]); }; }
49
- function step(op) {
50
- if (f) throw new TypeError("Generator is already executing.");
51
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
- if (y = 0, t) op = [op[0] & 2, t.value];
54
- switch (op[0]) {
55
- case 0: case 1: t = op; break;
56
- case 4: _.label++; return { value: op[1], done: false };
57
- case 5: _.label++; y = op[1]; op = [0]; continue;
58
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
- default:
60
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
- if (t[2]) _.ops.pop();
65
- _.trys.pop(); continue;
66
- }
67
- op = body.call(thisArg, _);
68
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
- }
71
- };
72
34
  var __asyncValues = (this && this.__asyncValues) || function (o) {
73
35
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
74
36
  var m = o[Symbol.asyncIterator], i;
@@ -81,117 +43,75 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
81
43
  };
82
44
  Object.defineProperty(exports, "__esModule", { value: true });
83
45
  exports.initIndexFile = exports.toast = exports.colorConfig = exports.getPort = exports.getFormatRouter = exports.copyDirFiles = void 0;
84
- var portfinder_1 = __importDefault(require("portfinder"));
85
- var fs_extra_1 = __importDefault(require("fs-extra"));
86
- var path_1 = __importDefault(require("path"));
87
- var chalk_1 = __importDefault(require("chalk"));
88
- var process = __importStar(require("process"));
89
- var copyDirFiles = function (src, dest, filter) { return __awaiter(void 0, void 0, void 0, function () {
90
- var _copy, e_1;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0:
94
- _copy = function (src, dest) { return __awaiter(void 0, void 0, void 0, function () {
95
- var files, filterFiles, _a, filterFiles_1, filterFiles_1_1, file, srcPath, destPath, srcStat, e_2_1;
96
- var _b, e_2, _c, _d;
97
- return __generator(this, function (_e) {
98
- switch (_e.label) {
99
- case 0: return [4, fs_extra_1.default.readdir(src)];
100
- case 1:
101
- files = _e.sent();
102
- filterFiles = files.filter(function (fileName) { return (filter ? filter(fileName) === true : true); });
103
- _e.label = 2;
104
- case 2:
105
- _e.trys.push([2, 10, 11, 16]);
106
- _a = true, filterFiles_1 = __asyncValues(filterFiles);
107
- _e.label = 3;
108
- case 3: return [4, filterFiles_1.next()];
109
- case 4:
110
- if (!(filterFiles_1_1 = _e.sent(), _b = filterFiles_1_1.done, !_b)) return [3, 9];
111
- _d = filterFiles_1_1.value;
112
- _a = false;
113
- file = _d;
114
- srcPath = path_1.default.join(src, file);
115
- destPath = path_1.default.join(dest, file);
116
- return [4, fs_extra_1.default.stat(srcPath)];
117
- case 5:
118
- srcStat = _e.sent();
119
- if (!srcStat.isDirectory()) return [3, 6];
120
- _copy(srcPath, destPath);
121
- return [3, 8];
122
- case 6: return [4, fs_extra_1.default.copyFile(srcPath, destPath)];
123
- case 7:
124
- _e.sent();
125
- _e.label = 8;
126
- case 8:
127
- _a = true;
128
- return [3, 3];
129
- case 9: return [3, 16];
130
- case 10:
131
- e_2_1 = _e.sent();
132
- e_2 = { error: e_2_1 };
133
- return [3, 16];
134
- case 11:
135
- _e.trys.push([11, , 14, 15]);
136
- if (!(!_a && !_b && (_c = filterFiles_1.return))) return [3, 13];
137
- return [4, _c.call(filterFiles_1)];
138
- case 12:
139
- _e.sent();
140
- _e.label = 13;
141
- case 13: return [3, 15];
142
- case 14:
143
- if (e_2) throw e_2.error;
144
- return [7];
145
- case 15: return [7];
146
- case 16: return [2, null];
147
- }
148
- });
149
- }); };
150
- _a.label = 1;
151
- case 1:
152
- _a.trys.push([1, 3, , 5]);
153
- return [4, fs_extra_1.default.access(dest)];
154
- case 2:
155
- _a.sent();
156
- return [3, 5];
157
- case 3:
158
- e_1 = _a.sent();
159
- return [4, fs_extra_1.default.mkdir(dest, { recursive: true })];
160
- case 4:
161
- _a.sent();
162
- return [3, 5];
163
- case 5: return [4, _copy(src, dest)];
164
- case 6:
165
- _a.sent();
166
- return [2];
46
+ const portfinder_1 = __importDefault(require("portfinder"));
47
+ const fs_extra_1 = __importDefault(require("fs-extra"));
48
+ const path_1 = __importDefault(require("path"));
49
+ const chalk_1 = __importDefault(require("chalk"));
50
+ const process = __importStar(require("process"));
51
+ const copyDirFiles = (src, dest, filter) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const _copy = (src, dest) => __awaiter(void 0, void 0, void 0, function* () {
53
+ var _a, e_1, _b, _c;
54
+ const files = yield fs_extra_1.default.readdir(src);
55
+ const filterFiles = files.filter((fileName) => (filter ? filter(fileName) === true : true));
56
+ try {
57
+ for (var _d = true, filterFiles_1 = __asyncValues(filterFiles), filterFiles_1_1; filterFiles_1_1 = yield filterFiles_1.next(), _a = filterFiles_1_1.done, !_a; _d = true) {
58
+ _c = filterFiles_1_1.value;
59
+ _d = false;
60
+ const file = _c;
61
+ const srcPath = path_1.default.join(src, file);
62
+ const destPath = path_1.default.join(dest, file);
63
+ const srcStat = yield fs_extra_1.default.stat(srcPath);
64
+ if (srcStat.isDirectory()) {
65
+ _copy(srcPath, destPath);
66
+ }
67
+ else {
68
+ yield fs_extra_1.default.copyFile(srcPath, destPath);
69
+ }
70
+ }
71
+ }
72
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
73
+ finally {
74
+ try {
75
+ if (!_d && !_a && (_b = filterFiles_1.return)) yield _b.call(filterFiles_1);
76
+ }
77
+ finally { if (e_1) throw e_1.error; }
167
78
  }
79
+ return null;
168
80
  });
169
- }); };
81
+ try {
82
+ yield fs_extra_1.default.access(dest);
83
+ }
84
+ catch (e) {
85
+ yield fs_extra_1.default.mkdir(dest, { recursive: true });
86
+ }
87
+ yield _copy(src, dest);
88
+ });
170
89
  exports.copyDirFiles = copyDirFiles;
171
- var getFormatRouter = function (projectPath, routes, templateType) {
172
- var _main = function (item) {
173
- var component = item.component, name = item.name, children = item.children, redirect = item.redirect, decorator = item.decorator;
90
+ const getFormatRouter = (projectPath, routes, templateType) => {
91
+ const _main = (item) => {
92
+ const { component, name, children, redirect, decorator } = item;
174
93
  return decorator
175
- ? __assign(__assign({}, item), { component: "()=>import('".concat(projectPath, "/src/pages/").concat(decorator).concat(templateType === 'vue' ? '.vue' : '', "')"), children: [
94
+ ? Object.assign(Object.assign({}, item), { component: `()=>import('${projectPath}/src/pages/${decorator}${templateType === 'vue' ? '.vue' : ''}')`, children: [
176
95
  {
177
96
  path: '',
178
97
  component: component
179
- ? "()=>import('".concat(projectPath, "/src/pages/").concat(component).concat(templateType === 'vue' ? '.vue' : '', "')")
98
+ ? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
180
99
  : undefined,
181
- name: name,
182
- redirect: redirect,
183
- children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined
100
+ name,
101
+ redirect,
102
+ children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined
184
103
  }
185
- ] }) : __assign(__assign({}, item), { component: component
186
- ? "()=>import('".concat(projectPath, "/src/pages/").concat(component).concat(templateType === 'vue' ? '.vue' : '', "')")
187
- : undefined, name: name, redirect: redirect, children: children ? children === null || children === void 0 ? void 0 : children.map(function (item) { return _main(item); }) : undefined });
104
+ ] }) : Object.assign(Object.assign({}, item), { component: component
105
+ ? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
106
+ : undefined, name,
107
+ redirect, children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined });
188
108
  };
189
- return routes.map(function (item) {
109
+ return routes.map((item) => {
190
110
  return _main(item);
191
111
  });
192
112
  };
193
113
  exports.getFormatRouter = getFormatRouter;
194
- var getPort = function () {
114
+ const getPort = () => {
195
115
  return portfinder_1.default.getPortPromise({
196
116
  port: 3000,
197
117
  stopPort: 3333
@@ -205,93 +125,77 @@ exports.colorConfig = {
205
125
  error: '#ff0000'
206
126
  };
207
127
  exports.toast = {
208
- info: function (message, options) {
209
- var _a = (options || {}).wrap, wrap = _a === void 0 ? false : _a;
210
- console.log("".concat(chalk_1.default.hex(exports.colorConfig.theme).bold('info'), " - ").concat(message).concat(wrap ? '\n' : ''));
128
+ info: (message, options) => {
129
+ const { wrap = false } = options || {};
130
+ console.log(`${chalk_1.default.hex(exports.colorConfig.theme).bold('info')} - ${message}${wrap ? '\n' : ''}`);
211
131
  },
212
- success: function (message, options) {
213
- var _a = (options || {}).wrap, wrap = _a === void 0 ? true : _a;
214
- console.log("".concat(chalk_1.default.hex(exports.colorConfig.success).bold('info'), " - ").concat(message).concat(wrap ? '\n' : ''));
132
+ success: (message, options) => {
133
+ const { wrap = true } = options || {};
134
+ console.log(`${chalk_1.default.hex(exports.colorConfig.success).bold('info')} - ${message}${wrap ? '\n' : ''}`);
215
135
  },
216
- error: function (message, options) {
217
- var _a = options || {}, inline = _a.inline, title = _a.title;
136
+ error: (message, options) => {
137
+ const { inline, title } = options || {};
218
138
  if (inline) {
219
- console.log("".concat(chalk_1.default.red.bold('error'), " - ").concat(message));
139
+ console.log(`${chalk_1.default.red.bold('error')} - ${message}`);
220
140
  }
221
141
  else {
222
142
  if (Array.isArray(message)) {
223
143
  if (message.length > 0) {
224
- console.log("".concat(chalk_1.default.red.bold('error'), " - ").concat(title || 'There are some errors about Swico', "\uFF1A"));
144
+ console.log(`${chalk_1.default.red.bold('error')} - ${title || 'There are some errors about Swico'}:`);
225
145
  }
226
- message.forEach(function (item) {
227
- console.log("> ".concat(chalk_1.default.red.bold(item)));
146
+ message.forEach((item) => {
147
+ console.log(`> ${chalk_1.default.red.bold(item)}`);
228
148
  });
229
149
  }
230
150
  else if (message) {
231
- console.log("".concat(chalk_1.default.red.bold('error'), " - ").concat(title || 'There are some errors about Swico', "\uFF1A"));
232
- console.log("> ".concat(chalk_1.default.red.bold(message)));
151
+ console.log(`${chalk_1.default.red.bold('error')} - ${title || 'There are some errors about Swico'}:`);
152
+ console.log(`> ${chalk_1.default.red.bold(message)}`);
233
153
  }
234
154
  }
235
155
  },
236
- warning: function (message, options) {
237
- var _a = options || {}, inline = _a.inline, title = _a.title;
238
- var color = exports.colorConfig.warning;
156
+ warning: (message, options) => {
157
+ const { inline, title } = options || {};
158
+ const { warning: color } = exports.colorConfig;
239
159
  if (inline) {
240
- console.log("".concat(chalk_1.default.hex(color).bold('warning'), " - ").concat(message));
160
+ console.log(`${chalk_1.default.hex(color).bold('warning')} - ${message}`);
241
161
  }
242
162
  else {
243
- console.log("".concat(chalk_1.default.hex(color).bold('warning'), " - ").concat(title || 'There are some warnings about Swico', "\uFF1A"));
163
+ console.log(`${chalk_1.default.hex(color).bold('warning')} - ${title || 'There are some warnings about Swico'}:`);
244
164
  if (Array.isArray(message)) {
245
- message.forEach(function (item) {
246
- console.log("> ".concat(chalk_1.default.hex(color).bold(item)));
165
+ message.forEach((item) => {
166
+ console.log(`> ${chalk_1.default.hex(color).bold(item)}`);
247
167
  });
248
168
  }
249
169
  else if (message) {
250
- console.log("> ".concat(chalk_1.default.hex(color).bold(message)));
170
+ console.log(`> ${chalk_1.default.hex(color).bold(message)}`);
251
171
  }
252
172
  }
253
173
  }
254
174
  };
255
- var initIndexFile = function () { return __awaiter(void 0, void 0, void 0, function () {
256
- var fileText, targetPath, projectPath, formatHooksPath, formatDevHistoryPath, formatProdHistoryPath;
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0: return [4, fs_extra_1.default.readFile(path_1.default.resolve(__dirname, '../index.js'), 'utf8')];
260
- case 1:
261
- fileText = _a.sent();
262
- targetPath = path_1.default.resolve(__dirname, '../index.js');
263
- projectPath = process.cwd();
264
- formatHooksPath = path_1.default
265
- .resolve(projectPath, './.swico/react-hooks')
266
- .replaceAll('\\', '/');
267
- if (!fileText.includes("require(\"".concat(formatHooksPath, "\");"))) return [3, 3];
268
- fileText = fileText.replaceAll("require(\"".concat(formatHooksPath, "\");"), 'require("./project-path/.swico-react/react-hooks");');
269
- return [4, fs_extra_1.default.writeFile(targetPath, fileText)];
270
- case 2:
271
- _a.sent();
272
- _a.label = 3;
273
- case 3:
274
- formatDevHistoryPath = path_1.default
275
- .resolve(projectPath, './.swico/.dev/history')
276
- .replaceAll('\\', '/');
277
- formatProdHistoryPath = path_1.default
278
- .resolve(projectPath, './.swico/.prod/history')
279
- .replaceAll('\\', '/');
280
- if (!fileText.includes("require(\"".concat(formatDevHistoryPath, "\");"))) return [3, 5];
281
- fileText = fileText.replaceAll("require(\"".concat(formatDevHistoryPath, "\");"), 'require("./mock-history");');
282
- return [4, fs_extra_1.default.writeFile(targetPath, fileText)];
283
- case 4:
284
- _a.sent();
285
- return [3, 7];
286
- case 5:
287
- if (!fileText.includes("require(\"".concat(formatProdHistoryPath, "\");"))) return [3, 7];
288
- fileText = fileText.replaceAll("require(\"".concat(formatProdHistoryPath, "\");"), 'require("./mock-history");');
289
- return [4, fs_extra_1.default.writeFile(targetPath, fileText)];
290
- case 6:
291
- _a.sent();
292
- _a.label = 7;
293
- case 7: return [2];
294
- }
295
- });
296
- }); };
175
+ const initIndexFile = () => __awaiter(void 0, void 0, void 0, function* () {
176
+ let fileText = yield fs_extra_1.default.readFile(path_1.default.resolve(__dirname, '../index.js'), 'utf8');
177
+ const targetPath = path_1.default.resolve(__dirname, '../index.js');
178
+ const projectPath = process.cwd();
179
+ const formatHooksPath = path_1.default
180
+ .resolve(projectPath, './.swico/react-hooks')
181
+ .replaceAll('\\', '/');
182
+ if (fileText.includes(`require("${formatHooksPath}");`)) {
183
+ fileText = fileText.replaceAll(`require("${formatHooksPath}");`, 'require("./project-path/.swico-react/react-hooks");');
184
+ yield fs_extra_1.default.writeFile(targetPath, fileText);
185
+ }
186
+ const formatDevHistoryPath = path_1.default
187
+ .resolve(projectPath, './.swico/.dev/history')
188
+ .replaceAll('\\', '/');
189
+ const formatProdHistoryPath = path_1.default
190
+ .resolve(projectPath, './.swico/.prod/history')
191
+ .replaceAll('\\', '/');
192
+ if (fileText.includes(`require("${formatDevHistoryPath}");`)) {
193
+ fileText = fileText.replaceAll(`require("${formatDevHistoryPath}");`, 'require("./mock-history");');
194
+ yield fs_extra_1.default.writeFile(targetPath, fileText);
195
+ }
196
+ else if (fileText.includes(`require("${formatProdHistoryPath}");`)) {
197
+ fileText = fileText.replaceAll(`require("${formatProdHistoryPath}");`, 'require("./mock-history");');
198
+ yield fs_extra_1.default.writeFile(targetPath, fileText);
199
+ }
200
+ });
297
201
  exports.initIndexFile = initIndexFile;