-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.mjs
54 lines (40 loc) · 1.47 KB
/
release.mjs
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
// script.mjs
import fs from 'fs';
import prompts from 'prompts';
import simpleGit from 'simple-git';
const git = simpleGit();
function incrementVersion(version) {
const versions = version.split('.').map(Number);
versions[2] += 1; // Increment PATCH version
return versions.join('.');
}
(async function() {
const currentVersion = JSON.parse(fs.readFileSync('./package.json')).version;
const incrementedVersion = incrementVersion(currentVersion);
const response = await prompts({
type: 'text',
name: 'version',
message: 'Enter the version to publish',
initial: incrementedVersion
});
const version = response.version;
const packageJson = JSON.parse(fs.readFileSync('package.json'));
packageJson.version = version;
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2));
const tagVersion = `v${version}`;
await git.add('./*');
console.log('Files staged.');
await git.commit(`Release ${tagVersion}`);
console.log('Files committed.');
try {
await git.addTag(tagVersion);
console.log('Tag version added.');
} catch (err) {
console.log('No previous tags found. New tag created.');
}
await git.push('origin', 'HEAD'); // Pushes changes to the repository
console.log('Repository changes pushed.');
await git.push('origin', tagVersion); // Pushes the new tag
console.log('Tag version pushed.');
console.log('Push complete.');
})();