-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
111 lines (81 loc) · 2.63 KB
/
gulpfile.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const inquirer = require('inquirer');
function updateReadme(newVersion) {
const re = /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/gm;
let readme = fs.readFileSync('./README.md', {encoding:'utf8', flag:'r'});
readme = readme.replaceAll(re, newVersion);
fs.writeFileSync('./README.md', readme, {encoding:'utf-8'});
console.log(`README updated ✅`);
};
function updateManifest(newVersion) {
const re = /"version":.*/gm;
let manifest = fs.readFileSync('./package.json', {encoding:'utf8', flag:'r'});
manifest = manifest.replace(re, `"version": "${newVersion}",`);
fs.writeFileSync('./package.json', manifest, {encoding:'utf-8'});
console.log(`Manifest updated ✅`);
};
async function promptChange(changes) {
if (!changes) {
changes = [];
}
return await inquirer.prompt([
{
type: 'input',
name: 'change',
message: 'Enter a change for the changelog:',
validate: changeInput => {
if (changeInput) {
return true;
} else {
console.log('Please enter a change!');
return false;
}
}
},
{
type: 'confirm',
name: 'confirmAddChange',
message: 'Would you like to enter another change?',
default: false
}
])
.then((answers) => {
changes.push(answers.change);
if (answers.confirmAddChange) {
return promptChange(changes);
} else {
return changes;
}
})
.catch((error) => {
if (error.isTtyError) {
console.log("Prompt couldn't be rendered in the current environment");
} else {
console.log(error);
}
});
};
async function updateChangelog(newVersion) {
const changes = await promptChange();
let logText = `## [${newVersion}] \n \n`;
changes.forEach((change) => {
logText += `- ${change} \n \n`;
});
let changelog = fs.readFileSync('./CHANGELOG.md', {encoding:'utf8', flag:'r'});
changelog = logText + changelog;
fs.writeFileSync('./CHANGELOG.md', changelog, {encoding:'utf-8'});
console.log(`Changelog updated ✅`);
};
async function upver() {
const newVersion = process.argv[4];
try {
updateReadme(newVersion);
updateManifest(newVersion);
await updateChangelog(newVersion);
}
catch(err){
console.log(err);
}
}
exports.upver = upver;