@apdesign/code-style-react 1.1.0 → 1.1.2
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/cli.js +3 -0
- package/eslint/.eslintrc.build.js +10 -1
- package/eslint/.eslintrc.js +12 -3
- 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/package.json +1 -1
- package/scripts/buildEslint.sh +51 -51
- package/scripts/buildStylelint.sh +49 -49
- package/scripts/runEslint.js +127 -0
package/cli.js
CHANGED
@@ -21,6 +21,9 @@ module.exports = {
|
|
21
21
|
camelcase: 'off',
|
22
22
|
'class-methods-use-this': 'off',
|
23
23
|
|
24
|
+
'dot-notation': 'warn',
|
25
|
+
|
26
|
+
'import/order': 'warn',
|
24
27
|
'import/first': 'off',
|
25
28
|
'import/extensions': 'off',
|
26
29
|
'import/prefer-default-export': 'off',
|
@@ -30,6 +33,7 @@ module.exports = {
|
|
30
33
|
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
31
34
|
|
32
35
|
'linebreak-style': 'off',
|
36
|
+
'lines-between-class-members': 'warn',
|
33
37
|
|
34
38
|
'max-classes-per-file': 'off',
|
35
39
|
|
@@ -47,6 +51,11 @@ module.exports = {
|
|
47
51
|
'react/self-closing-comp': 'off',
|
48
52
|
'react/jsx-no-useless-fragment': 'off',
|
49
53
|
|
54
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
55
|
+
|
56
|
+
'no-use-before-define': 'off',
|
57
|
+
'@typescript-eslint/no-use-before-define': ['warn'],
|
58
|
+
|
50
59
|
'no-unused-vars': 'off',
|
51
60
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
52
61
|
|
@@ -56,7 +65,7 @@ module.exports = {
|
|
56
65
|
'no-shadow': 'off',
|
57
66
|
'@typescript-eslint/no-shadow': 'warn',
|
58
67
|
|
59
|
-
'no-empty-function': ['warn', { allow: ['constructors'] }],
|
68
|
+
'no-empty-function': ['warn', { allow: ['constructors', 'arrowFunctions'] }],
|
60
69
|
'no-param-reassign': ['warn', { props: true, ignorePropertyModificationsFor: ['draft'] }],
|
61
70
|
'no-restricted-syntax': [
|
62
71
|
'warn',
|
package/eslint/.eslintrc.js
CHANGED
@@ -21,6 +21,9 @@ module.exports = {
|
|
21
21
|
camelcase: 'off',
|
22
22
|
'class-methods-use-this': 'off',
|
23
23
|
|
24
|
+
'dot-notation': 'warn',
|
25
|
+
|
26
|
+
'import/order': 'warn',
|
24
27
|
'import/first': 'off',
|
25
28
|
'import/extensions': 'off',
|
26
29
|
'import/prefer-default-export': 'off',
|
@@ -30,6 +33,7 @@ module.exports = {
|
|
30
33
|
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
31
34
|
|
32
35
|
'linebreak-style': 'off',
|
36
|
+
'lines-between-class-members': 'warn',
|
33
37
|
|
34
38
|
'max-classes-per-file': 'off',
|
35
39
|
|
@@ -47,6 +51,11 @@ module.exports = {
|
|
47
51
|
'react/self-closing-comp': 'off',
|
48
52
|
'react/jsx-no-useless-fragment': 'off',
|
49
53
|
|
54
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
55
|
+
|
56
|
+
'no-use-before-define': 'off',
|
57
|
+
'@typescript-eslint/no-use-before-define': ['warn'],
|
58
|
+
|
50
59
|
'no-unused-vars': 'off',
|
51
60
|
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
52
61
|
|
@@ -54,10 +63,10 @@ module.exports = {
|
|
54
63
|
'@typescript-eslint/no-useless-constructor': 'error',
|
55
64
|
|
56
65
|
'no-shadow': 'off',
|
57
|
-
'@typescript-eslint/no-shadow': '
|
66
|
+
'@typescript-eslint/no-shadow': 'warn',
|
58
67
|
|
59
|
-
'no-empty-function': ['
|
60
|
-
'no-param-reassign': ['
|
68
|
+
'no-empty-function': ['warn', { allow: ['constructors', 'arrowFunctions'] }],
|
69
|
+
'no-param-reassign': ['warn', { props: true, ignorePropertyModificationsFor: ['draft'] }],
|
61
70
|
'no-restricted-syntax': [
|
62
71
|
'warn',
|
63
72
|
{
|
package/husky/_/h
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
#!/usr/bin/env sh
|
2
|
-
[ "$HUSKY" = "2" ] && set -x
|
3
|
-
n=$(basename "$0")
|
4
|
-
s=$(dirname "$(dirname "$0")")/$n
|
5
|
-
|
6
|
-
if [[ "$(uname)" == "Darwin" ]]; then
|
7
|
-
elif [[ "$(uname -o)" == "Msys" || "$(uname)" == "CYGWIN" || "$(uname)" == "MINGW"* ]]; then
|
8
|
-
sed -i 's/\r//' "$0"
|
9
|
-
fi
|
10
|
-
|
11
|
-
[ ! -f "$s" ] && exit 0
|
12
|
-
|
13
|
-
if [ -f "$HOME/.huskyrc" ]; then
|
14
|
-
echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
|
15
|
-
fi
|
16
|
-
i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
|
17
|
-
[ -f "$i" ] && . "$i"
|
18
|
-
|
19
|
-
[ "${HUSKY-}" = "0" ] && exit 0
|
20
|
-
|
21
|
-
export PATH="node_modules/.bin:$PATH"
|
22
|
-
sh -e "$s" "$@"
|
23
|
-
c=$?
|
24
|
-
|
25
|
-
[ $c != 0 ] && echo "husky - $n script failed (code $c)"
|
26
|
-
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
|
27
|
-
exit $c
|
1
|
+
#!/usr/bin/env sh
|
2
|
+
[ "$HUSKY" = "2" ] && set -x
|
3
|
+
n=$(basename "$0")
|
4
|
+
s=$(dirname "$(dirname "$0")")/$n
|
5
|
+
|
6
|
+
if [[ "$(uname)" == "Darwin" ]]; then
|
7
|
+
elif [[ "$(uname -o)" == "Msys" || "$(uname)" == "CYGWIN" || "$(uname)" == "MINGW"* ]]; then
|
8
|
+
sed -i 's/\r//' "$0"
|
9
|
+
fi
|
10
|
+
|
11
|
+
[ ! -f "$s" ] && exit 0
|
12
|
+
|
13
|
+
if [ -f "$HOME/.huskyrc" ]; then
|
14
|
+
echo "husky - '~/.huskyrc' is DEPRECATED, please move your code to ~/.config/husky/init.sh"
|
15
|
+
fi
|
16
|
+
i="${XDG_CONFIG_HOME:-$HOME/.config}/husky/init.sh"
|
17
|
+
[ -f "$i" ] && . "$i"
|
18
|
+
|
19
|
+
[ "${HUSKY-}" = "0" ] && exit 0
|
20
|
+
|
21
|
+
export PATH="node_modules/.bin:$PATH"
|
22
|
+
sh -e "$s" "$@"
|
23
|
+
c=$?
|
24
|
+
|
25
|
+
[ $c != 0 ] && echo "husky - $n script failed (code $c)"
|
26
|
+
[ $c = 127 ] && echo "husky - command not found in PATH=$PATH"
|
27
|
+
exit $c
|
package/husky/_/pre-commit
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#!/usr/bin/env sh
|
1
|
+
#!/usr/bin/env sh
|
2
2
|
. "$(dirname "$0")/h"
|
package/husky/_/pre-push
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#!/usr/bin/env sh
|
1
|
+
#!/usr/bin/env sh
|
2
2
|
. "$(dirname "$0")/h"
|
package/husky/pre-commit
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#!/usr/bin/env sh
|
1
|
+
#!/usr/bin/env sh
|
2
2
|
npx lint-staged
|
package/husky/pre-push
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
#!/usr/bin/env sh
|
2
|
-
branch_name=$(git symbolic-ref --short HEAD)
|
3
|
-
|
4
|
-
branch_regex_master="^master$"
|
5
|
-
branch_regex_env="^(master|uat|dev)-[a-z]+$"
|
6
|
-
branch_regex_feature="^(feature|test|hotfix)-[a-z]+-[a-zA-Z0-9]+(-[A-Z]+[0-9]+)?$"
|
7
|
-
branch_regex_release="^release-[a-z]+-[0-9]{8}$"
|
8
|
-
|
9
|
-
if echo "$branch_name" | grep -Eq "$branch_regex_master"; then
|
10
|
-
exit 0
|
11
|
-
elif echo "$branch_name" | grep -Eq "$branch_regex_env"; then
|
12
|
-
exit 0
|
13
|
-
elif echo "$branch_name" | grep -Eq "$branch_regex_feature"; then
|
14
|
-
exit 0
|
15
|
-
elif echo "$branch_name" | grep -Eq "$branch_regex_release"; then
|
16
|
-
exit 0
|
17
|
-
else
|
18
|
-
echo -e "❌ \033[31m[ERROR] 当前分支名 '$branch_name' 不符合规范!\033[0m"
|
19
|
-
echo "分支命名规范要求如下:"
|
20
|
-
echo "✅ master"
|
21
|
-
echo "✅ master|uat|dev-[小写字母]"
|
22
|
-
echo "✅ feature|test|hotfix-[小写字母]+-[字母或数字]+(可选 -大写字母+数字)"
|
23
|
-
echo "✅ release-[小写字母]+-8位日期"
|
24
|
-
exit 1
|
25
|
-
fi
|
1
|
+
#!/usr/bin/env sh
|
2
|
+
branch_name=$(git symbolic-ref --short HEAD)
|
3
|
+
|
4
|
+
branch_regex_master="^master$"
|
5
|
+
branch_regex_env="^(master|uat|dev)-[a-z]+$"
|
6
|
+
branch_regex_feature="^(feature|test|hotfix)-[a-z]+-[a-zA-Z0-9]+(-[A-Z]+[0-9]+)?$"
|
7
|
+
branch_regex_release="^release-[a-z]+-[0-9]{8}$"
|
8
|
+
|
9
|
+
if echo "$branch_name" | grep -Eq "$branch_regex_master"; then
|
10
|
+
exit 0
|
11
|
+
elif echo "$branch_name" | grep -Eq "$branch_regex_env"; then
|
12
|
+
exit 0
|
13
|
+
elif echo "$branch_name" | grep -Eq "$branch_regex_feature"; then
|
14
|
+
exit 0
|
15
|
+
elif echo "$branch_name" | grep -Eq "$branch_regex_release"; then
|
16
|
+
exit 0
|
17
|
+
else
|
18
|
+
echo -e "❌ \033[31m[ERROR] 当前分支名 '$branch_name' 不符合规范!\033[0m"
|
19
|
+
echo "分支命名规范要求如下:"
|
20
|
+
echo "✅ master"
|
21
|
+
echo "✅ master|uat|dev-[小写字母]"
|
22
|
+
echo "✅ feature|test|hotfix-[小写字母]+-[字母或数字]+(可选 -大写字母+数字)"
|
23
|
+
echo "✅ release-[小写字母]+-8位日期"
|
24
|
+
exit 1
|
25
|
+
fi
|
package/package.json
CHANGED
package/scripts/buildEslint.sh
CHANGED
@@ -1,52 +1,52 @@
|
|
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
|
-
TARGET_COMMIT=$1
|
9
|
-
LATEST_COMMIT=$(git rev-parse HEAD)
|
10
|
-
|
11
|
-
if [ -z "$TARGET_COMMIT" ]; then
|
12
|
-
echo "❗ Error: Missing target commit ID."
|
13
|
-
echo "👉 Usage: $0 <target-commit-id>"
|
14
|
-
exit 1
|
15
|
-
fi
|
16
|
-
|
17
|
-
echo "获取到上一次运行commit ID: $TARGET_COMMIT"
|
18
|
-
echo "获取到当前最新的commit ID: $LATEST_COMMIT"
|
19
|
-
|
20
|
-
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.ts' '*.tsx' '*.js' '*.jsx')
|
21
|
-
|
22
|
-
if [ -z "$DIFF_FILES" ]; then
|
23
|
-
echo "✅ No matching file changes detected, skipping ESLint check"
|
24
|
-
exit 0
|
25
|
-
fi
|
26
|
-
|
27
|
-
echo "📂 Changed files:"
|
28
|
-
echo "$DIFF_FILES"
|
29
|
-
|
30
|
-
FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
|
31
|
-
echo "🧾 Total changed files: $FILE_COUNT"
|
32
|
-
|
33
|
-
ESLINT_CONFIG_FILE="$PROJECT_ROOT/.eslintrc.build.cjs"
|
34
|
-
|
35
|
-
ESLINT_CMD_ARGS="--no-error-on-unmatched-pattern --report-unused-disable-directives"
|
36
|
-
|
37
|
-
if [ -f "$ESLINT_CONFIG_FILE" ]; then
|
38
|
-
echo "🔧 Using ESLint config file: $ESLINT_CONFIG_FILE"
|
39
|
-
ESLINT_CMD_ARGS="--config $ESLINT_CONFIG_FILE $ESLINT_CMD_ARGS"
|
40
|
-
else
|
41
|
-
echo "⚠️ ESLint config file not found, using default ESLint config resolution."
|
42
|
-
fi
|
43
|
-
|
44
|
-
echo "$DIFF_FILES" | tr -d '\r' | \
|
45
|
-
xargs -d '\n' -P 4 -n 30 npx --no-install eslint $ESLINT_CMD_ARGS
|
46
|
-
|
47
|
-
if [ $? -ne 0 ]; then
|
48
|
-
echo "❌ ESLint check failed. Aborting build process"
|
49
|
-
exit 1
|
50
|
-
fi
|
51
|
-
|
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
|
+
TARGET_COMMIT=$1
|
9
|
+
LATEST_COMMIT=$(git rev-parse HEAD)
|
10
|
+
|
11
|
+
if [ -z "$TARGET_COMMIT" ]; then
|
12
|
+
echo "❗ Error: Missing target commit ID."
|
13
|
+
echo "👉 Usage: $0 <target-commit-id>"
|
14
|
+
exit 1
|
15
|
+
fi
|
16
|
+
|
17
|
+
echo "获取到上一次运行commit ID: $TARGET_COMMIT"
|
18
|
+
echo "获取到当前最新的commit ID: $LATEST_COMMIT"
|
19
|
+
|
20
|
+
DIFF_FILES=$(git diff --name-only "$TARGET_COMMIT" "$LATEST_COMMIT" -- '*.ts' '*.tsx' '*.js' '*.jsx')
|
21
|
+
|
22
|
+
if [ -z "$DIFF_FILES" ]; then
|
23
|
+
echo "✅ No matching file changes detected, skipping ESLint check"
|
24
|
+
exit 0
|
25
|
+
fi
|
26
|
+
|
27
|
+
echo "📂 Changed files:"
|
28
|
+
echo "$DIFF_FILES"
|
29
|
+
|
30
|
+
FILE_COUNT=$(echo "$DIFF_FILES" | wc -l)
|
31
|
+
echo "🧾 Total changed files: $FILE_COUNT"
|
32
|
+
|
33
|
+
ESLINT_CONFIG_FILE="$PROJECT_ROOT/.eslintrc.build.cjs"
|
34
|
+
|
35
|
+
ESLINT_CMD_ARGS="--no-error-on-unmatched-pattern --report-unused-disable-directives"
|
36
|
+
|
37
|
+
if [ -f "$ESLINT_CONFIG_FILE" ]; then
|
38
|
+
echo "🔧 Using ESLint config file: $ESLINT_CONFIG_FILE"
|
39
|
+
ESLINT_CMD_ARGS="--config $ESLINT_CONFIG_FILE $ESLINT_CMD_ARGS"
|
40
|
+
else
|
41
|
+
echo "⚠️ ESLint config file not found, using default ESLint config resolution."
|
42
|
+
fi
|
43
|
+
|
44
|
+
echo "$DIFF_FILES" | tr -d '\r' | \
|
45
|
+
xargs -d '\n' -P 4 -n 30 npx --no-install eslint $ESLINT_CMD_ARGS
|
46
|
+
|
47
|
+
if [ $? -ne 0 ]; then
|
48
|
+
echo "❌ ESLint check failed. Aborting build process"
|
49
|
+
exit 1
|
50
|
+
fi
|
51
|
+
|
52
52
|
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"
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
let spawnSync;
|
4
|
+
let spawn;
|
5
|
+
let path;
|
6
|
+
let fs;
|
7
|
+
|
8
|
+
(async () => {
|
9
|
+
try {
|
10
|
+
if (typeof require !== 'undefined') {
|
11
|
+
// CommonJS
|
12
|
+
({ spawnSync, spawn } = require('child_process'));
|
13
|
+
path = require('path');
|
14
|
+
fs = require('fs');
|
15
|
+
} else {
|
16
|
+
// ESM
|
17
|
+
({ spawnSync, spawn } = await import('node:child_process'));
|
18
|
+
path = await import('node:path');
|
19
|
+
fs = await import('node:fs');
|
20
|
+
}
|
21
|
+
|
22
|
+
// 获取目标路径
|
23
|
+
const targetPath = process.argv[2] || process.cwd();
|
24
|
+
let rootDir = path.resolve(targetPath);
|
25
|
+
|
26
|
+
// 如果传的是单个目录名且路径不存在,则在 packages/ 下查找
|
27
|
+
if (!fs.existsSync(rootDir) && targetPath !== process.cwd()) {
|
28
|
+
const baseDir = process.cwd(); // 当前项目根目录
|
29
|
+
const fullPath = path.join(baseDir, 'packages', targetPath);
|
30
|
+
if (fs.existsSync(fullPath)) {
|
31
|
+
rootDir = fullPath;
|
32
|
+
} else {
|
33
|
+
console.error(`找不到目录: packages/${targetPath}`);
|
34
|
+
process.exit(1);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
console.log('目标路径:', rootDir);
|
39
|
+
|
40
|
+
const gitRootResult = spawnSync('git', ['rev-parse', '--show-toplevel'], {
|
41
|
+
cwd: rootDir,
|
42
|
+
encoding: 'utf-8',
|
43
|
+
shell: true,
|
44
|
+
});
|
45
|
+
|
46
|
+
if (gitRootResult.status !== 0 || !gitRootResult.stdout) {
|
47
|
+
console.error('无法获取 Git 根目录,请确保路径在 Git 仓库内');
|
48
|
+
process.exit(1);
|
49
|
+
}
|
50
|
+
|
51
|
+
const gitRoot = gitRootResult.stdout.trim();
|
52
|
+
console.log('Git 根目录:', gitRoot);
|
53
|
+
|
54
|
+
let targetBranch = 'master';
|
55
|
+
if (targetPath !== process.cwd()) {
|
56
|
+
const lastDir = path.basename(rootDir);
|
57
|
+
targetBranch = `master-${lastDir.split('-').pop()}`;
|
58
|
+
}
|
59
|
+
console.log('目标分支:', targetBranch);
|
60
|
+
|
61
|
+
// 获取当前分支
|
62
|
+
const currentBranchResult = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
63
|
+
cwd: gitRoot,
|
64
|
+
encoding: 'utf-8',
|
65
|
+
shell: true,
|
66
|
+
});
|
67
|
+
|
68
|
+
if (currentBranchResult.status !== 0 || !currentBranchResult.stdout) {
|
69
|
+
console.error('无法获取当前 Git 分支');
|
70
|
+
process.exit(1);
|
71
|
+
}
|
72
|
+
|
73
|
+
const currentBranch = currentBranchResult.stdout.trim();
|
74
|
+
console.log('当前分支:', currentBranch);
|
75
|
+
|
76
|
+
// 切换分支并拉取最新代码
|
77
|
+
if (currentBranch !== targetBranch) {
|
78
|
+
console.log(`切换到分支 ${targetBranch} ...`);
|
79
|
+
const checkout = spawnSync('git', ['checkout', targetBranch], {
|
80
|
+
cwd: gitRoot,
|
81
|
+
stdio: 'inherit',
|
82
|
+
shell: true,
|
83
|
+
});
|
84
|
+
if (checkout.status !== 0) {
|
85
|
+
console.error(`切换分支失败`);
|
86
|
+
process.exit(1);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
console.log('拉取最新代码...');
|
91
|
+
const pull = spawnSync('git', ['pull'], {
|
92
|
+
cwd: gitRoot,
|
93
|
+
stdio: 'inherit',
|
94
|
+
shell: true,
|
95
|
+
});
|
96
|
+
if (pull.status !== 0) {
|
97
|
+
console.error('git pull 失败');
|
98
|
+
process.exit(1);
|
99
|
+
}
|
100
|
+
|
101
|
+
const srcPath = path.join(rootDir, 'src');
|
102
|
+
const eslintTarget = fs.existsSync(srcPath) ? srcPath : '.';
|
103
|
+
if (!fs.existsSync(srcPath)) {
|
104
|
+
console.warn(`src 文件夹不存在,改为检查当前目录: ${eslintTarget}`);
|
105
|
+
} else {
|
106
|
+
console.log(`检查目录: ${eslintTarget}`);
|
107
|
+
}
|
108
|
+
|
109
|
+
console.log('执行 ESLint...');
|
110
|
+
const eslint = spawn(
|
111
|
+
'npx',
|
112
|
+
['eslint', eslintTarget, '--ext', 'ts,tsx,js,jsx', '--report-unused-disable-directives'],
|
113
|
+
{
|
114
|
+
cwd: rootDir,
|
115
|
+
stdio: 'inherit',
|
116
|
+
shell: true,
|
117
|
+
},
|
118
|
+
);
|
119
|
+
|
120
|
+
eslint.on('close', (code) => {
|
121
|
+
process.exit(code);
|
122
|
+
});
|
123
|
+
} catch (err) {
|
124
|
+
console.error('脚本执行出错:', err);
|
125
|
+
process.exit(1);
|
126
|
+
}
|
127
|
+
})();
|