paper.js/gulp/tasks/publish.js

106 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-01-31 08:30:14 -05:00
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
var gulp = require('gulp'),
git = require('gulp-git-streamed'),
2017-04-19 16:07:46 -04:00
jsonEditor = require('gulp-json-editor'),
merge = require('merge-stream'),
run = require('run-sequence'),
2016-01-31 08:30:14 -05:00
shell = require('gulp-shell'),
options = require('../utils/options.js');
2016-01-31 08:30:14 -05:00
2017-04-19 16:07:46 -04:00
var packages = ['paper-jsdom', 'paper-jsdom-canvas'],
jsonOptions = {
end_with_newline: true
};
gulp.task('publish', function() {
if (options.branch !== 'develop') {
throw new Error('Publishing is only allowed on the develop branch.');
}
return run(
'publish:version',
'publish:packages',
'publish:dist',
'publish:commit',
'publish:release',
'publish:load'
);
});
gulp.task('publish:version', function() {
// Reset the version value since we're executing this on the develop branch,
2016-07-09 15:20:47 -04:00
// but we don't wan the published version suffixed with '-develop'.
options.resetVersion();
return gulp.src(['package.json'])
.pipe(jsonEditor({
version: options.version
}, jsonOptions))
.pipe(gulp.dest('.'));
2016-01-31 08:30:14 -05:00
});
2017-04-19 16:07:46 -04:00
gulp.task('publish:packages',
packages.map(function(name) {
return 'publish:packages:' + name;
})
);
packages.forEach(function(name) {
gulp.task('publish:packages:' + name, function() {
options.resetVersion(); // See 'publish:version'
var message = 'Release version ' + options.version,
path = 'packages/' + name,
opts = { cwd: path };
gulp.src(['package.json'], opts)
.pipe(jsonEditor({
version: options.version,
dependencies: {
paper: options.version
}
}, jsonOptions))
.pipe(gulp.dest(path))
.pipe(git.add(opts))
.pipe(git.commit(message, opts))
.pipe(git.tag('v' + options.version, message, opts))
.pipe(git.push('origin', 'master', { args: '--tags', cwd: path }))
.pipe(shell('npm publish', opts));
});
});
gulp.task('publish:dist', ['dist']);
gulp.task('publish:commit', function() {
2017-04-19 17:34:35 -04:00
options.resetVersion(); // See 'publish:version'
2016-01-31 08:30:14 -05:00
var message = 'Release version ' + options.version;
return gulp.src('.')
2016-07-09 15:20:47 -04:00
.pipe(git.checkout('develop'))
.pipe(git.add())
2016-01-31 08:30:14 -05:00
.pipe(git.commit(message))
.pipe(git.tag('v' + options.version, message));
});
gulp.task('publish:release', function() {
return gulp.src('.')
2016-01-31 08:30:14 -05:00
.pipe(git.checkout('master'))
.pipe(git.merge('develop', { args: '-X theirs' }))
.pipe(git.push('origin', ['master', 'develop'], { args: '--tags' }))
2016-07-09 15:20:47 -04:00
.pipe(shell('npm publish'));
2016-01-31 08:30:14 -05:00
});
gulp.task('publish:load', ['load'], function() {
return gulp.src('dist')
2016-07-09 15:20:47 -04:00
.pipe(git.checkout('develop'))
.pipe(git.add())
.pipe(git.commit('Switch back to load.js versions on develop branch.'))
.pipe(git.push('origin', 'develop'));
});