forked from different-ai/file-organizer-2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
81 lines (64 loc) · 2.25 KB
/
release.js
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
const { execSync } = require('child_process');
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function executeCommand(command) {
try {
return execSync(command, { encoding: 'utf8' });
} catch (error) {
console.error(`Error executing command: ${command}`);
console.error(error.message);
process.exit(1);
}
}
function updatePackageVersion(version) {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
packageJson.version = version;
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2));
}
function updateVersionFiles() {
executeCommand('node version-bump.mjs');
}
async function release() {
// Get current version
const currentVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
console.log(`Current version: ${currentVersion}`);
// Prompt for new version
const newVersion = await new Promise(resolve => {
rl.question('Enter new version number: ', resolve);
});
// Prompt for release description
const description = await new Promise(resolve => {
rl.question('Enter release description: ', resolve);
});
// Update package.json
updatePackageVersion(newVersion);
// Run version-bump.mjs
updateVersionFiles();
// Build the plugin
executeCommand('npm run build');
// Git commands
executeCommand('git add .');
executeCommand(`git commit -m "Release ${newVersion}: ${description}"`);
executeCommand(`git tag -a ${newVersion} -m "${description}"`);
executeCommand('git push');
executeCommand(`git push origin ${newVersion}`);
// Create source code archives
executeCommand('git archive --format=zip HEAD > source-code.zip');
executeCommand('git archive --format=tar.gz HEAD > source-code.tar.gz');
// Create GitHub release
const releaseCommand = `gh release create ${newVersion} \
--title "${newVersion}" \
--notes "${description}" \
main.js manifest.json styles.css source-code.zip source-code.tar.gz`;
executeCommand(releaseCommand);
// Clean up temporary files
fs.unlinkSync('source-code.zip');
fs.unlinkSync('source-code.tar.gz');
console.log(`Version ${newVersion} has been released!`);
rl.close();
}
release();