@zairakai/js-dev-tools 1.0.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/.editorconfig +86 -0
- package/.gitlab/ci/pipeline-js-app.yml +75 -0
- package/.gitlab/ci/pipeline-js-package.yml +360 -0
- package/LICENSE +21 -0
- package/README.md +206 -0
- package/config/.markdownlint.json +7 -0
- package/config/.markdownlintignore +5 -0
- package/config/.prettierignore +11 -0
- package/config/.stylelintignore +7 -0
- package/config/eslint.config.js +198 -0
- package/config/knip.config.js +40 -0
- package/config/prettier.config.js +121 -0
- package/config/stylelint.config.js +56 -0
- package/config/tsconfig.base.json +20 -0
- package/config/vitest.config.js +25 -0
- package/index.js +24 -0
- package/package.json +148 -0
- package/scripts/build.sh +58 -0
- package/scripts/ci-quality.sh +51 -0
- package/scripts/config.sh +254 -0
- package/scripts/doctor.sh +74 -0
- package/scripts/eslint-fix.sh +38 -0
- package/scripts/eslint.sh +49 -0
- package/scripts/install-bats.sh +227 -0
- package/scripts/install-hooks.sh +167 -0
- package/scripts/install-markdownlint.sh +31 -0
- package/scripts/install-shellcheck.sh +232 -0
- package/scripts/knip.sh +40 -0
- package/scripts/markdownlint-fix.sh +8 -0
- package/scripts/markdownlint.sh +84 -0
- package/scripts/outdated.sh +70 -0
- package/scripts/prettier-fix.sh +52 -0
- package/scripts/prettier.sh +53 -0
- package/scripts/setup-project.sh +816 -0
- package/scripts/stylelint-fix.sh +64 -0
- package/scripts/stylelint.sh +66 -0
- package/scripts/test.sh +40 -0
- package/scripts/typecheck.sh +41 -0
- package/scripts/validate-shellcheck.sh +70 -0
- package/stubs/githooks/commit-msg +34 -0
- package/stubs/githooks/pre-commit +58 -0
- package/stubs/githooks/pre-push +57 -0
- package/stubs/githooks/prepare-commit-msg +39 -0
- package/stubs/gitlab-ci/gitlab-ci.yml.stub +18 -0
- package/stubs/gitlab-ci/gitlab-pipeline-js-app.yml.stub +16 -0
- package/stubs/governance/CODE_OF_CONDUCT.md.stub +8 -0
- package/stubs/governance/CONTRIBUTING.md.stub +39 -0
- package/stubs/governance/SECURITY.md.stub +41 -0
- package/stubs/quality/eslint.config.js.stub +18 -0
- package/stubs/quality/knip.config.js.stub +14 -0
- package/stubs/style/prettier.config.js.stub +16 -0
- package/stubs/style/stylelint.config.js.stub +17 -0
- package/stubs/testing/vitest.config.js.stub +18 -0
- package/stubs/typescript/tsconfig.json.stub +10 -0
- package/tools/make/bats.mk +49 -0
- package/tools/make/code-style.mk +20 -0
- package/tools/make/core.mk +56 -0
- package/tools/make/help.mk +32 -0
- package/tools/make/knip.mk +7 -0
- package/tools/make/markdownlint.mk +17 -0
- package/tools/make/quality.mk +19 -0
- package/tools/make/shellcheck.mk +14 -0
- package/tools/make/stylelint.mk +11 -0
- package/tools/make/test.mk +19 -0
- package/tools/make/typescript.mk +10 -0
- package/tools/make/utils.mk +44 -0
- package/tools/make/variables.mk +42 -0
- package/tools/scripts/git-cleanup.sh +53 -0
- package/tools/scripts/git-update.sh +37 -0
package/scripts/knip.sh
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# Knip — Dead Code & Unused Dependency Detection
|
|
4
|
+
# Finds unused exports, files, and dependencies in TypeScript/JavaScript projects.
|
|
5
|
+
# https://knip.dev
|
|
6
|
+
#
|
|
7
|
+
# Optional: skips gracefully if knip is not installed.
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
# bash scripts/knip.sh
|
|
11
|
+
#
|
|
12
|
+
# Installation:
|
|
13
|
+
# npm install --save-dev knip
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
set -euo pipefail
|
|
17
|
+
|
|
18
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
19
|
+
# shellcheck disable=SC1091
|
|
20
|
+
source "${SCRIPT_DIR}/config.sh"
|
|
21
|
+
|
|
22
|
+
KNIP_BIN="${BIN_DIR}/knip"
|
|
23
|
+
|
|
24
|
+
log_header "Knip — Dead Code Detection"
|
|
25
|
+
|
|
26
|
+
if ! ensure_bin_optional "$KNIP_BIN" "knip"; then
|
|
27
|
+
log_info "Install: npm install --save-dev knip"
|
|
28
|
+
exit 0
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
KNIP_ARGS=()
|
|
32
|
+
|
|
33
|
+
if [[ -n "$KNIP_CONFIG" ]]; then
|
|
34
|
+
log_step "Using configuration: ${KNIP_CONFIG#"$PROJECT_ROOT"/}"
|
|
35
|
+
KNIP_ARGS+=(--config "$KNIP_CONFIG")
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
"$KNIP_BIN" "${KNIP_ARGS[@]}"
|
|
39
|
+
|
|
40
|
+
log_success "Knip check passed — no dead code found"
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
# shellcheck disable=SC1091
|
|
6
|
+
source "$SCRIPT_DIR/config.sh"
|
|
7
|
+
|
|
8
|
+
FIX_MODE=false
|
|
9
|
+
EXTRA_IGNORES=()
|
|
10
|
+
while [[ $# -gt 0 ]]; do
|
|
11
|
+
case "$1" in
|
|
12
|
+
--fix) FIX_MODE=true; shift ;;
|
|
13
|
+
--ignore) EXTRA_IGNORES+=("$2"); shift 2 ;;
|
|
14
|
+
--ignore=*) EXTRA_IGNORES+=("${1#--ignore=}"); shift ;;
|
|
15
|
+
*) shift ;;
|
|
16
|
+
esac
|
|
17
|
+
done
|
|
18
|
+
|
|
19
|
+
if [[ "$FIX_MODE" == "true" ]]; then
|
|
20
|
+
log_header "Markdownlint Documentation Auto-Fix"
|
|
21
|
+
else
|
|
22
|
+
log_header "Markdownlint Documentation Validation"
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
ensure_bin "$MARKDOWNLINT_BIN" "markdownlint-cli2" || exit 1
|
|
26
|
+
|
|
27
|
+
if [[ -z "$MARKDOWNLINT_CONFIG" ]]; then
|
|
28
|
+
log_error "No markdownlint configuration found"
|
|
29
|
+
log_warning "Expected one of:"
|
|
30
|
+
log_warning " .markdownlint.json (project root)"
|
|
31
|
+
log_warning " config/dev-tools/.markdownlint.json (published config)"
|
|
32
|
+
log_warning " node_modules/@zairakai/js-dev-tools/config/.markdownlint.json (default)"
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
log_step "Configuration: ${MARKDOWNLINT_CONFIG#"$PROJECT_ROOT"/}"
|
|
37
|
+
|
|
38
|
+
# Parse a gitignore-format file and inject each entry as !pattern
|
|
39
|
+
_add_ignore_file() {
|
|
40
|
+
local file="$1"
|
|
41
|
+
[[ ! -f "$file" ]] && return
|
|
42
|
+
while IFS= read -r _line || [[ -n "$_line" ]]; do
|
|
43
|
+
[[ -z "$_line" || "$_line" =~ ^[[:space:]]*# || "$_line" =~ ^! ]] && continue
|
|
44
|
+
MARKDOWNLINT_ARGS+=("!${_line}")
|
|
45
|
+
done < "$file"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
MARKDOWNLINT_ARGS=("--config" "$MARKDOWNLINT_CONFIG" "**/*.md" "!.git" "!node_modules" "!vendor")
|
|
49
|
+
|
|
50
|
+
# Parse .gitignore entries as exclusion patterns
|
|
51
|
+
_add_ignore_file "${PROJECT_ROOT}/.gitignore"
|
|
52
|
+
|
|
53
|
+
# Parse project-specific markdownlint ignore file
|
|
54
|
+
if [[ -n "$MARKDOWNLINT_IGNORE" ]]; then
|
|
55
|
+
_add_ignore_file "$MARKDOWNLINT_IGNORE"
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# Extra ignores passed via --ignore
|
|
59
|
+
if [[ ${#EXTRA_IGNORES[@]} -gt 0 ]]; then
|
|
60
|
+
for _ignore in "${EXTRA_IGNORES[@]}"; do
|
|
61
|
+
MARKDOWNLINT_ARGS+=("!${_ignore}")
|
|
62
|
+
done
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
if [[ "$FIX_MODE" == "true" ]]; then
|
|
66
|
+
MARKDOWNLINT_ARGS=("--fix" "${MARKDOWNLINT_ARGS[@]}")
|
|
67
|
+
log_step "Fixing Markdown documentation..."
|
|
68
|
+
else
|
|
69
|
+
log_step "Validating Markdown documentation..."
|
|
70
|
+
fi
|
|
71
|
+
|
|
72
|
+
if "$MARKDOWNLINT_BIN" "${MARKDOWNLINT_ARGS[@]}"; then
|
|
73
|
+
if [[ "$FIX_MODE" == "true" ]]; then
|
|
74
|
+
log_success "Markdown documentation fixed"
|
|
75
|
+
else
|
|
76
|
+
log_success "Markdown validation passed"
|
|
77
|
+
fi
|
|
78
|
+
exit 0
|
|
79
|
+
else
|
|
80
|
+
log_error "Markdownlint found documentation issues"
|
|
81
|
+
echo ""
|
|
82
|
+
echo "Fix automatically with: make markdownlint-fix"
|
|
83
|
+
exit 1
|
|
84
|
+
fi
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
# shellcheck disable=SC1091
|
|
6
|
+
source "$SCRIPT_DIR/config.sh"
|
|
7
|
+
|
|
8
|
+
log_header "NPM Outdated Check"
|
|
9
|
+
|
|
10
|
+
ensure_dir "build/reports"
|
|
11
|
+
|
|
12
|
+
# ─── IGNORE LIST ──────────────────────────────────────────────────────────────
|
|
13
|
+
# Packages to exclude from the outdated check.
|
|
14
|
+
# Populated from two sources (merged):
|
|
15
|
+
# 1. OUTDATED_IGNORE env var — comma-separated list
|
|
16
|
+
# e.g. OUTDATED_IGNORE=prettier-plugin-blade,some-other-pkg
|
|
17
|
+
# 2. package.json "outdatedIgnore" array field (optional, project-level)
|
|
18
|
+
# e.g. "outdatedIgnore": ["prettier-plugin-blade"]
|
|
19
|
+
# ──────────────────────────────────────────────────────────────────────────────
|
|
20
|
+
build_jq_filter() {
|
|
21
|
+
local ignore_csv="${OUTDATED_IGNORE:-}"
|
|
22
|
+
local pkg_json="${PROJECT_ROOT}/package.json"
|
|
23
|
+
local from_pkg_json=""
|
|
24
|
+
|
|
25
|
+
if command_exists jq && [[ -f "$pkg_json" ]]; then
|
|
26
|
+
from_pkg_json="$(jq -r '(.outdatedIgnore // []) | join(",")' "$pkg_json" 2>/dev/null || true)"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Merge both sources
|
|
30
|
+
local combined="${ignore_csv}${ignore_csv:+,}${from_pkg_json}"
|
|
31
|
+
|
|
32
|
+
if [[ -z "$combined" ]]; then
|
|
33
|
+
echo "."
|
|
34
|
+
return
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
# Build: del(.pkg1) | del(.pkg2) | ...
|
|
38
|
+
local filter="."
|
|
39
|
+
IFS=',' read -ra packages <<< "$combined"
|
|
40
|
+
for pkg in "${packages[@]}"; do
|
|
41
|
+
pkg="${pkg// /}" # trim spaces
|
|
42
|
+
[[ -z "$pkg" ]] && continue
|
|
43
|
+
filter+=" | del(.\"${pkg}\")"
|
|
44
|
+
done
|
|
45
|
+
|
|
46
|
+
echo "$filter"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
log_step "Checking direct dependencies for outdated packages..."
|
|
50
|
+
|
|
51
|
+
npm outdated --omit=peer --json > build/reports/npm-outdated.json 2>/dev/null || true
|
|
52
|
+
|
|
53
|
+
JQ_FILTER="$(build_jq_filter)"
|
|
54
|
+
|
|
55
|
+
if command_exists jq && [[ "$JQ_FILTER" != "." ]]; then
|
|
56
|
+
log_step "Ignoring: ${OUTDATED_IGNORE:-}$(jq -r '(.outdatedIgnore // []) | join(", ")' "${PROJECT_ROOT}/package.json" 2>/dev/null || true)"
|
|
57
|
+
filtered="$(jq "${JQ_FILTER}" build/reports/npm-outdated.json 2>/dev/null || cat build/reports/npm-outdated.json)"
|
|
58
|
+
echo "$filtered" > build/reports/npm-outdated.json
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
if [[ ! -s build/reports/npm-outdated.json ]] || [[ "$(cat build/reports/npm-outdated.json)" == "{}" ]]; then
|
|
62
|
+
log_success "All dependencies are up to date"
|
|
63
|
+
exit 0
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
log_error "Outdated packages found:"
|
|
67
|
+
cat build/reports/npm-outdated.json
|
|
68
|
+
echo ""
|
|
69
|
+
echo "Run: npm update (or update package.json manually)"
|
|
70
|
+
exit 1
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
# shellcheck disable=SC1091
|
|
6
|
+
source "$SCRIPT_DIR/config.sh"
|
|
7
|
+
|
|
8
|
+
EXTRA_IGNORES=()
|
|
9
|
+
while [[ $# -gt 0 ]]; do
|
|
10
|
+
case "$1" in
|
|
11
|
+
--ignore) EXTRA_IGNORES+=("$2"); shift 2 ;;
|
|
12
|
+
--ignore=*) EXTRA_IGNORES+=("${1#--ignore=}"); shift ;;
|
|
13
|
+
*) shift ;;
|
|
14
|
+
esac
|
|
15
|
+
done
|
|
16
|
+
|
|
17
|
+
log_header "Prettier Fix"
|
|
18
|
+
|
|
19
|
+
ensure_bin "$PRETTIER_BIN" "prettier" || exit 1
|
|
20
|
+
|
|
21
|
+
if [[ -n "$PRETTIER_CONFIG" ]]; then
|
|
22
|
+
log_step "Using configuration: ${PRETTIER_CONFIG#"$PROJECT_ROOT"/}"
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
PRETTIER_ARGS=(--write)
|
|
26
|
+
|
|
27
|
+
if [[ -n "$PRETTIER_CONFIG" ]] && [[ "$PRETTIER_CONFIG" != "${PROJECT_ROOT}/prettier.config.js" ]]; then
|
|
28
|
+
PRETTIER_ARGS+=(--config "$PRETTIER_CONFIG")
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if [[ -n "$PRETTIER_IGNORE" ]]; then
|
|
32
|
+
PRETTIER_ARGS+=(--ignore-path "$PRETTIER_IGNORE")
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Also respect .gitignore if present
|
|
36
|
+
if [[ -f "${PROJECT_ROOT}/.gitignore" ]]; then
|
|
37
|
+
PRETTIER_ARGS+=(--ignore-path "${PROJECT_ROOT}/.gitignore")
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Extra ignores passed via --ignore
|
|
41
|
+
if [[ ${#EXTRA_IGNORES[@]} -gt 0 ]]; then
|
|
42
|
+
_TMP_IGNORE=$(mktemp)
|
|
43
|
+
trap 'rm -f "$_TMP_IGNORE"' EXIT
|
|
44
|
+
printf '%s\n' "${EXTRA_IGNORES[@]}" > "$_TMP_IGNORE"
|
|
45
|
+
PRETTIER_ARGS+=(--ignore-path "$_TMP_IGNORE")
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
PRETTIER_ARGS+=(".")
|
|
49
|
+
|
|
50
|
+
"$PRETTIER_BIN" "${PRETTIER_ARGS[@]}"
|
|
51
|
+
|
|
52
|
+
log_success "Prettier fix applied"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
5
|
+
# shellcheck disable=SC1091
|
|
6
|
+
source "$SCRIPT_DIR/config.sh"
|
|
7
|
+
|
|
8
|
+
EXTRA_IGNORES=()
|
|
9
|
+
while [[ $# -gt 0 ]]; do
|
|
10
|
+
case "$1" in
|
|
11
|
+
--ignore) EXTRA_IGNORES+=("$2"); shift 2 ;;
|
|
12
|
+
--ignore=*) EXTRA_IGNORES+=("${1#--ignore=}"); shift ;;
|
|
13
|
+
*) shift ;;
|
|
14
|
+
esac
|
|
15
|
+
done
|
|
16
|
+
|
|
17
|
+
log_header "Prettier Check"
|
|
18
|
+
|
|
19
|
+
ensure_bin "$PRETTIER_BIN" "prettier" || exit 1
|
|
20
|
+
|
|
21
|
+
if [[ -n "$PRETTIER_CONFIG" ]]; then
|
|
22
|
+
log_step "Using configuration: ${PRETTIER_CONFIG#"$PROJECT_ROOT"/}"
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
PRETTIER_ARGS=(--check)
|
|
26
|
+
|
|
27
|
+
if [[ -n "$PRETTIER_CONFIG" ]] && [[ "$PRETTIER_CONFIG" != "${PROJECT_ROOT}/prettier.config.js" ]]; then
|
|
28
|
+
PRETTIER_ARGS+=(--config "$PRETTIER_CONFIG")
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
if [[ -n "$PRETTIER_IGNORE" ]]; then
|
|
32
|
+
PRETTIER_ARGS+=(--ignore-path "$PRETTIER_IGNORE")
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Also respect .gitignore if present
|
|
36
|
+
if [[ -f "${PROJECT_ROOT}/.gitignore" ]]; then
|
|
37
|
+
PRETTIER_ARGS+=(--ignore-path "${PROJECT_ROOT}/.gitignore")
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Extra ignores passed via --ignore
|
|
41
|
+
if [[ ${#EXTRA_IGNORES[@]} -gt 0 ]]; then
|
|
42
|
+
_TMP_IGNORE=$(mktemp)
|
|
43
|
+
trap 'rm -f "$_TMP_IGNORE"' EXIT
|
|
44
|
+
printf '%s\n' "${EXTRA_IGNORES[@]}" > "$_TMP_IGNORE"
|
|
45
|
+
PRETTIER_ARGS+=(--ignore-path "$_TMP_IGNORE")
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Prettier checks all supported files from project root
|
|
49
|
+
PRETTIER_ARGS+=(".")
|
|
50
|
+
|
|
51
|
+
"$PRETTIER_BIN" "${PRETTIER_ARGS[@]}"
|
|
52
|
+
|
|
53
|
+
log_success "Prettier check passed"
|