@apdesign/code-style-react 1.2.9 → 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/.prettierrc.js +10 -10
- package/cli.js +15 -15
- package/eslint/.eslintrc.build.js +116 -116
- package/eslint/.eslintrc.js +114 -114
- package/husky/_/h +27 -27
- package/husky/_/pre-commit +1 -1
- package/husky/_/pre-push +1 -1
- package/husky/pre-commit +1 -1
- package/husky/pre-push +25 -25
- package/index.js +13 -13
- package/package.json +45 -45
- package/scripts/buildEslint.sh +59 -59
- package/scripts/buildStylelint.sh +49 -49
- package/scripts/initConfigs.js +98 -98
- package/scripts/initHusky.js +33 -33
- package/scripts/initScripts.js +36 -36
- package/scripts/runEslint.js +176 -176
- package/scripts/runStylelint.js +137 -137
- package/stylelint/.stylelintrc.js +39 -39
- package/stylelint/rules/color-must-use-variable.js +61 -61
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const initHusky = require('./scripts/initHusky');
|
|
4
|
-
const initScripts = require('./scripts/initScripts');
|
|
5
|
-
const initConfigs = require('./scripts/initConfigs');
|
|
6
|
-
|
|
7
|
-
function main() {
|
|
8
|
-
initHusky();
|
|
9
|
-
initScripts();
|
|
10
|
-
initConfigs();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = main;
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const initHusky = require('./scripts/initHusky');
|
|
4
|
+
const initScripts = require('./scripts/initScripts');
|
|
5
|
+
const initConfigs = require('./scripts/initConfigs');
|
|
6
|
+
|
|
7
|
+
function main() {
|
|
8
|
+
initHusky();
|
|
9
|
+
initScripts();
|
|
10
|
+
initConfigs();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = main;
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@apdesign/code-style-react",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"scripts": {},
|
|
5
|
-
"bin": {
|
|
6
|
-
"apdesign-code-style": "cli.js"
|
|
7
|
-
},
|
|
8
|
-
"files": [
|
|
9
|
-
"index.js",
|
|
10
|
-
".prettierrc.js",
|
|
11
|
-
"eslint",
|
|
12
|
-
"stylelint",
|
|
13
|
-
"husky",
|
|
14
|
-
"scripts"
|
|
15
|
-
],
|
|
16
|
-
"keywords": [],
|
|
17
|
-
"author": "",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"description": "",
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@types/glob": "^8.1.0",
|
|
22
|
-
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
23
|
-
"@typescript-eslint/parser": "^6.21.0",
|
|
24
|
-
"css-color-names": "^1.0.1",
|
|
25
|
-
"eslint": "^8.57.1",
|
|
26
|
-
"eslint-config-airbnb": "^19.0.4",
|
|
27
|
-
"eslint-config-prettier": "^9.1.0",
|
|
28
|
-
"eslint-import-resolver-alias": "^1.1.2",
|
|
29
|
-
"eslint-plugin-import": "^2.31.0",
|
|
30
|
-
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
31
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
32
|
-
"eslint-plugin-react": "^7.37.2",
|
|
33
|
-
"eslint-plugin-react-hooks": "^4.6.2",
|
|
34
|
-
"glob": "^11.0.3",
|
|
35
|
-
"husky": "^9.1.7",
|
|
36
|
-
"lint-staged": "^15.3.0",
|
|
37
|
-
"postcss-less": "^6.0.0",
|
|
38
|
-
"postcss-scss": "^4.0.9",
|
|
39
|
-
"prettier": "^3.3.3",
|
|
40
|
-
"stylelint": "^16.19.1",
|
|
41
|
-
"stylelint-config-standard": "^38.0.0",
|
|
42
|
-
"stylelint-less": "^3.0.1",
|
|
43
|
-
"stylelint-scss": "^6.12.0"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@apdesign/code-style-react",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"scripts": {},
|
|
5
|
+
"bin": {
|
|
6
|
+
"apdesign-code-style": "cli.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
".prettierrc.js",
|
|
11
|
+
"eslint",
|
|
12
|
+
"stylelint",
|
|
13
|
+
"husky",
|
|
14
|
+
"scripts"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"description": "",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@types/glob": "^8.1.0",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
23
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
24
|
+
"css-color-names": "^1.0.1",
|
|
25
|
+
"eslint": "^8.57.1",
|
|
26
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
27
|
+
"eslint-config-prettier": "^9.1.0",
|
|
28
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
29
|
+
"eslint-plugin-import": "^2.31.0",
|
|
30
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
31
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
32
|
+
"eslint-plugin-react": "^7.37.2",
|
|
33
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
34
|
+
"glob": "^11.0.3",
|
|
35
|
+
"husky": "^9.1.7",
|
|
36
|
+
"lint-staged": "^15.3.0",
|
|
37
|
+
"postcss-less": "^6.0.0",
|
|
38
|
+
"postcss-scss": "^4.0.9",
|
|
39
|
+
"prettier": "^3.3.3",
|
|
40
|
+
"stylelint": "^16.19.1",
|
|
41
|
+
"stylelint-config-standard": "^38.0.0",
|
|
42
|
+
"stylelint-less": "^3.0.1",
|
|
43
|
+
"stylelint-scss": "^6.12.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/scripts/buildEslint.sh
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
#!/usr/bin/env sh
|
|
2
|
-
echo "🔍 Starting ESLint check (Git diff files only)..."
|
|
3
|
-
|
|
4
|
-
# 切换到 Git 仓库根目录
|
|
5
|
-
PROJECT_ROOT=$(git rev-parse --show-toplevel)
|
|
6
|
-
cd "$PROJECT_ROOT" || exit 1
|
|
7
|
-
|
|
8
|
-
# 参数:commitId(必填),路径(可选)
|
|
9
|
-
TARGET_COMMIT=$1
|
|
10
|
-
LATEST_COMMIT=$(git rev-parse HEAD)
|
|
11
|
-
|
|
12
|
-
if [ -z "$TARGET_COMMIT" ]; then
|
|
13
|
-
echo "❗ Error: Missing target commit ID."
|
|
14
|
-
echo "👉 Usage: $0 <target-commit-id> [project-path]"
|
|
15
|
-
exit 1
|
|
16
|
-
fi
|
|
17
|
-
|
|
18
|
-
echo "获取到上一次运行commit ID: $TARGET_COMMIT"
|
|
19
|
-
echo "获取到当前最新的commit ID: $LATEST_COMMIT"
|
|
20
|
-
|
|
21
|
-
# 处理路径参数
|
|
22
|
-
if [ -n "$FULL_PATH" ]; then
|
|
23
|
-
PROJECT_NAME=$(basename "$FULL_PATH")
|
|
24
|
-
echo "📂 检测子项目: $PROJECT_NAME"
|
|
25
|
-
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- "*/$PROJECT_NAME/*.{ts,tsx,js,jsx}")
|
|
26
|
-
else
|
|
27
|
-
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.ts' '*.tsx' '*.js' '*.jsx')
|
|
28
|
-
fi
|
|
29
|
-
|
|
30
|
-
if [ -z "$DIFF_FILES" ]; then
|
|
31
|
-
echo "✅ No matching file changes detected, skipping ESLint check"
|
|
32
|
-
exit 0
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
echo "📂 Changed files:"
|
|
36
|
-
echo "$DIFF_FILES"
|
|
37
|
-
|
|
38
|
-
FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
|
|
39
|
-
echo "🧾 Total changed files: $FILE_COUNT"
|
|
40
|
-
|
|
41
|
-
ESLINT_CONFIG_FILE="$PROJECT_ROOT/.eslintrc.build.cjs"
|
|
42
|
-
|
|
43
|
-
ESLINT_CMD_ARGS="--no-error-on-unmatched-pattern --report-unused-disable-directives"
|
|
44
|
-
|
|
45
|
-
if [ -f "$ESLINT_CONFIG_FILE" ]; then
|
|
46
|
-
echo "🔧 Using ESLint config file: $ESLINT_CONFIG_FILE"
|
|
47
|
-
ESLINT_CMD_ARGS="--config $ESLINT_CONFIG_FILE $ESLINT_CMD_ARGS"
|
|
48
|
-
else
|
|
49
|
-
echo "⚠️ ESLint config file not found, using default ESLint config resolution."
|
|
50
|
-
fi
|
|
51
|
-
|
|
52
|
-
echo "$DIFF_FILES" | tr -d '\r' | \
|
|
53
|
-
xargs -d '\n' -P 4 -n 30 npx --no-install eslint $ESLINT_CMD_ARGS
|
|
54
|
-
|
|
55
|
-
if [ $? -ne 0 ]; then
|
|
56
|
-
echo "❌ ESLint check failed. Aborting build process"
|
|
57
|
-
exit 1
|
|
58
|
-
fi
|
|
59
|
-
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
echo "🔍 Starting ESLint check (Git diff files only)..."
|
|
3
|
+
|
|
4
|
+
# 切换到 Git 仓库根目录
|
|
5
|
+
PROJECT_ROOT=$(git rev-parse --show-toplevel)
|
|
6
|
+
cd "$PROJECT_ROOT" || exit 1
|
|
7
|
+
|
|
8
|
+
# 参数:commitId(必填),路径(可选)
|
|
9
|
+
TARGET_COMMIT=$1
|
|
10
|
+
LATEST_COMMIT=$(git rev-parse HEAD)
|
|
11
|
+
|
|
12
|
+
if [ -z "$TARGET_COMMIT" ]; then
|
|
13
|
+
echo "❗ Error: Missing target commit ID."
|
|
14
|
+
echo "👉 Usage: $0 <target-commit-id> [project-path]"
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
echo "获取到上一次运行commit ID: $TARGET_COMMIT"
|
|
19
|
+
echo "获取到当前最新的commit ID: $LATEST_COMMIT"
|
|
20
|
+
|
|
21
|
+
# 处理路径参数
|
|
22
|
+
if [ -n "$FULL_PATH" ]; then
|
|
23
|
+
PROJECT_NAME=$(basename "$FULL_PATH")
|
|
24
|
+
echo "📂 检测子项目: $PROJECT_NAME"
|
|
25
|
+
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- "*/$PROJECT_NAME/*.{ts,tsx,js,jsx}")
|
|
26
|
+
else
|
|
27
|
+
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.ts' '*.tsx' '*.js' '*.jsx')
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
if [ -z "$DIFF_FILES" ]; then
|
|
31
|
+
echo "✅ No matching file changes detected, skipping ESLint check"
|
|
32
|
+
exit 0
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
echo "📂 Changed files:"
|
|
36
|
+
echo "$DIFF_FILES"
|
|
37
|
+
|
|
38
|
+
FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
|
|
39
|
+
echo "🧾 Total changed files: $FILE_COUNT"
|
|
40
|
+
|
|
41
|
+
ESLINT_CONFIG_FILE="$PROJECT_ROOT/.eslintrc.build.cjs"
|
|
42
|
+
|
|
43
|
+
ESLINT_CMD_ARGS="--no-error-on-unmatched-pattern --report-unused-disable-directives"
|
|
44
|
+
|
|
45
|
+
if [ -f "$ESLINT_CONFIG_FILE" ]; then
|
|
46
|
+
echo "🔧 Using ESLint config file: $ESLINT_CONFIG_FILE"
|
|
47
|
+
ESLINT_CMD_ARGS="--config $ESLINT_CONFIG_FILE $ESLINT_CMD_ARGS"
|
|
48
|
+
else
|
|
49
|
+
echo "⚠️ ESLint config file not found, using default ESLint config resolution."
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
echo "$DIFF_FILES" | tr -d '\r' | \
|
|
53
|
+
xargs -d '\n' -P 4 -n 30 npx --no-install eslint $ESLINT_CMD_ARGS
|
|
54
|
+
|
|
55
|
+
if [ $? -ne 0 ]; then
|
|
56
|
+
echo "❌ ESLint check failed. Aborting build process"
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
60
|
echo "✅ ESLint check passed"
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
#!/usr/bin/env sh
|
|
2
|
-
echo "🔍 Starting Stylelint check (Git diff files only)..."
|
|
3
|
-
|
|
4
|
-
PROJECT_ROOT=$(git rev-parse --show-toplevel)
|
|
5
|
-
cd "$PROJECT_ROOT" || exit 1
|
|
6
|
-
|
|
7
|
-
TARGET_COMMIT=$1
|
|
8
|
-
LATEST_COMMIT=$(git rev-parse HEAD)
|
|
9
|
-
|
|
10
|
-
if [ -z "$TARGET_COMMIT" ]; then
|
|
11
|
-
echo "❗ Error: Missing target commit ID."
|
|
12
|
-
echo "👉 Usage: $0 <target-commit-id>"
|
|
13
|
-
exit 1
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
echo "获取到上一次运行commit ID: $TARGET_COMMIT"
|
|
17
|
-
echo "获取到当前最新的commit ID: $LATEST_COMMIT"
|
|
18
|
-
|
|
19
|
-
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.css' '*.scss' '*.sass' '*.less')
|
|
20
|
-
|
|
21
|
-
if [ -z "$DIFF_FILES" ]; then
|
|
22
|
-
echo "✅ No matching file changes detected, skipping Stylelint check"
|
|
23
|
-
exit 0
|
|
24
|
-
fi
|
|
25
|
-
|
|
26
|
-
echo "📂 Changed files:"
|
|
27
|
-
echo "$DIFF_FILES"
|
|
28
|
-
|
|
29
|
-
FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
|
|
30
|
-
echo "🧾 Total changed files: $FILE_COUNT"
|
|
31
|
-
|
|
32
|
-
STYLELINT_CONFIG_FILE="$PROJECT_ROOT/.stylelintrc.build.cjs"
|
|
33
|
-
STYLELINT_CMD_ARGS="--allow-empty-input --report-needless-disables --report-invalid-scope-disables"
|
|
34
|
-
|
|
35
|
-
if [ -f "$STYLELINT_CONFIG_FILE" ]; then
|
|
36
|
-
echo "🔧 Using Stylelint config file: $STYLELINT_CONFIG_FILE"
|
|
37
|
-
STYLELINT_CMD_ARGS="--config $STYLELINT_CONFIG_FILE $STYLELINT_CMD_ARGS"
|
|
38
|
-
else
|
|
39
|
-
echo "⚠️ Stylelint config file not found, using default Stylelint config resolution."
|
|
40
|
-
fi
|
|
41
|
-
|
|
42
|
-
echo "$DIFF_FILES" | tr -d '\r' | \
|
|
43
|
-
xargs -d '\n' -P 4 -n 30 npx --no-install stylelint $STYLELINT_CMD_ARGS
|
|
44
|
-
|
|
45
|
-
if [ $? -ne 0 ]; then
|
|
46
|
-
echo "❌ Stylelint check failed. Aborting build process"
|
|
47
|
-
exit 1
|
|
48
|
-
fi
|
|
49
|
-
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
echo "🔍 Starting Stylelint check (Git diff files only)..."
|
|
3
|
+
|
|
4
|
+
PROJECT_ROOT=$(git rev-parse --show-toplevel)
|
|
5
|
+
cd "$PROJECT_ROOT" || exit 1
|
|
6
|
+
|
|
7
|
+
TARGET_COMMIT=$1
|
|
8
|
+
LATEST_COMMIT=$(git rev-parse HEAD)
|
|
9
|
+
|
|
10
|
+
if [ -z "$TARGET_COMMIT" ]; then
|
|
11
|
+
echo "❗ Error: Missing target commit ID."
|
|
12
|
+
echo "👉 Usage: $0 <target-commit-id>"
|
|
13
|
+
exit 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
echo "获取到上一次运行commit ID: $TARGET_COMMIT"
|
|
17
|
+
echo "获取到当前最新的commit ID: $LATEST_COMMIT"
|
|
18
|
+
|
|
19
|
+
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.css' '*.scss' '*.sass' '*.less')
|
|
20
|
+
|
|
21
|
+
if [ -z "$DIFF_FILES" ]; then
|
|
22
|
+
echo "✅ No matching file changes detected, skipping Stylelint check"
|
|
23
|
+
exit 0
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
echo "📂 Changed files:"
|
|
27
|
+
echo "$DIFF_FILES"
|
|
28
|
+
|
|
29
|
+
FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
|
|
30
|
+
echo "🧾 Total changed files: $FILE_COUNT"
|
|
31
|
+
|
|
32
|
+
STYLELINT_CONFIG_FILE="$PROJECT_ROOT/.stylelintrc.build.cjs"
|
|
33
|
+
STYLELINT_CMD_ARGS="--allow-empty-input --report-needless-disables --report-invalid-scope-disables"
|
|
34
|
+
|
|
35
|
+
if [ -f "$STYLELINT_CONFIG_FILE" ]; then
|
|
36
|
+
echo "🔧 Using Stylelint config file: $STYLELINT_CONFIG_FILE"
|
|
37
|
+
STYLELINT_CMD_ARGS="--config $STYLELINT_CONFIG_FILE $STYLELINT_CMD_ARGS"
|
|
38
|
+
else
|
|
39
|
+
echo "⚠️ Stylelint config file not found, using default Stylelint config resolution."
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
echo "$DIFF_FILES" | tr -d '\r' | \
|
|
43
|
+
xargs -d '\n' -P 4 -n 30 npx --no-install stylelint $STYLELINT_CMD_ARGS
|
|
44
|
+
|
|
45
|
+
if [ $? -ne 0 ]; then
|
|
46
|
+
echo "❌ Stylelint check failed. Aborting build process"
|
|
47
|
+
exit 1
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
50
|
echo "✅ Stylelint check passed"
|
package/scripts/initConfigs.js
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
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 eslintConfigFiles = [
|
|
34
|
-
'.eslintrc.js',
|
|
35
|
-
'.eslintrc.cjs',
|
|
36
|
-
'.eslintrc.json',
|
|
37
|
-
'.eslintrc.yaml',
|
|
38
|
-
'.eslintrc.yml',
|
|
39
|
-
'.eslintrc',
|
|
40
|
-
'eslint.config.js',
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
const stylelintConfigFiles = [
|
|
44
|
-
'.stylelintrc.js',
|
|
45
|
-
'.stylelintrc.cjs',
|
|
46
|
-
'.stylelintrc.json',
|
|
47
|
-
'.stylelintrc.yaml',
|
|
48
|
-
'.stylelintrc.yml',
|
|
49
|
-
'.stylelintrc',
|
|
50
|
-
'stylelint.config.js',
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
const prettierConfigFiles = [
|
|
54
|
-
'.prettierrc',
|
|
55
|
-
'.prettierrc.js',
|
|
56
|
-
'.prettierrc.cjs',
|
|
57
|
-
'.prettierrc.json',
|
|
58
|
-
'.prettierrc.yaml',
|
|
59
|
-
'.prettierrc.yml',
|
|
60
|
-
'prettier.config.js',
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
if (!hasAnyFileExist(eslintConfigFiles)) {
|
|
65
|
-
const eslintContent = `const baseConfig = require('@apdesign/code-style-react/eslint/.eslintrc.js');
|
|
66
|
-
module.exports = {
|
|
67
|
-
...baseConfig,
|
|
68
|
-
rules: {
|
|
69
|
-
...baseConfig.rules,
|
|
70
|
-
},
|
|
71
|
-
};`;
|
|
72
|
-
createIfNotExists('.eslintrc.cjs', eslintContent);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!hasAnyFileExist(stylelintConfigFiles)) {
|
|
76
|
-
const stylelintContent = `const baseConfig = require('@apdesign/code-style-react/stylelint/.stylelintrc.js');
|
|
77
|
-
module.exports = {
|
|
78
|
-
...baseConfig,
|
|
79
|
-
rules: {
|
|
80
|
-
...baseConfig.rules,
|
|
81
|
-
},
|
|
82
|
-
};`;
|
|
83
|
-
createIfNotExists('.stylelintrc.cjs', stylelintContent);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!hasAnyFileExist(prettierConfigFiles)) {
|
|
87
|
-
const prettierContent = `const baseConfig = require('@apdesign/code-style-react/.prettierrc.js');
|
|
88
|
-
module.exports = {
|
|
89
|
-
...baseConfig
|
|
90
|
-
};`;
|
|
91
|
-
createIfNotExists('.prettierrc.cjs', prettierContent);
|
|
92
|
-
}
|
|
93
|
-
} catch (err) {
|
|
94
|
-
console.error('❌ Failed to initialize configuration:', err);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
module.exports = initConfigs;
|
|
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 eslintConfigFiles = [
|
|
34
|
+
'.eslintrc.js',
|
|
35
|
+
'.eslintrc.cjs',
|
|
36
|
+
'.eslintrc.json',
|
|
37
|
+
'.eslintrc.yaml',
|
|
38
|
+
'.eslintrc.yml',
|
|
39
|
+
'.eslintrc',
|
|
40
|
+
'eslint.config.js',
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const stylelintConfigFiles = [
|
|
44
|
+
'.stylelintrc.js',
|
|
45
|
+
'.stylelintrc.cjs',
|
|
46
|
+
'.stylelintrc.json',
|
|
47
|
+
'.stylelintrc.yaml',
|
|
48
|
+
'.stylelintrc.yml',
|
|
49
|
+
'.stylelintrc',
|
|
50
|
+
'stylelint.config.js',
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const prettierConfigFiles = [
|
|
54
|
+
'.prettierrc',
|
|
55
|
+
'.prettierrc.js',
|
|
56
|
+
'.prettierrc.cjs',
|
|
57
|
+
'.prettierrc.json',
|
|
58
|
+
'.prettierrc.yaml',
|
|
59
|
+
'.prettierrc.yml',
|
|
60
|
+
'prettier.config.js',
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
if (!hasAnyFileExist(eslintConfigFiles)) {
|
|
65
|
+
const eslintContent = `const baseConfig = require('@apdesign/code-style-react/eslint/.eslintrc.js');
|
|
66
|
+
module.exports = {
|
|
67
|
+
...baseConfig,
|
|
68
|
+
rules: {
|
|
69
|
+
...baseConfig.rules,
|
|
70
|
+
},
|
|
71
|
+
};`;
|
|
72
|
+
createIfNotExists('.eslintrc.cjs', eslintContent);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!hasAnyFileExist(stylelintConfigFiles)) {
|
|
76
|
+
const stylelintContent = `const baseConfig = require('@apdesign/code-style-react/stylelint/.stylelintrc.js');
|
|
77
|
+
module.exports = {
|
|
78
|
+
...baseConfig,
|
|
79
|
+
rules: {
|
|
80
|
+
...baseConfig.rules,
|
|
81
|
+
},
|
|
82
|
+
};`;
|
|
83
|
+
createIfNotExists('.stylelintrc.cjs', stylelintContent);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!hasAnyFileExist(prettierConfigFiles)) {
|
|
87
|
+
const prettierContent = `const baseConfig = require('@apdesign/code-style-react/.prettierrc.js');
|
|
88
|
+
module.exports = {
|
|
89
|
+
...baseConfig
|
|
90
|
+
};`;
|
|
91
|
+
createIfNotExists('.prettierrc.cjs', prettierContent);
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.error('❌ Failed to initialize configuration:', err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = initConfigs;
|
package/scripts/initHusky.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execSync } = require('child_process');
|
|
6
|
-
|
|
7
|
-
function initHusky() {
|
|
8
|
-
const projectRoot = process.cwd();
|
|
9
|
-
const huskyTarget = path.join(projectRoot, '.husky');
|
|
10
|
-
const huskySource = path.join(__dirname, '../husky');
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
if (fs.existsSync(huskyTarget)) {
|
|
14
|
-
fs.rmSync(huskyTarget, { recursive: true, force: true });
|
|
15
|
-
}
|
|
16
|
-
fs.cpSync(huskySource, huskyTarget, { recursive: true });
|
|
17
|
-
|
|
18
|
-
fs.readdirSync(huskyTarget).forEach((file) => {
|
|
19
|
-
const filePath = path.join(huskyTarget, file);
|
|
20
|
-
if (fs.statSync(filePath).isFile()) {
|
|
21
|
-
fs.chmodSync(filePath, 0o755);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
execSync('git config core.hooksPath .husky');
|
|
26
|
-
|
|
27
|
-
console.log('✅ Husky hooks installed from @apdesign/code-style-react');
|
|
28
|
-
} catch (err) {
|
|
29
|
-
console.error('❌ Failed to initialize husky:', err);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = initHusky;
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
function initHusky() {
|
|
8
|
+
const projectRoot = process.cwd();
|
|
9
|
+
const huskyTarget = path.join(projectRoot, '.husky');
|
|
10
|
+
const huskySource = path.join(__dirname, '../husky');
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
if (fs.existsSync(huskyTarget)) {
|
|
14
|
+
fs.rmSync(huskyTarget, { recursive: true, force: true });
|
|
15
|
+
}
|
|
16
|
+
fs.cpSync(huskySource, huskyTarget, { recursive: true });
|
|
17
|
+
|
|
18
|
+
fs.readdirSync(huskyTarget).forEach((file) => {
|
|
19
|
+
const filePath = path.join(huskyTarget, file);
|
|
20
|
+
if (fs.statSync(filePath).isFile()) {
|
|
21
|
+
fs.chmodSync(filePath, 0o755);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
execSync('git config core.hooksPath .husky');
|
|
26
|
+
|
|
27
|
+
console.log('✅ Husky hooks installed from @apdesign/code-style-react');
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error('❌ Failed to initialize husky:', err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = initHusky;
|