Skip to content

Commit

Permalink
Merge pull request #50 from ryanraposo/gulp
Browse files Browse the repository at this point in the history
Add custom task, 'upver'
  • Loading branch information
ryanraposo authored Jul 10, 2022
2 parents c39b879 + 380a026 commit 28ab88e
Show file tree
Hide file tree
Showing 5 changed files with 10,207 additions and 1,597 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
env : {
"browser":true,
"node": true,
"commonjs": true,
"es6": true
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
Expand Down
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Changelog

## [1.0.1]

- Update license
Expand Down
111 changes: 111 additions & 0 deletions gulpfile.js
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;
Loading

0 comments on commit 28ab88e

Please sign in to comment.