mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-21 17:14:38 -05:00
updated build scripts
This commit is contained in:
parent
046013ee0b
commit
6b698ea2f6
3 changed files with 12886 additions and 304 deletions
368
Gulpfile.js
368
Gulpfile.js
|
@ -1,209 +1,41 @@
|
||||||
var gulp = require('gulp');
|
"use strict";
|
||||||
var uglify = require('gulp-uglify');
|
|
||||||
var rename = require('gulp-rename');
|
|
||||||
var header = require('gulp-header');
|
|
||||||
var eslint = require('gulp-eslint');
|
|
||||||
var bump = require('gulp-bump');
|
|
||||||
var changelog = require('gulp-conventional-changelog');
|
|
||||||
var tag = require('gulp-tag-version');
|
|
||||||
var release = require('gulp-github-release');
|
|
||||||
var sequence = require('run-sequence');
|
|
||||||
var gutil = require('gulp-util');
|
|
||||||
var replace = require('gulp-replace');
|
|
||||||
var webserver = require('gulp-webserver');
|
|
||||||
var concat = require('gulp-concat');
|
|
||||||
var preprocess = require('gulp-preprocess');
|
|
||||||
var browserify = require('browserify');
|
|
||||||
var derequire = require('gulp-derequire');
|
|
||||||
var transform = require('vinyl-transform');
|
|
||||||
var through2 = require('through2');
|
|
||||||
var pkg = require('./package.json');
|
|
||||||
var clone = require('gulp-clone');
|
|
||||||
var livereload = require('connect-livereload');
|
|
||||||
var es = require('event-stream');
|
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var watchify = require('watchify');
|
|
||||||
var extend = require('util')._extend;
|
|
||||||
var exec = require('child_process').exec;
|
|
||||||
var buildDirectory = 'build';
|
|
||||||
var server;
|
|
||||||
|
|
||||||
gulp.task('default', ['build:dev']);
|
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';
|
||||||
|
|
||||||
gulp.task('dev', function(callback) {
|
const shellExec = (command, callback) => {
|
||||||
sequence('watch', 'serve', callback);
|
const args = process.argv.slice(3).join(' '),
|
||||||
});
|
proc = exec(command + ' ' + args, (err, stdout, stderr) => {
|
||||||
|
callback(err, stdout, stderr, proc);
|
||||||
|
});
|
||||||
|
|
||||||
gulp.task('release', function(callback) {
|
proc.stdout.on('data', data => process.stdout.write(data));
|
||||||
shell('git status --porcelain', function(err, stdout) {
|
proc.stderr.on('data', data => process.stderr.write(data));
|
||||||
if (stdout && stdout.trim()) {
|
};
|
||||||
throw new gutil.PluginError({
|
|
||||||
plugin: 'release',
|
|
||||||
message: 'cannot build release as there are uncomitted changes'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
sequence('test', 'bump', 'reload', 'build:release', 'doc', 'changelog', callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('release:push', function(callback) {
|
const shell = command => (callback => { shellExec(command, callback); });
|
||||||
shell('git status --porcelain', function(err, stdout) {
|
|
||||||
if (stdout && stdout.trim()) {
|
|
||||||
throw new gutil.PluginError({
|
|
||||||
plugin: 'release',
|
|
||||||
message: 'cannot push release as it has not yet been committed'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
sequence('tag', 'release:push:git', 'release:push:npm', callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('release:push:github', function(callback) {
|
const hint = command => (callback => {
|
||||||
return gulp.src([
|
gutil.log(gutil.colors.red('Error'), 'use', gutil.colors.yellow(command), 'instead.');
|
||||||
'CHANGELOG.md',
|
|
||||||
'LICENSE',
|
|
||||||
buildDirectory + '/matter.min.js',
|
|
||||||
buildDirectory + '/matter.js'
|
|
||||||
]).pipe(release({
|
|
||||||
owner: 'liabru',
|
|
||||||
repo: pkg.name,
|
|
||||||
tag: pkg.version,
|
|
||||||
name: 'Matter.js ' + pkg.version
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('release:push:git', function(callback) {
|
|
||||||
shell('git push', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('release:push:npm', function(callback) {
|
|
||||||
shell('npm publish', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build:dev', function() {
|
|
||||||
return build(extend(extend({}, pkg), { version: pkg.version + '-dev' }));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build:edge', function() {
|
|
||||||
return build(extend(extend({}, pkg), { version: pkg.version + '-alpha' }));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build:release', function() {
|
|
||||||
return build(extend(extend({}, pkg), { version: pkg.version }));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('build:examples', function() {
|
|
||||||
var options = extend(extend({}, pkg), { version: pkg.version + '-dev' });
|
|
||||||
options.name = options.name + '-examples';
|
|
||||||
options.date = options.date || new Date().toISOString().slice(0, 10);
|
|
||||||
options.author = '@liabru';
|
|
||||||
|
|
||||||
return gulp.src('examples/**/*.js')
|
|
||||||
.pipe(concat('examples.js'))
|
|
||||||
.pipe(header(banner, { context: options }))
|
|
||||||
.pipe(gulp.dest('examples/build'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('watch', function() {
|
|
||||||
var b = browserify({
|
|
||||||
entries: ['src/module/main.js'],
|
|
||||||
standalone: 'Matter',
|
|
||||||
plugin: [watchify]
|
|
||||||
});
|
|
||||||
|
|
||||||
var bundle = function() {
|
|
||||||
gutil.log('Updated bundle build/matter-dev.js');
|
|
||||||
b.bundle()
|
|
||||||
.on('error', function(err) {
|
|
||||||
gutil.log('ERROR', err.message);
|
|
||||||
this.emit('end');
|
|
||||||
})
|
|
||||||
.pipe(through2({ objectMode: true }, function(chunk, encoding, callback) {
|
|
||||||
return callback(
|
|
||||||
null,
|
|
||||||
chunk.toString().replace(/@@VERSION@@/g, pkg.version + '-dev')
|
|
||||||
);
|
|
||||||
}))
|
|
||||||
.pipe(fs.createWriteStream('build/matter-dev.js'));
|
|
||||||
};
|
|
||||||
|
|
||||||
b.on('update', bundle);
|
|
||||||
bundle();
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('bump', function() {
|
|
||||||
return gulp.src(['package.json', 'bower.json'])
|
|
||||||
.pipe(bump({ type: process.argv[4] || 'minor' }))
|
|
||||||
.pipe(gulp.dest('.'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('reload', function(callback) {
|
|
||||||
delete require.cache[require.resolve('./package.json')];
|
|
||||||
pkg = require('./package.json');
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('tag', function() {
|
gulp.task('default', hint('npm run build'));
|
||||||
return gulp.src('package.json')
|
gulp.task('dev', hint('npm run dev'));
|
||||||
.pipe(tag({ prefix: '' }));
|
gulp.task('build', hint('npm run build'));
|
||||||
});
|
gulp.task('test', hint('npm run test'));
|
||||||
|
gulp.task('lint', hint('npm run lint'));
|
||||||
|
|
||||||
gulp.task('changelog', function () {
|
gulp.task('doc', callback => {
|
||||||
return gulp.src('CHANGELOG.md')
|
const options = {
|
||||||
.pipe(changelog())
|
|
||||||
.pipe(gulp.dest('.'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('serve', function() {
|
|
||||||
serve(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('serve:test', function() {
|
|
||||||
serve(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('serve:stop', function() {
|
|
||||||
if (server) {
|
|
||||||
try {
|
|
||||||
server.emit('kill');
|
|
||||||
} catch (e) {} // eslint-disable-line no-empty
|
|
||||||
gutil.log('Web server stopped');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test', function(callback) {
|
|
||||||
// TODO: fix tests by switching to nightmare instead of phantom
|
|
||||||
// sequence('serve:test', 'lint', 'build:dev', 'test:browser', 'test:node', 'serve:stop', callback);
|
|
||||||
sequence('lint', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test:browser', function(callback) {
|
|
||||||
shell('phantomjs test/browser/TestDemo.js', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test:node', function(callback) {
|
|
||||||
shell('node test/node/TestDemo.js', callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('lint', function() {
|
|
||||||
return gulp.src([
|
|
||||||
'src/**/*.js',
|
|
||||||
'demo/js/*.js',
|
|
||||||
'examples/*.js',
|
|
||||||
'test/browser/TestDemo.js',
|
|
||||||
'test/node/TestDemo.js',
|
|
||||||
'Gulpfile.js'
|
|
||||||
])
|
|
||||||
.pipe(eslint())
|
|
||||||
.pipe(eslint.format())
|
|
||||||
.pipe(eslint.failAfterError());
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('doc', function(callback) {
|
|
||||||
var options = {
|
|
||||||
paths: ['src'],
|
paths: ['src'],
|
||||||
themedir: 'matter-doc-theme',
|
themedir: 'matter-doc-theme',
|
||||||
outdir: 'doc/build',
|
outdir: 'doc/build',
|
||||||
|
@ -216,98 +48,72 @@ gulp.task('doc', function(callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var Y = require('yuidocjs');
|
const doc = require('yuidocjs');
|
||||||
var json = new Y.YUIDoc(options).run();
|
const json = new doc.YUIDoc(options).run();
|
||||||
json.project = options.project;
|
json.project = options.project;
|
||||||
|
|
||||||
var builder = new Y.DocBuilder(options, json);
|
const builder = new doc.DocBuilder(options, json);
|
||||||
builder.compile(callback);
|
builder.compile(callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
var serve = function(isTest) {
|
gulp.task('bump', () => {
|
||||||
process.on('uncaughtException', function(err) {
|
return gulp.src(['package.json', 'bower.json'])
|
||||||
if (err.errno === 'EADDRINUSE') {
|
.pipe(bump({ type: process.argv[4] || 'minor' }))
|
||||||
gutil.log('Server already running (or port is otherwise in use)');
|
.pipe(gulp.dest('.'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('tag', () => {
|
||||||
|
return gulp.src('package.json')
|
||||||
|
.pipe(tag({ prefix: '' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('changelog', () => {
|
||||||
|
return gulp.src('CHANGELOG.md')
|
||||||
|
.pipe(changelog())
|
||||||
|
.pipe(gulp.dest('.'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('release', callback => {
|
||||||
|
shellExec('git status --porcelain', (err, stdout) => {
|
||||||
|
if (stdout && stdout.trim()) {
|
||||||
|
throw new gutil.PluginError({
|
||||||
|
plugin: 'release',
|
||||||
|
message: 'cannot build release as there are uncomitted changes'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sequence('release:test', 'bump', 'release:build', 'doc', 'changelog', callback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
server = gulp.src('.')
|
gulp.task('release:test', shell('npm run test'));
|
||||||
.pipe(webserver({
|
gulp.task('release:build', shell('npm run build'));
|
||||||
host: '0.0.0.0',
|
gulp.task('release:push:git', shell('git push'));
|
||||||
livereload: {
|
gulp.task('release:push:npm', shell('npm publish'));
|
||||||
enable: !isTest,
|
|
||||||
filter: function(filename) {
|
|
||||||
return filename.match(/build|demo/);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
middleware: livereload(),
|
|
||||||
open: isTest ? false : 'http://localhost:8000/demo/index.html',
|
|
||||||
directoryListing: true
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
var build = function(options) {
|
gulp.task('release:push', callback => {
|
||||||
var isDev = options.version.indexOf('-dev') !== -1,
|
shellExec('git status --porcelain', (err, stdout) => {
|
||||||
filename = buildDirectory + (isDev ? '/matter-dev' : '/matter'),
|
if (stdout && stdout.trim()) {
|
||||||
dest = filename + '.js',
|
throw new gutil.PluginError({
|
||||||
destMin = filename + '.min.js';
|
plugin: 'release',
|
||||||
|
message: 'cannot push release as it has not yet been committed'
|
||||||
options.date = options.date || new Date().toISOString().slice(0, 10);
|
});
|
||||||
options.author = '@liabru';
|
} else {
|
||||||
|
sequence('tag', 'release:push:git', 'release:push:npm', callback);
|
||||||
gutil.log('Building', filename, options.date);
|
}
|
||||||
|
|
||||||
var compiled = gulp.src(['src/module/main.js'])
|
|
||||||
.pipe(through2.obj(function(file, enc, next){
|
|
||||||
browserify(file.path, { standalone: 'Matter' })
|
|
||||||
.bundle(function(err, res){
|
|
||||||
file.contents = res;
|
|
||||||
next(null, file);
|
|
||||||
});
|
|
||||||
}))
|
|
||||||
.pipe(derequire())
|
|
||||||
.pipe(replace('@@VERSION@@', options.version));
|
|
||||||
|
|
||||||
if (!isDev) {
|
|
||||||
compiled.pipe(preprocess({ context: { DEBUG: false } }));
|
|
||||||
}
|
|
||||||
|
|
||||||
var build = compiled.pipe(clone())
|
|
||||||
.pipe(header(banner + '\n' + license + '\n\n', { context: options }))
|
|
||||||
.pipe(rename(dest))
|
|
||||||
.pipe(gulp.dest('.'));
|
|
||||||
|
|
||||||
var buildMin = compiled.pipe(clone())
|
|
||||||
.pipe(uglify({ output: { max_line_len: 1000 } }))
|
|
||||||
.pipe(header(banner, { context: options }))
|
|
||||||
.pipe(rename(destMin))
|
|
||||||
.pipe(gulp.dest('.'));
|
|
||||||
|
|
||||||
return es.merge(build, buildMin);
|
|
||||||
};
|
|
||||||
|
|
||||||
var shell = function(command, callback) {
|
|
||||||
var args = process.argv.slice(3).join(' '),
|
|
||||||
proc = exec(command + ' ' + args, function(err, stdout, stderr) {
|
|
||||||
callback(err, stdout, stderr, proc);
|
|
||||||
});
|
|
||||||
|
|
||||||
proc.stdout.on('data', function(data) {
|
|
||||||
process.stdout.write(data);
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
proc.stderr.on('data', function(data) {
|
gulp.task('release:push:github', () => {
|
||||||
process.stderr.write(data);
|
return gulp.src([
|
||||||
});
|
'CHANGELOG.md',
|
||||||
};
|
'LICENSE',
|
||||||
|
buildDirectory + '/matter.min.js',
|
||||||
var license = fs.readFileSync('src/module/license.js');
|
buildDirectory + '/matter.js'
|
||||||
|
]).pipe(release({
|
||||||
var banner = [
|
owner: 'liabru',
|
||||||
'/**',
|
repo: pkg.name,
|
||||||
'* <%= context.name %> <%= context.version %> by <%= context.author %> <%= context.date %>',
|
tag: pkg.version,
|
||||||
'* <%= context.homepage %>',
|
name: 'Matter.js ' + pkg.version
|
||||||
'* License <%= context.license %>',
|
}));
|
||||||
'*/',
|
});
|
||||||
''
|
|
||||||
].join('\n');
|
|
||||||
|
|
12794
package-lock.json
generated
Normal file
12794
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
28
package.json
28
package.json
|
@ -20,45 +20,27 @@
|
||||||
"rigid body physics"
|
"rigid body physics"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^14.0.0",
|
"eslint": "^6.3.0",
|
||||||
"cheerio": "^0.22.0",
|
"gulp": "^4.0.2",
|
||||||
"connect-livereload": "^0.6.0",
|
|
||||||
"event-stream": "^3.3.2",
|
|
||||||
"fast-json-patch": "^1.1.4",
|
|
||||||
"gulp": "^3.9.0",
|
|
||||||
"gulp-bump": "^2.6.1",
|
"gulp-bump": "^2.6.1",
|
||||||
"gulp-clone": "^1.0.0",
|
|
||||||
"gulp-concat": "^2.6.0",
|
|
||||||
"gulp-conventional-changelog": "^1.1.0",
|
"gulp-conventional-changelog": "^1.1.0",
|
||||||
"gulp-derequire": "^2.1.0",
|
|
||||||
"gulp-eslint": "^3.0.1",
|
|
||||||
"gulp-github-release": "^1.2.1",
|
"gulp-github-release": "^1.2.1",
|
||||||
"gulp-header": "^1.7.1",
|
|
||||||
"gulp-preprocess": "^2.0.0",
|
|
||||||
"gulp-rename": "^1.2.2",
|
|
||||||
"gulp-replace": "^0.5.4",
|
|
||||||
"gulp-tag-version": "^1.3.0",
|
"gulp-tag-version": "^1.3.0",
|
||||||
"gulp-uglify": "^2.0.1",
|
|
||||||
"gulp-util": "^3.0.8",
|
"gulp-util": "^3.0.8",
|
||||||
"gulp-webdriver": "^2.0.3",
|
"jest": "^24.9.0",
|
||||||
"gulp-webserver": "^0.9.1",
|
|
||||||
"mkdirp": "^0.5.1",
|
|
||||||
"rimraf": "^2.4.2",
|
|
||||||
"run-sequence": "^1.1.4",
|
"run-sequence": "^1.1.4",
|
||||||
"through2": "^2.0.3",
|
|
||||||
"vinyl-transform": "^1.0.0",
|
|
||||||
"watchify": "^3.9.0",
|
|
||||||
"webpack": "^4.39.3",
|
"webpack": "^4.39.3",
|
||||||
"webpack-cli": "^3.3.8",
|
"webpack-cli": "^3.3.8",
|
||||||
"webpack-dev-server": "^3.8.0",
|
"webpack-dev-server": "^3.8.0",
|
||||||
"yuidocjs": "^0.10.2"
|
"yuidocjs": "^0.10.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "gulp build:dev && gulp lint"
|
|
||||||
"dev": "webpack-dev-server",
|
"dev": "webpack-dev-server",
|
||||||
"build": "webpack --mode=production & webpack --mode=production --env.MINIMIZE",
|
"build": "webpack --mode=production & webpack --mode=production --env.MINIMIZE",
|
||||||
"build-alpha": "webpack --mode=production --env.EDGE & webpack --mode=production --env.MINIMIZE --env.EDGE",
|
"build-alpha": "webpack --mode=production --env.EDGE & webpack --mode=production --env.MINIMIZE --env.EDGE",
|
||||||
"build-examples": "webpack --config webpack.examples.config.js --mode=production --env.EDGE & webpack --config webpack.examples.config.js --mode=production --env.MINIMIZE --env.EDGE",
|
"build-examples": "webpack --config webpack.examples.config.js --mode=production --env.EDGE & webpack --config webpack.examples.config.js --mode=production --env.MINIMIZE --env.EDGE",
|
||||||
|
"lint": "eslint 'src/**/*.js' 'demo/js/Demo.js' 'examples/*.js'",
|
||||||
|
"doc": "gulp doc",
|
||||||
},
|
},
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"files": [
|
"files": [
|
||||||
|
|
Loading…
Add table
Reference in a new issue