Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.DS_Store
*.orig
.tmp
npm-debug.log
84 changes: 84 additions & 0 deletions gulp/tasks/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use strict';

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var logger = require('gulplog');
var inquirer = require('inquirer');
var exec = require('child_process').spawn;

var allowedBranch = 'master';
var bumpTypeQuestion = {
type: 'list',
name: 'bump',
message: 'What type of bump would you like to do?',
default: 'minor',
choices: ['patch', 'minor', 'major']
};

// Makes sure we do this on the master branch
var assertBranchAllowed = function(done) {
$.git.revParse({args:'--abbrev-ref HEAD', quiet: true}, function(err, currentBranch) {
if (currentBranch != allowedBranch) {
logger.error('ERR: You need to be on the %s branch to be able to deploy', allowedBranch);
process.exit(1);
}
done();
});
}
assertBranchAllowed.displayName = 'Verify branch';

// Asks for the bump type
var askBumpType = function(done) {
inquirer.prompt([bumpTypeQuestion], function( answers ) {
if (answers !== null && answers[bumpTypeQuestion.name] !== null) {
bumpVersion(answers[bumpTypeQuestion.name], done);
} else {
logger.error('ERR: There was an error with the provided bump type');
process.exit(1);
}
});
}
askBumpType.displayName = 'Ask bump type';

// Bumps the version of the project
var bumpVersion = function(bumpType, done) {
var p = exec('npm', ['version', bumpType], { cwd: process.cwd()});
var stderr = '';

p.stderr.on('data', function(buf) {
stderr += buf;
});

p.on('close', function(code){
if (code !== 0) {
logger.error('ERR: There was an error running \'npm version\' && git push && git push --tags:');
logger.error('Details:');
logger.error('%s', stderr);
process.exit(1);
} else {
done();
}
});
}
bumpVersion.displayName = 'Bump Version';

// Display the next release steps
var displayNextReleaseSteps = function(done) {
logger.info('The project now has a new version and was pushed to master');
logger.info('Next steps:');
logger.info(' 1. Got to github and create a pull request from master to release');
logger.info(' 2. Somebody else should review the PR and merge it');
logger.info(' 3. The CI will publish it and create a release on github');
done();
}
bumpVersion.displayName = 'Display next release steps';

// Bumps the version on package.json and commits it locally and pushes to master
var releaseTask = function(done) {
return new Promise(gulp.series(assertBranchAllowed, askBumpType, displayNextReleaseSteps));
}
releaseTask.description = 'Bumps the npm version';

module.exports = function(gulp, $, config) {
return releaseTask;
};
7 changes: 7 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ gulp.task(
gulp.task('deploy', t.getTask('deploy'));


/////////////
// Release //
/////////////

gulp.task('release', t.getTask('release'));


/////////////
// Others //
/////////////
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "project-name",
"description": "",
"version": "0.0.0",
"version": "0.3.0",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an actual skeleton release number? Seeing as we had a skeleton 2 branch? We should at least have a major release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I did was matching to the current release number on github:
https://github.com/ginetta/skeleton/releases

Will take care of proper releases once this is in and the CI part is done

"main": "dist/index.html",
"scripts": {
"start": "./node_modules/.bin/gulp",
"build": "./node_modules/.bin/gulp build",
"test": "./node_modules/.bin/gulp test",
"serve": "./node_modules/.bin/gulp serve",
"deploy": "./node_modules/.bin/gulp deploy"
"deploy": "./node_modules/.bin/gulp deploy",
"release": "./node_modules/.bin/gulp release",
"postversion": "git push && git push --tags"
},
"dependencies": {
"sensible": "0.5.4"
Expand All @@ -23,12 +25,14 @@
"gulp-a11y": "^0.1.1",
"gulp-accessibility": "^1.2.1",
"gulp-autoprefixer": "^2.2.0",
"gulp-bump": "^1.0.0",
"gulp-changed": "^1.2.1",
"gulp-cli": "github:gulpjs/gulp-cli#4.0",
"gulp-concat": "^2.5.2",
"gulp-css-globbing": "^0.1.7",
"gulp-data": "^1.2.0",
"gulp-eslint": "^1.0.0",
"gulp-git": "^1.6.0",
"gulp-jade": "^1.0.0",
"gulp-jade-globbing": "0.1.6",
"gulp-load-plugins": "^0.10.0",
Expand All @@ -38,6 +42,8 @@
"gulp-sourcemaps": "^1.5.2",
"gulp-sync": "^0.1.4",
"gulp-util": "^3.0.4",
"gulplog": "^1.0.0",
"inquirer": "^0.11.0",
"jade": "^1.11.0",
"jade-glob-include": "^1.0.1",
"jade-inline-file": "^0.1.0",
Expand Down