@wyxos/zephyr 0.9.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wyxos/zephyr",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "A streamlined deployment tool for web applications with intelligent Laravel project detection",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -1,6 +1,8 @@
1
1
  import fs from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
 
4
+ import semver from 'semver'
5
+
4
6
  import {commandExists} from '../../utils/command.mjs'
5
7
  import {gitCommitArgs} from '../../utils/git-hooks.mjs'
6
8
  import {resolveReleaseType} from '../../release/release-type.mjs'
@@ -20,28 +22,73 @@ async function isGitIgnored(rootDir, filePath, {runCommand} = {}) {
20
22
  }
21
23
  }
22
24
 
23
- async function readLatestVersionBumpCommit(rootDir, {runCommand} = {}) {
24
- if (typeof runCommand !== 'function') {
25
+ function parseVersionBumpCommit(line) {
26
+ const [hash, shortHash, subject] = line.split('\0')
27
+ const match = /^chore: bump version to (\d+\.\d+\.\d+(?:[-+][^\s]+)?)$/i.exec(subject ?? '')
28
+
29
+ if (!match) {
25
30
  return null
26
31
  }
27
32
 
33
+ return {hash, shortHash, version: match[1]}
34
+ }
35
+
36
+ async function readVersionBumpCommits(rootDir, {runCommand} = {}) {
37
+ if (typeof runCommand !== 'function') {
38
+ return []
39
+ }
40
+
28
41
  try {
29
- const {stdout = ''} = await runCommand('git', ['log', '--format=%H%x00%h%x00%s', '-50'], {
42
+ const {stdout = ''} = await runCommand('git', ['log', '--format=%H%x00%h%x00%s', '-1000'], {
30
43
  capture: true,
31
44
  cwd: rootDir
32
45
  })
33
46
 
34
- for (const line of stdout.split('\n')) {
35
- const [hash, shortHash, subject] = line.split('\0')
36
- if (/^chore: bump version to \d+\.\d+\.\d+(?:[-+].*)?$/i.test(subject ?? '')) {
37
- return {hash, shortHash}
38
- }
39
- }
47
+ return stdout
48
+ .split('\n')
49
+ .map(parseVersionBumpCommit)
50
+ .filter(Boolean)
40
51
  } catch {
52
+ return []
53
+ }
54
+ }
55
+
56
+ function selectVersionSuggestionReference(currentVersion, versionBumps) {
57
+ const current = semver.parse(currentVersion)
58
+
59
+ if (!current) {
60
+ return versionBumps[0] ?? null
61
+ }
62
+
63
+ const currentMinorBoundary = versionBumps.find(({version}) => {
64
+ const parsed = semver.parse(version)
65
+
66
+ return parsed
67
+ && parsed.major === current.major
68
+ && parsed.minor === current.minor
69
+ && parsed.patch === 0
70
+ && parsed.prerelease.length === 0
71
+ })
72
+
73
+ return currentMinorBoundary ?? versionBumps[0] ?? null
74
+ }
75
+
76
+ function formatVersionReferenceLabel(reference, currentVersion) {
77
+ if (!reference) {
41
78
  return null
42
79
  }
43
80
 
44
- return null
81
+ const current = semver.parse(currentVersion)
82
+ const parsed = semver.parse(reference.version)
83
+ const isCurrentMinorBoundary = current
84
+ && parsed
85
+ && parsed.major === current.major
86
+ && parsed.minor === current.minor
87
+ && parsed.patch === 0
88
+ && parsed.prerelease.length === 0
89
+ const prefix = isCurrentMinorBoundary ? 'current app minor baseline' : 'last app version bump'
90
+
91
+ return `${prefix} ${reference.shortHash} (${reference.version})`
45
92
  }
46
93
 
47
94
  async function resolveDeploymentVersionValue(rootDir, {
@@ -57,7 +104,8 @@ async function resolveDeploymentVersionValue(rootDir, {
57
104
  return String(versionArg).trim()
58
105
  }
59
106
 
60
- const latestVersionBump = await readLatestVersionBumpCommit(rootDir, {runCommand})
107
+ const versionBumps = await readVersionBumpCommits(rootDir, {runCommand})
108
+ const versionReference = selectVersionSuggestionReference(pkg.version, versionBumps)
61
109
 
62
110
  return await resolveReleaseType({
63
111
  currentVersion: pkg.version,
@@ -68,8 +116,8 @@ async function resolveDeploymentVersionValue(rootDir, {
68
116
  runCommand,
69
117
  logStep: logProcessing,
70
118
  logWarning,
71
- latestTag: latestVersionBump?.hash ?? null,
72
- referenceLabel: latestVersionBump ? `last app version bump ${latestVersionBump.shortHash}` : null
119
+ latestTag: versionReference?.hash ?? null,
120
+ referenceLabel: formatVersionReferenceLabel(versionReference, pkg.version)
73
121
  })
74
122
  }
75
123