Gulp: Define publish:website task to keep paperjs.org in sync.

This commit is contained in:
Jürg Lehni 2017-04-20 12:50:09 +02:00
parent 91199f19f0
commit 118deea20b
3 changed files with 101 additions and 50 deletions

4
.gitignore vendored
View file

@ -1,3 +1,5 @@
/.nvmrc
/node_modules/ /node_modules/
/dist/*/ /dist/*/
/.nvmrc /dist/*.min.js
/dist/paperjs.zip

View file

@ -28,17 +28,19 @@ gulp.task('docs', ['docs:local', 'build:full'], function() {
}); });
Object.keys(docOptions).forEach(function(name) { Object.keys(docOptions).forEach(function(name) {
gulp.task('docs:' + name, ['clean:docs:' + name], shell.task([ gulp.task('docs:' + name, ['clean:docs:' + name], function() {
'java -cp jsrun.jar:lib/* JsRun app/run.js -c=conf/' + name + '.conf ' + var mode = docOptions[name];
'-D="renderMode:' + docOptions[name] + '" ' + return gulp.src('src')
'-D="version:' + options.version + '"' .pipe(shell(
], { ['java -cp jsrun.jar:lib/* JsRun app/run.js',
cwd: 'gulp/jsdoc' ' -c=conf/', name, '.conf ',
})); ' -D="renderMode:', mode, '" ',
' -D="version:', options.version, '"'].join(''),
{ cwd: 'gulp/jsdoc' })
)
});
gulp.task('clean:docs:' + name, function() { gulp.task('clean:docs:' + name, function() {
return del([ return del([ 'dist/' + docOptions[name] + '/**' ]);
'dist/' + docOptions[name] + '/**',
]);
}); });
}); });

View file

@ -11,14 +11,22 @@
*/ */
var gulp = require('gulp'), var gulp = require('gulp'),
git = require('gulp-git-streamed'), path = require('path'),
jsonEditor = require('gulp-json-editor'), fs = require('fs'),
merge = require('merge-stream'), del = require('del'),
run = require('run-sequence'), run = require('run-sequence'),
git = require('gulp-git-streamed'),
shell = require('gulp-shell'), shell = require('gulp-shell'),
merge = require('merge-stream'),
rename = require('gulp-rename'),
jsonEditor = require('gulp-json-editor'),
options = require('../utils/options.js'); options = require('../utils/options.js');
var packages = ['paper-jsdom', 'paper-jsdom-canvas'], var packages = ['paper-jsdom', 'paper-jsdom-canvas'],
sitePath = path.resolve('../paperjs.org'),
referencePath = sitePath + '/content/08-Reference',
downloadPath = sitePath + '/content/11-Download',
releaseMessage = null,
jsonOptions = { jsonOptions = {
end_with_newline: true end_with_newline: true
}; };
@ -28,11 +36,12 @@ gulp.task('publish', function() {
throw new Error('Publishing is only allowed on the develop branch.'); throw new Error('Publishing is only allowed on the develop branch.');
} }
return run( return run(
'publish:version', 'publish:json',
'publish:packages',
'publish:dist', 'publish:dist',
'publish:commit', 'publish:commit',
'publish:release', 'publish:release',
'publish:packages',
'publish:website',
'publish:load' 'publish:load'
); );
}); });
@ -41,6 +50,10 @@ gulp.task('publish:version', function() {
// Reset the version value since we're executing this on the develop branch, // Reset the version value since we're executing this on the develop branch,
// but we don't wan the published version suffixed with '-develop'. // but we don't wan the published version suffixed with '-develop'.
options.resetVersion(); options.resetVersion();
releaseMessage = 'Release version ' + options.version;
});
gulp.task('publish:json', ['publish:version'], function() {
return gulp.src(['package.json']) return gulp.src(['package.json'])
.pipe(jsonEditor({ .pipe(jsonEditor({
version: options.version version: options.version
@ -48,44 +61,14 @@ gulp.task('publish:version', function() {
.pipe(gulp.dest('.')); .pipe(gulp.dest('.'));
}); });
gulp.task('publish:packages', gulp.task('publish:dist', ['zip']);
packages.map(function(name) {
return 'publish:packages:' + name;
})
);
packages.forEach(function(name) { gulp.task('publish:commit', ['publish:version'], function() {
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() {
options.resetVersion(); // See 'publish:version'
var message = 'Release version ' + options.version;
return gulp.src('.') return gulp.src('.')
.pipe(git.checkout('develop')) .pipe(git.checkout('develop'))
.pipe(git.add()) .pipe(git.add())
.pipe(git.commit(message)) .pipe(git.commit(releaseMessage))
.pipe(git.tag('v' + options.version, message)); .pipe(git.tag('v' + options.version, releaseMessage));
}); });
gulp.task('publish:release', function() { gulp.task('publish:release', function() {
@ -96,6 +79,70 @@ gulp.task('publish:release', function() {
.pipe(shell('npm publish')); .pipe(shell('npm publish'));
}); });
gulp.task('publish:packages',
packages.map(function(name) {
return 'publish:packages:' + name;
})
);
packages.forEach(function(name) {
gulp.task('publish:packages:' + name, ['publish:version'], function() {
var 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(releaseMessage, opts))
.pipe(git.tag('v' + options.version, releaseMessage, opts))
.pipe(git.push('origin', 'master', { args: '--tags', cwd: path }))
.pipe(shell('npm publish', opts));
});
});
gulp.task('publish:website', function() {
if (fs.lstatSync(sitePath).isDirectory()) {
return run(
'publish:website:build',
'publish:website:push'
);
}
});
gulp.task('publish:website:build',
['publish:website:docs', 'publish:website:zip']);
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));
});
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 }));
});
gulp.task('publish:load', ['load'], function() { gulp.task('publish:load', ['load'], function() {
return gulp.src('dist') return gulp.src('dist')
.pipe(git.checkout('develop')) .pipe(git.checkout('develop'))