zixulu 1.68.0 → 1.68.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/dist/utils/addEslint.js +4 -0
- package/dist/utils/addEslint.js.map +2 -2
- package/dist/utils/rsbuild.js +8 -8
- package/dist/utils/rsbuild.js.map +2 -2
- package/dist/utils/sortArrayOrObject.d.ts +1 -1
- package/dist/utils/writeRsbuildConfig.d.ts +9 -2
- package/dist/utils/writeRsbuildConfig.js +27 -6
- package/dist/utils/writeRsbuildConfig.js.map +2 -2
- package/package.json +1 -1
- package/src/utils/addEslint.ts +4 -0
- package/src/utils/rsbuild.ts +9 -9
- package/src/utils/writeRsbuildConfig.ts +36 -4
- package/dist/utils/createIndexHtml.d.ts +0 -10
- package/dist/utils/createIndexHtml.js +0 -69
- package/dist/utils/createIndexHtml.js.map +0 -7
- package/src/utils/createIndexHtml.ts +0 -39
package/dist/utils/addEslint.js
CHANGED
|
@@ -50,6 +50,10 @@ export default tseslint.config([
|
|
|
50
50
|
},
|
|
51
51
|
rules: {
|
|
52
52
|
"@typescript-eslint/no-empty-object-type": "off",
|
|
53
|
+
"no-empty": "off",
|
|
54
|
+
"no-extra-boolean-cast": "off",
|
|
55
|
+
"no-unused-vars": "off",
|
|
56
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
53
57
|
"prefer-const": [
|
|
54
58
|
"off",
|
|
55
59
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/addEslint.ts"],
|
|
4
|
-
"sourcesContent": ["import { writeFile } from \"node:fs/promises\"\n\nimport { CommitType } from \"@src/constant\"\n\nimport { addDependency } from \"./addDependency\"\nimport { addScript } from \"./addScript\"\nimport { getCommitMessage } from \"./getCommitMessage\"\nimport { hasDependency } from \"./hasDependency\"\nimport { installDependceny } from \"./installDependceny\"\n\ninterface GetEslintConfigParams {\n isReact: boolean\n}\n\nfunction getEslintConfig({ isReact }: GetEslintConfigParams) {\n const eslintConfig = `// @ts-check\n\nimport js from \"@eslint/js\"${\n isReact\n ? `\nimport reactHooks from \"eslint-plugin-react-hooks\"\nimport reactRefresh from \"eslint-plugin-react-refresh\"`\n : \"\"\n }\nimport { globalIgnores } from \"eslint/config\"\nimport globals from \"globals\"\nimport tseslint from \"typescript-eslint\"\n\nexport default tseslint.config([\n globalIgnores([\"dist\"]),\n {\n files: [\"**/*.{js,mjs,ts${isReact ? \",tsx\" : \"\"}}\"],\n extends: [js.configs.recommended, tseslint.configs.recommended${isReact ? `, reactHooks.configs[\"recommended-latest\"], reactRefresh.configs.vite` : \"\"}],\n languageOptions: {\n ecmaVersion: \"latest\",\n globals: globals.browser,\n },\n rules: {\n \"@typescript-eslint/no-empty-object-type\": \"off\",\n \"prefer-const\": [\n \"off\",\n {\n destructuring: \"any\",\n },\n ],\n },\n },\n])\n`\n return eslintConfig\n}\n\nexport async function addEslint() {\n const isReact = await hasDependency(\"react\")\n const config = getEslintConfig({ isReact })\n await writeFile(\"eslint.config.mjs\", config)\n const packages = [\"@eslint/js\", \"typescript-eslint\", \"globals\"]\n if (isReact) packages.push(\"eslint-plugin-react-hooks\", \"eslint-plugin-react-refresh\")\n await addDependency({\n package: packages,\n type: \"devDependencies\",\n })\n await installDependceny()\n await addScript({ lint: \"eslint .\" })\n return getCommitMessage(CommitType.feature, \"add eslint\")\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAE1B,sBAA2B;AAE3B,2BAA8B;AAC9B,uBAA0B;AAC1B,8BAAiC;AACjC,2BAA8B;AAC9B,+BAAkC;AAMlC,SAAS,gBAAgB,EAAE,QAAQ,GAA0B;AACzD,QAAM,eAAe;AAAA;AAAA,6BAGjB,UACM;AAAA;AAAA,0DAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCASoB,UAAU,SAAS;AAAA,wEACmB,UAAU,0EAA0E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { writeFile } from \"node:fs/promises\"\n\nimport { CommitType } from \"@src/constant\"\n\nimport { addDependency } from \"./addDependency\"\nimport { addScript } from \"./addScript\"\nimport { getCommitMessage } from \"./getCommitMessage\"\nimport { hasDependency } from \"./hasDependency\"\nimport { installDependceny } from \"./installDependceny\"\n\ninterface GetEslintConfigParams {\n isReact: boolean\n}\n\nfunction getEslintConfig({ isReact }: GetEslintConfigParams) {\n const eslintConfig = `// @ts-check\n\nimport js from \"@eslint/js\"${\n isReact\n ? `\nimport reactHooks from \"eslint-plugin-react-hooks\"\nimport reactRefresh from \"eslint-plugin-react-refresh\"`\n : \"\"\n }\nimport { globalIgnores } from \"eslint/config\"\nimport globals from \"globals\"\nimport tseslint from \"typescript-eslint\"\n\nexport default tseslint.config([\n globalIgnores([\"dist\"]),\n {\n files: [\"**/*.{js,mjs,ts${isReact ? \",tsx\" : \"\"}}\"],\n extends: [js.configs.recommended, tseslint.configs.recommended${isReact ? `, reactHooks.configs[\"recommended-latest\"], reactRefresh.configs.vite` : \"\"}],\n languageOptions: {\n ecmaVersion: \"latest\",\n globals: globals.browser,\n },\n rules: {\n \"@typescript-eslint/no-empty-object-type\": \"off\",\n \"no-empty\": \"off\",\n \"no-extra-boolean-cast\": \"off\",\n \"no-unused-vars\": \"off\",\n \"@typescript-eslint/no-unused-vars\": \"warn\",\n \"prefer-const\": [\n \"off\",\n {\n destructuring: \"any\",\n },\n ],\n },\n },\n])\n`\n return eslintConfig\n}\n\nexport async function addEslint() {\n const isReact = await hasDependency(\"react\")\n const config = getEslintConfig({ isReact })\n await writeFile(\"eslint.config.mjs\", config)\n const packages = [\"@eslint/js\", \"typescript-eslint\", \"globals\"]\n if (isReact) packages.push(\"eslint-plugin-react-hooks\", \"eslint-plugin-react-refresh\")\n await addDependency({\n package: packages,\n type: \"devDependencies\",\n })\n await installDependceny()\n await addScript({ lint: \"eslint .\" })\n return getCommitMessage(CommitType.feature, \"add eslint\")\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAE1B,sBAA2B;AAE3B,2BAA8B;AAC9B,uBAA0B;AAC1B,8BAAiC;AACjC,2BAA8B;AAC9B,+BAAkC;AAMlC,SAAS,gBAAgB,EAAE,QAAQ,GAA0B;AACzD,QAAM,eAAe;AAAA;AAAA,6BAGjB,UACM;AAAA;AAAA,0DAGA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCASoB,UAAU,SAAS;AAAA,wEACmB,UAAU,0EAA0E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBxJ,SAAO;AACX;AAEA,eAAsB,YAAY;AAC9B,QAAM,UAAU,UAAM,oCAAc,OAAO;AAC3C,QAAM,SAAS,gBAAgB,EAAE,QAAQ,CAAC;AAC1C,YAAM,2BAAU,qBAAqB,MAAM;AAC3C,QAAM,WAAW,CAAC,cAAc,qBAAqB,SAAS;AAC9D,MAAI;AAAS,aAAS,KAAK,6BAA6B,6BAA6B;AACrF,YAAM,oCAAc;AAAA,IAChB,SAAS;AAAA,IACT,MAAM;AAAA,EACV,CAAC;AACD,YAAM,4CAAkB;AACxB,YAAM,4BAAU,EAAE,MAAM,WAAW,CAAC;AACpC,aAAO,0CAAiB,2BAAW,SAAS,YAAY;AAC5D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/utils/rsbuild.js
CHANGED
|
@@ -36,7 +36,6 @@ var import_promises = require("fs/promises");
|
|
|
36
36
|
var import_consola = __toESM(require("consola"));
|
|
37
37
|
var import_addDependency = require("./addDependency");
|
|
38
38
|
var import_checkTailwind = require("./checkTailwind");
|
|
39
|
-
var import_createIndexHtml = require("./createIndexHtml");
|
|
40
39
|
var import_readPackageJson = require("./readPackageJson");
|
|
41
40
|
var import_readTsConfig = require("./readTsConfig");
|
|
42
41
|
var import_writeRsbuildConfig = require("./writeRsbuildConfig");
|
|
@@ -45,7 +44,7 @@ async function rsbuild() {
|
|
|
45
44
|
import_consola.default.start("开始设置 rsbuild 配置");
|
|
46
45
|
const { default: inquirer } = await import("inquirer");
|
|
47
46
|
await (0, import_addDependency.addDependency)({
|
|
48
|
-
package: ["@rsbuild/plugin-svgr"],
|
|
47
|
+
package: ["@rsbuild/plugin-svgr", "@rsbuild/plugin-babel", "babel-plugin-react-compiler"],
|
|
49
48
|
type: "devDependencies"
|
|
50
49
|
});
|
|
51
50
|
const packageJson = await (0, import_readPackageJson.readPackageJson)();
|
|
@@ -53,7 +52,7 @@ async function rsbuild() {
|
|
|
53
52
|
tsConfig.compilerOptions.lib = tsConfig.compilerOptions.lib.map((item) => item === tsConfig.compilerOptions.target ? "ESNext" : item);
|
|
54
53
|
tsConfig.compilerOptions.target = "ESNext";
|
|
55
54
|
await (0, import_writeTsConfig.writeTsConfig)(tsConfig);
|
|
56
|
-
const { description, title,
|
|
55
|
+
const { description, title, mountId } = await inquirer.prompt([
|
|
57
56
|
{
|
|
58
57
|
type: "input",
|
|
59
58
|
name: "description",
|
|
@@ -68,13 +67,12 @@ async function rsbuild() {
|
|
|
68
67
|
},
|
|
69
68
|
{
|
|
70
69
|
type: "input",
|
|
71
|
-
name: "
|
|
70
|
+
name: "mountId",
|
|
72
71
|
message: "入口 id",
|
|
73
72
|
default: "root"
|
|
74
73
|
}
|
|
75
74
|
]);
|
|
76
|
-
await (0, import_writeRsbuildConfig.writeRsbuildConfig)();
|
|
77
|
-
await (0, import_createIndexHtml.createIndexHtml)({ description, title, entryId });
|
|
75
|
+
await (0, import_writeRsbuildConfig.writeRsbuildConfig)({ description, title, mountId });
|
|
78
76
|
await (0, import_promises.rm)(`src/App.css`, { force: true });
|
|
79
77
|
await (0, import_promises.writeFile)(
|
|
80
78
|
`src/index.css`,
|
|
@@ -98,12 +96,14 @@ export default App`,
|
|
|
98
96
|
await (0, import_promises.writeFile)(
|
|
99
97
|
`src/index.tsx`,
|
|
100
98
|
`import { StrictMode } from "react"
|
|
101
|
-
import
|
|
99
|
+
import { createRoot } from "react-dom/client"
|
|
102
100
|
import App from "./App"
|
|
103
101
|
|
|
104
102
|
import "./index.css"
|
|
105
103
|
|
|
106
|
-
|
|
104
|
+
const root = createRoot(document.getElementById("${mountId}") as HTMLDivElement)
|
|
105
|
+
|
|
106
|
+
root.render(
|
|
107
107
|
<StrictMode>
|
|
108
108
|
<App />
|
|
109
109
|
</StrictMode>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/rsbuild.ts"],
|
|
4
|
-
"sourcesContent": ["import { rm, writeFile } from \"fs/promises\"\nimport consola from \"consola\"\n\nimport { addDependency } from \"./addDependency\"\nimport { checkTailwind } from \"./checkTailwind\"\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA8B;AAC9B,qBAAoB;AAEpB,2BAA8B;AAC9B,2BAA8B;AAC9B,6BAAgC;AAChC,
|
|
4
|
+
"sourcesContent": ["import { rm, writeFile } from \"fs/promises\"\nimport consola from \"consola\"\n\nimport { addDependency } from \"./addDependency\"\nimport { checkTailwind } from \"./checkTailwind\"\nimport { readPackageJson } from \"./readPackageJson\"\nimport { readTsConfig } from \"./readTsConfig\"\nimport { WriteRsbuildConfigParams, writeRsbuildConfig } from \"./writeRsbuildConfig\"\nimport { writeTsConfig } from \"./writeTsConfig\"\n\nexport async function rsbuild() {\n consola.start(\"开始设置 rsbuild 配置\")\n const { default: inquirer } = await import(\"inquirer\")\n await addDependency({\n package: [\"@rsbuild/plugin-svgr\", \"@rsbuild/plugin-babel\", \"babel-plugin-react-compiler\"],\n type: \"devDependencies\",\n })\n const packageJson = await readPackageJson()\n const tsConfig = await readTsConfig()\n tsConfig.compilerOptions.lib = tsConfig.compilerOptions.lib.map((item: string) => (item === tsConfig.compilerOptions.target ? \"ESNext\" : item))\n tsConfig.compilerOptions.target = \"ESNext\"\n await writeTsConfig(tsConfig)\n const { description, title, mountId } = await inquirer.prompt<WriteRsbuildConfigParams>([\n {\n type: \"input\",\n name: \"description\",\n message: \"项目描述\",\n default: \"designed by someone\",\n },\n {\n type: \"input\",\n name: \"title\",\n message: \"项目标题\",\n default: packageJson.name,\n },\n {\n type: \"input\",\n name: \"mountId\",\n message: \"入口 id\",\n default: \"root\",\n },\n ])\n await writeRsbuildConfig({ description, title, mountId })\n await rm(`src/App.css`, { force: true })\n\n await writeFile(\n `src/index.css`,\n (await checkTailwind())\n ? `@tailwind base; \n@tailwind components;\n@tailwind utilities;\n`\n : ``,\n \"utf-8\",\n )\n\n await writeFile(\n `src/App.tsx`,\n `import { FC } from \"react\"\n\nconst App: FC = () => {\n return <div>Hello, World!</div>\n}\n\nexport default App`,\n \"utf-8\",\n )\n\n await writeFile(\n `src/index.tsx`,\n `import { StrictMode } from \"react\"\nimport { createRoot } from \"react-dom/client\"\nimport App from \"./App\"\n\nimport \"./index.css\"\n\nconst root = createRoot(document.getElementById(\"${mountId}\") as HTMLDivElement)\n\nroot.render(\n <StrictMode>\n <App />\n </StrictMode>\n)`,\n \"utf-8\",\n )\n consola.success(\"设置 rsbuild 配置成功\")\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA8B;AAC9B,qBAAoB;AAEpB,2BAA8B;AAC9B,2BAA8B;AAC9B,6BAAgC;AAChC,0BAA6B;AAC7B,gCAA6D;AAC7D,2BAA8B;AAE9B,eAAsB,UAAU;AAC5B,iBAAAA,QAAQ,MAAM,iBAAiB;AAC/B,QAAM,EAAE,SAAS,SAAS,IAAI,MAAM,OAAO,UAAU;AACrD,YAAM,oCAAc;AAAA,IAChB,SAAS,CAAC,wBAAwB,yBAAyB,6BAA6B;AAAA,IACxF,MAAM;AAAA,EACV,CAAC;AACD,QAAM,cAAc,UAAM,wCAAgB;AAC1C,QAAM,WAAW,UAAM,kCAAa;AACpC,WAAS,gBAAgB,MAAM,SAAS,gBAAgB,IAAI,IAAI,CAAC,SAAkB,SAAS,SAAS,gBAAgB,SAAS,WAAW,IAAK;AAC9I,WAAS,gBAAgB,SAAS;AAClC,YAAM,oCAAc,QAAQ;AAC5B,QAAM,EAAE,aAAa,OAAO,QAAQ,IAAI,MAAM,SAAS,OAAiC;AAAA,IACpF;AAAA,MACI,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,IACb;AAAA,IACA;AAAA,MACI,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS,YAAY;AAAA,IACzB;AAAA,IACA;AAAA,MACI,MAAM;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,MACT,SAAS;AAAA,IACb;AAAA,EACJ,CAAC;AACD,YAAM,8CAAmB,EAAE,aAAa,OAAO,QAAQ,CAAC;AACxD,YAAM,oBAAG,eAAe,EAAE,OAAO,KAAK,CAAC;AAEvC,YAAM;AAAA,IACF;AAAA,IACC,UAAM,oCAAc,IACf;AAAA;AAAA;AAAA,IAIA;AAAA,IACN;AAAA,EACJ;AAEA,YAAM;AAAA,IACF;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA;AAAA,EACJ;AAEA,YAAM;AAAA,IACF;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mDAM2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO3C;AAAA,EACJ;AACA,iBAAAA,QAAQ,QAAQ,iBAAiB;AACrC;",
|
|
6
6
|
"names": ["consola"]
|
|
7
7
|
}
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param data 要排序的数组或对象
|
|
4
4
|
* @returns 排序后的数组或对象
|
|
5
5
|
*/
|
|
6
|
-
export declare function sortArrayOrObject(data: Record<string, unknown> | unknown[]): Record<string, unknown
|
|
6
|
+
export declare function sortArrayOrObject(data: Record<string, unknown> | unknown[]): unknown[] | Record<string, unknown>;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export interface WriteRsbuildConfigParams {
|
|
2
|
+
/** 项目标题 */
|
|
3
|
+
title: string;
|
|
4
|
+
/** 项目描述 */
|
|
5
|
+
description: string;
|
|
6
|
+
/** 挂载 id */
|
|
7
|
+
mountId: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function writeRsbuildConfig({ title, description, mountId }: WriteRsbuildConfigParams): Promise<void>;
|
|
@@ -19,24 +19,47 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/utils/writeRsbuildConfig.ts
|
|
20
20
|
var writeRsbuildConfig_exports = {};
|
|
21
21
|
__export(writeRsbuildConfig_exports, {
|
|
22
|
-
rsbuildConfig: () => rsbuildConfig,
|
|
23
22
|
writeRsbuildConfig: () => writeRsbuildConfig
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(writeRsbuildConfig_exports);
|
|
26
25
|
var import_promises = require("fs/promises");
|
|
27
|
-
|
|
26
|
+
async function writeRsbuildConfig({ title, description, mountId }) {
|
|
27
|
+
const rsbuildConfig = `import { defineConfig } from "@rsbuild/core"
|
|
28
|
+
import { pluginBabel } from "@rsbuild/plugin-babel"
|
|
28
29
|
import { pluginReact } from "@rsbuild/plugin-react"
|
|
29
30
|
import { pluginSvgr } from "@rsbuild/plugin-svgr"
|
|
30
31
|
|
|
31
32
|
export default defineConfig({
|
|
32
33
|
html: {
|
|
33
|
-
|
|
34
|
+
title: "${title}",
|
|
35
|
+
meta: {
|
|
36
|
+
description: "${description}",
|
|
37
|
+
},
|
|
38
|
+
mountId: "${mountId}",
|
|
34
39
|
},
|
|
35
40
|
plugins: [
|
|
36
41
|
pluginReact(),
|
|
42
|
+
pluginBabel({
|
|
43
|
+
include: /\\.(?:jsx|tsx)$/,
|
|
44
|
+
babelLoaderOptions(config) {
|
|
45
|
+
config.plugins ??= []
|
|
46
|
+
config.plugins?.unshift("babel-plugin-react-compiler")
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
37
49
|
pluginSvgr({
|
|
38
50
|
svgrOptions: {
|
|
39
51
|
exportType: "default",
|
|
52
|
+
svgoConfig: {
|
|
53
|
+
plugins: [
|
|
54
|
+
{
|
|
55
|
+
name: "prefixIds",
|
|
56
|
+
params: {
|
|
57
|
+
prefixIds: false,
|
|
58
|
+
prefixClassNames: false,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
40
63
|
},
|
|
41
64
|
}),
|
|
42
65
|
],
|
|
@@ -44,16 +67,14 @@ export default defineConfig({
|
|
|
44
67
|
port: 5173,
|
|
45
68
|
},
|
|
46
69
|
output: {
|
|
47
|
-
polyfill: "
|
|
70
|
+
polyfill: "entry",
|
|
48
71
|
},
|
|
49
72
|
})
|
|
50
73
|
`;
|
|
51
|
-
async function writeRsbuildConfig() {
|
|
52
74
|
await (0, import_promises.writeFile)("rsbuild.config.ts", rsbuildConfig, "utf-8");
|
|
53
75
|
}
|
|
54
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
77
|
0 && (module.exports = {
|
|
56
|
-
rsbuildConfig,
|
|
57
78
|
writeRsbuildConfig
|
|
58
79
|
});
|
|
59
80
|
//# sourceMappingURL=writeRsbuildConfig.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/writeRsbuildConfig.ts"],
|
|
4
|
-
"sourcesContent": ["import { writeFile } from \"fs/promises\"\n\nexport const rsbuildConfig = `import { defineConfig } from \"@rsbuild/core\"\nimport { pluginReact } from \"@rsbuild/plugin-react\"\nimport { pluginSvgr } from \"@rsbuild/plugin-svgr\"\n\nexport default defineConfig({\n html: {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import { writeFile } from \"fs/promises\"\n\nexport interface WriteRsbuildConfigParams {\n /** 项目标题 */\n title: string\n /** 项目描述 */\n description: string\n /** 挂载 id */\n mountId: string\n}\n\nexport async function writeRsbuildConfig({ title, description, mountId }: WriteRsbuildConfigParams) {\n const rsbuildConfig = `import { defineConfig } from \"@rsbuild/core\"\nimport { pluginBabel } from \"@rsbuild/plugin-babel\"\nimport { pluginReact } from \"@rsbuild/plugin-react\"\nimport { pluginSvgr } from \"@rsbuild/plugin-svgr\"\n\nexport default defineConfig({\n html: {\n title: \"${title}\",\n meta: {\n description: \"${description}\",\n },\n mountId: \"${mountId}\",\n },\n plugins: [\n pluginReact(),\n pluginBabel({\n include: /\\\\.(?:jsx|tsx)$/,\n babelLoaderOptions(config) {\n config.plugins ??= []\n config.plugins?.unshift(\"babel-plugin-react-compiler\")\n },\n }),\n pluginSvgr({\n svgrOptions: {\n exportType: \"default\",\n svgoConfig: {\n plugins: [\n {\n name: \"prefixIds\",\n params: {\n prefixIds: false,\n prefixClassNames: false,\n },\n },\n ],\n },\n },\n }),\n ],\n server: {\n port: 5173,\n },\n output: {\n polyfill: \"entry\",\n },\n})\n`\n\n await writeFile(\"rsbuild.config.ts\", rsbuildConfig, \"utf-8\")\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0B;AAW1B,eAAsB,mBAAmB,EAAE,OAAO,aAAa,QAAQ,GAA6B;AAChG,QAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAOR;AAAA;AAAA,4BAEU;AAAA;AAAA,oBAER;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqChB,YAAM,2BAAU,qBAAqB,eAAe,OAAO;AAC/D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/src/utils/addEslint.ts
CHANGED
|
@@ -37,6 +37,10 @@ export default tseslint.config([
|
|
|
37
37
|
},
|
|
38
38
|
rules: {
|
|
39
39
|
"@typescript-eslint/no-empty-object-type": "off",
|
|
40
|
+
"no-empty": "off",
|
|
41
|
+
"no-extra-boolean-cast": "off",
|
|
42
|
+
"no-unused-vars": "off",
|
|
43
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
40
44
|
"prefer-const": [
|
|
41
45
|
"off",
|
|
42
46
|
{
|
package/src/utils/rsbuild.ts
CHANGED
|
@@ -3,17 +3,16 @@ import consola from "consola"
|
|
|
3
3
|
|
|
4
4
|
import { addDependency } from "./addDependency"
|
|
5
5
|
import { checkTailwind } from "./checkTailwind"
|
|
6
|
-
import { createIndexHtml } from "./createIndexHtml"
|
|
7
6
|
import { readPackageJson } from "./readPackageJson"
|
|
8
7
|
import { readTsConfig } from "./readTsConfig"
|
|
9
|
-
import { writeRsbuildConfig } from "./writeRsbuildConfig"
|
|
8
|
+
import { WriteRsbuildConfigParams, writeRsbuildConfig } from "./writeRsbuildConfig"
|
|
10
9
|
import { writeTsConfig } from "./writeTsConfig"
|
|
11
10
|
|
|
12
11
|
export async function rsbuild() {
|
|
13
12
|
consola.start("开始设置 rsbuild 配置")
|
|
14
13
|
const { default: inquirer } = await import("inquirer")
|
|
15
14
|
await addDependency({
|
|
16
|
-
package: ["@rsbuild/plugin-svgr"],
|
|
15
|
+
package: ["@rsbuild/plugin-svgr", "@rsbuild/plugin-babel", "babel-plugin-react-compiler"],
|
|
17
16
|
type: "devDependencies",
|
|
18
17
|
})
|
|
19
18
|
const packageJson = await readPackageJson()
|
|
@@ -21,7 +20,7 @@ export async function rsbuild() {
|
|
|
21
20
|
tsConfig.compilerOptions.lib = tsConfig.compilerOptions.lib.map((item: string) => (item === tsConfig.compilerOptions.target ? "ESNext" : item))
|
|
22
21
|
tsConfig.compilerOptions.target = "ESNext"
|
|
23
22
|
await writeTsConfig(tsConfig)
|
|
24
|
-
const { description, title,
|
|
23
|
+
const { description, title, mountId } = await inquirer.prompt<WriteRsbuildConfigParams>([
|
|
25
24
|
{
|
|
26
25
|
type: "input",
|
|
27
26
|
name: "description",
|
|
@@ -36,13 +35,12 @@ export async function rsbuild() {
|
|
|
36
35
|
},
|
|
37
36
|
{
|
|
38
37
|
type: "input",
|
|
39
|
-
name: "
|
|
38
|
+
name: "mountId",
|
|
40
39
|
message: "入口 id",
|
|
41
40
|
default: "root",
|
|
42
41
|
},
|
|
43
42
|
])
|
|
44
|
-
await writeRsbuildConfig()
|
|
45
|
-
await createIndexHtml({ description, title, entryId })
|
|
43
|
+
await writeRsbuildConfig({ description, title, mountId })
|
|
46
44
|
await rm(`src/App.css`, { force: true })
|
|
47
45
|
|
|
48
46
|
await writeFile(
|
|
@@ -71,12 +69,14 @@ export default App`,
|
|
|
71
69
|
await writeFile(
|
|
72
70
|
`src/index.tsx`,
|
|
73
71
|
`import { StrictMode } from "react"
|
|
74
|
-
import
|
|
72
|
+
import { createRoot } from "react-dom/client"
|
|
75
73
|
import App from "./App"
|
|
76
74
|
|
|
77
75
|
import "./index.css"
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
const root = createRoot(document.getElementById("${mountId}") as HTMLDivElement)
|
|
78
|
+
|
|
79
|
+
root.render(
|
|
80
80
|
<StrictMode>
|
|
81
81
|
<App />
|
|
82
82
|
</StrictMode>
|
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
import { writeFile } from "fs/promises"
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface WriteRsbuildConfigParams {
|
|
4
|
+
/** 项目标题 */
|
|
5
|
+
title: string
|
|
6
|
+
/** 项目描述 */
|
|
7
|
+
description: string
|
|
8
|
+
/** 挂载 id */
|
|
9
|
+
mountId: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function writeRsbuildConfig({ title, description, mountId }: WriteRsbuildConfigParams) {
|
|
13
|
+
const rsbuildConfig = `import { defineConfig } from "@rsbuild/core"
|
|
14
|
+
import { pluginBabel } from "@rsbuild/plugin-babel"
|
|
4
15
|
import { pluginReact } from "@rsbuild/plugin-react"
|
|
5
16
|
import { pluginSvgr } from "@rsbuild/plugin-svgr"
|
|
6
17
|
|
|
7
18
|
export default defineConfig({
|
|
8
19
|
html: {
|
|
9
|
-
|
|
20
|
+
title: "${title}",
|
|
21
|
+
meta: {
|
|
22
|
+
description: "${description}",
|
|
23
|
+
},
|
|
24
|
+
mountId: "${mountId}",
|
|
10
25
|
},
|
|
11
26
|
plugins: [
|
|
12
27
|
pluginReact(),
|
|
28
|
+
pluginBabel({
|
|
29
|
+
include: /\\.(?:jsx|tsx)$/,
|
|
30
|
+
babelLoaderOptions(config) {
|
|
31
|
+
config.plugins ??= []
|
|
32
|
+
config.plugins?.unshift("babel-plugin-react-compiler")
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
13
35
|
pluginSvgr({
|
|
14
36
|
svgrOptions: {
|
|
15
37
|
exportType: "default",
|
|
38
|
+
svgoConfig: {
|
|
39
|
+
plugins: [
|
|
40
|
+
{
|
|
41
|
+
name: "prefixIds",
|
|
42
|
+
params: {
|
|
43
|
+
prefixIds: false,
|
|
44
|
+
prefixClassNames: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
16
49
|
},
|
|
17
50
|
}),
|
|
18
51
|
],
|
|
@@ -20,11 +53,10 @@ export default defineConfig({
|
|
|
20
53
|
port: 5173,
|
|
21
54
|
},
|
|
22
55
|
output: {
|
|
23
|
-
polyfill: "
|
|
56
|
+
polyfill: "entry",
|
|
24
57
|
},
|
|
25
58
|
})
|
|
26
59
|
`
|
|
27
60
|
|
|
28
|
-
export async function writeRsbuildConfig() {
|
|
29
61
|
await writeFile("rsbuild.config.ts", rsbuildConfig, "utf-8")
|
|
30
62
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type CreateIndexHtmlConfig = {
|
|
2
|
-
title: string;
|
|
3
|
-
description: string;
|
|
4
|
-
entryId: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* 创建项目的 index.html 文件
|
|
8
|
-
* @param config 配置对象,包含标题、描述和入口节点ID
|
|
9
|
-
*/
|
|
10
|
-
export declare function createIndexHtml(config: CreateIndexHtmlConfig): Promise<void>;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/utils/createIndexHtml.ts
|
|
30
|
-
var createIndexHtml_exports = {};
|
|
31
|
-
__export(createIndexHtml_exports, {
|
|
32
|
-
createIndexHtml: () => createIndexHtml
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(createIndexHtml_exports);
|
|
35
|
-
var import_promises = require("fs/promises");
|
|
36
|
-
var import_consola = __toESM(require("consola"));
|
|
37
|
-
async function createIndexHtml(config) {
|
|
38
|
-
const { title, description, entryId } = config;
|
|
39
|
-
const indexHtml = `<!doctype html>
|
|
40
|
-
<html lang="zh">
|
|
41
|
-
<head>
|
|
42
|
-
<meta charset="UTF-8" />
|
|
43
|
-
<link rel="icon" href="/logo.webp" />
|
|
44
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
45
|
-
<meta name="description" content="${description}" />
|
|
46
|
-
<title>${title}</title>
|
|
47
|
-
</head>
|
|
48
|
-
<body>
|
|
49
|
-
<div id="${entryId}"></div>
|
|
50
|
-
</body>
|
|
51
|
-
</html>
|
|
52
|
-
`;
|
|
53
|
-
const dir = await (0, import_promises.readdir)(".");
|
|
54
|
-
let hasPublic = false;
|
|
55
|
-
if (dir.includes("public")) {
|
|
56
|
-
const stats = await (0, import_promises.stat)("public");
|
|
57
|
-
if (stats.isDirectory())
|
|
58
|
-
hasPublic = true;
|
|
59
|
-
}
|
|
60
|
-
if (!hasPublic)
|
|
61
|
-
await (0, import_promises.mkdir)("public", { recursive: true });
|
|
62
|
-
await (0, import_promises.writeFile)("public/index.html", indexHtml, "utf-8");
|
|
63
|
-
import_consola.default.success("创建 index.html 成功");
|
|
64
|
-
}
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 && (module.exports = {
|
|
67
|
-
createIndexHtml
|
|
68
|
-
});
|
|
69
|
-
//# sourceMappingURL=createIndexHtml.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/createIndexHtml.ts"],
|
|
4
|
-
"sourcesContent": ["import { mkdir, readdir, stat, writeFile } from \"fs/promises\"\nimport consola from \"consola\"\n\nexport type CreateIndexHtmlConfig = {\n title: string\n description: string\n entryId: string\n}\n\n/**\n * 创建项目的 index.html 文件\n * @param config 配置对象,包含标题、描述和入口节点ID\n */\nexport async function createIndexHtml(config: CreateIndexHtmlConfig) {\n const { title, description, entryId } = config\n const indexHtml = `<!doctype html>\n<html lang=\"zh\">\n <head>\n <meta charset=\"UTF-8\" />\n <link rel=\"icon\" href=\"/logo.webp\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta name=\"description\" content=\"${description}\" />\n <title>${title}</title>\n </head>\n <body>\n <div id=\"${entryId}\"></div>\n </body>\n</html>\n`\n const dir = await readdir(\".\")\n let hasPublic = false\n if (dir.includes(\"public\")) {\n const stats = await stat(\"public\")\n if (stats.isDirectory()) hasPublic = true\n }\n if (!hasPublic) await mkdir(\"public\", { recursive: true })\n await writeFile(\"public/index.html\", indexHtml, \"utf-8\")\n consola.success(\"创建 index.html 成功\")\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAgD;AAChD,qBAAoB;AAYpB,eAAsB,gBAAgB,QAA+B;AACjE,QAAM,EAAE,OAAO,aAAa,QAAQ,IAAI;AACxC,QAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4CAMsB;AAAA,iBAC3B;AAAA;AAAA;AAAA,mBAGE;AAAA;AAAA;AAAA;AAIf,QAAM,MAAM,UAAM,yBAAQ,GAAG;AAC7B,MAAI,YAAY;AAChB,MAAI,IAAI,SAAS,QAAQ,GAAG;AACxB,UAAM,QAAQ,UAAM,sBAAK,QAAQ;AACjC,QAAI,MAAM,YAAY;AAAG,kBAAY;AAAA,EACzC;AACA,MAAI,CAAC;AAAW,cAAM,uBAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AACzD,YAAM,2BAAU,qBAAqB,WAAW,OAAO;AACvD,iBAAAA,QAAQ,QAAQ,kBAAkB;AACtC;",
|
|
6
|
-
"names": ["consola"]
|
|
7
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { mkdir, readdir, stat, writeFile } from "fs/promises"
|
|
2
|
-
import consola from "consola"
|
|
3
|
-
|
|
4
|
-
export type CreateIndexHtmlConfig = {
|
|
5
|
-
title: string
|
|
6
|
-
description: string
|
|
7
|
-
entryId: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 创建项目的 index.html 文件
|
|
12
|
-
* @param config 配置对象,包含标题、描述和入口节点ID
|
|
13
|
-
*/
|
|
14
|
-
export async function createIndexHtml(config: CreateIndexHtmlConfig) {
|
|
15
|
-
const { title, description, entryId } = config
|
|
16
|
-
const indexHtml = `<!doctype html>
|
|
17
|
-
<html lang="zh">
|
|
18
|
-
<head>
|
|
19
|
-
<meta charset="UTF-8" />
|
|
20
|
-
<link rel="icon" href="/logo.webp" />
|
|
21
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
22
|
-
<meta name="description" content="${description}" />
|
|
23
|
-
<title>${title}</title>
|
|
24
|
-
</head>
|
|
25
|
-
<body>
|
|
26
|
-
<div id="${entryId}"></div>
|
|
27
|
-
</body>
|
|
28
|
-
</html>
|
|
29
|
-
`
|
|
30
|
-
const dir = await readdir(".")
|
|
31
|
-
let hasPublic = false
|
|
32
|
-
if (dir.includes("public")) {
|
|
33
|
-
const stats = await stat("public")
|
|
34
|
-
if (stats.isDirectory()) hasPublic = true
|
|
35
|
-
}
|
|
36
|
-
if (!hasPublic) await mkdir("public", { recursive: true })
|
|
37
|
-
await writeFile("public/index.html", indexHtml, "utf-8")
|
|
38
|
-
consola.success("创建 index.html 成功")
|
|
39
|
-
}
|