@apdesign/code-style-react 1.2.3 → 2.0.1
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/.prettierrc.js +10 -10
- package/CHANGELOG.md +179 -0
- package/MIGRATION.md +211 -0
- package/README.md +262 -0
- package/biome.jsonc +107 -0
- package/cli.js +49 -15
- package/index.js +13 -13
- package/lefthook.yml +19 -0
- package/package.json +67 -45
- package/scripts/buildEslint.sh +59 -59
- package/scripts/initConfigs.js +121 -98
- package/scripts/initHusky.js +36 -33
- package/scripts/initScripts.js +39 -36
- package/scripts/runEslint.js +189 -189
- package/scripts/runStylelint.js +137 -137
- package/stylelint/{.stylelintrc.js → rules/.stylelintrc.js} +39 -39
- package/stylelint/rules/color-must-use-variable.js +63 -61
- package/eslint/.eslintrc.build.js +0 -107
- package/eslint/.eslintrc.js +0 -107
package/scripts/initConfigs.js
CHANGED
@@ -1,98 +1,121 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
const fs = require('fs');
|
4
|
-
const path = require('path');
|
5
|
-
|
6
|
-
function fileExists(filepath) {
|
7
|
-
try {
|
8
|
-
return fs.existsSync(filepath);
|
9
|
-
} catch (err) {
|
10
|
-
console.error(`❌ Check whether there are any errors in the file: ${filepath}`, err);
|
11
|
-
return false;
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
function createIfNotExists(filename, content) {
|
16
|
-
const filepath = path.resolve(process.cwd(), filename);
|
17
|
-
try {
|
18
|
-
if (!fs.existsSync(filepath)) {
|
19
|
-
fs.writeFileSync(filepath, content, { encoding: 'utf-8' });
|
20
|
-
console.log(`✅ The ${filename} has been created`);
|
21
|
-
}
|
22
|
-
} catch (err) {
|
23
|
-
console.error(`❌ Failed to create the file: ${filename}`, err);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
function hasAnyFileExist(files) {
|
28
|
-
const cwd = process.cwd();
|
29
|
-
return files.some((file) => fileExists(path.join(cwd, file)));
|
30
|
-
}
|
31
|
-
|
32
|
-
function initConfigs() {
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
-
'.
|
37
|
-
'.
|
38
|
-
'.
|
39
|
-
'.
|
40
|
-
'
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
'.
|
47
|
-
'.
|
48
|
-
'.
|
49
|
-
'.
|
50
|
-
'
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const fs = require('node:fs');
|
4
|
+
const path = require('node:path');
|
5
|
+
|
6
|
+
function fileExists(filepath) {
|
7
|
+
try {
|
8
|
+
return fs.existsSync(filepath);
|
9
|
+
} catch (err) {
|
10
|
+
console.error(`❌ Check whether there are any errors in the file: ${filepath}`, err);
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
function createIfNotExists(filename, content) {
|
16
|
+
const filepath = path.resolve(process.cwd(), filename);
|
17
|
+
try {
|
18
|
+
if (!fs.existsSync(filepath)) {
|
19
|
+
fs.writeFileSync(filepath, content, { encoding: 'utf-8' });
|
20
|
+
console.log(`✅ The ${filename} has been created`);
|
21
|
+
}
|
22
|
+
} catch (err) {
|
23
|
+
console.error(`❌ Failed to create the file: ${filename}`, err);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
function hasAnyFileExist(files) {
|
28
|
+
const cwd = process.cwd();
|
29
|
+
return files.some((file) => fileExists(path.join(cwd, file)));
|
30
|
+
}
|
31
|
+
|
32
|
+
function initConfigs() {
|
33
|
+
const biomeConfigFiles = ['biome.json', 'biome.jsonc'];
|
34
|
+
|
35
|
+
const stylelintConfigFiles = [
|
36
|
+
'.stylelintrc.js',
|
37
|
+
'.stylelintrc.cjs',
|
38
|
+
'.stylelintrc.json',
|
39
|
+
'.stylelintrc.yaml',
|
40
|
+
'.stylelintrc.yml',
|
41
|
+
'.stylelintrc',
|
42
|
+
'stylelint.config.js',
|
43
|
+
];
|
44
|
+
|
45
|
+
const prettierConfigFiles = [
|
46
|
+
'.prettierrc',
|
47
|
+
'.prettierrc.js',
|
48
|
+
'.prettierrc.cjs',
|
49
|
+
'.prettierrc.json',
|
50
|
+
'.prettierrc.yaml',
|
51
|
+
'.prettierrc.yml',
|
52
|
+
'prettier.config.js',
|
53
|
+
];
|
54
|
+
|
55
|
+
try {
|
56
|
+
// 创建 biome.jsonc 配置(替代 ESLint 和 Prettier)
|
57
|
+
if (!hasAnyFileExist(biomeConfigFiles)) {
|
58
|
+
const biomeContent = `{
|
59
|
+
"$schema": "https://biomejs.dev/schemas/2.2.6/schema.json",
|
60
|
+
"extends": ["@apdesign/code-style-react/biome.jsonc"],
|
61
|
+
"linter": {
|
62
|
+
"rules": {
|
63
|
+
// 在这里添加你的自定义规则
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}`;
|
67
|
+
createIfNotExists('biome.jsonc', biomeContent);
|
68
|
+
}
|
69
|
+
|
70
|
+
// 创建 Stylelint 配置
|
71
|
+
if (!hasAnyFileExist(stylelintConfigFiles)) {
|
72
|
+
const stylelintContent = `const baseConfig = require('@apdesign/code-style-react/stylelint/.stylelintrc.js');
|
73
|
+
module.exports = {
|
74
|
+
...baseConfig,
|
75
|
+
rules: {
|
76
|
+
...baseConfig.rules,
|
77
|
+
},
|
78
|
+
};`;
|
79
|
+
createIfNotExists('.stylelintrc.cjs', stylelintContent);
|
80
|
+
}
|
81
|
+
|
82
|
+
// 创建 Prettier 配置(向后兼容)
|
83
|
+
if (!hasAnyFileExist(prettierConfigFiles)) {
|
84
|
+
const prettierContent = `const baseConfig = require('@apdesign/code-style-react/.prettierrc.js');
|
85
|
+
module.exports = {
|
86
|
+
...baseConfig
|
87
|
+
};`;
|
88
|
+
createIfNotExists('.prettierrc.cjs', prettierContent);
|
89
|
+
}
|
90
|
+
|
91
|
+
// 创建 lefthook 配置
|
92
|
+
const lefthookConfigPath = path.resolve(process.cwd(), 'lefthook.yml');
|
93
|
+
if (!fs.existsSync(lefthookConfigPath)) {
|
94
|
+
const lefthookContent = `pre-commit:
|
95
|
+
parallel: true
|
96
|
+
commands:
|
97
|
+
lint:
|
98
|
+
glob: "*.{js,jsx,ts,tsx,json,jsonc,css,scss,md,mdx}"
|
99
|
+
run: npx lint-staged
|
100
|
+
`;
|
101
|
+
createIfNotExists('lefthook.yml', lefthookContent);
|
102
|
+
}
|
103
|
+
|
104
|
+
// 创建 lint-staged 配置(如果 package.json 中没有)
|
105
|
+
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
|
106
|
+
if (fs.existsSync(packageJsonPath)) {
|
107
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
108
|
+
if (!packageJson['lint-staged']) {
|
109
|
+
packageJson['lint-staged'] = {
|
110
|
+
'*.{js,jsx,ts,tsx,json,jsonc,css,scss,md,mdx}': ['npx ultracite fix'],
|
111
|
+
};
|
112
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
|
113
|
+
console.log('✅ lint-staged configuration added to package.json');
|
114
|
+
}
|
115
|
+
}
|
116
|
+
} catch (err) {
|
117
|
+
console.error('❌ Failed to initialize configuration:', err);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
module.exports = initConfigs;
|
package/scripts/initHusky.js
CHANGED
@@ -1,33 +1,36 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
const fs = require('fs');
|
4
|
-
const path = require('path');
|
5
|
-
const { execSync } = require('child_process');
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
fs.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const fs = require('node:fs');
|
4
|
+
const path = require('node:path');
|
5
|
+
const { execSync } = require('node:child_process');
|
6
|
+
|
7
|
+
// 文件权限常量:可执行文件权限 (rwxr-xr-x)
|
8
|
+
const EXECUTABLE_PERMISSION = 0o755;
|
9
|
+
|
10
|
+
function initHusky() {
|
11
|
+
const projectRoot = process.cwd();
|
12
|
+
const huskyTarget = path.join(projectRoot, '.husky');
|
13
|
+
const huskySource = path.join(__dirname, '../husky');
|
14
|
+
|
15
|
+
try {
|
16
|
+
if (fs.existsSync(huskyTarget)) {
|
17
|
+
fs.rmSync(huskyTarget, { recursive: true, force: true });
|
18
|
+
}
|
19
|
+
fs.cpSync(huskySource, huskyTarget, { recursive: true });
|
20
|
+
|
21
|
+
fs.readdirSync(huskyTarget).forEach((file) => {
|
22
|
+
const filePath = path.join(huskyTarget, file);
|
23
|
+
if (fs.statSync(filePath).isFile()) {
|
24
|
+
fs.chmodSync(filePath, EXECUTABLE_PERMISSION);
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
execSync('git config core.hooksPath .husky');
|
29
|
+
|
30
|
+
console.log('✅ Husky hooks installed from @apdesign/code-style-react');
|
31
|
+
} catch (err) {
|
32
|
+
console.error('❌ Failed to initialize husky:', err);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
module.exports = initHusky;
|
package/scripts/initScripts.js
CHANGED
@@ -1,36 +1,39 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
|
3
|
-
const fs = require('fs');
|
4
|
-
const path = require('path');
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
|
36
|
-
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const fs = require('node:fs');
|
4
|
+
const path = require('node:path');
|
5
|
+
|
6
|
+
// 文件权限常量:可执行文件权限 (rwxr-xr-x)
|
7
|
+
const EXECUTABLE_PERMISSION = 0o755;
|
8
|
+
|
9
|
+
function initScripts() {
|
10
|
+
const projectRoot = process.cwd();
|
11
|
+
const projectScriptsDir = path.join(projectRoot, 'scripts');
|
12
|
+
const packageScriptsDir = path.join(__dirname, '../scripts');
|
13
|
+
|
14
|
+
try {
|
15
|
+
if (!fs.existsSync(projectScriptsDir)) {
|
16
|
+
fs.mkdirSync(projectScriptsDir, { recursive: true });
|
17
|
+
console.log('📁 Created scripts directory in project');
|
18
|
+
}
|
19
|
+
|
20
|
+
fs.readdirSync(packageScriptsDir)
|
21
|
+
.filter((file) => file.endsWith('.sh'))
|
22
|
+
.forEach((file) => {
|
23
|
+
const srcFile = path.join(packageScriptsDir, file);
|
24
|
+
const destFile = path.join(projectScriptsDir, file);
|
25
|
+
|
26
|
+
if (fs.existsSync(destFile)) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
|
30
|
+
fs.copyFileSync(srcFile, destFile);
|
31
|
+
fs.chmodSync(destFile, EXECUTABLE_PERMISSION);
|
32
|
+
console.log(`📄 Copied ${file} to scripts/`);
|
33
|
+
});
|
34
|
+
} catch (err) {
|
35
|
+
console.error('❌ Failed to initialize scripts:', err);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
module.exports = initScripts;
|