-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from ryanraposo/gulp
Add custom task, 'upver'
- Loading branch information
Showing
5 changed files
with
10,207 additions
and
1,597 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# Changelog | ||
|
||
## [1.0.1] | ||
|
||
- Update license | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; |
Oops, something went wrong.