-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.js
More file actions
executable file
·75 lines (57 loc) · 1.97 KB
/
Copy pathversion.js
File metadata and controls
executable file
·75 lines (57 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
/**
* Version increment helper for Phantom.js
*
* Versioning rules:
* - Each commit increments patch: 0.0.1 -> 0.0.2 -> 0.0.3 ...
* - Every 10 patch increments, increment minor: 0.0.9 -> 0.1.0
* - Every 10 minor increments, increment major: 0.9.9 -> 1.0.0
*/
const fs = require('fs');
const path = require('path');
function parseVersion(version) {
const parts = version.split('.').map(Number);
return {
major: parts[0],
minor: parts[1],
patch: parts[2]
};
}
function formatVersion(parts) {
return `${parts.major}.${parts.minor}.${parts.patch}`;
}
function incrementVersion(currentVersion) {
const v = parseVersion(currentVersion);
// Increment patch
v.patch++;
// If patch reaches 10, increment minor and reset patch
if (v.patch >= 10) {
v.patch = 0;
v.minor++;
}
// If minor reaches 10, increment major and reset minor
if (v.minor >= 10) {
v.minor = 0;
v.major++;
}
return formatVersion(v);
}
function updateVersionInFile(filePath, oldVersion, newVersion) {
const content = fs.readFileSync(filePath, 'utf8');
const updated = content.replace(new RegExp(oldVersion.replace(/\./g, '\\.'), 'g'), newVersion);
fs.writeFileSync(filePath, updated, 'utf8');
}
// Get current version from package.json
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const currentVersion = packageJson.version;
// Calculate new version
const newVersion = incrementVersion(currentVersion);
console.log(`Incrementing version: ${currentVersion} -> ${newVersion}`);
// Update package.json
packageJson.version = newVersion;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf8');
// Update phantom.js
const phantomJsPath = path.join(__dirname, '..', 'phantom.js');
updateVersionInFile(phantomJsPath, currentVersion, newVersion);
console.log(`Version updated to ${newVersion} in package.json and phantom.js`);