@zairakai/js-dev-tools 4.0.0 → 4.1.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.
@@ -30,6 +30,8 @@ variables:
30
30
  # Consumer projects do NOT need to override these.
31
31
  # dev-tools itself overrides them in its own .gitlab-ci.yml.
32
32
  JS_DEV_TOOLS_SCRIPTS: 'node_modules/@zairakai/js-dev-tools/scripts'
33
+ # The scripts of the jobs of the release: the notes of a version.
34
+ JS_DEV_TOOLS_GITLAB_SCRIPTS: 'node_modules/@zairakai/js-dev-tools/.gitlab/scripts'
33
35
 
34
36
  # NODE
35
37
  # ================
@@ -68,9 +68,14 @@ js:publish:
68
68
  # RELEASE
69
69
  # ================
70
70
  js:release:
71
- extends: .js:base
71
+ extends:
72
+ - .js:base
73
+ - .js:cache
72
74
  stage: release
73
75
  image: ${RELEASE_CLI_IMAGE}
76
+ variables:
77
+ # All the history and all the tags: the notes cover the range since the previous tag
78
+ GIT_DEPTH: 0
74
79
  rules:
75
80
  - if: $UPDATE_DEPENDENCIES == "true"
76
81
  when: never
@@ -82,18 +87,11 @@ js:release:
82
87
  - git config --global user.email "ci@gitlab.com"
83
88
  script:
84
89
  - |
85
- # Tags are listed newest first, with or without the old "v" prefix (v2.1.0 then 2.2.0)
86
- PREVIOUS_TAG=$(git tag | sed -E 's/^v?(.*)$/\1 &/' | sort -k1,1 -Vr | cut -d' ' -f2 | grep -A1 -Fx "${CI_COMMIT_TAG}" | tail -n 1 || echo "")
87
- if [[ -n "$PREVIOUS_TAG" && "$PREVIOUS_TAG" != "$CI_COMMIT_TAG" ]]; then
88
- COMMITS=$(git log --pretty=format:"- %s" "${PREVIOUS_TAG}..${CI_COMMIT_TAG}" | head -20)
89
- else
90
- COMMITS="- Initial release"
90
+ bash "${JS_DEV_TOOLS_GITLAB_SCRIPTS}/generate-release-notes.sh"
91
+ if [ ! -s release_notes.md ]; then
92
+ echo "❌ ERROR: release_notes.md is missing or empty"
93
+ exit 1
91
94
  fi
92
- cat > release_notes.md << NOTES
93
- ## ${CI_COMMIT_TAG}
94
-
95
- ${COMMITS}
96
- NOTES
97
95
  release-cli create \
98
96
  --tag-name "${CI_COMMIT_TAG}" \
99
97
  --name "Release ${CI_COMMIT_TAG}" \
@@ -0,0 +1,236 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Generate the release notes of a tag from the commits since the previous tag,
4
+ # following the git-rules conventions.
5
+ # Usage: bash .gitlab/scripts/generate-release-notes.sh [from_tag] [to_tag]
6
+ # from_tag the previous tag (default: the version tag before to_tag, none
7
+ # for a first release)
8
+ # to_tag the tag to describe (default: the tag of HEAD)
9
+ # Writes release_notes.md in the current directory, and never leaves it empty.
10
+ set -euo pipefail
11
+
12
+ # The CI clones with a small depth and fetches only the tag of the pipeline:
13
+ # without the history and the other tags the
14
+ # previous tag is unknown, and the range between the tag and itself is empty.
15
+ fetch_history() {
16
+ if [ "$(git rev-parse --is-shallow-repository 2>/dev/null)" = "true" ]; then
17
+ git fetch --quiet --unshallow --tags \
18
+ || echo "⚠️ Could not fetch the history: the notes may be incomplete"
19
+ else
20
+ git fetch --quiet --tags 2>/dev/null || true
21
+ fi
22
+ }
23
+
24
+ # The version tags, newest first, with or without the old "v" prefix (v2.2.0
25
+ # then 2.3.0). The order does not rely on "sort -V": the busybox of the images
26
+ # of the CI sorts a pre-release (1.0.0-rc.1) after its release. The key of a
27
+ # tag is its three numbers, padded, then "1" for a release, which comes before
28
+ # its pre-releases ("0" and the pre-release).
29
+ version_tags() {
30
+ git tag \
31
+ | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+(-.+)?$' \
32
+ | awk '{
33
+ version = $0
34
+ sub(/^v/, "", version)
35
+ pre = ""
36
+ dash = index(version, "-")
37
+ if (dash > 0) {
38
+ pre = substr(version, dash + 1)
39
+ version = substr(version, 1, dash - 1)
40
+ }
41
+ split(version, number, ".")
42
+ printf "%010d.%010d.%010d.%s %s\n", number[1], number[2], number[3], \
43
+ (pre == "" ? "1" : "0" pre), $0
44
+ }' \
45
+ | sort -r \
46
+ | cut -d' ' -f2 \
47
+ || true
48
+ }
49
+
50
+ fetch_history
51
+
52
+ TO_TAG="${2:-$(git describe --tags --abbrev=0 HEAD)}"
53
+ FROM_TAG="${1:-$(version_tags | grep -A1 -Fx "${TO_TAG}" | sed -n 2p || true)}"
54
+
55
+ if [ -n "${FROM_TAG}" ]; then
56
+ RANGE="${FROM_TAG}..${TO_TAG}"
57
+ else
58
+ # A first release: all its commits
59
+ RANGE="${TO_TAG}"
60
+ fi
61
+
62
+ RELEASE_NOTES="release_notes.md"
63
+
64
+ echo "━━━━━━━━━━━━━━━━"
65
+ echo "📝 Generating Release Notes"
66
+ echo "━━━━━━━━━━━━━━━━"
67
+ echo ""
68
+ echo "→ From: ${FROM_TAG:-(first release)}"
69
+ echo "→ To: ${TO_TAG}"
70
+ echo "→ Output: ${RELEASE_NOTES}"
71
+ echo ""
72
+
73
+ : > "${RELEASE_NOTES}"
74
+
75
+ # Write to both stdout and the file
76
+ output() {
77
+ echo "$@" | tee -a "${RELEASE_NOTES}"
78
+ }
79
+
80
+ footer() {
81
+ output "---"
82
+ output ""
83
+ if [ -n "${FROM_TAG}" ]; then
84
+ output "**Full Changelog**: ${FROM_TAG}...${TO_TAG}"
85
+ else
86
+ output "**First release**: ${TO_TAG}"
87
+ fi
88
+ }
89
+
90
+ # Commits of the range, without the merge commits
91
+ COMMITS=$(git log "${RANGE}" --pretty=format:"%s" --no-merges)
92
+
93
+ output "## What's Changed"
94
+ output ""
95
+
96
+ if [ -z "${COMMITS}" ]; then
97
+ output "No commit${FROM_TAG:+ since ${FROM_TAG}}."
98
+ output ""
99
+ footer
100
+ exit 0
101
+ fi
102
+
103
+ # The breaking changes: the paragraph that starts with "BREAKING CHANGE:", up to
104
+ # the next blank line, as one bullet. The
105
+ # paragraph "Migration:" that follows it is added under it.
106
+ breaking_changes() {
107
+ local commit
108
+ for commit in $(git log "${RANGE}" --pretty=format:"%H" --no-merges); do
109
+ git show --no-patch --pretty=format:"%b" "${commit}" | awk '
110
+ function end_paragraph() {
111
+ if (kind == "b") { print "- " text; after = "b" }
112
+ else if (kind == "m") { print " " text; after = "" }
113
+ else { after = "" }
114
+ kind = ""; text = ""
115
+ }
116
+ /^[[:space:]]*$/ { end_paragraph(); next }
117
+ kind == "" {
118
+ if ($0 ~ /^BREAKING CHANGE:/) {
119
+ kind = "b"; text = $0
120
+ sub(/^BREAKING CHANGE:[[:space:]]*/, "", text)
121
+ }
122
+ else if (after == "b" && $0 ~ /^Migration:/) { kind = "m"; text = $0 }
123
+ else { kind = "x" }
124
+ next
125
+ }
126
+ kind == "b" || kind == "m" { text = text " " $0 }
127
+ END { end_paragraph() }
128
+ '
129
+ done
130
+ }
131
+
132
+ # Format a commit message: without the type and the scope, with its ticket at
133
+ # the end
134
+ format_commit() {
135
+ local commit="$1"
136
+ local type_pattern="$2"
137
+ local message ticket
138
+
139
+ message=$(echo "${commit}" | sed -E "s/^${type_pattern}(\([^)]*\))?: //")
140
+ ticket=$(echo "${message}" | grep -oE "#[0-9]+" | head -n1 || true)
141
+
142
+ if [ -n "${ticket}" ]; then
143
+ # The pattern is quoted: a "#" at its start would anchor it at the start of
144
+ # the message
145
+ message="${message/"${ticket} "/}"
146
+ echo "- ${message} (${ticket})"
147
+ else
148
+ echo "- ${message}"
149
+ fi
150
+ }
151
+
152
+ # A section of the notes: section <title> <commits> <type>
153
+ section() {
154
+ local title="$1"
155
+ local commits="$2"
156
+ local type="$3"
157
+
158
+ [ -n "${commits}" ] || return 0
159
+
160
+ output "### ${title}"
161
+ output ""
162
+
163
+ while read -r commit; do
164
+ output "$(format_commit "${commit}" "${type}")"
165
+ done <<< "${commits}"
166
+
167
+ output ""
168
+ }
169
+
170
+ # Categorize the commits by type (following git-rules)
171
+ commits_of() {
172
+ echo "${COMMITS}" | grep "^$1" || true
173
+ }
174
+
175
+ BREAKING_CHANGES=$(breaking_changes)
176
+
177
+ if [ -n "${BREAKING_CHANGES}" ]; then
178
+ output "### ⚠️ BREAKING CHANGES"
179
+ output ""
180
+ echo "${BREAKING_CHANGES}" | while IFS= read -r line; do
181
+ output "${line}"
182
+ done
183
+ output ""
184
+ fi
185
+
186
+ section "✨ Features" "$(commits_of feat)" "feat"
187
+ section "🐛 Bug Fixes" "$(commits_of fix)" "fix"
188
+ section "🚨 Hotfixes" "$(commits_of hotfix)" "hotfix"
189
+ section "⚡ Performance" "$(commits_of perf)" "perf"
190
+ section "♻️ Refactoring" "$(commits_of refactor)" "refactor"
191
+ section "📝 Documentation" "$(commits_of docs)" "docs"
192
+ section "🧪 Tests" "$(commits_of test)" "test"
193
+ section "🏗️ Build System" "$(commits_of build)" "build"
194
+ section "👷 CI/CD" "$(commits_of ci)" "ci"
195
+ section "💄 Code Style" "$(commits_of style)" "style"
196
+ section "🔧 Maintenance" "$(commits_of chore)" "chore"
197
+
198
+ # Other commits (not following convention)
199
+ TYPES="feat|fix|hotfix|docs|style|refactor|perf|test|build|ci|chore"
200
+ OTHER=$(echo "${COMMITS}" | grep -vE "^(${TYPES})" || true)
201
+
202
+ if [ -n "${OTHER}" ]; then
203
+ output "### 📦 Other Changes"
204
+ output ""
205
+ while read -r commit; do
206
+ output "- ${commit}"
207
+ done <<< "${OTHER}"
208
+ output ""
209
+ fi
210
+
211
+ # The issues of the release: the tickets of the subjects, and the issues that
212
+ # the footers close
213
+ output "### 🎫 Issues"
214
+ output ""
215
+ ISSUES=$({
216
+ echo "${COMMITS}" | grep -oE "#[0-9]+" || true
217
+ git log "${RANGE}" --pretty=format:"%b" --no-merges \
218
+ | grep -oE "(Closes|Fixes|Resolves) #[0-9]+(, #[0-9]+)*" \
219
+ | grep -oE "#[0-9]+" || true
220
+ } | sed 's/^#//' | sort -nu | sed 's/^/#/')
221
+
222
+ if [ -n "${ISSUES}" ]; then
223
+ output "The issues of this release:"
224
+ output ""
225
+ while read -r issue; do
226
+ output "- ${issue}"
227
+ done <<< "${ISSUES}"
228
+ else
229
+ output "No issues referenced in commits."
230
+ fi
231
+
232
+ output ""
233
+ footer
234
+
235
+ echo ""
236
+ echo "✅ Release notes generated: ${RELEASE_NOTES}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zairakai/js-dev-tools",
3
- "version": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "The development toolkit of the JavaScript and TypeScript projects for the web: shared ESLint, Prettier, Stylelint, Vitest, TypeScript and markdownlint rules, Knip, Makefile targets, Git hooks and GitLab CI pipeline templates",
5
5
  "keywords": [
6
6
  "dev-tools",
@@ -108,12 +108,12 @@
108
108
  "smol-toml": "1.9.0"
109
109
  },
110
110
  "dependencies": {
111
- "@stanislas-poisson/js-dev-tools": "^3.0.0",
111
+ "@stanislas-poisson/js-dev-tools": "^3.1.0",
112
112
  "eslint": "^10.14.0",
113
113
  "markdownlint-cli2": "^0.24.0",
114
114
  "prettier": "^3.9.10",
115
115
  "semver": "^7.8.6",
116
- "stylelint": "^17.16.0"
116
+ "stylelint": "^18.0.0"
117
117
  },
118
118
  "devDependencies": {
119
119
  "@vitest/coverage-v8": "^5.1.0",
@@ -24,16 +24,23 @@ if [[ -n "$STYLELINT_CONFIG" ]]; then
24
24
  fi
25
25
 
26
26
  if [[ "$PROJECT_TYPE" == "laravel-app" ]]; then
27
- STYLELINT_TARGET="${STYLELINT_TARGET:-resources/**/*.scss}"
27
+ STYLELINT_TARGET="${STYLELINT_TARGET:-resources/**/*.scss resources/**/*.css resources/**/*.vue}"
28
28
  else
29
- STYLELINT_TARGET="${STYLELINT_TARGET:-src/**/*.scss}"
29
+ STYLELINT_TARGET="${STYLELINT_TARGET:-src/**/*.scss src/**/*.css src/**/*.vue}"
30
30
  fi
31
31
 
32
+ # STYLELINT_TARGET is a list of globs separated by spaces (one per file type: stylelint lints the style blocks of .vue)
33
+ read -r -a STYLELINT_PATTERNS <<< "$STYLELINT_TARGET"
34
+ STYLELINT_ABSOLUTE=()
35
+ for _pattern in "${STYLELINT_PATTERNS[@]}"; do
36
+ STYLELINT_ABSOLUTE+=("${PROJECT_ROOT}/${_pattern}")
37
+ done
38
+
32
39
  log_step "Fixing: $STYLELINT_TARGET"
33
40
 
34
41
  # Skip gracefully if no matching files exist
35
- if ! has_files "${PROJECT_ROOT}/${STYLELINT_TARGET}"; then
36
- log_info "No SCSS/CSS files found matching ${STYLELINT_TARGET} - skipping"
42
+ if ! has_files "${STYLELINT_ABSOLUTE[@]}"; then
43
+ log_info "No SCSS, CSS or Vue files found matching ${STYLELINT_TARGET} - skipping"
37
44
  exit 0
38
45
  fi
39
46
 
@@ -60,6 +67,6 @@ if [[ ${#EXTRA_IGNORES[@]} -gt 0 ]]; then
60
67
  STYLELINT_ARGS+=(--ignore-path "$_TMP_IGNORE")
61
68
  fi
62
69
 
63
- "$STYLELINT_BIN" "${STYLELINT_ARGS[@]}" "$STYLELINT_TARGET"
70
+ "$STYLELINT_BIN" "${STYLELINT_ARGS[@]}" "${STYLELINT_PATTERNS[@]}"
64
71
 
65
72
  log_success "Stylelint fix applied"
@@ -26,16 +26,23 @@ fi
26
26
 
27
27
  # Lint target depends on project type (overridable via env)
28
28
  if [[ "$PROJECT_TYPE" == "laravel-app" ]]; then
29
- STYLELINT_TARGET="${STYLELINT_TARGET:-resources/**/*.scss}"
29
+ STYLELINT_TARGET="${STYLELINT_TARGET:-resources/**/*.scss resources/**/*.css resources/**/*.vue}"
30
30
  else
31
- STYLELINT_TARGET="${STYLELINT_TARGET:-src/**/*.scss}"
31
+ STYLELINT_TARGET="${STYLELINT_TARGET:-src/**/*.scss src/**/*.css src/**/*.vue}"
32
32
  fi
33
33
 
34
+ # STYLELINT_TARGET is a list of globs separated by spaces (one per file type: stylelint lints the style blocks of .vue)
35
+ read -r -a STYLELINT_PATTERNS <<< "$STYLELINT_TARGET"
36
+ STYLELINT_ABSOLUTE=()
37
+ for _pattern in "${STYLELINT_PATTERNS[@]}"; do
38
+ STYLELINT_ABSOLUTE+=("${PROJECT_ROOT}/${_pattern}")
39
+ done
40
+
34
41
  log_step "Checking: $STYLELINT_TARGET"
35
42
 
36
43
  # Skip gracefully if no matching files exist (stylelint v16 errors on empty glob)
37
- if ! has_files "${PROJECT_ROOT}/${STYLELINT_TARGET}"; then
38
- log_info "No SCSS/CSS files found matching ${STYLELINT_TARGET} - skipping"
44
+ if ! has_files "${STYLELINT_ABSOLUTE[@]}"; then
45
+ log_info "No SCSS, CSS or Vue files found matching ${STYLELINT_TARGET} - skipping"
39
46
  exit 0
40
47
  fi
41
48
 
@@ -62,6 +69,6 @@ if [[ ${#EXTRA_IGNORES[@]} -gt 0 ]]; then
62
69
  STYLELINT_ARGS+=(--ignore-path "$_TMP_IGNORE")
63
70
  fi
64
71
 
65
- "$STYLELINT_BIN" "${STYLELINT_ARGS[@]}" "$STYLELINT_TARGET"
72
+ "$STYLELINT_BIN" "${STYLELINT_ARGS[@]}" "${STYLELINT_PATTERNS[@]}"
66
73
 
67
74
  log_success "Stylelint check passed"
@@ -6,7 +6,8 @@ quality:: markdownlint shellcheck eslint prettier stylelint knip ## Run all qual
6
6
  @echo "✅ All quality checks passed"
7
7
 
8
8
  .PHONY: quality-fix
9
- quality-fix:: eslint-fix prettier-fix stylelint-fix markdownlint-fix ## Auto-fix all fixable issues
9
+ # Stylelint before Prettier: the fix of a style attribute leaves it badly spaced, and Prettier formats it again
10
+ quality-fix:: eslint-fix stylelint-fix prettier-fix markdownlint-fix ## Auto-fix all fixable issues
10
11
  @echo "✅ All auto-fixes applied"
11
12
 
12
13
  .PHONY: quality-fast