@eldrforge/kodrdriv 1.2.7 â 1.2.8
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/.kodrdriv-example-branch-targeting.yaml +71 -0
- package/dist/application.js +7 -3
- package/dist/application.js.map +1 -1
- package/dist/arguments.js +47 -7
- package/dist/arguments.js.map +1 -1
- package/dist/commands/development.js +246 -227
- package/dist/commands/development.js.map +1 -1
- package/dist/commands/link.js +64 -4
- package/dist/commands/link.js.map +1 -1
- package/dist/commands/publish.js +199 -47
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/tree.js +149 -7
- package/dist/commands/tree.js.map +1 -1
- package/dist/commands/updates.js +56 -0
- package/dist/commands/updates.js.map +1 -0
- package/dist/constants.js +27 -4
- package/dist/constants.js.map +1 -1
- package/dist/util/general.js +199 -2
- package/dist/util/general.js.map +1 -1
- package/dist/util/github.js +1 -107
- package/dist/util/github.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,261 +1,280 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { getDryRunLogger } from '../logging.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { incrementPatchVersion, incrementMinorVersion, incrementMajorVersion, validateVersionString } from '../util/general.js';
|
|
8
|
-
import { ensureMilestoneForVersion } from '../util/github.js';
|
|
9
|
-
import { execute as execute$1 } from './commit.js';
|
|
3
|
+
import { run } from '../util/child.js';
|
|
4
|
+
import { getCurrentBranch, localBranchExists } from '../util/git.js';
|
|
5
|
+
import { findDevelopmentBranch } from '../util/general.js';
|
|
6
|
+
import { KODRDRIV_DEFAULTS } from '../constants.js';
|
|
10
7
|
|
|
11
|
-
/**
|
|
12
|
-
* Parse version string to get numeric components for comparison
|
|
13
|
-
*/ function parseVersion(version) {
|
|
14
|
-
const cleanVersion = version.startsWith('v') ? version.slice(1) : version;
|
|
15
|
-
const parts = cleanVersion.split('.');
|
|
16
|
-
if (parts.length < 3) {
|
|
17
|
-
throw new Error(`Invalid version format: ${version}`);
|
|
18
|
-
}
|
|
19
|
-
const major = parseInt(parts[0], 10);
|
|
20
|
-
const minor = parseInt(parts[1], 10);
|
|
21
|
-
// Handle patch with potential prerelease
|
|
22
|
-
const patchPart = parts[2];
|
|
23
|
-
const patchComponents = patchPart.split('-');
|
|
24
|
-
const patch = parseInt(patchComponents[0], 10);
|
|
25
|
-
const prerelease = patchComponents.length > 1 ? patchComponents.slice(1).join('-') : undefined;
|
|
26
|
-
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
27
|
-
throw new Error(`Invalid version numbers in: ${version}`);
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
major,
|
|
31
|
-
minor,
|
|
32
|
-
patch,
|
|
33
|
-
prerelease
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Compare two versions to determine if first is greater than second
|
|
38
|
-
*/ function isVersionGreater(version1, version2) {
|
|
39
|
-
const v1 = parseVersion(version1);
|
|
40
|
-
const v2 = parseVersion(version2);
|
|
41
|
-
if (v1.major !== v2.major) return v1.major > v2.major;
|
|
42
|
-
if (v1.minor !== v2.minor) return v1.minor > v2.minor;
|
|
43
|
-
if (v1.patch !== v2.patch) return v1.patch > v2.patch;
|
|
44
|
-
// If versions are equal up to patch, check prerelease
|
|
45
|
-
// No prerelease is considered greater than prerelease
|
|
46
|
-
if (!v1.prerelease && v2.prerelease) return true;
|
|
47
|
-
if (v1.prerelease && !v2.prerelease) return false;
|
|
48
|
-
// Both have prerelease or both don't - consider equal for our purposes
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Create a development version from a release version
|
|
53
|
-
*/ function createDevelopmentVersion(version, targetVersion = 'patch') {
|
|
54
|
-
let baseVersion;
|
|
55
|
-
const targetLower = targetVersion.toLowerCase();
|
|
56
|
-
if (targetLower === 'patch') {
|
|
57
|
-
baseVersion = incrementPatchVersion(version);
|
|
58
|
-
} else if (targetLower === 'minor') {
|
|
59
|
-
baseVersion = incrementMinorVersion(version);
|
|
60
|
-
} else if (targetLower === 'major') {
|
|
61
|
-
baseVersion = incrementMajorVersion(version);
|
|
62
|
-
} else {
|
|
63
|
-
// Assume it's an explicit version string
|
|
64
|
-
if (validateVersionString(targetVersion)) {
|
|
65
|
-
baseVersion = targetVersion.startsWith('v') ? targetVersion.slice(1) : targetVersion;
|
|
66
|
-
} else {
|
|
67
|
-
throw new Error(`Invalid target version: ${targetVersion}. Expected "patch", "minor", "major", or a valid version string like "2.1.0"`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return `${baseVersion}-dev.0`;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get current branch name
|
|
74
|
-
*/ async function getCurrentBranch() {
|
|
75
|
-
const { stdout } = await run('git branch --show-current');
|
|
76
|
-
return stdout.trim();
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get package.json version from a specific branch
|
|
80
|
-
*/ async function getVersionFromBranch(branchName) {
|
|
81
|
-
try {
|
|
82
|
-
// Validate branch name to prevent injection
|
|
83
|
-
if (!validateGitRef(branchName)) {
|
|
84
|
-
throw new Error(`Invalid branch name: ${branchName}`);
|
|
85
|
-
}
|
|
86
|
-
const { stdout } = await runSecure('git', [
|
|
87
|
-
'show',
|
|
88
|
-
`${branchName}:package.json`
|
|
89
|
-
]);
|
|
90
|
-
const packageJson = safeJsonParse(stdout, 'package.json');
|
|
91
|
-
const validated = validatePackageJson(packageJson, 'package.json');
|
|
92
|
-
return validated.version;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
throw new Error(`Failed to get version from branch ${branchName}: ${error}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Analyze current state and determine what actions need to be taken
|
|
99
|
-
*/ async function analyzeVersionState() {
|
|
100
|
-
const currentBranch = await getCurrentBranch();
|
|
101
|
-
const workingBranchExists = await localBranchExists('working');
|
|
102
|
-
// Get current version from working directory
|
|
103
|
-
const storage = create({
|
|
104
|
-
log: ()=>{}
|
|
105
|
-
});
|
|
106
|
-
const packageJsonContents = await storage.readFile('package.json', 'utf-8');
|
|
107
|
-
const packageJson = safeJsonParse(packageJsonContents, 'package.json');
|
|
108
|
-
const validated = validatePackageJson(packageJson, 'package.json');
|
|
109
|
-
const currentVersion = validated.version;
|
|
110
|
-
// Get version from main branch
|
|
111
|
-
const mainVersion = await getVersionFromBranch('main');
|
|
112
|
-
// Get version from working branch if it exists
|
|
113
|
-
let workingVersion;
|
|
114
|
-
if (workingBranchExists) {
|
|
115
|
-
try {
|
|
116
|
-
workingVersion = await getVersionFromBranch('working');
|
|
117
|
-
} catch {
|
|
118
|
-
// Working branch exists but doesn't have package.json or it's malformed
|
|
119
|
-
workingVersion = undefined;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
const needsVersionBump = workingBranchExists && workingVersion ? !isVersionGreater(workingVersion, mainVersion) : !isVersionGreater(currentVersion, mainVersion);
|
|
123
|
-
return {
|
|
124
|
-
currentVersion,
|
|
125
|
-
mainVersion,
|
|
126
|
-
workingVersion,
|
|
127
|
-
needsVersionBump,
|
|
128
|
-
isOnMain: currentBranch === 'main',
|
|
129
|
-
isOnWorking: currentBranch === 'working',
|
|
130
|
-
workingBranchExists
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
8
|
/**
|
|
134
9
|
* Execute the development command
|
|
135
10
|
*/ const execute = async (runConfig)=>{
|
|
136
11
|
const isDryRun = runConfig.dryRun || false;
|
|
137
12
|
const logger = getDryRunLogger(isDryRun);
|
|
138
|
-
|
|
139
|
-
log: logger.debug
|
|
140
|
-
});
|
|
141
|
-
logger.info('đ Setting up development environment...');
|
|
13
|
+
logger.info('đ Navigating to working branch for active development...');
|
|
142
14
|
try {
|
|
143
15
|
var _runConfig_development;
|
|
144
|
-
//
|
|
145
|
-
const
|
|
146
|
-
logger.
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
16
|
+
// Get current branch
|
|
17
|
+
const currentBranch = isDryRun ? 'mock-branch' : await getCurrentBranch();
|
|
18
|
+
logger.info(`đ Currently on branch: ${currentBranch}`);
|
|
19
|
+
// Find the working/development branch from configuration
|
|
20
|
+
let workingBranch = 'working'; // Default fallback
|
|
21
|
+
if (runConfig.branches) {
|
|
22
|
+
const configuredDevBranch = findDevelopmentBranch(runConfig.branches);
|
|
23
|
+
if (configuredDevBranch) {
|
|
24
|
+
workingBranch = configuredDevBranch;
|
|
25
|
+
logger.info(`đ¯ Found configured working branch: ${workingBranch}`);
|
|
26
|
+
} else {
|
|
27
|
+
logger.info(`đ¯ No working branch configured, using default: ${workingBranch}`);
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
logger.info(`đ¯ No branch configuration found, using default working branch: ${workingBranch}`);
|
|
152
31
|
}
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
32
|
+
// Track what actions are taken to determine the appropriate return message
|
|
33
|
+
let branchCreated = false;
|
|
34
|
+
let branchUpdated = false;
|
|
35
|
+
let alreadyOnBranch = false;
|
|
36
|
+
let mergedDevelopmentIntoWorking = false;
|
|
37
|
+
// Determine prerelease tag and increment level from configuration
|
|
38
|
+
const allBranchConfig = runConfig.branches || KODRDRIV_DEFAULTS.branches;
|
|
39
|
+
let prereleaseTag = 'dev'; // Default
|
|
40
|
+
let incrementLevel = 'patch'; // Default
|
|
41
|
+
// Check for development command specific targetVersion override
|
|
42
|
+
if ((_runConfig_development = runConfig.development) === null || _runConfig_development === void 0 ? void 0 : _runConfig_development.targetVersion) {
|
|
43
|
+
const targetVersion = runConfig.development.targetVersion;
|
|
44
|
+
// Validate targetVersion
|
|
45
|
+
if (![
|
|
46
|
+
'patch',
|
|
47
|
+
'minor',
|
|
48
|
+
'major'
|
|
49
|
+
].includes(targetVersion) && !/^\d+\.\d+\.\d+$/.test(targetVersion.replace(/^v/, ''))) {
|
|
50
|
+
throw new Error(`Invalid target version: ${targetVersion}. Expected "patch", "minor", "major", or a valid version string like "2.1.0"`);
|
|
51
|
+
}
|
|
52
|
+
incrementLevel = targetVersion;
|
|
53
|
+
} else if (allBranchConfig && allBranchConfig[workingBranch]) {
|
|
54
|
+
const workingBranchConfig = allBranchConfig[workingBranch];
|
|
55
|
+
if (workingBranchConfig.version) {
|
|
56
|
+
if (workingBranchConfig.version.tag) {
|
|
57
|
+
prereleaseTag = workingBranchConfig.version.tag;
|
|
58
|
+
}
|
|
59
|
+
if (workingBranchConfig.version.incrementLevel) {
|
|
60
|
+
incrementLevel = workingBranchConfig.version.incrementLevel;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
logger.info(`đˇī¸ Using prerelease tag: ${prereleaseTag}`);
|
|
65
|
+
logger.info(`đ Using increment level: ${incrementLevel}`);
|
|
66
|
+
// Step 1: Fetch latest remote information
|
|
67
|
+
if (!isDryRun) {
|
|
68
|
+
logger.info('đĄ Fetching latest remote information...');
|
|
69
|
+
try {
|
|
70
|
+
await run('git fetch origin');
|
|
71
|
+
logger.info('â
Fetched latest remote information');
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logger.warn(`â ī¸ Could not fetch from remote: ${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
logger.info('Would fetch latest remote information');
|
|
157
77
|
}
|
|
158
|
-
//
|
|
159
|
-
if (
|
|
78
|
+
// Special case: If currently on development branch, merge development into working
|
|
79
|
+
if (currentBranch === 'development') {
|
|
160
80
|
if (!isDryRun) {
|
|
161
|
-
logger.info('
|
|
162
|
-
await run(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
logger.warn(`Warning: Could not sync main with remote: ${syncResult.error}`);
|
|
81
|
+
logger.info('đ Currently on development branch, merging into working...');
|
|
82
|
+
await run(`git checkout ${workingBranch}`);
|
|
83
|
+
await run(`git merge development --no-ff -m "Merge development into working for continued development"`);
|
|
84
|
+
await run('npm install');
|
|
85
|
+
// Check if npm install created any changes and commit them
|
|
86
|
+
const gitStatus = await run('git status --porcelain');
|
|
87
|
+
if (gitStatus.stdout.trim()) {
|
|
88
|
+
await run('git add -A');
|
|
89
|
+
await run('git commit -m "chore: update package-lock.json after merge"');
|
|
171
90
|
}
|
|
91
|
+
await run('git checkout development');
|
|
92
|
+
mergedDevelopmentIntoWorking = true;
|
|
172
93
|
} else {
|
|
173
|
-
logger.info('Would
|
|
94
|
+
logger.info('Would merge development into working and switch to development branch');
|
|
95
|
+
mergedDevelopmentIntoWorking = true;
|
|
174
96
|
}
|
|
175
97
|
}
|
|
176
|
-
//
|
|
177
|
-
if (!
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
98
|
+
// Step 2: Switch to working branch (create if needed) - skip if we handled development branch case
|
|
99
|
+
if (!isDryRun && !mergedDevelopmentIntoWorking) {
|
|
100
|
+
const workingBranchExists = await localBranchExists(workingBranch);
|
|
101
|
+
if (!workingBranchExists) {
|
|
102
|
+
logger.info(`đ Working branch '${workingBranch}' doesn't exist, creating it...`);
|
|
103
|
+
await run(`git checkout -b ${workingBranch}`);
|
|
104
|
+
logger.info(`â
Created and switched to ${workingBranch}`);
|
|
105
|
+
branchCreated = true;
|
|
106
|
+
} else if (currentBranch !== workingBranch) {
|
|
107
|
+
logger.info(`đ Switching to ${workingBranch}...`);
|
|
108
|
+
await run(`git checkout ${workingBranch}`);
|
|
109
|
+
logger.info(`â
Switched to ${workingBranch}`);
|
|
110
|
+
branchUpdated = true;
|
|
181
111
|
} else {
|
|
182
|
-
logger.info(
|
|
112
|
+
logger.info(`â
Already on working branch: ${workingBranch}`);
|
|
113
|
+
alreadyOnBranch = true;
|
|
183
114
|
}
|
|
184
|
-
} else {
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
await run('git merge main --no-ff -m "Merge main into working for development"');
|
|
192
|
-
} catch (error) {
|
|
193
|
-
throw new Error(`Failed to merge main into working. Please resolve conflicts manually: ${error}`);
|
|
194
|
-
}
|
|
115
|
+
} else if (!mergedDevelopmentIntoWorking) {
|
|
116
|
+
// For dry run, we need to mock the logic
|
|
117
|
+
const workingBranchExists = await localBranchExists(workingBranch);
|
|
118
|
+
if (!workingBranchExists) {
|
|
119
|
+
branchCreated = true;
|
|
120
|
+
} else if (currentBranch !== workingBranch) {
|
|
121
|
+
branchUpdated = true;
|
|
195
122
|
} else {
|
|
196
|
-
|
|
123
|
+
alreadyOnBranch = true;
|
|
197
124
|
}
|
|
125
|
+
logger.info(`Would switch to ${workingBranch} branch (creating if needed)`);
|
|
126
|
+
logger.info(`Would sync ${workingBranch} with remote to avoid conflicts`);
|
|
198
127
|
}
|
|
199
|
-
//
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const milestonesEnabled = !((_runConfig_development2 = runConfig.development) === null || _runConfig_development2 === void 0 ? void 0 : _runConfig_development2.noMilestones);
|
|
208
|
-
if (!isDryRun) {
|
|
209
|
-
// Update package.json
|
|
210
|
-
const packageJsonContents = await storage.readFile('package.json', 'utf-8');
|
|
211
|
-
const packageJson = safeJsonParse(packageJsonContents, 'package.json');
|
|
212
|
-
const validated = validatePackageJson(packageJson, 'package.json');
|
|
213
|
-
validated.version = newDevVersion;
|
|
214
|
-
await storage.writeFile('package.json', JSON.stringify(validated, null, 2), 'utf-8');
|
|
215
|
-
// Run npm install to update lock files
|
|
216
|
-
logger.info('Running npm install to update lock files...');
|
|
217
|
-
await run('npm install');
|
|
218
|
-
// Handle GitHub milestones if enabled
|
|
219
|
-
if (milestonesEnabled) {
|
|
220
|
-
logger.info('đ Managing GitHub milestones...');
|
|
221
|
-
try {
|
|
222
|
-
await ensureMilestoneForVersion(baseVersion, state.mainVersion);
|
|
223
|
-
} catch (error) {
|
|
224
|
-
logger.warn(`â ī¸ Milestone management failed (continuing): ${error.message}`);
|
|
225
|
-
}
|
|
128
|
+
// Step 2.1: Sync with remote working branch to avoid conflicts
|
|
129
|
+
if (!isDryRun) {
|
|
130
|
+
try {
|
|
131
|
+
logger.info(`đ Syncing ${workingBranch} with remote to avoid conflicts...`);
|
|
132
|
+
const remoteExists = await run(`git ls-remote --exit-code --heads origin ${workingBranch}`).then(()=>true).catch(()=>false);
|
|
133
|
+
if (remoteExists) {
|
|
134
|
+
await run(`git pull origin ${workingBranch} --no-edit`);
|
|
135
|
+
logger.info(`â
Synced ${workingBranch} with remote`);
|
|
226
136
|
} else {
|
|
227
|
-
logger.
|
|
137
|
+
logger.info(`âšī¸ No remote ${workingBranch} branch found, will be created on first push`);
|
|
228
138
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error.message && error.message.includes('CONFLICT')) {
|
|
141
|
+
logger.error(`â Merge conflicts detected when syncing ${workingBranch} with remote`);
|
|
142
|
+
logger.error(` Please resolve the conflicts manually and then run:`);
|
|
143
|
+
logger.error(` 1. Resolve conflicts in the files`);
|
|
144
|
+
logger.error(` 2. git add <resolved-files>`);
|
|
145
|
+
logger.error(` 3. git commit`);
|
|
146
|
+
logger.error(` 4. kodrdriv development (to continue)`);
|
|
147
|
+
throw new Error(`Merge conflicts detected when syncing ${workingBranch} with remote. Please resolve conflicts manually.`);
|
|
148
|
+
} else {
|
|
149
|
+
logger.warn(`â ī¸ Could not sync with remote ${workingBranch}: ${error.message}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Step 3: Merge latest changes from development branch if it exists
|
|
154
|
+
if (!isDryRun) {
|
|
155
|
+
const developmentBranchExists = await localBranchExists('development');
|
|
156
|
+
if (developmentBranchExists) {
|
|
157
|
+
logger.info('đ Merging latest changes from development branch...');
|
|
158
|
+
try {
|
|
159
|
+
await run(`git merge development --no-ff -m "Merge latest development changes into ${workingBranch}"`);
|
|
160
|
+
logger.info('â
Successfully merged development changes');
|
|
161
|
+
// Run npm install after merge to update dependencies
|
|
162
|
+
logger.info('đĻ Running npm install after merge...');
|
|
163
|
+
await run('npm install');
|
|
164
|
+
// Check if npm install created any changes (e.g., package-lock.json)
|
|
165
|
+
const gitStatus = await run('git status --porcelain');
|
|
166
|
+
if (gitStatus.stdout.trim()) {
|
|
167
|
+
logger.info('đ Committing changes from npm install...');
|
|
168
|
+
await run('git add -A');
|
|
169
|
+
await run(`git commit -m "chore: update package-lock.json after merge"`);
|
|
170
|
+
logger.info('â
Changes committed');
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (error.message && error.message.includes('CONFLICT')) {
|
|
174
|
+
logger.error(`â Merge conflicts detected when merging development into ${workingBranch}`);
|
|
175
|
+
logger.error(` Please resolve the conflicts manually and then run:`);
|
|
176
|
+
logger.error(` 1. Resolve conflicts in the files`);
|
|
177
|
+
logger.error(` 2. git add <resolved-files>`);
|
|
178
|
+
logger.error(` 3. git commit`);
|
|
179
|
+
logger.error(` 4. npm install`);
|
|
180
|
+
logger.error(` 5. npm version pre${incrementLevel} --preid=${prereleaseTag}`);
|
|
181
|
+
throw new Error(`Merge conflicts detected when merging development into ${workingBranch}. Please resolve conflicts manually.`);
|
|
182
|
+
} else {
|
|
183
|
+
logger.error(`â Failed to merge development into ${workingBranch}: ${error.message}`);
|
|
184
|
+
throw error;
|
|
237
185
|
}
|
|
238
|
-
}
|
|
239
|
-
|
|
186
|
+
}
|
|
187
|
+
} else if (!developmentBranchExists) {
|
|
188
|
+
logger.info('âšī¸ Development branch does not exist, skipping merge step');
|
|
240
189
|
} else {
|
|
241
|
-
logger.info(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
190
|
+
logger.info('âšī¸ Already merged from development (was on development branch)');
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
logger.info('Would merge latest changes from development branch if it exists');
|
|
194
|
+
logger.info('Would run npm install after merge');
|
|
195
|
+
logger.info('Would commit any changes from npm install (e.g., package-lock.json)');
|
|
196
|
+
}
|
|
197
|
+
// Step 5: Check if we already have a proper development version
|
|
198
|
+
if (alreadyOnBranch && !mergedDevelopmentIntoWorking) {
|
|
199
|
+
// Check if current version is already a development version with the right tag
|
|
200
|
+
const fs = await import('fs/promises');
|
|
201
|
+
try {
|
|
202
|
+
const packageJson = JSON.parse(await fs.readFile('package.json', 'utf-8'));
|
|
203
|
+
const currentVersion = packageJson.version;
|
|
204
|
+
// If current version already has the dev tag, we're done
|
|
205
|
+
if (currentVersion.includes(`-${prereleaseTag}.`)) {
|
|
206
|
+
logger.info(`â
Already on working branch with development version ${currentVersion}`);
|
|
207
|
+
return 'Already on working branch with development version';
|
|
208
|
+
}
|
|
209
|
+
} catch (error) {
|
|
210
|
+
logger.debug('Could not check current version, proceeding with version bump');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Step 5: Run npm version to bump version with increment level
|
|
214
|
+
let versionCommand;
|
|
215
|
+
if ([
|
|
216
|
+
'patch',
|
|
217
|
+
'minor',
|
|
218
|
+
'major'
|
|
219
|
+
].includes(incrementLevel)) {
|
|
220
|
+
versionCommand = `pre${incrementLevel}`;
|
|
221
|
+
logger.info(`đ Bumping ${incrementLevel} version with prerelease tag '${prereleaseTag}'...`);
|
|
222
|
+
} else {
|
|
223
|
+
// Explicit version like "3.5.0"
|
|
224
|
+
const cleanVersion = incrementLevel.replace(/^v/, '');
|
|
225
|
+
versionCommand = `${cleanVersion}-${prereleaseTag}.0`;
|
|
226
|
+
logger.info(`đ Setting explicit version ${versionCommand}...`);
|
|
227
|
+
}
|
|
228
|
+
if (!isDryRun) {
|
|
229
|
+
try {
|
|
230
|
+
const versionResult = [
|
|
231
|
+
'patch',
|
|
232
|
+
'minor',
|
|
233
|
+
'major'
|
|
234
|
+
].includes(incrementLevel) ? await run(`npm version ${versionCommand} --preid=${prereleaseTag}`) : await run(`npm version ${versionCommand}`);
|
|
235
|
+
const newVersion = versionResult.stdout.trim();
|
|
236
|
+
logger.info(`â
Version bumped to: ${newVersion}`);
|
|
237
|
+
// Return appropriate message based on what actions were taken
|
|
238
|
+
if (mergedDevelopmentIntoWorking) {
|
|
239
|
+
return 'Merged development into working and switched to development branch';
|
|
240
|
+
} else if (branchCreated) {
|
|
241
|
+
return 'Created working branch with development version';
|
|
242
|
+
} else if (branchUpdated) {
|
|
243
|
+
return 'Updated working branch with development version';
|
|
244
|
+
} else if (alreadyOnBranch) {
|
|
245
|
+
return 'Already on working branch with development version';
|
|
247
246
|
} else {
|
|
248
|
-
|
|
247
|
+
return `Ready for development on ${workingBranch} with version ${newVersion}`;
|
|
249
248
|
}
|
|
250
|
-
|
|
249
|
+
} catch (error) {
|
|
250
|
+
logger.error(`â Failed to bump version: ${error.message}`);
|
|
251
|
+
throw new Error(`Failed to bump ${incrementLevel} version: ${error.message}`);
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
if ([
|
|
255
|
+
'patch',
|
|
256
|
+
'minor',
|
|
257
|
+
'major'
|
|
258
|
+
].includes(incrementLevel)) {
|
|
259
|
+
logger.info(`Would run: npm version ${versionCommand} --preid=${prereleaseTag}`);
|
|
260
|
+
} else {
|
|
261
|
+
logger.info(`Would run: npm version ${versionCommand}`);
|
|
262
|
+
}
|
|
263
|
+
// Return appropriate message based on what actions were taken
|
|
264
|
+
if (mergedDevelopmentIntoWorking) {
|
|
265
|
+
return 'Merged development into working and switched to development branch';
|
|
266
|
+
} else if (branchCreated) {
|
|
267
|
+
return 'Created working branch with development version';
|
|
268
|
+
} else if (branchUpdated) {
|
|
269
|
+
return 'Updated working branch with development version';
|
|
270
|
+
} else if (alreadyOnBranch) {
|
|
271
|
+
return 'Already on working branch with development version';
|
|
272
|
+
} else {
|
|
273
|
+
return `Ready for development on ${workingBranch} (dry run)`;
|
|
251
274
|
}
|
|
252
275
|
}
|
|
253
|
-
const finalMessage = state.workingBranchExists ? 'Updated working branch with development version' : 'Created working branch with development version';
|
|
254
|
-
logger.info(`â
${finalMessage}`);
|
|
255
|
-
logger.info(`Development version: ${state.needsVersionBump || !state.workingBranchExists ? createDevelopmentVersion(state.mainVersion, ((_runConfig_development = runConfig.development) === null || _runConfig_development === void 0 ? void 0 : _runConfig_development.targetVersion) || 'patch') : state.currentVersion}`);
|
|
256
|
-
return finalMessage;
|
|
257
276
|
} catch (error) {
|
|
258
|
-
logger.error('Failed to
|
|
277
|
+
logger.error('Failed to prepare working branch for development:', error.message);
|
|
259
278
|
throw error;
|
|
260
279
|
}
|
|
261
280
|
};
|