Skip to content

Commit

Permalink
Replace gulp with custom build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
eKoopmans committed Apr 25, 2021
1 parent ccdd2e8 commit 153531f
Show file tree
Hide file tree
Showing 4 changed files with 1,355 additions and 10,193 deletions.
69 changes: 69 additions & 0 deletions build-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env node

const { program } = require('commander');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const { readFileSync } = require('fs');

program
.command('release [newversion] [tagmessage]')
.description('Bump version, build, commit, tag, and promote to local stable branch')
.action(release)
program
.command('publish-gh')
.description('Push master and stable branches to GitHub with tags')
.action(publishGH)
program.parse(process.argv);

/* ----- HELPER ----- */

function getVersion() {
// Uses readFileSync() instead of require() to prevent caching of values.
const pkg = JSON.parse(readFileSync('./package.json'));
return `v${pkg.version}`;
}

/* ----- SUBTASKS ----- */

// Bump version using NPM (only affects package*.json, doesn't commit).
function bumpVersion(newversion) {
console.log('Bumping version number.');
return exec(`npm --no-git-tag-version version ${newversion}`);
}

// Build, commit, and tag in master with the new release version.
async function buildCommitTag(tagmessage) {
console.log('Running build process in master branch.');
await exec(`git checkout master && npm run build`);

const version = getVersion();
const fullTagMessage = tagmessage ? `${version} ${tagmessage}` : version;

console.log('Adding all changes and performing final commit.');
await exec(`git add -A && git commit --allow-empty -m "Build ${version}"`);

console.log('Tagging with provided tag message.');
return exec(`git tag -a ${version} -m "${fullTagMessage}"`);
}

// Pushes master into the local stable branch.
async function promoteToStable() {
console.log('Getting repo root location.');
const res = await exec('git rev-parse --show-toplevel');
const repoRoot = res.stdout.trim('\n');

console.log('Pushing release to local stable branch.');
return exec(`git push --follow-tags ${repoRoot} master:stable`)
}

/* ----- TASKS ----- */

async function release(newversion, tagmessage) {
await bumpVersion(newversion || 'patch');
await buildCommitTag(tagmessage);
await promoteToStable();
}

function publishGH() {
return exec('git push --follow-tags origin master stable');
}
59 changes: 0 additions & 59 deletions gulpfile.js

This file was deleted.

Loading

0 comments on commit 153531f

Please sign in to comment.