@l-comedy/core 0.1.0
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/bin/lcomedy.js +1 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +34 -0
- package/dist/plugins/app-config/createLComedyPluginAppConfig.d.ts +8 -0
- package/dist/plugins/app-config/createLComedyPluginAppConfig.js +161 -0
- package/dist/plugins/app-config/index.d.ts +5 -0
- package/dist/plugins/app-config/index.js +159 -0
- package/dist/plugins/html/createHtmlFile.d.ts +8 -0
- package/dist/plugins/html/createHtmlFile.js +61 -0
- package/dist/plugins/html/createLComedyPluginHtml.d.ts +8 -0
- package/dist/plugins/html/createLComedyPluginHtml.js +147 -0
- package/dist/plugins/html/createTemplateParameters.d.ts +12 -0
- package/dist/plugins/html/createTemplateParameters.js +39 -0
- package/dist/plugins/html/index.d.ts +5 -0
- package/dist/plugins/html/index.js +145 -0
- package/dist/plugins/layout/createLComedyPluginLayout.d.ts +8 -0
- package/dist/plugins/layout/createLComedyPluginLayout.js +69 -0
- package/dist/plugins/layout/index.d.ts +5 -0
- package/dist/plugins/layout/index.js +67 -0
- package/dist/plugins/page-loading/createLComedyPluginPageLoading.d.ts +8 -0
- package/dist/plugins/page-loading/createLComedyPluginPageLoading.js +67 -0
- package/dist/plugins/page-loading/index.d.ts +5 -0
- package/dist/plugins/page-loading/index.js +65 -0
- package/dist/plugins/route/createLComedyPluginRoute.d.ts +8 -0
- package/dist/plugins/route/createLComedyPluginRoute.js +118 -0
- package/dist/plugins/route/index.d.ts +5 -0
- package/dist/plugins/route/index.js +116 -0
- package/dist/plugins/types.d-gldCJl0t.d.ts +83 -0
- package/dist/run.d.ts +2 -0
- package/dist/run.js +634 -0
- package/package.json +66 -0
package/dist/run.js
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
39
|
+
mod
|
|
40
|
+
));
|
|
41
|
+
var __async = (__this, __arguments, generator) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
var fulfilled = (value) => {
|
|
44
|
+
try {
|
|
45
|
+
step(generator.next(value));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var rejected = (value) => {
|
|
51
|
+
try {
|
|
52
|
+
step(generator.throw(value));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
reject(e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
58
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/run.ts
|
|
63
|
+
var import_commander = require("commander");
|
|
64
|
+
|
|
65
|
+
// src/commands/dev.ts
|
|
66
|
+
var import_path8 = __toESM(require("path"));
|
|
67
|
+
var import_core2 = require("@rspack/core");
|
|
68
|
+
var import_dev_server = require("@rspack/dev-server");
|
|
69
|
+
var import_chokidar = __toESM(require("chokidar"));
|
|
70
|
+
|
|
71
|
+
// src/setup.ts
|
|
72
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
73
|
+
var import_path7 = __toESM(require("path"));
|
|
74
|
+
|
|
75
|
+
// src/utils/setup/generateEntryFile.ts
|
|
76
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
77
|
+
var import_path = __toESM(require("path"));
|
|
78
|
+
function generateEntryFile(modifiers, targetDir, setupConfig) {
|
|
79
|
+
return __async(this, null, function* () {
|
|
80
|
+
var _a;
|
|
81
|
+
const allImports = /* @__PURE__ */ new Set();
|
|
82
|
+
const allReactImports = /* @__PURE__ */ new Set();
|
|
83
|
+
modifiers.forEach((m) => {
|
|
84
|
+
var _a2, _b;
|
|
85
|
+
(_a2 = m.imports) == null ? void 0 : _a2.forEach((i) => allImports.add(i));
|
|
86
|
+
(_b = m.reactImports) == null ? void 0 : _b.forEach((i) => allReactImports.add(i));
|
|
87
|
+
});
|
|
88
|
+
let appCode = "<div />";
|
|
89
|
+
let entryCode = `import React${allReactImports.size >= 0 ? `, { ${Array.from(allReactImports).join(", ")} }` : ""} from 'react';
|
|
90
|
+
import { createRoot } from 'react-dom/client';
|
|
91
|
+
`;
|
|
92
|
+
entryCode += Array.from(allImports).join("\n") + "\n";
|
|
93
|
+
modifiers.forEach((m) => {
|
|
94
|
+
if (m.beforeRender) {
|
|
95
|
+
entryCode += m.beforeRender + "\n";
|
|
96
|
+
}
|
|
97
|
+
if (m.app) {
|
|
98
|
+
appCode = m.app(appCode);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
modifiers.forEach((m) => {
|
|
102
|
+
if (m.appWrap) {
|
|
103
|
+
appCode = m.appWrap(appCode);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
appCode = `<React.StrictMode>
|
|
107
|
+
${appCode}
|
|
108
|
+
</React.StrictMode>`;
|
|
109
|
+
let renderCode = `function render() {
|
|
110
|
+
const rootContainer = document.getElementById('${((_a = setupConfig.userConfig.html) == null ? void 0 : _a.rootId) || "root"}');
|
|
111
|
+
|
|
112
|
+
if (rootContainer) {
|
|
113
|
+
const root = createRoot(rootContainer);
|
|
114
|
+
root.render(${appCode});
|
|
115
|
+
}
|
|
116
|
+
}`;
|
|
117
|
+
let renderRunCode = `render();`;
|
|
118
|
+
modifiers.forEach((m) => {
|
|
119
|
+
if (m.render) {
|
|
120
|
+
renderCode = m.render(renderCode);
|
|
121
|
+
}
|
|
122
|
+
if (m.renderRun) {
|
|
123
|
+
renderRunCode = m.renderRun(renderCode);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
entryCode += renderCode + "\n";
|
|
127
|
+
entryCode += renderRunCode + "\n";
|
|
128
|
+
modifiers.forEach((m) => {
|
|
129
|
+
if (m.afterRender) {
|
|
130
|
+
entryCode += m.afterRender + "\n";
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
yield import_fs_extra.default.outputFile(import_path.default.posix.join(targetDir, "entry.tsx"), entryCode);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/plugins/app-config/createLComedyPluginAppConfig.ts
|
|
138
|
+
var import_path2 = __toESM(require("path"));
|
|
139
|
+
var import_core = require("@rspack/core");
|
|
140
|
+
function createLComedyPluginAppConfig() {
|
|
141
|
+
return {
|
|
142
|
+
name: "l-comedy-plugin-app-config",
|
|
143
|
+
rspackConfig(rspackConfig, setupConfig) {
|
|
144
|
+
var _a;
|
|
145
|
+
const publicDir = setupConfig.userConfig.publicDir || "public";
|
|
146
|
+
const newConfig = __spreadProps(__spreadValues({}, rspackConfig), {
|
|
147
|
+
entry: import_path2.default.posix.join(setupConfig.workPath, "entry.tsx"),
|
|
148
|
+
output: {
|
|
149
|
+
publicPath: "/",
|
|
150
|
+
path: import_path2.default.posix.join(
|
|
151
|
+
setupConfig.root,
|
|
152
|
+
setupConfig.userConfig.output || "dist"
|
|
153
|
+
),
|
|
154
|
+
filename: setupConfig.isProd ? "static/js/[name].[contenthash:8].js" : "static/js/[name].js",
|
|
155
|
+
clean: true
|
|
156
|
+
},
|
|
157
|
+
module: __spreadProps(__spreadValues({}, rspackConfig.module), {
|
|
158
|
+
rules: [
|
|
159
|
+
...((_a = rspackConfig.module) == null ? void 0 : _a.rules) || [],
|
|
160
|
+
{
|
|
161
|
+
test: /\.(ts|tsx)$/,
|
|
162
|
+
exclude: /node_modules/,
|
|
163
|
+
use: [
|
|
164
|
+
{
|
|
165
|
+
loader: require.resolve("ts-loader"),
|
|
166
|
+
options: {
|
|
167
|
+
transpileOnly: true,
|
|
168
|
+
compilerOptions: {
|
|
169
|
+
paths: {
|
|
170
|
+
"@/*": ["src/*"]
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
test: /\.(css|less)$/,
|
|
179
|
+
use: [
|
|
180
|
+
setupConfig.isProd ? import_core.CssExtractRspackPlugin.loader : require.resolve("style-loader"),
|
|
181
|
+
{
|
|
182
|
+
loader: require.resolve("css-loader"),
|
|
183
|
+
options: {
|
|
184
|
+
modules: {
|
|
185
|
+
mode: "local",
|
|
186
|
+
auto: true,
|
|
187
|
+
localIdentName: setupConfig.isProd ? "[local]--[hash:base64:8]" : "[path][name]__[local]--[hash:base64:5]",
|
|
188
|
+
exportLocalsConvention: "camelCaseOnly",
|
|
189
|
+
namedExport: false,
|
|
190
|
+
exportOnlyLocals: false
|
|
191
|
+
},
|
|
192
|
+
esModule: true
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
loader: require.resolve("postcss-loader")
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
loader: require.resolve("less-loader"),
|
|
200
|
+
options: {
|
|
201
|
+
lessOptions: {
|
|
202
|
+
javascriptEnabled: true
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}),
|
|
210
|
+
plugins: [
|
|
211
|
+
...rspackConfig.plugins || [],
|
|
212
|
+
...setupConfig.isProd ? [
|
|
213
|
+
new import_core.CssExtractRspackPlugin({
|
|
214
|
+
filename: "static/css/[name].[contenthash:8].css",
|
|
215
|
+
chunkFilename: "static/css/[name].[contenthash:8].chunk.css"
|
|
216
|
+
}),
|
|
217
|
+
new import_core.CopyRspackPlugin({
|
|
218
|
+
patterns: [
|
|
219
|
+
{
|
|
220
|
+
from: publicDir,
|
|
221
|
+
to: "."
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
})
|
|
225
|
+
] : []
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
if (!setupConfig.isProd) {
|
|
229
|
+
newConfig.devServer = __spreadProps(__spreadValues({}, rspackConfig.devServer), {
|
|
230
|
+
port: setupConfig.userConfig.port,
|
|
231
|
+
hot: true,
|
|
232
|
+
historyApiFallback: true,
|
|
233
|
+
static: {
|
|
234
|
+
publicPath: "/",
|
|
235
|
+
directory: publicDir
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return newConfig;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/plugins/html/createLComedyPluginHtml.ts
|
|
245
|
+
var import_path4 = __toESM(require("path"));
|
|
246
|
+
var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
|
|
247
|
+
|
|
248
|
+
// src/plugins/html/createHtmlFile.ts
|
|
249
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
250
|
+
var import_path3 = __toESM(require("path"));
|
|
251
|
+
function createHtmlFile(setupConfig) {
|
|
252
|
+
var _a, _b, _c;
|
|
253
|
+
const htmlConfig = setupConfig.userConfig.html || {};
|
|
254
|
+
import_fs_extra2.default.outputFileSync(
|
|
255
|
+
import_path3.default.posix.join(setupConfig.workDir, "index.html"),
|
|
256
|
+
`<!DOCTYPE html>
|
|
257
|
+
<html>
|
|
258
|
+
<head>
|
|
259
|
+
<meta charset="utf-8" />
|
|
260
|
+
<title><%= TITLE %></title>
|
|
261
|
+
${((_a = htmlConfig.headTags) == null ? void 0 : _a.join("\n")) || ""}
|
|
262
|
+
</head>
|
|
263
|
+
<body>
|
|
264
|
+
${((_b = htmlConfig.bodyBeforeTags) == null ? void 0 : _b.join("\n")) || ""}
|
|
265
|
+
<div id="<%= ROOT_ID %>"></div>
|
|
266
|
+
${((_c = htmlConfig.bodyAfterTags) == null ? void 0 : _c.join("\n")) || ""}
|
|
267
|
+
</body>
|
|
268
|
+
</html>`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/plugins/html/createTemplateParameters.ts
|
|
273
|
+
function createTemplateParameters(setupConfig) {
|
|
274
|
+
var _a, _b;
|
|
275
|
+
return {
|
|
276
|
+
BUILD_TIME: (/* @__PURE__ */ new Date()).toISOString(),
|
|
277
|
+
// BUILD_TIMESTAMP: Date.now(),
|
|
278
|
+
// IS_PROD: setupConfig.isProd,
|
|
279
|
+
TITLE: ((_a = setupConfig.userConfig.html) == null ? void 0 : _a.title) || "App",
|
|
280
|
+
ROOT_ID: ((_b = setupConfig.userConfig.html) == null ? void 0 : _b.rootId) || "root"
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/plugins/html/createLComedyPluginHtml.ts
|
|
285
|
+
function createLComedyPluginHtml() {
|
|
286
|
+
return {
|
|
287
|
+
name: "l-comedy-plugin-html",
|
|
288
|
+
rspackConfig(rspackConfig, setupConfig) {
|
|
289
|
+
var _a2, _b;
|
|
290
|
+
return __spreadProps(__spreadValues({}, rspackConfig), {
|
|
291
|
+
plugins: [
|
|
292
|
+
...rspackConfig.plugins || [],
|
|
293
|
+
new import_html_webpack_plugin.default(__spreadProps(__spreadValues({
|
|
294
|
+
template: import_path4.default.posix.join(setupConfig.workDir, "index.html"),
|
|
295
|
+
filename: "index.html",
|
|
296
|
+
minify: setupConfig.isProd ? {
|
|
297
|
+
collapseWhitespace: true,
|
|
298
|
+
removeComments: true,
|
|
299
|
+
removeRedundantAttributes: true
|
|
300
|
+
} : false,
|
|
301
|
+
cache: true,
|
|
302
|
+
inject: true
|
|
303
|
+
}, (_a2 = setupConfig.userConfig.html) == null ? void 0 : _a2.htmlWebpackOptions), {
|
|
304
|
+
templateParameters: __spreadValues(__spreadValues({}, (_b = setupConfig.userConfig.html) == null ? void 0 : _b.htmlTemplateParametersData), createTemplateParameters(setupConfig))
|
|
305
|
+
}))
|
|
306
|
+
]
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
generateFiles(setupConfig) {
|
|
310
|
+
return __async(this, null, function* () {
|
|
311
|
+
createHtmlFile(setupConfig);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/plugins/page-loading/createLComedyPluginPageLoading.ts
|
|
318
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
319
|
+
var import_path5 = __toESM(require("path"));
|
|
320
|
+
function createLComedyPluginPageLoading() {
|
|
321
|
+
return {
|
|
322
|
+
name: "l-comedy-plugin-page-loading",
|
|
323
|
+
modifyEntry(setupConfig) {
|
|
324
|
+
let hasLoading = false;
|
|
325
|
+
const imports = [];
|
|
326
|
+
const pageLoadingPath = import_path5.default.posix.join(
|
|
327
|
+
setupConfig.sourceDir,
|
|
328
|
+
"layout/PageLoading.tsx"
|
|
329
|
+
);
|
|
330
|
+
if (import_fs_extra3.default.existsSync(pageLoadingPath)) {
|
|
331
|
+
hasLoading = true;
|
|
332
|
+
imports.push("import PageLoading from '@/layout/PageLoading'");
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
imports,
|
|
336
|
+
reactImports: ["Suspense"],
|
|
337
|
+
appWrap(app) {
|
|
338
|
+
return `<Suspense fallback={${hasLoading ? "<PageLoading />" : "<div />"}}>
|
|
339
|
+
${app}
|
|
340
|
+
</Suspense>`;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/plugins/layout/createLComedyPluginLayout.ts
|
|
348
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
349
|
+
var import_path6 = __toESM(require("path"));
|
|
350
|
+
function createLComedyPluginLayout() {
|
|
351
|
+
return {
|
|
352
|
+
name: "l-comedy-plugin-layout",
|
|
353
|
+
modifyEntry(setupConfig) {
|
|
354
|
+
let hasLayout = false;
|
|
355
|
+
const imports = [];
|
|
356
|
+
const layoutPath = import_path6.default.posix.join(
|
|
357
|
+
setupConfig.sourceDir,
|
|
358
|
+
"layout/index.tsx"
|
|
359
|
+
);
|
|
360
|
+
if (import_fs_extra4.default.existsSync(layoutPath)) {
|
|
361
|
+
hasLayout = true;
|
|
362
|
+
imports.push("import Layout from '@/layout/index'");
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
imports,
|
|
366
|
+
appWrap(app) {
|
|
367
|
+
if (!hasLayout) {
|
|
368
|
+
return app;
|
|
369
|
+
}
|
|
370
|
+
return `<Layout>
|
|
371
|
+
${app}
|
|
372
|
+
</Layout>`;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/setup.ts
|
|
380
|
+
function setup(userConfig, options) {
|
|
381
|
+
return __async(this, null, function* () {
|
|
382
|
+
const isProd = options.isProd;
|
|
383
|
+
const workDir = ".comedy";
|
|
384
|
+
const sourceDir = userConfig.sourceDir || "src";
|
|
385
|
+
const baseConfig = {
|
|
386
|
+
isProd,
|
|
387
|
+
root: options.root,
|
|
388
|
+
workDir,
|
|
389
|
+
workPath: import_path7.default.posix.join(options.root, workDir),
|
|
390
|
+
sourceDir,
|
|
391
|
+
sourcePath: import_path7.default.posix.join(options.root, sourceDir),
|
|
392
|
+
userConfig
|
|
393
|
+
};
|
|
394
|
+
const plugins = [
|
|
395
|
+
createLComedyPluginAppConfig(),
|
|
396
|
+
createLComedyPluginHtml(),
|
|
397
|
+
createLComedyPluginLayout(),
|
|
398
|
+
createLComedyPluginPageLoading()
|
|
399
|
+
];
|
|
400
|
+
for (const plugin of userConfig.plugins || []) {
|
|
401
|
+
if (typeof plugin === "string") {
|
|
402
|
+
plugins.push(
|
|
403
|
+
require(import_path7.default.posix.join(__dirname, `./plugins/${plugin}`)).default()
|
|
404
|
+
);
|
|
405
|
+
} else if (typeof plugin === "object") {
|
|
406
|
+
plugins.push(plugin);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
import_fs_extra5.default.ensureDirSync(baseConfig.workPath);
|
|
410
|
+
import_fs_extra5.default.emptyDirSync(baseConfig.workPath);
|
|
411
|
+
const modifiers = [];
|
|
412
|
+
for (const plugin of plugins) {
|
|
413
|
+
if (plugin.generateFiles) {
|
|
414
|
+
yield plugin.generateFiles(baseConfig);
|
|
415
|
+
}
|
|
416
|
+
if (plugin.modifyEntry) {
|
|
417
|
+
const modifier = yield plugin.modifyEntry(baseConfig);
|
|
418
|
+
modifiers.push(modifier);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const setupConfig = __spreadProps(__spreadValues({}, baseConfig), {
|
|
422
|
+
plugins
|
|
423
|
+
});
|
|
424
|
+
yield generateEntryFile(
|
|
425
|
+
modifiers,
|
|
426
|
+
import_path7.default.posix.join(baseConfig.root, baseConfig.workDir),
|
|
427
|
+
setupConfig
|
|
428
|
+
);
|
|
429
|
+
let rspackConfig = {
|
|
430
|
+
mode: isProd ? "production" : "development",
|
|
431
|
+
resolve: {
|
|
432
|
+
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
433
|
+
alias: {
|
|
434
|
+
"@": setupConfig.sourcePath
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
for (const plugin of plugins) {
|
|
439
|
+
if (plugin.rspackConfig) {
|
|
440
|
+
rspackConfig = yield plugin.rspackConfig(rspackConfig, setupConfig);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return rspackConfig;
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/utils/config/loadUserConfig.ts
|
|
448
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
449
|
+
var import_vm = __toESM(require("vm"));
|
|
450
|
+
var import_module = __toESM(require("module"));
|
|
451
|
+
var import_esbuild = require("esbuild");
|
|
452
|
+
function loadUserConfig(filepath) {
|
|
453
|
+
try {
|
|
454
|
+
return runFileConfig(filepath);
|
|
455
|
+
} catch (e) {
|
|
456
|
+
console.log(`\u52A0\u8F7D\u914D\u7F6E\u51FA\u9519${filepath}:
|
|
457
|
+
${e}`);
|
|
458
|
+
return {};
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function runFileConfig(filepath) {
|
|
462
|
+
try {
|
|
463
|
+
const fileContent = import_fs_extra6.default.readFileSync(filepath, "utf-8");
|
|
464
|
+
const result = (0, import_esbuild.transformSync)(fileContent, {
|
|
465
|
+
loader: "tsx",
|
|
466
|
+
format: "cjs"
|
|
467
|
+
});
|
|
468
|
+
const m = new import_module.default(`l_comedy_config_${Date.now()}`);
|
|
469
|
+
const script = new import_vm.default.Script(result.code);
|
|
470
|
+
const context = import_vm.default.createContext({
|
|
471
|
+
module: m,
|
|
472
|
+
exports: m.exports,
|
|
473
|
+
require,
|
|
474
|
+
__filename: filepath,
|
|
475
|
+
__dirname: require("path").dirname(filepath),
|
|
476
|
+
console,
|
|
477
|
+
process
|
|
478
|
+
});
|
|
479
|
+
script.runInContext(context);
|
|
480
|
+
return m.exports.default || m.exports || {};
|
|
481
|
+
} catch (e) {
|
|
482
|
+
throw e;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// src/utils/config/getDefaultUserConfigName.ts
|
|
487
|
+
function getDefaultUserConfigName() {
|
|
488
|
+
return "lcomedy.config.ts";
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// src/commands/dev.ts
|
|
492
|
+
function dev(options) {
|
|
493
|
+
return __async(this, null, function* () {
|
|
494
|
+
const root = process.cwd().replace(/\\/g, "/");
|
|
495
|
+
const filePath = import_path8.default.posix.join(
|
|
496
|
+
root,
|
|
497
|
+
(options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
|
|
498
|
+
);
|
|
499
|
+
let devServer = yield createDevServer(root, filePath);
|
|
500
|
+
yield devServer.start();
|
|
501
|
+
const watcher = import_chokidar.default.watch(filePath).on("change", () => __async(null, null, function* () {
|
|
502
|
+
console.log(`\u914D\u7F6E\u53D8\u66F4: ${filePath}
|
|
503
|
+
\u91CD\u542F\u670D\u52A1...`);
|
|
504
|
+
devServer.stop();
|
|
505
|
+
devServer = yield createDevServer(root, filePath);
|
|
506
|
+
yield devServer.start();
|
|
507
|
+
}));
|
|
508
|
+
["SIGINT", "SIGTERM"].forEach((signal) => {
|
|
509
|
+
process.on(signal, () => {
|
|
510
|
+
watcher.close();
|
|
511
|
+
devServer.stop();
|
|
512
|
+
process.exit();
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
function createDevServer(root, filePath) {
|
|
518
|
+
return __async(this, null, function* () {
|
|
519
|
+
const userConfig = loadUserConfig(filePath);
|
|
520
|
+
const rspackConfig = yield setup(userConfig, { root, isProd: false });
|
|
521
|
+
const compiler = (0, import_core2.rspack)(rspackConfig);
|
|
522
|
+
return new import_dev_server.RspackDevServer(rspackConfig.devServer || {}, compiler);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/commands/build.ts
|
|
527
|
+
var import_path9 = __toESM(require("path"));
|
|
528
|
+
var import_core3 = require("@rspack/core");
|
|
529
|
+
function build(options) {
|
|
530
|
+
return __async(this, null, function* () {
|
|
531
|
+
const root = process.cwd().replace(/\\/g, "/");
|
|
532
|
+
const filePath = import_path9.default.posix.join(
|
|
533
|
+
root,
|
|
534
|
+
(options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
|
|
535
|
+
);
|
|
536
|
+
const userConfig = loadUserConfig(filePath);
|
|
537
|
+
const rspackConfig = yield setup(userConfig, { root, isProd: true });
|
|
538
|
+
yield runBuild(rspackConfig);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
function runBuild(rspackConfig) {
|
|
542
|
+
return new Promise((resolve, reject) => {
|
|
543
|
+
const compiler = (0, import_core3.rspack)(rspackConfig);
|
|
544
|
+
compiler.run((err, stats) => {
|
|
545
|
+
if (err) {
|
|
546
|
+
console.error(err);
|
|
547
|
+
reject(err);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (stats && stats.hasErrors()) {
|
|
551
|
+
const info = stats.toJson();
|
|
552
|
+
console.error("Build errors:", info.errors);
|
|
553
|
+
reject(new Error("Build failed with errors"));
|
|
554
|
+
return;
|
|
555
|
+
} else if (stats) {
|
|
556
|
+
console.log(
|
|
557
|
+
stats.toString({
|
|
558
|
+
colors: true,
|
|
559
|
+
modules: false,
|
|
560
|
+
chunks: false,
|
|
561
|
+
chunkModules: false
|
|
562
|
+
})
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
compiler.close((closeErr) => {
|
|
566
|
+
if (closeErr) {
|
|
567
|
+
console.error(closeErr);
|
|
568
|
+
reject(closeErr);
|
|
569
|
+
} else {
|
|
570
|
+
console.log("Build completed successfully!");
|
|
571
|
+
resolve();
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/commands/test.ts
|
|
579
|
+
var import_path10 = __toESM(require("path"));
|
|
580
|
+
|
|
581
|
+
// src/utils/setup/loadOptionalDependency.ts
|
|
582
|
+
function loadOptionalDependency(packageName, importName) {
|
|
583
|
+
return __async(this, null, function* () {
|
|
584
|
+
try {
|
|
585
|
+
const module2 = yield import(packageName);
|
|
586
|
+
return importName ? module2[importName] : module2.default || module2;
|
|
587
|
+
} catch (error) {
|
|
588
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
589
|
+
console.log(`\u26A0\uFE0F \u672A\u5B89\u88C5 optional dependency: ${packageName}`);
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
console.error(`\u2717 \u52A0\u8F7D ${packageName} \u65F6\u51FA\u9519:`, error);
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// src/commands/test.ts
|
|
599
|
+
function test(options) {
|
|
600
|
+
return __async(this, null, function* () {
|
|
601
|
+
const jestPreset = yield loadOptionalDependency(
|
|
602
|
+
"@l-comedy/jest-preset"
|
|
603
|
+
);
|
|
604
|
+
if (jestPreset) {
|
|
605
|
+
const type = (options == null ? void 0 : options.type) || "all";
|
|
606
|
+
const root = process.cwd().replace(/\\/g, "/");
|
|
607
|
+
const filePath = import_path10.default.posix.join(
|
|
608
|
+
root,
|
|
609
|
+
(options == null ? void 0 : options.config) ? options.config : getDefaultUserConfigName()
|
|
610
|
+
);
|
|
611
|
+
const userConfig = loadUserConfig(filePath);
|
|
612
|
+
const { unit, components } = jestPreset.createJestConfig(userConfig.test);
|
|
613
|
+
try {
|
|
614
|
+
if (type === "unit" || type === "all") {
|
|
615
|
+
console.log("\n\u8FD0\u884C\u5355\u5143\u6D4B\u8BD5...");
|
|
616
|
+
yield jestPreset.runJest(unit);
|
|
617
|
+
}
|
|
618
|
+
if (type === "components" || type === "all") {
|
|
619
|
+
console.log("\n\u8FD0\u884C\u7EC4\u4EF6\u6D4B\u8BD5...");
|
|
620
|
+
yield jestPreset.runJest(components);
|
|
621
|
+
}
|
|
622
|
+
} catch (e) {
|
|
623
|
+
console.log(e);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/run.ts
|
|
630
|
+
var program = new import_commander.Command();
|
|
631
|
+
program.command("dev").description("Start development server").option("-c, --config <path>", "\u6307\u5B9A\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").action(dev);
|
|
632
|
+
program.command("build").description("Build app").option("-c, --config <path>", "\u6307\u5B9A\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").action(build);
|
|
633
|
+
program.command("test").description("Run test").option("-c, --config <path>", "\u6307\u5B9A\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").option("-t, --type <type>", "\u6307\u5B9A\u6D4B\u8BD5\u7C7B\u578B\uFF08unit/components/all\uFF09", "all").action(test);
|
|
634
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@l-comedy/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lcomedy": "bin/lcomedy.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/Lang-lll/l-comedy"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"description": "通过配置快速创建react应用",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"l-comedy",
|
|
23
|
+
"react",
|
|
24
|
+
"cli",
|
|
25
|
+
"config",
|
|
26
|
+
"rspack"
|
|
27
|
+
],
|
|
28
|
+
"author": "lang-lll",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "pnpm install && pnpm build-index && pnpm build-run && pnpm build-plugins",
|
|
32
|
+
"build-index": "tsup src/index.ts --format cjs --dts --clean",
|
|
33
|
+
"build-run": "tsup src/run.ts --format cjs --dts",
|
|
34
|
+
"build-plugins": "tsup src/plugins --format cjs --dts --outDir dist/plugins"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@rspack/cli": "^1.6.6",
|
|
38
|
+
"@rspack/core": "^1.6.6",
|
|
39
|
+
"@rspack/dev-server": "^1.1.4",
|
|
40
|
+
"chokidar": "^5.0.0",
|
|
41
|
+
"commander": "^14.0.2",
|
|
42
|
+
"css-loader": "7.1.2",
|
|
43
|
+
"esbuild": "^0.27.1",
|
|
44
|
+
"fs-extra": "^11.3.2",
|
|
45
|
+
"html-webpack-plugin": "^5.6.5",
|
|
46
|
+
"less": "4.4.2",
|
|
47
|
+
"less-loader": "^10.0.0",
|
|
48
|
+
"postcss-loader": "8.2.0",
|
|
49
|
+
"style-loader": "4.0.0",
|
|
50
|
+
"ts-loader": "^9.5.4"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
54
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
55
|
+
},
|
|
56
|
+
"optionalDependencies": {
|
|
57
|
+
"@l-comedy/jest-preset": "^0.1.0",
|
|
58
|
+
"react-router": "^7.0.0"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@jest/types": "29.6.3",
|
|
62
|
+
"@types/fs-extra": "^11.0.4",
|
|
63
|
+
"@types/node": "^22.19.1",
|
|
64
|
+
"tsup": "^8.5.1"
|
|
65
|
+
}
|
|
66
|
+
}
|