-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-version.js
More file actions
executable file
·84 lines (65 loc) · 2.54 KB
/
update-version.js
File metadata and controls
executable file
·84 lines (65 loc) · 2.54 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
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* Simple script to update the Showpass plugin version
* Usage: node update-version.js 4.0.2
*/
const fs = require('fs');
const path = require('path');
// Get version from command line arguments
const newVersion = process.argv[2];
if (!newVersion) {
console.log('Usage: node update-version.js <new-version>');
console.log('Example: node update-version.js 4.0.2');
process.exit(1);
}
// Validate version format (simple check)
if (!/^\d+\.\d+\.\d+$/.test(newVersion)) {
console.log('Error: Version must be in format X.Y.Z (e.g., 4.0.2)');
process.exit(1);
}
const pluginFile = path.join(__dirname, 'plugin', 'showpass-wordpress-plugin.php');
const readmeFile = path.join(__dirname, 'plugin', 'readme.txt');
if (!fs.existsSync(pluginFile)) {
console.log(`Error: Plugin file not found at ${pluginFile}`);
process.exit(1);
}
if (!fs.existsSync(readmeFile)) {
console.log(`Error: Readme file not found at ${readmeFile}`);
process.exit(1);
}
try {
// Update plugin file
let pluginContent = fs.readFileSync(pluginFile, 'utf8');
// Update the version in the plugin header
pluginContent = pluginContent.replace(
/Version: \d+\.\d+\.\d+/,
`Version: ${newVersion}`
);
// Update the version constant
pluginContent = pluginContent.replace(
/define\('SHOWPASS_PLUGIN_VERSION', '\d+\.\d+\.\d+'\);/,
`define('SHOWPASS_PLUGIN_VERSION', '${newVersion}');`
);
// Write back to plugin file
fs.writeFileSync(pluginFile, pluginContent, 'utf8');
console.log(`✅ Successfully updated version to ${newVersion} in ${pluginFile}`);
// Update readme file
let readmeContent = fs.readFileSync(readmeFile, 'utf8');
// Update the stable tag version
readmeContent = readmeContent.replace(
/Stable tag: \d+\.\d+\.\d+/,
`Stable tag: ${newVersion}`
);
// Write back to readme file
fs.writeFileSync(readmeFile, readmeContent, 'utf8');
console.log(`✅ Successfully updated version to ${newVersion} in ${readmeFile}`);
// Optional: Show what was changed
console.log('\n📝 Changes made:');
console.log(` - Plugin header: Version: ${newVersion}`);
console.log(` - Plugin constant: SHOWPASS_PLUGIN_VERSION = '${newVersion}'`);
console.log(` - Readme stable tag: Stable tag: ${newVersion}`);
console.log('\n💡 All script enqueues using SHOWPASS_PLUGIN_VERSION will now use this version automatically!');
} catch (error) {
console.log(`Error: ${error.message}`);
process.exit(1);
}