swico 1.7.3 → 2.0.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 +7 -13
- package/src/bin.js +6 -6
- package/src/command/build.js +33 -73
- package/src/command/start.js +99 -191
- package/src/config/rsbpack.dev.js +104 -0
- package/src/config/{webpack.base.react.d.ts → rspack.base.react.d.ts} +13 -3
- package/src/config/rspack.base.react.js +193 -0
- package/src/config/{webpack.base.vue.d.ts → rspack.base.vue.d.ts} +13 -1
- package/src/config/rspack.base.vue.js +282 -0
- package/src/config/rspack.prod.js +123 -0
- package/src/index.js +3 -5
- package/src/index.react.js +5 -10
- package/src/index.vue.js +4 -6
- package/src/project-path/.swico-react/$env/history.js +65 -66
- package/src/project-path/.swico-react/$env/index.js +29 -47
- package/src/project-path/.swico-react/loading.js +1 -1
- package/src/project-path/.swico-react/react-hooks.js +24 -37
- package/src/project-path/.swico-vue/$env/history.js +25 -36
- package/src/project-path/.swico-vue/$env/index.js +7 -7
- package/src/project-path/.swico-vue/Container.js +1 -1
- package/src/project-path/.swico-vue/vue-hooks.js +17 -28
- package/src/project-path/src/layout/Layout.js +1 -1
- package/src/project-path/src/layout/index.js +3 -3
- package/src/task.js +13 -58
- package/src/utils/config.js +185 -349
- package/src/utils/tools.js +103 -199
- package/src/config/webpack.base.react.js +0 -315
- package/src/config/webpack.base.vue.js +0 -338
- package/src/config/webpack.dev.js +0 -159
- package/src/config/webpack.prod.js +0 -193
- /package/src/config/{webpack.dev.d.ts → rsbpack.dev.d.ts} +0 -0
- /package/src/config/{webpack.prod.d.ts → rspack.prod.d.ts} +0 -0
package/src/utils/tools.js
CHANGED
|
@@ -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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
90
|
+
const getFormatRouter = (projectPath, routes, templateType) => {
|
|
91
|
+
const _main = (item) => {
|
|
92
|
+
const { component, name, children, redirect, decorator } = item;
|
|
174
93
|
return decorator
|
|
175
|
-
?
|
|
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
|
-
?
|
|
98
|
+
? `()=>import('${projectPath}/src/pages/${component}${templateType === 'vue' ? '.vue' : ''}')`
|
|
180
99
|
: undefined,
|
|
181
|
-
name
|
|
182
|
-
redirect
|
|
183
|
-
children: children ? children === null || children === void 0 ? void 0 : children.map(
|
|
100
|
+
name,
|
|
101
|
+
redirect,
|
|
102
|
+
children: children ? children === null || children === void 0 ? void 0 : children.map((item) => _main(item)) : undefined
|
|
184
103
|
}
|
|
185
|
-
] }) :
|
|
186
|
-
?
|
|
187
|
-
: undefined, name
|
|
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(
|
|
109
|
+
return routes.map((item) => {
|
|
190
110
|
return _main(item);
|
|
191
111
|
});
|
|
192
112
|
};
|
|
193
113
|
exports.getFormatRouter = getFormatRouter;
|
|
194
|
-
|
|
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:
|
|
209
|
-
|
|
210
|
-
console.log(
|
|
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:
|
|
213
|
-
|
|
214
|
-
console.log(
|
|
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:
|
|
217
|
-
|
|
136
|
+
error: (message, options) => {
|
|
137
|
+
const { inline, title } = options || {};
|
|
218
138
|
if (inline) {
|
|
219
|
-
console.log(
|
|
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(
|
|
144
|
+
console.log(`${chalk_1.default.red.bold('error')} - ${title || 'There are some errors about Swico'}:`);
|
|
225
145
|
}
|
|
226
|
-
message.forEach(
|
|
227
|
-
console.log(
|
|
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(
|
|
232
|
-
console.log(
|
|
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:
|
|
237
|
-
|
|
238
|
-
|
|
156
|
+
warning: (message, options) => {
|
|
157
|
+
const { inline, title } = options || {};
|
|
158
|
+
const { warning: color } = exports.colorConfig;
|
|
239
159
|
if (inline) {
|
|
240
|
-
console.log(
|
|
160
|
+
console.log(`${chalk_1.default.hex(color).bold('warning')} - ${message}`);
|
|
241
161
|
}
|
|
242
162
|
else {
|
|
243
|
-
console.log(
|
|
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(
|
|
246
|
-
console.log(
|
|
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(
|
|
170
|
+
console.log(`> ${chalk_1.default.hex(color).bold(message)}`);
|
|
251
171
|
}
|
|
252
172
|
}
|
|
253
173
|
}
|
|
254
174
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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;
|