@sybz-components/utils 1.0.10 → 1.0.12

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 (43) hide show
  1. package/dist/base.cjs +2 -1
  2. package/dist/base.d.cts +6 -1
  3. package/dist/base.d.mts +6 -1
  4. package/dist/base.d.ts +6 -1
  5. package/dist/base.mjs +2 -1
  6. package/dist/codeStandard.cjs +108 -0
  7. package/dist/codeStandard.d.cts +17 -0
  8. package/dist/codeStandard.d.mts +17 -0
  9. package/dist/codeStandard.d.ts +17 -0
  10. package/dist/codeStandard.mjs +93 -0
  11. package/dist/confirmSemantic.d.cts +3 -1
  12. package/dist/confirmSemantic.d.mts +3 -1
  13. package/dist/confirmSemantic.d.ts +3 -1
  14. package/dist/format.cjs +2 -1
  15. package/dist/format.mjs +2 -1
  16. package/dist/http.cjs +20 -0
  17. package/dist/http.d.cts +66 -0
  18. package/dist/http.d.mts +66 -0
  19. package/dist/http.d.ts +66 -0
  20. package/dist/http.mjs +8 -0
  21. package/dist/index.cjs +12 -1
  22. package/dist/index.d.cts +3 -0
  23. package/dist/index.d.mts +3 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.mjs +3 -1
  26. package/dist/shared/{utils.V4Kpqes0.cjs → utils.-eWHeuS_.cjs} +134 -2
  27. package/dist/shared/{utils.JIlaBPw3.mjs → utils.S76wYqQ8.mjs} +129 -4
  28. package/dist/sybz-code-standard.cjs +119 -0
  29. package/dist/sybz-code-standard.d.cts +1 -0
  30. package/dist/sybz-code-standard.d.mts +1 -0
  31. package/dist/sybz-code-standard.d.ts +1 -0
  32. package/dist/sybz-code-standard.mjs +112 -0
  33. package/dist/theme.cjs +11 -0
  34. package/dist/theme.d.cts +12 -0
  35. package/dist/theme.d.mts +12 -0
  36. package/dist/theme.d.ts +12 -0
  37. package/dist/theme.mjs +8 -0
  38. package/dist/vite.cjs +8 -0
  39. package/dist/vite.d.cts +4 -1
  40. package/dist/vite.d.mts +4 -1
  41. package/dist/vite.d.ts +4 -1
  42. package/dist/vite.mjs +4 -0
  43. package/package.json +24 -2
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ import { execFileSync } from 'node:child_process';
3
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { resolve } from 'node:path';
6
+ import husky from 'husky';
7
+
8
+ const cwd = process.cwd();
9
+ const require2 = createRequire(import.meta.url);
10
+ const generatedFiles = {
11
+ "eslint.config.js": "export { sybzEslintConfig as default } from '@sybz-components/utils/codeStandard'\n",
12
+ ".prettierrc.js": "export { sybzPrettierConfig as default } from '@sybz-components/utils/codeStandard'\n",
13
+ "lint-staged.config.js": "export { sybzLintStagedConfig as default } from '@sybz-components/utils/codeStandard'\n",
14
+ ".editorconfig": `root = true
15
+
16
+ [*]
17
+ charset = utf-8
18
+ end_of_line = lf
19
+ indent_style = space
20
+ indent_size = 2
21
+ insert_final_newline = true
22
+ trim_trailing_whitespace = true
23
+ max_line_length = 120
24
+
25
+ [*.md]
26
+ trim_trailing_whitespace = false
27
+ `
28
+ };
29
+ const scripts = {
30
+ prepare: "sybz-code-standard prepare",
31
+ lint: "sybz-code-standard eslint . --fix",
32
+ "lint:check": "sybz-code-standard eslint .",
33
+ "lint:prettier": "sybz-code-standard prettier . --write",
34
+ "lint:prettier:check": "sybz-code-standard prettier . --check"
35
+ };
36
+ const runPackageBin = (packageName, binPath, args2) => {
37
+ const packageJsonPath = require2.resolve(`${packageName}/package.json`);
38
+ const executablePath = resolve(packageJsonPath, "..", binPath);
39
+ execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
40
+ };
41
+ const writeIfMissing = (relativePath, content) => {
42
+ const filePath = resolve(cwd, relativePath);
43
+ if (!existsSync(filePath)) {
44
+ writeFileSync(filePath, content, "utf8");
45
+ console.log(`\u521B\u5EFA ${relativePath}`);
46
+ return;
47
+ }
48
+ if (readFileSync(filePath, "utf8") !== content) {
49
+ console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9`);
50
+ }
51
+ };
52
+ const configurePackageJson = () => {
53
+ const packageJsonPath = resolve(cwd, "package.json");
54
+ if (!existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
55
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
56
+ packageJson.scripts ??= {};
57
+ for (const [name, command2] of Object.entries(scripts)) {
58
+ const current = packageJson.scripts[name];
59
+ if (!current || current === command2) {
60
+ packageJson.scripts[name] = command2;
61
+ } else {
62
+ console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
63
+ }
64
+ }
65
+ writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
66
+ `, "utf8");
67
+ console.log("\u66F4\u65B0 package.json scripts");
68
+ };
69
+ const prepareHusky = () => {
70
+ const result = husky();
71
+ if (result) console.warn(result);
72
+ };
73
+ const configurePreCommit = () => {
74
+ prepareHusky();
75
+ const huskyDir = resolve(cwd, ".husky");
76
+ const hookPath = resolve(huskyDir, "pre-commit");
77
+ const command2 = "pnpm exec sybz-code-standard staged";
78
+ mkdirSync(huskyDir, { recursive: true });
79
+ const current = existsSync(hookPath) ? readFileSync(hookPath, "utf8").trimEnd() : "";
80
+ if (current.includes("sybz-code-standard staged")) return;
81
+ writeFileSync(hookPath, `${current ? `${current}
82
+ ` : ""}${command2}
83
+ `, { encoding: "utf8", mode: 493 });
84
+ console.log("\u66F4\u65B0 .husky/pre-commit");
85
+ };
86
+ const init = () => {
87
+ configurePackageJson();
88
+ for (const [filePath, content] of Object.entries(generatedFiles)) writeIfMissing(filePath, content);
89
+ configurePreCommit();
90
+ console.log("\n\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2\u63A5\u5165\u3002");
91
+ };
92
+ const [command = "init", ...args] = process.argv.slice(2);
93
+ switch (command) {
94
+ case "init":
95
+ init();
96
+ break;
97
+ case "prepare":
98
+ prepareHusky();
99
+ break;
100
+ case "eslint":
101
+ runPackageBin("eslint", "bin/eslint.js", args);
102
+ break;
103
+ case "prettier":
104
+ runPackageBin("prettier", "bin/prettier.cjs", args);
105
+ break;
106
+ case "staged":
107
+ runPackageBin("lint-staged", "bin/lint-staged.js", args);
108
+ break;
109
+ default:
110
+ console.error(`\u672A\u77E5\u547D\u4EE4\uFF1A${command}`);
111
+ process.exitCode = 1;
112
+ }
package/dist/theme.cjs ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const SYBZ_THEME_PREFIX = {
4
+ chenghua: "--s-ch-",
5
+ shijingshan: "--s-sjs-",
6
+ sybz: "--s-sybz-"
7
+ };
8
+ const isSybzTheme = (theme) => typeof theme === "string" && Object.prototype.hasOwnProperty.call(SYBZ_THEME_PREFIX, theme);
9
+
10
+ exports.SYBZ_THEME_PREFIX = SYBZ_THEME_PREFIX;
11
+ exports.isSybzTheme = isSybzTheme;
@@ -0,0 +1,12 @@
1
+ /** 内置主题注册表:新增主题名称和颜色前缀只在这里维护。 */
2
+ declare const SYBZ_THEME_PREFIX: {
3
+ readonly chenghua: "--s-ch-";
4
+ readonly shijingshan: "--s-sjs-";
5
+ readonly sybz: "--s-sybz-";
6
+ };
7
+ type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
8
+ type SybzComponentTheme = 'default' | SybzThemeName;
9
+ declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz";
10
+
11
+ export { SYBZ_THEME_PREFIX, isSybzTheme };
12
+ export type { SybzComponentTheme, SybzThemeName };
@@ -0,0 +1,12 @@
1
+ /** 内置主题注册表:新增主题名称和颜色前缀只在这里维护。 */
2
+ declare const SYBZ_THEME_PREFIX: {
3
+ readonly chenghua: "--s-ch-";
4
+ readonly shijingshan: "--s-sjs-";
5
+ readonly sybz: "--s-sybz-";
6
+ };
7
+ type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
8
+ type SybzComponentTheme = 'default' | SybzThemeName;
9
+ declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz";
10
+
11
+ export { SYBZ_THEME_PREFIX, isSybzTheme };
12
+ export type { SybzComponentTheme, SybzThemeName };
@@ -0,0 +1,12 @@
1
+ /** 内置主题注册表:新增主题名称和颜色前缀只在这里维护。 */
2
+ declare const SYBZ_THEME_PREFIX: {
3
+ readonly chenghua: "--s-ch-";
4
+ readonly shijingshan: "--s-sjs-";
5
+ readonly sybz: "--s-sybz-";
6
+ };
7
+ type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
8
+ type SybzComponentTheme = 'default' | SybzThemeName;
9
+ declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz";
10
+
11
+ export { SYBZ_THEME_PREFIX, isSybzTheme };
12
+ export type { SybzComponentTheme, SybzThemeName };
package/dist/theme.mjs ADDED
@@ -0,0 +1,8 @@
1
+ const SYBZ_THEME_PREFIX = {
2
+ chenghua: "--s-ch-",
3
+ shijingshan: "--s-sjs-",
4
+ sybz: "--s-sybz-"
5
+ };
6
+ const isSybzTheme = (theme) => typeof theme === "string" && Object.prototype.hasOwnProperty.call(SYBZ_THEME_PREFIX, theme);
7
+
8
+ export { SYBZ_THEME_PREFIX, isSybzTheme };
package/dist/vite.cjs CHANGED
@@ -1,11 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const codeInspectorPlugin = require('code-inspector-plugin');
4
+ const tailwindcss = require('@tailwindcss/vite');
4
5
  const gitCommitLog = require('./gitCommitLog.cjs');
5
6
  require('node:child_process');
6
7
  require('node:fs');
7
8
  require('node:path');
8
9
 
10
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
+
12
+ const tailwindcss__default = /*#__PURE__*/_interopDefaultCompat(tailwindcss);
13
+
9
14
  const createCodeInspector = (options = {}) => codeInspectorPlugin.codeInspectorPlugin({ ...options, bundler: "vite" });
10
15
  const formatBuildTime = (date) => {
11
16
  const pad = (value) => String(value).padStart(2, "0");
@@ -38,6 +43,9 @@ const createBuildTime = (metaName = "buildTime") => {
38
43
  };
39
44
  const sybzVitePlugins = (options = {}) => {
40
45
  const plugins = [];
46
+ if (options.tailwind !== false) {
47
+ plugins.push(...tailwindcss__default(typeof options.tailwind === "object" ? options.tailwind : {}));
48
+ }
41
49
  if (options.codeInspector !== false) {
42
50
  plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
43
51
  }
package/dist/vite.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
2
+ import { PluginOptions } from '@tailwindcss/vite';
2
3
  import { PluginOption } from 'vite';
3
4
  import { GitCommitLogOptions } from './gitCommitLog.cjs';
4
5
 
@@ -9,6 +10,8 @@ declare global {
9
10
  }
10
11
  type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
11
12
  interface SybzVitePluginsOptions {
13
+ /** Tailwind CSS v4 Vite 插件配置;默认启用,设为 false 时关闭。 */
14
+ tailwind?: boolean | PluginOptions;
12
15
  /** 代码定位插件配置;默认启用,设为 false 时关闭。 */
13
16
  codeInspector?: boolean | SybzCodeInspectorOptions;
14
17
  /** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
@@ -19,7 +22,7 @@ interface SybzVitePluginsOptions {
19
22
  };
20
23
  }
21
24
  /**
22
- * 创建 sybz 项目的 Vite 插件预设,默认包含代码定位、Git 提交信息和打包时间。
25
+ * 创建 sybz 项目的 Vite 插件预设,默认包含 Tailwind CSS v4、代码定位、Git 提交信息和打包时间。
23
26
  * Vite 会自动扁平化插件数组,推荐直接写入 plugins,无需展开运算符。
24
27
  */
25
28
  declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => PluginOption;
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
2
+ import { PluginOptions } from '@tailwindcss/vite';
2
3
  import { PluginOption } from 'vite';
3
4
  import { GitCommitLogOptions } from './gitCommitLog.mjs';
4
5
 
@@ -9,6 +10,8 @@ declare global {
9
10
  }
10
11
  type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
11
12
  interface SybzVitePluginsOptions {
13
+ /** Tailwind CSS v4 Vite 插件配置;默认启用,设为 false 时关闭。 */
14
+ tailwind?: boolean | PluginOptions;
12
15
  /** 代码定位插件配置;默认启用,设为 false 时关闭。 */
13
16
  codeInspector?: boolean | SybzCodeInspectorOptions;
14
17
  /** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
@@ -19,7 +22,7 @@ interface SybzVitePluginsOptions {
19
22
  };
20
23
  }
21
24
  /**
22
- * 创建 sybz 项目的 Vite 插件预设,默认包含代码定位、Git 提交信息和打包时间。
25
+ * 创建 sybz 项目的 Vite 插件预设,默认包含 Tailwind CSS v4、代码定位、Git 提交信息和打包时间。
23
26
  * Vite 会自动扁平化插件数组,推荐直接写入 plugins,无需展开运算符。
24
27
  */
25
28
  declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => PluginOption;
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CodeInspectorPluginOptions } from 'code-inspector-plugin';
2
+ import { PluginOptions } from '@tailwindcss/vite';
2
3
  import { PluginOption } from 'vite';
3
4
  import { GitCommitLogOptions } from './gitCommitLog.js';
4
5
 
@@ -9,6 +10,8 @@ declare global {
9
10
  }
10
11
  type SybzCodeInspectorOptions = Omit<CodeInspectorPluginOptions, 'bundler'>;
11
12
  interface SybzVitePluginsOptions {
13
+ /** Tailwind CSS v4 Vite 插件配置;默认启用,设为 false 时关闭。 */
14
+ tailwind?: boolean | PluginOptions;
12
15
  /** 代码定位插件配置;默认启用,设为 false 时关闭。 */
13
16
  codeInspector?: boolean | SybzCodeInspectorOptions;
14
17
  /** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
@@ -19,7 +22,7 @@ interface SybzVitePluginsOptions {
19
22
  };
20
23
  }
21
24
  /**
22
- * 创建 sybz 项目的 Vite 插件预设,默认包含代码定位、Git 提交信息和打包时间。
25
+ * 创建 sybz 项目的 Vite 插件预设,默认包含 Tailwind CSS v4、代码定位、Git 提交信息和打包时间。
23
26
  * Vite 会自动扁平化插件数组,推荐直接写入 plugins,无需展开运算符。
24
27
  */
25
28
  declare const sybzVitePlugins: (options?: SybzVitePluginsOptions) => PluginOption;
package/dist/vite.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { codeInspectorPlugin } from 'code-inspector-plugin';
2
+ import tailwindcss from '@tailwindcss/vite';
2
3
  import { gitCommitLog } from './gitCommitLog.mjs';
3
4
  import 'node:child_process';
4
5
  import 'node:fs';
@@ -36,6 +37,9 @@ const createBuildTime = (metaName = "buildTime") => {
36
37
  };
37
38
  const sybzVitePlugins = (options = {}) => {
38
39
  const plugins = [];
40
+ if (options.tailwind !== false) {
41
+ plugins.push(...tailwindcss(typeof options.tailwind === "object" ? options.tailwind : {}));
42
+ }
39
43
  if (options.codeInspector !== false) {
40
44
  plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
41
45
  }
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
10
+ "bin": {
11
+ "sybz-code-standard": "./dist/sybz-code-standard.mjs"
12
+ },
10
13
  "exports": {
11
14
  ".": {
12
15
  "types": "./dist/index.d.ts",
@@ -23,6 +26,11 @@
23
26
  "import": "./dist/vite.mjs",
24
27
  "require": "./dist/vite.cjs"
25
28
  },
29
+ "./codeStandard": {
30
+ "types": "./dist/codeStandard.d.ts",
31
+ "import": "./dist/codeStandard.mjs",
32
+ "require": "./dist/codeStandard.cjs"
33
+ },
26
34
  "./*": {
27
35
  "types": "./dist/*.d.ts",
28
36
  "import": "./dist/*.mjs",
@@ -46,14 +54,28 @@
46
54
  },
47
55
  "author": "",
48
56
  "dependencies": {
57
+ "axios": "^1.19.0",
58
+ "@eslint/js": "9.39.4",
59
+ "@tailwindcss/vite": "^4.3.3",
60
+ "@typescript-eslint/eslint-plugin": "8.62.0",
61
+ "@typescript-eslint/parser": "8.62.0",
49
62
  "@vue/reactivity": "^3.5.18",
50
63
  "@vue/shared": "^3.5.18",
51
64
  "code-inspector-plugin": "^0.10.1",
52
65
  "consola": "^3.4.2",
53
66
  "element-plus": "^2.11.5",
67
+ "eslint": "9.39.4",
68
+ "eslint-config-prettier": "9.1.2",
69
+ "eslint-plugin-vue": "10.9.2",
54
70
  "es-toolkit": "^1.39.10",
55
71
  "lodash-es": "^4.17.21",
56
- "vue": "3.4.15"
72
+ "globals": "16.5.0",
73
+ "husky": "9.1.7",
74
+ "lint-staged": "15.5.2",
75
+ "prettier": "3.8.4",
76
+ "tailwindcss": "^4.3.3",
77
+ "vue": "3.4.15",
78
+ "vue-eslint-parser": "10.4.1"
57
79
  },
58
80
  "peerDependencies": {
59
81
  "vite": ">=5 <8"