zixulu 1.1.1 → 1.3.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/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import { execSync } from 'child_process';
2
3
  import { Command } from 'commander';
3
- import { readFileSync, writeFileSync } from 'fs';
4
+ import { readFileSync, writeFileSync, unlinkSync } from 'fs';
5
+ import inquirer from 'inquirer';
4
6
 
5
7
  const program = new Command();
6
8
  const pkg = JSON.parse(readFileSync(import.meta.resolve("../package.json").slice(8), "utf-8"));
@@ -25,4 +27,78 @@ program
25
27
  const { tailwind } = options;
26
28
  writeFileSync("./prettier.config.cjs", tailwind ? prettierWithTailwind : prettier);
27
29
  });
30
+ program
31
+ .command("vite")
32
+ .description("删除 vite 模板中的某些配置")
33
+ .action(options => {
34
+ try {
35
+ unlinkSync("./.eslintrc.cjs");
36
+ }
37
+ catch (error) {
38
+ console.log("删除 .eslintrc.cjs 文件失败");
39
+ }
40
+ try {
41
+ const text = readFileSync("./tsconfig.json", "utf-8");
42
+ const newText = text.replace(/^ +?"noUnusedLocals": true,$\n/m, "").replace(/^ +?"noUnusedParameters": true,$\n/m, "");
43
+ writeFileSync("./tsconfig.json", newText, "utf-8");
44
+ }
45
+ catch (error) {
46
+ console.log("修改 tsconfig.json 配置失败");
47
+ }
48
+ });
49
+ // 获取 npm 包最新版本号
50
+ async function getLatestVersion(packageName) {
51
+ const url = `https://registry.npmjs.org/${packageName}/latest`;
52
+ const response = await fetch(url);
53
+ const data = await response.json();
54
+ return data.version;
55
+ }
56
+ program
57
+ .command("tailwind")
58
+ .description("添加 tailwind 配置文件")
59
+ .action(async () => {
60
+ const version = await getLatestVersion("tailwindcss");
61
+ const version1 = await getLatestVersion("autoprefixer");
62
+ const version2 = await getLatestVersion("postcss");
63
+ const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"));
64
+ packageJson.devDependencies.tailwindcss = `^${version}`;
65
+ packageJson.devDependencies.autoprefixer = `^${version1}`;
66
+ packageJson.devDependencies.postcss = `^${version2}`;
67
+ writeFileSync("./package.json", JSON.stringify(packageJson, undefined, 4), "utf-8");
68
+ writeFileSync("./tailwind.config.js", `/** @type {import('tailwindcss').Config} */
69
+ export default {
70
+ content: [
71
+ "./index.html",
72
+ "./src/**/*.{js,ts,jsx,tsx}",
73
+ ],
74
+ theme: {
75
+ extend: {},
76
+ },
77
+ plugins: [],
78
+ }`, "utf-8");
79
+ writeFileSync("./postcss.config.js", `export default {
80
+ plugins: {
81
+ tailwindcss: {},
82
+ autoprefixer: {}
83
+ }
84
+ }`, "utf-8");
85
+ const css = readFileSync("./src/index.css", "utf-8");
86
+ writeFileSync("./src/index.css", `@tailwind base;
87
+ @tailwind components;
88
+ @tailwind utilities;
89
+
90
+ ${css}`, "utf-8");
91
+ const { install } = await inquirer.prompt([
92
+ {
93
+ questions: "选择安装方式",
94
+ type: "list",
95
+ name: "install",
96
+ choices: ["npm", "yarn", "pnpm"],
97
+ default: "yarn"
98
+ }
99
+ ]);
100
+ install === "yarn" && execSync("yarn");
101
+ install === "npm" && execSync("npm install");
102
+ install === "pnpm" && execSync("pnpm install");
103
+ });
28
104
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zixulu",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,13 +14,16 @@
14
14
  "@types/inquirer": "^9.0.6",
15
15
  "@types/node": "^20.8.9",
16
16
  "@types/rollup": "^0.54.0",
17
+ "autoprefixer": "^10.4.16",
18
+ "postcss": "^8.4.31",
17
19
  "rollup": "^4.1.5",
20
+ "tailwindcss": "^3.3.5",
18
21
  "tslib": "^2.6.2",
19
22
  "typescript": "^5.2.2"
20
23
  },
21
24
  "dependencies": {
22
25
  "commander": "^11.1.0",
23
- "inquirer": "^9.2.11",
26
+ "inquirer": "^9.2.12",
24
27
  "prettier": "^3.1.0"
25
28
  }
26
29
  }
@@ -0,0 +1,6 @@
1
+ export default {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {}
5
+ }
6
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { exec, execSync } from "child_process"
3
4
  import { Command } from "commander"
4
- import { readFileSync, writeFileSync } from "fs"
5
+ import { readFileSync, unlinkSync, writeFileSync } from "fs"
6
+ import inquirer from "inquirer"
5
7
  import type { Config } from "prettier"
6
8
 
7
9
  const program = new Command()
@@ -35,4 +37,91 @@ program
35
37
  writeFileSync("./prettier.config.cjs", tailwind ? prettierWithTailwind : prettier)
36
38
  })
37
39
 
40
+ program
41
+ .command("vite")
42
+ .description("删除 vite 模板中的某些配置")
43
+ .action(options => {
44
+ try {
45
+ unlinkSync("./.eslintrc.cjs")
46
+ } catch (error) {
47
+ console.log("删除 .eslintrc.cjs 文件失败")
48
+ }
49
+ try {
50
+ const text = readFileSync("./tsconfig.json", "utf-8")
51
+ const newText = text.replace(/^ +?"noUnusedLocals": true,$\n/m, "").replace(/^ +?"noUnusedParameters": true,$\n/m, "")
52
+ writeFileSync("./tsconfig.json", newText, "utf-8")
53
+ } catch (error) {
54
+ console.log("修改 tsconfig.json 配置失败")
55
+ }
56
+ })
57
+
58
+ // 获取 npm 包最新版本号
59
+ async function getLatestVersion(packageName: string) {
60
+ const url = `https://registry.npmjs.org/${packageName}/latest`
61
+ const response = await fetch(url)
62
+ const data = await response.json()
63
+ return data.version
64
+ }
65
+
66
+ program
67
+ .command("tailwind")
68
+ .description("添加 tailwind 配置文件")
69
+ .action(async () => {
70
+ const version = await getLatestVersion("tailwindcss")
71
+ const version1 = await getLatestVersion("autoprefixer")
72
+ const version2 = await getLatestVersion("postcss")
73
+ const packageJson = JSON.parse(readFileSync("./package.json", "utf-8"))
74
+ packageJson.devDependencies.tailwindcss = `^${version}`
75
+ packageJson.devDependencies.autoprefixer = `^${version1}`
76
+ packageJson.devDependencies.postcss = `^${version2}`
77
+ writeFileSync("./package.json", JSON.stringify(packageJson, undefined, 4), "utf-8")
78
+ writeFileSync(
79
+ "./tailwind.config.js",
80
+ `/** @type {import('tailwindcss').Config} */
81
+ export default {
82
+ content: [
83
+ "./index.html",
84
+ "./src/**/*.{js,ts,jsx,tsx}",
85
+ ],
86
+ theme: {
87
+ extend: {},
88
+ },
89
+ plugins: [],
90
+ }`,
91
+ "utf-8"
92
+ )
93
+ writeFileSync(
94
+ "./postcss.config.js",
95
+ `export default {
96
+ plugins: {
97
+ tailwindcss: {},
98
+ autoprefixer: {}
99
+ }
100
+ }`,
101
+ "utf-8"
102
+ )
103
+ const css = readFileSync("./src/index.css", "utf-8")
104
+ writeFileSync(
105
+ "./src/index.css",
106
+ `@tailwind base;
107
+ @tailwind components;
108
+ @tailwind utilities;
109
+
110
+ ${css}`,
111
+ "utf-8"
112
+ )
113
+ const { install } = await inquirer.prompt([
114
+ {
115
+ questions: "选择安装方式",
116
+ type: "list",
117
+ name: "install",
118
+ choices: ["npm", "yarn", "pnpm"],
119
+ default: "yarn"
120
+ }
121
+ ])
122
+ install === "yarn" && execSync("yarn")
123
+ install === "npm" && execSync("npm install")
124
+ install === "pnpm" && execSync("pnpm install")
125
+ })
126
+
38
127
  program.parse()
@@ -0,0 +1,9 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ export default {
3
+ content: [],
4
+ theme: {
5
+ extend: {},
6
+ },
7
+ plugins: [],
8
+ }
9
+