@sybz-components/utils 1.0.10 → 1.0.11
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/base.cjs +1 -1
- package/dist/base.mjs +1 -1
- package/dist/codeStandard.cjs +108 -0
- package/dist/codeStandard.d.cts +17 -0
- package/dist/codeStandard.d.mts +17 -0
- package/dist/codeStandard.d.ts +17 -0
- package/dist/codeStandard.mjs +93 -0
- package/dist/format.cjs +1 -1
- package/dist/format.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/shared/{utils.JIlaBPw3.mjs → utils.CJdEsMHi.mjs} +1 -1
- package/dist/shared/{utils.V4Kpqes0.cjs → utils.DfuweQgy.cjs} +1 -1
- package/dist/sybz-code-standard.cjs +119 -0
- package/dist/sybz-code-standard.d.cts +1 -0
- package/dist/sybz-code-standard.d.mts +1 -0
- package/dist/sybz-code-standard.d.ts +1 -0
- package/dist/sybz-code-standard.mjs +112 -0
- package/dist/vite.cjs +8 -0
- package/dist/vite.d.cts +4 -1
- package/dist/vite.d.mts +4 -1
- package/dist/vite.d.ts +4 -1
- package/dist/vite.mjs +4 -0
- package/package.json +23 -2
package/dist/base.cjs
CHANGED
package/dist/base.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'vue';
|
|
2
2
|
import 'consola';
|
|
3
3
|
import 'es-toolkit';
|
|
4
|
-
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.
|
|
4
|
+
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.CJdEsMHi.mjs';
|
|
5
5
|
import './confirmSemantic.mjs';
|
|
6
6
|
import 'element-plus';
|
|
7
7
|
import './is.mjs';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const js = require('@eslint/js');
|
|
4
|
+
const tsPlugin = require('@typescript-eslint/eslint-plugin');
|
|
5
|
+
const tsParser = require('@typescript-eslint/parser');
|
|
6
|
+
const prettier = require('eslint-config-prettier');
|
|
7
|
+
const vue = require('eslint-plugin-vue');
|
|
8
|
+
const globals = require('globals');
|
|
9
|
+
const vueParser = require('vue-eslint-parser');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
12
|
+
|
|
13
|
+
const js__default = /*#__PURE__*/_interopDefaultCompat(js);
|
|
14
|
+
const tsPlugin__default = /*#__PURE__*/_interopDefaultCompat(tsPlugin);
|
|
15
|
+
const tsParser__default = /*#__PURE__*/_interopDefaultCompat(tsParser);
|
|
16
|
+
const prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
|
|
17
|
+
const vue__default = /*#__PURE__*/_interopDefaultCompat(vue);
|
|
18
|
+
const globals__default = /*#__PURE__*/_interopDefaultCompat(globals);
|
|
19
|
+
const vueParser__default = /*#__PURE__*/_interopDefaultCompat(vueParser);
|
|
20
|
+
|
|
21
|
+
const sybzPrettierConfig = {
|
|
22
|
+
singleQuote: true,
|
|
23
|
+
semi: false,
|
|
24
|
+
trailingComma: "all",
|
|
25
|
+
printWidth: 120,
|
|
26
|
+
endOfLine: "lf",
|
|
27
|
+
htmlWhitespaceSensitivity: "ignore"
|
|
28
|
+
};
|
|
29
|
+
const sybzLintStagedConfig = {
|
|
30
|
+
"**/*.{js,jsx,ts,tsx,vue,mjs,cjs}": [
|
|
31
|
+
"sybz-code-standard prettier --write",
|
|
32
|
+
"sybz-code-standard eslint --fix --max-warnings=0"
|
|
33
|
+
],
|
|
34
|
+
"**/*.{css,scss,json,yaml,yml,html,md}": ["sybz-code-standard prettier --write"]
|
|
35
|
+
};
|
|
36
|
+
const baseEslintConfig = [
|
|
37
|
+
{
|
|
38
|
+
ignores: [
|
|
39
|
+
"node_modules/**",
|
|
40
|
+
"dist/**",
|
|
41
|
+
"dist-ssr/**",
|
|
42
|
+
"coverage/**",
|
|
43
|
+
"docs/.vitepress/cache/**",
|
|
44
|
+
"docs/.vitepress/dist/**",
|
|
45
|
+
"packages/*/dist/**",
|
|
46
|
+
".vitepress/**",
|
|
47
|
+
".codex-types-temp/**",
|
|
48
|
+
"*.tsbuildinfo",
|
|
49
|
+
"*.local"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
js__default.configs.recommended,
|
|
53
|
+
tsPlugin__default.configs["flat/base"],
|
|
54
|
+
...vue__default.configs["flat/recommended"],
|
|
55
|
+
{
|
|
56
|
+
files: ["**/*.{js,jsx,ts,tsx,cjs,mjs,vue}"],
|
|
57
|
+
languageOptions: {
|
|
58
|
+
ecmaVersion: "latest",
|
|
59
|
+
sourceType: "module",
|
|
60
|
+
globals: {
|
|
61
|
+
...globals__default.browser,
|
|
62
|
+
...globals__default.node,
|
|
63
|
+
...globals__default.es2021
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
rules: {
|
|
67
|
+
"no-console": "off",
|
|
68
|
+
"no-unused-vars": "off",
|
|
69
|
+
"vue/no-unused-vars": "off",
|
|
70
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
71
|
+
"vue/multi-word-component-names": "off",
|
|
72
|
+
"vue/no-template-shadow": "off",
|
|
73
|
+
"vue/attribute-hyphenation": ["warn", "always", { ignore: ["dangerouslyUseHTMLString"] }],
|
|
74
|
+
"vue/require-default-prop": "off"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
files: ["**/*.{ts,tsx,vue}"],
|
|
79
|
+
rules: {
|
|
80
|
+
"no-undef": "off",
|
|
81
|
+
"no-redeclare": "off"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
files: ["**/*.vue"],
|
|
86
|
+
languageOptions: {
|
|
87
|
+
parser: vueParser__default,
|
|
88
|
+
parserOptions: {
|
|
89
|
+
parser: tsParser__default,
|
|
90
|
+
ecmaVersion: "latest",
|
|
91
|
+
sourceType: "module",
|
|
92
|
+
ecmaFeatures: { jsx: true },
|
|
93
|
+
extraFileExtensions: [".vue"]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
const createSybzEslintConfig = (...extensions) => [
|
|
99
|
+
...baseEslintConfig,
|
|
100
|
+
...extensions,
|
|
101
|
+
prettier__default
|
|
102
|
+
];
|
|
103
|
+
const sybzEslintConfig = createSybzEslintConfig();
|
|
104
|
+
|
|
105
|
+
exports.createSybzEslintConfig = createSybzEslintConfig;
|
|
106
|
+
exports.sybzEslintConfig = sybzEslintConfig;
|
|
107
|
+
exports.sybzLintStagedConfig = sybzLintStagedConfig;
|
|
108
|
+
exports.sybzPrettierConfig = sybzPrettierConfig;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Linter } from 'eslint';
|
|
2
|
+
import { Config } from 'prettier';
|
|
3
|
+
|
|
4
|
+
type SybzEslintConfig = Linter.Config;
|
|
5
|
+
/** 公司前端项目统一使用的 Prettier 配置。 */
|
|
6
|
+
declare const sybzPrettierConfig: Config;
|
|
7
|
+
/** 公司前端项目统一使用的 lint-staged 配置。 */
|
|
8
|
+
declare const sybzLintStagedConfig: Record<string, string[]>;
|
|
9
|
+
/**
|
|
10
|
+
* 创建公司统一的 ESLint flat config。项目级扩展会插入到 Prettier 兼容配置之前。
|
|
11
|
+
*/
|
|
12
|
+
declare const createSybzEslintConfig: (...extensions: Linter.Config[]) => Linter.Config[];
|
|
13
|
+
/** 公司前端项目默认的 ESLint flat config。 */
|
|
14
|
+
declare const sybzEslintConfig: SybzEslintConfig[];
|
|
15
|
+
|
|
16
|
+
export { createSybzEslintConfig, sybzEslintConfig, sybzLintStagedConfig, sybzPrettierConfig };
|
|
17
|
+
export type { SybzEslintConfig };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Linter } from 'eslint';
|
|
2
|
+
import { Config } from 'prettier';
|
|
3
|
+
|
|
4
|
+
type SybzEslintConfig = Linter.Config;
|
|
5
|
+
/** 公司前端项目统一使用的 Prettier 配置。 */
|
|
6
|
+
declare const sybzPrettierConfig: Config;
|
|
7
|
+
/** 公司前端项目统一使用的 lint-staged 配置。 */
|
|
8
|
+
declare const sybzLintStagedConfig: Record<string, string[]>;
|
|
9
|
+
/**
|
|
10
|
+
* 创建公司统一的 ESLint flat config。项目级扩展会插入到 Prettier 兼容配置之前。
|
|
11
|
+
*/
|
|
12
|
+
declare const createSybzEslintConfig: (...extensions: Linter.Config[]) => Linter.Config[];
|
|
13
|
+
/** 公司前端项目默认的 ESLint flat config。 */
|
|
14
|
+
declare const sybzEslintConfig: SybzEslintConfig[];
|
|
15
|
+
|
|
16
|
+
export { createSybzEslintConfig, sybzEslintConfig, sybzLintStagedConfig, sybzPrettierConfig };
|
|
17
|
+
export type { SybzEslintConfig };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Linter } from 'eslint';
|
|
2
|
+
import { Config } from 'prettier';
|
|
3
|
+
|
|
4
|
+
type SybzEslintConfig = Linter.Config;
|
|
5
|
+
/** 公司前端项目统一使用的 Prettier 配置。 */
|
|
6
|
+
declare const sybzPrettierConfig: Config;
|
|
7
|
+
/** 公司前端项目统一使用的 lint-staged 配置。 */
|
|
8
|
+
declare const sybzLintStagedConfig: Record<string, string[]>;
|
|
9
|
+
/**
|
|
10
|
+
* 创建公司统一的 ESLint flat config。项目级扩展会插入到 Prettier 兼容配置之前。
|
|
11
|
+
*/
|
|
12
|
+
declare const createSybzEslintConfig: (...extensions: Linter.Config[]) => Linter.Config[];
|
|
13
|
+
/** 公司前端项目默认的 ESLint flat config。 */
|
|
14
|
+
declare const sybzEslintConfig: SybzEslintConfig[];
|
|
15
|
+
|
|
16
|
+
export { createSybzEslintConfig, sybzEslintConfig, sybzLintStagedConfig, sybzPrettierConfig };
|
|
17
|
+
export type { SybzEslintConfig };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
|
3
|
+
import tsParser from '@typescript-eslint/parser';
|
|
4
|
+
import prettier from 'eslint-config-prettier';
|
|
5
|
+
import vue from 'eslint-plugin-vue';
|
|
6
|
+
import globals from 'globals';
|
|
7
|
+
import vueParser from 'vue-eslint-parser';
|
|
8
|
+
|
|
9
|
+
const sybzPrettierConfig = {
|
|
10
|
+
singleQuote: true,
|
|
11
|
+
semi: false,
|
|
12
|
+
trailingComma: "all",
|
|
13
|
+
printWidth: 120,
|
|
14
|
+
endOfLine: "lf",
|
|
15
|
+
htmlWhitespaceSensitivity: "ignore"
|
|
16
|
+
};
|
|
17
|
+
const sybzLintStagedConfig = {
|
|
18
|
+
"**/*.{js,jsx,ts,tsx,vue,mjs,cjs}": [
|
|
19
|
+
"sybz-code-standard prettier --write",
|
|
20
|
+
"sybz-code-standard eslint --fix --max-warnings=0"
|
|
21
|
+
],
|
|
22
|
+
"**/*.{css,scss,json,yaml,yml,html,md}": ["sybz-code-standard prettier --write"]
|
|
23
|
+
};
|
|
24
|
+
const baseEslintConfig = [
|
|
25
|
+
{
|
|
26
|
+
ignores: [
|
|
27
|
+
"node_modules/**",
|
|
28
|
+
"dist/**",
|
|
29
|
+
"dist-ssr/**",
|
|
30
|
+
"coverage/**",
|
|
31
|
+
"docs/.vitepress/cache/**",
|
|
32
|
+
"docs/.vitepress/dist/**",
|
|
33
|
+
"packages/*/dist/**",
|
|
34
|
+
".vitepress/**",
|
|
35
|
+
".codex-types-temp/**",
|
|
36
|
+
"*.tsbuildinfo",
|
|
37
|
+
"*.local"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
js.configs.recommended,
|
|
41
|
+
tsPlugin.configs["flat/base"],
|
|
42
|
+
...vue.configs["flat/recommended"],
|
|
43
|
+
{
|
|
44
|
+
files: ["**/*.{js,jsx,ts,tsx,cjs,mjs,vue}"],
|
|
45
|
+
languageOptions: {
|
|
46
|
+
ecmaVersion: "latest",
|
|
47
|
+
sourceType: "module",
|
|
48
|
+
globals: {
|
|
49
|
+
...globals.browser,
|
|
50
|
+
...globals.node,
|
|
51
|
+
...globals.es2021
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
rules: {
|
|
55
|
+
"no-console": "off",
|
|
56
|
+
"no-unused-vars": "off",
|
|
57
|
+
"vue/no-unused-vars": "off",
|
|
58
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
59
|
+
"vue/multi-word-component-names": "off",
|
|
60
|
+
"vue/no-template-shadow": "off",
|
|
61
|
+
"vue/attribute-hyphenation": ["warn", "always", { ignore: ["dangerouslyUseHTMLString"] }],
|
|
62
|
+
"vue/require-default-prop": "off"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
files: ["**/*.{ts,tsx,vue}"],
|
|
67
|
+
rules: {
|
|
68
|
+
"no-undef": "off",
|
|
69
|
+
"no-redeclare": "off"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
files: ["**/*.vue"],
|
|
74
|
+
languageOptions: {
|
|
75
|
+
parser: vueParser,
|
|
76
|
+
parserOptions: {
|
|
77
|
+
parser: tsParser,
|
|
78
|
+
ecmaVersion: "latest",
|
|
79
|
+
sourceType: "module",
|
|
80
|
+
ecmaFeatures: { jsx: true },
|
|
81
|
+
extraFileExtensions: [".vue"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
const createSybzEslintConfig = (...extensions) => [
|
|
87
|
+
...baseEslintConfig,
|
|
88
|
+
...extensions,
|
|
89
|
+
prettier
|
|
90
|
+
];
|
|
91
|
+
const sybzEslintConfig = createSybzEslintConfig();
|
|
92
|
+
|
|
93
|
+
export { createSybzEslintConfig, sybzEslintConfig, sybzLintStagedConfig, sybzPrettierConfig };
|
package/dist/format.cjs
CHANGED
package/dist/format.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.
|
|
1
|
+
export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.CJdEsMHi.mjs';
|
|
2
2
|
import './is.mjs';
|
|
3
3
|
import 'consola';
|
|
4
4
|
import 'vue';
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.
|
|
1
|
+
export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.CJdEsMHi.mjs';
|
|
2
2
|
export { resolveConfirmSemantic } from './confirmSemantic.mjs';
|
|
3
3
|
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
|
|
4
4
|
import 'vue';
|
|
@@ -1070,7 +1070,7 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1070
1070
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1071
1071
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1072
1072
|
{
|
|
1073
|
-
return "2026-09-
|
|
1073
|
+
return "2026-09-04 17:01:04";
|
|
1074
1074
|
}
|
|
1075
1075
|
}
|
|
1076
1076
|
function test() {
|
|
@@ -1072,7 +1072,7 @@ function getVariable(propertyName, fallback = "") {
|
|
|
1072
1072
|
const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
|
|
1073
1073
|
function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
|
|
1074
1074
|
{
|
|
1075
|
-
return "2026-09-
|
|
1075
|
+
return "2026-09-04 17:01:04";
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
function test() {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const node_child_process = require('node:child_process');
|
|
5
|
+
const node_fs = require('node:fs');
|
|
6
|
+
const node_module = require('node:module');
|
|
7
|
+
const node_path = require('node:path');
|
|
8
|
+
const husky = require('husky');
|
|
9
|
+
|
|
10
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
11
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
12
|
+
|
|
13
|
+
const husky__default = /*#__PURE__*/_interopDefaultCompat(husky);
|
|
14
|
+
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('sybz-code-standard.cjs', document.baseURI).href)));
|
|
17
|
+
const generatedFiles = {
|
|
18
|
+
"eslint.config.js": "export { sybzEslintConfig as default } from '@sybz-components/utils/codeStandard'\n",
|
|
19
|
+
".prettierrc.js": "export { sybzPrettierConfig as default } from '@sybz-components/utils/codeStandard'\n",
|
|
20
|
+
"lint-staged.config.js": "export { sybzLintStagedConfig as default } from '@sybz-components/utils/codeStandard'\n",
|
|
21
|
+
".editorconfig": `root = true
|
|
22
|
+
|
|
23
|
+
[*]
|
|
24
|
+
charset = utf-8
|
|
25
|
+
end_of_line = lf
|
|
26
|
+
indent_style = space
|
|
27
|
+
indent_size = 2
|
|
28
|
+
insert_final_newline = true
|
|
29
|
+
trim_trailing_whitespace = true
|
|
30
|
+
max_line_length = 120
|
|
31
|
+
|
|
32
|
+
[*.md]
|
|
33
|
+
trim_trailing_whitespace = false
|
|
34
|
+
`
|
|
35
|
+
};
|
|
36
|
+
const scripts = {
|
|
37
|
+
prepare: "sybz-code-standard prepare",
|
|
38
|
+
lint: "sybz-code-standard eslint . --fix",
|
|
39
|
+
"lint:check": "sybz-code-standard eslint .",
|
|
40
|
+
"lint:prettier": "sybz-code-standard prettier . --write",
|
|
41
|
+
"lint:prettier:check": "sybz-code-standard prettier . --check"
|
|
42
|
+
};
|
|
43
|
+
const runPackageBin = (packageName, binPath, args2) => {
|
|
44
|
+
const packageJsonPath = require2.resolve(`${packageName}/package.json`);
|
|
45
|
+
const executablePath = node_path.resolve(packageJsonPath, "..", binPath);
|
|
46
|
+
node_child_process.execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
|
|
47
|
+
};
|
|
48
|
+
const writeIfMissing = (relativePath, content) => {
|
|
49
|
+
const filePath = node_path.resolve(cwd, relativePath);
|
|
50
|
+
if (!node_fs.existsSync(filePath)) {
|
|
51
|
+
node_fs.writeFileSync(filePath, content, "utf8");
|
|
52
|
+
console.log(`\u521B\u5EFA ${relativePath}`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (node_fs.readFileSync(filePath, "utf8") !== content) {
|
|
56
|
+
console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const configurePackageJson = () => {
|
|
60
|
+
const packageJsonPath = node_path.resolve(cwd, "package.json");
|
|
61
|
+
if (!node_fs.existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
|
|
62
|
+
const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, "utf8"));
|
|
63
|
+
packageJson.scripts ??= {};
|
|
64
|
+
for (const [name, command2] of Object.entries(scripts)) {
|
|
65
|
+
const current = packageJson.scripts[name];
|
|
66
|
+
if (!current || current === command2) {
|
|
67
|
+
packageJson.scripts[name] = command2;
|
|
68
|
+
} else {
|
|
69
|
+
console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
node_fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
73
|
+
`, "utf8");
|
|
74
|
+
console.log("\u66F4\u65B0 package.json scripts");
|
|
75
|
+
};
|
|
76
|
+
const prepareHusky = () => {
|
|
77
|
+
const result = husky__default();
|
|
78
|
+
if (result) console.warn(result);
|
|
79
|
+
};
|
|
80
|
+
const configurePreCommit = () => {
|
|
81
|
+
prepareHusky();
|
|
82
|
+
const huskyDir = node_path.resolve(cwd, ".husky");
|
|
83
|
+
const hookPath = node_path.resolve(huskyDir, "pre-commit");
|
|
84
|
+
const command2 = "pnpm exec sybz-code-standard staged";
|
|
85
|
+
node_fs.mkdirSync(huskyDir, { recursive: true });
|
|
86
|
+
const current = node_fs.existsSync(hookPath) ? node_fs.readFileSync(hookPath, "utf8").trimEnd() : "";
|
|
87
|
+
if (current.includes("sybz-code-standard staged")) return;
|
|
88
|
+
node_fs.writeFileSync(hookPath, `${current ? `${current}
|
|
89
|
+
` : ""}${command2}
|
|
90
|
+
`, { encoding: "utf8", mode: 493 });
|
|
91
|
+
console.log("\u66F4\u65B0 .husky/pre-commit");
|
|
92
|
+
};
|
|
93
|
+
const init = () => {
|
|
94
|
+
configurePackageJson();
|
|
95
|
+
for (const [filePath, content] of Object.entries(generatedFiles)) writeIfMissing(filePath, content);
|
|
96
|
+
configurePreCommit();
|
|
97
|
+
console.log("\n\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2\u63A5\u5165\u3002");
|
|
98
|
+
};
|
|
99
|
+
const [command = "init", ...args] = process.argv.slice(2);
|
|
100
|
+
switch (command) {
|
|
101
|
+
case "init":
|
|
102
|
+
init();
|
|
103
|
+
break;
|
|
104
|
+
case "prepare":
|
|
105
|
+
prepareHusky();
|
|
106
|
+
break;
|
|
107
|
+
case "eslint":
|
|
108
|
+
runPackageBin("eslint", "bin/eslint.js", args);
|
|
109
|
+
break;
|
|
110
|
+
case "prettier":
|
|
111
|
+
runPackageBin("prettier", "bin/prettier.cjs", args);
|
|
112
|
+
break;
|
|
113
|
+
case "staged":
|
|
114
|
+
runPackageBin("lint-staged", "bin/lint-staged.js", args);
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
console.error(`\u672A\u77E5\u547D\u4EE4\uFF1A${command}`);
|
|
118
|
+
process.exitCode = 1;
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -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/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
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.0.11",
|
|
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,27 @@
|
|
|
46
54
|
},
|
|
47
55
|
"author": "",
|
|
48
56
|
"dependencies": {
|
|
57
|
+
"@eslint/js": "9.39.4",
|
|
58
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "8.62.0",
|
|
60
|
+
"@typescript-eslint/parser": "8.62.0",
|
|
49
61
|
"@vue/reactivity": "^3.5.18",
|
|
50
62
|
"@vue/shared": "^3.5.18",
|
|
51
63
|
"code-inspector-plugin": "^0.10.1",
|
|
52
64
|
"consola": "^3.4.2",
|
|
53
65
|
"element-plus": "^2.11.5",
|
|
66
|
+
"eslint": "9.39.4",
|
|
67
|
+
"eslint-config-prettier": "9.1.2",
|
|
68
|
+
"eslint-plugin-vue": "10.9.2",
|
|
54
69
|
"es-toolkit": "^1.39.10",
|
|
55
70
|
"lodash-es": "^4.17.21",
|
|
56
|
-
"
|
|
71
|
+
"globals": "16.5.0",
|
|
72
|
+
"husky": "9.1.7",
|
|
73
|
+
"lint-staged": "15.5.2",
|
|
74
|
+
"prettier": "3.8.4",
|
|
75
|
+
"tailwindcss": "^4.3.3",
|
|
76
|
+
"vue": "3.4.15",
|
|
77
|
+
"vue-eslint-parser": "10.4.1"
|
|
57
78
|
},
|
|
58
79
|
"peerDependencies": {
|
|
59
80
|
"vite": ">=5 <8"
|