paper.js/gulp/tasks/publish.js

177 lines
5.5 KiB
JavaScript
Raw Permalink 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 - 2020, Jürg Lehni & Jonathan Puckey
* http://juerglehni.com/ & https://puckey.studio/
2016-01-31 08:30:14 -05:00
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
var gulp = require('gulp'),
path = require('path'),
fs = require('fs'),
del = require('del'),
run = require('run-sequence'),
git = require('gulp-git-streamed'),
2016-01-31 08:30:14 -05:00
shell = require('gulp-shell'),
merge = require('merge-stream'),
rename = require('gulp-rename'),
jsonEditor = require('gulp-json-editor'),
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'],
sitePath = path.resolve('../paperjs.org'),
referencePath = sitePath + '/content/08-Reference',
downloadPath = sitePath + '/content/11-Download',
2017-04-20 12:16:21 -04:00
assetPath = sitePath + '/assets/js',
releaseMessage = null,
2017-04-19 16:07:46 -04:00
jsonOptions = {
end_with_newline: true
};
gulp.task('publish', function(callback) {
if (options.branch !== 'develop') {
throw new Error('Publishing is only allowed on the develop branch.');
}
// publish:website comes before publish:release, so paperjs.zip file is gone
// before npm publish:
2019-06-22 08:40:54 -04:00
run(
'publish:json',
'publish:dist',
'publish:packages',
'publish:commit',
'publish:website',
'publish:release',
'publish:load',
callback
);
});
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();
releaseMessage = 'Release version ' + options.version;
});
gulp.task('publish:json', ['publish:version'], function() {
return gulp.src(['package.json'])
.pipe(jsonEditor({
version: options.version
}, jsonOptions))
.pipe(gulp.dest('.'));
2016-01-31 08:30:14 -05:00
});
gulp.task('publish:dist', ['zip']);
gulp.task('publish:commit', ['publish:version'], function() {
return gulp.src('.')
.pipe(git.checkout('develop'))
.pipe(git.add())
.pipe(git.commit(releaseMessage))
.pipe(git.tag('v' + options.version, releaseMessage));
});
gulp.task('publish:release', function() {
return gulp.src('.')
.pipe(git.checkout('master'))
.pipe(git.merge('develop', { args: '-X theirs' }))
.pipe(git.push('origin', ['master', 'develop'], { args: '--tags' }))
.pipe(shell('npm publish'));
});
2019-06-22 08:40:54 -04:00
gulp.task('publish:packages',
packages.map(function(name) {
return 'publish:packages:' + name;
})
2019-06-22 08:40:54 -04:00
);
2017-04-19 16:07:46 -04:00
packages.forEach(function(name) {
gulp.task('publish:packages:' + name, ['publish:version'], function() {
var path = 'packages/' + name,
2017-04-19 16:07:46 -04:00
opts = { cwd: path };
2018-10-17 10:49:04 -04:00
return gulp.src(['package.json'], opts)
2017-04-19 16:07:46 -04:00
.pipe(jsonEditor({
version: options.version,
dependencies: {
paper: options.version
}
}, jsonOptions))
.pipe(gulp.dest(path))
.pipe(git.add(opts))
.pipe(git.commit(releaseMessage, opts))
.pipe(git.tag('v' + options.version, releaseMessage, opts))
2017-04-19 16:07:46 -04:00
.pipe(git.push('origin', 'master', { args: '--tags', cwd: path }))
.pipe(shell('npm publish', opts));
});
});
gulp.task('publish:website', function(callback) {
if (fs.lstatSync(sitePath).isDirectory()) {
2019-06-22 08:40:54 -04:00
run(
'publish:website:build',
'publish:website:push',
callback
);
}
});
gulp.task('publish:website:build', [
'publish:website:json', 'publish:website:docs',
'publish:website:zip', 'publish:website:assets'
]);
gulp.task('publish:website:json', ['publish:version'], function() {
return gulp.src([sitePath + '/package.json'])
.pipe(jsonEditor({
version: options.version
}, jsonOptions))
.pipe(gulp.dest(sitePath));
});
gulp.task('publish:website:docs:clean', function() {
return del([ referencePath + '/*' ], { force: true });
});
gulp.task('publish:website:docs',
['publish:version', 'publish:website:docs:clean', 'docs:server'],
function() {
return gulp.src('dist/serverdocs/**')
.pipe(gulp.dest(referencePath));
});
gulp.task('publish:website:zip', ['publish:version'], function() {
return gulp.src('dist/paperjs.zip')
.pipe(rename({ suffix: '-v' + options.version }))
.pipe(gulp.dest(downloadPath));
});
2017-04-20 13:51:45 -04:00
gulp.task('publish:website:assets', function() {
// Always delete the old asset first, in case it's a symlink which Gulp
// doesn't handle well.
fs.unlinkSync(assetPath + '/paper.js');
2017-04-20 12:16:21 -04:00
return gulp.src('dist/paper-full.js')
.pipe(rename({ basename: 'paper' }))
.pipe(gulp.dest(assetPath));
});
gulp.task('publish:website:push', ['publish:version'], function() {
var opts = { cwd: sitePath };
return gulp.src(sitePath)
.pipe(git.add(opts))
.pipe(git.commit(releaseMessage, opts))
.pipe(git.tag('v' + options.version, releaseMessage, opts))
.pipe(git.push('origin', 'master', { args: '--tags', cwd: sitePath }));
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'));
});