0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-25 13:39:06 -05:00
liabru-matter-js/Gulpfile.js

124 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-09-14 13:49:24 -04:00
"use strict";
const gulp = require('gulp');
const bump = require('gulp-bump');
const changelog = require('gulp-conventional-changelog');
const tag = require('gulp-tag-version');
const release = require('gulp-github-release');
const sequence = require('run-sequence');
const gutil = require('gulp-util');
const pkg = require('./package.json');
const exec = require('child_process').exec;
const buildDirectory = 'build';
const shellExec = (command, callback) => {
const args = process.argv.slice(3).join(' '),
proc = exec(command + ' ' + args, (err, stdout, stderr) => {
callback(err, stdout, stderr, proc);
});
proc.stdout.on('data', data => process.stdout.write(data));
proc.stderr.on('data', data => process.stderr.write(data));
};
const shell = command => (callback => { shellExec(command, callback); });
const hint = command => (callback => {
gutil.log(gutil.colors.red('Error'), 'use', gutil.colors.yellow(command), 'instead.');
callback();
});
gulp.task('default', hint('npm run build'));
gulp.task('dev', hint('npm run dev'));
gulp.task('build', hint('npm run build'));
gulp.task('test', hint('npm run test'));
gulp.task('lint', hint('npm run lint'));
2019-09-14 13:49:24 -04:00
gulp.task('doc', callback => {
const options = {
paths: ['src'],
themedir: 'matter-doc-theme',
outdir: 'doc/build',
linkNatives: true,
project: {
name: pkg.name + ' ' + pkg.version + ' Physics Engine API Docs',
description: pkg.description,
version: pkg.version,
url: pkg.homepage
}
};
const doc = require('yuidocjs');
const json = new doc.YUIDoc(options).run();
json.project = options.project;
const builder = new doc.DocBuilder(options, json);
builder.compile(callback);
});
gulp.task('bump', () => {
return gulp.src(['package.json', 'bower.json'])
.pipe(bump({ type: process.argv[4] || 'minor' }))
.pipe(gulp.dest('.'));
});
gulp.task('tag', () => {
return gulp.src('package.json')
.pipe(tag({ prefix: '' }));
});
2019-09-14 13:49:24 -04:00
gulp.task('changelog', () => {
return gulp.src('CHANGELOG.md')
.pipe(changelog())
.pipe(gulp.dest('.'));
2015-12-05 11:34:48 -05:00
});
2019-09-14 13:49:24 -04:00
gulp.task('release', callback => {
shellExec('git status --porcelain', (err, stdout) => {
2016-04-19 07:18:33 -04:00
if (stdout && stdout.trim()) {
throw new gutil.PluginError({
plugin: 'release',
message: 'cannot build release as there are uncomitted changes'
});
} else {
2019-09-14 14:31:31 -04:00
sequence(
'release:lint', 'bump', 'release:build', 'release:test',
'doc', 'changelog', callback
);
2016-04-19 07:18:33 -04:00
}
});
});
2019-09-14 14:31:31 -04:00
gulp.task('release:lint', shell('npm run lint'));
2019-09-14 13:49:24 -04:00
gulp.task('release:build', shell('npm run build'));
2019-09-14 14:31:31 -04:00
gulp.task('release:test', shell('TEST_BUILD=true npm run test'));
2019-09-14 13:49:24 -04:00
gulp.task('release:push:git', shell('git push'));
gulp.task('release:push:npm', shell('npm publish'));
gulp.task('release:push', callback => {
shellExec('git status --porcelain', (err, stdout) => {
2016-04-19 07:18:33 -04:00
if (stdout && stdout.trim()) {
throw new gutil.PluginError({
plugin: 'release',
message: 'cannot push release as it has not yet been committed'
});
} else {
2016-11-03 20:14:50 -04:00
sequence('tag', 'release:push:git', 'release:push:npm', callback);
2016-04-19 07:18:33 -04:00
}
});
2016-01-14 18:44:04 -05:00
});
2019-09-14 13:49:24 -04:00
gulp.task('release:push:github', () => {
2016-01-14 18:44:04 -05:00
return gulp.src([
'CHANGELOG.md',
'LICENSE',
2016-01-16 16:02:33 -05:00
buildDirectory + '/matter.min.js',
buildDirectory + '/matter.js'
2016-01-14 18:44:04 -05:00
]).pipe(release({
owner: 'liabru',
repo: pkg.name,
tag: pkg.version,
name: 'Matter.js ' + pkg.version
}));
});