Files
yjs/gulpfile.js

203 lines
4.9 KiB
JavaScript
Raw Normal View History

2015-07-21 17:14:03 +02:00
/* eslint-env node */
2015-06-15 14:53:02 +02:00
2015-06-16 14:36:00 +02:00
/** Gulp Commands
gulp command*
[--export ModuleType]
[--name ModuleName]
[--testport TestPort]
[--testfiles TestFiles]
2015-06-16 14:36:00 +02:00
Module name (ModuleName):
Compile this to "y.js" (default)
Supported module types (ModuleType):
- amd
- amdStrict
- common
- commonStrict
- ignore (default)
- system
- umd
- umdStrict
Test port (TestPort):
2015-06-16 14:41:35 +02:00
Serve the specs on port 8888 (default)
2015-06-16 14:36:00 +02:00
Test files (TestFiles):
Specify which specs to use!
2015-06-16 14:36:00 +02:00
Commands:
2015-09-29 13:59:38 +02:00
- build:deploy
Build this library for deployment (es6->es5, minified)
- dev:browser
2015-06-16 14:36:00 +02:00
Watch the ./src directory.
Builds the library on changes.
2015-06-16 14:36:00 +02:00
Starts an http-server and serves the test suite on http://127.0.0.1:8888.
- dev:node
Watch the ./src directory.
Builds and specs the library on changes.
Usefull to run with node-inspector.
`node-debug $(which gulp) dev:node
2015-06-16 14:36:00 +02:00
- test:
Test this library
*/
2015-07-21 17:14:03 +02:00
var gulp = require('gulp')
var sourcemaps = require('gulp-sourcemaps')
var babel = require('gulp-babel')
var uglify = require('gulp-uglify')
var minimist = require('minimist')
var jasmine = require('gulp-jasmine')
var jasmineBrowser = require('gulp-jasmine-browser')
var concat = require('gulp-concat')
var watch = require('gulp-watch')
2015-10-30 16:00:08 +01:00
var $ = require('gulp-load-plugins')()
2015-06-17 19:16:52 +02:00
2015-06-15 14:53:02 +02:00
var options = minimist(process.argv.slice(2), {
2015-10-02 08:01:58 +00:00
string: ['export', 'name', 'testport', 'testfiles', 'regenerator'],
2015-06-16 14:36:00 +02:00
default: {
2015-07-21 17:14:03 +02:00
export: 'ignore',
name: 'y.js',
testport: '8888',
2015-10-02 08:01:58 +00:00
testfiles: 'src/**/*.js',
regenerator: process.version < 'v0.12'
2015-06-16 14:36:00 +02:00
}
2015-07-21 17:14:03 +02:00
})
var polyfills = [
'./node_modules/gulp-babel/node_modules/babel-core/node_modules/regenerator/runtime.js'
]
var concatOrder = [
'y.js',
'Connector.js',
2015-10-14 18:08:39 +02:00
'Database.js',
'Transaction.js',
'Struct.js',
'Utils.js',
2015-10-14 18:08:39 +02:00
'Databases/RedBlackTree.js',
'Databases/Memory.js',
'Databases/IndexedDB.js',
'Connectors/Test.js',
'Connectors/WebRTC.js',
'Types/Array.js',
'Types/Map.js',
'Types/TextBind.js'
]
2015-06-15 14:53:02 +02:00
var files = {
2015-09-28 23:54:56 +02:00
src: polyfills.concat(concatOrder.map(function (f) {
return 'src/' + f
})),
test: ['build/Helper.spec.js'].concat(concatOrder.map(function (f) {
return 'build/' + f
2015-09-28 23:54:56 +02:00
}).concat(['build/**/*.spec.js']))
2015-07-21 17:14:03 +02:00
}
2015-10-02 08:01:58 +00:00
if (options.regenerator) {
files.test = polyfills.concat(files.test)
}
2015-11-02 13:04:08 +00:00
gulp.task('deploy:build', function () {
2015-10-30 16:00:08 +01:00
return gulp.src(files.src)
2015-07-21 17:14:03 +02:00
.pipe(sourcemaps.init())
.pipe(concat('y.js'))
2015-07-21 17:14:03 +02:00
.pipe(babel({
loose: 'all',
modules: 'ignore',
experimental: true
}))
.pipe(uglify())
2015-09-28 23:54:56 +02:00
.pipe(sourcemaps.write('.'))
2015-07-21 17:14:03 +02:00
.pipe(gulp.dest('.'))
})
2015-10-30 16:00:08 +01:00
gulp.task('deploy:updateSubmodule', function () {
return $.git.updateSubmodule({ args: '--init' })
})
2015-11-02 13:04:08 +00:00
gulp.task('deploy:copy', ['deploy:build'], function () {
return gulp.src(['./y.js', './y.js.map', './README.md', 'package.json', 'LICENSE'])
2015-10-30 16:00:08 +01:00
.pipe(gulp.dest('./dist/'))
})
2015-11-02 13:04:08 +00:00
gulp.task('deploy:bump', function () {
return gulp.src('./package.json')
2015-10-30 16:00:08 +01:00
.pipe($.bump({type: 'patch'}))
2015-11-02 13:04:08 +00:00
.pipe(gulp.dest('./'))
})
gulp.task('deploy:commit', function () {
return gulp.src(['./*', '!./node_modules', '!./build', '!./y.*', '!./dist'] )
.pipe($.git.commit('bumps package version', {args: '-n'}))
/* return gulp.src('./dist/*')
.pipe($.git.commit('New release', {cwd: './dist/'}))*/
})
gulp.task('deploy:tag', function () {
return gulp.src('./package.json')
2015-10-30 16:00:08 +01:00
.pipe($.tagVersion({cwd: './dist'}))
})
2015-11-02 13:04:08 +00:00
gulp.task('deploy', ['deploy:updateSubmodule', 'deploy:bump', 'deploy:copy', 'deploy:commit', 'deploy:tag'], function () {
$.git.push('origin', 'master', function (err) {
if (err) throw err
})
})
2015-10-30 16:00:08 +01:00
gulp.task('build:test', function () {
2015-10-02 08:01:58 +00:00
var babelOptions = {
loose: 'all',
modules: 'ignore',
experimental: true
}
if (!options.regenerator) {
babelOptions.blacklist = 'regenerator'
}
gulp.src(files.src)
.pipe(sourcemaps.init())
.pipe(concat('y.js'))
.pipe(babel(babelOptions))
.pipe(sourcemaps.write())
.pipe(gulp.dest('.'))
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
2015-10-02 08:01:58 +00:00
.pipe(babel(babelOptions))
2015-09-11 18:35:32 +02:00
.pipe(sourcemaps.write())
2015-07-21 17:14:03 +02:00
.pipe(gulp.dest('build'))
})
2015-06-15 14:53:02 +02:00
gulp.task('dev:node', ['test'], function () {
gulp.watch('src/**/*.js', ['test'])
2015-07-21 17:14:03 +02:00
})
gulp.task('dev:browser', ['build:test'], function () {
gulp.watch('src/**/*.js', ['build:test'])
gulp.src(files.test)
.pipe(watch(['build/**/*.js']))
2015-06-16 14:36:00 +02:00
.pipe(jasmineBrowser.specRunner())
2015-07-21 17:14:03 +02:00
.pipe(jasmineBrowser.server({port: options.testport}))
})
2015-06-15 14:53:02 +02:00
gulp.task('dev', ['build:test'], function () {
gulp.start('dev:browser')
gulp.start('dev:node')
})
gulp.task('test', ['build:test'], function () {
2015-10-02 08:01:58 +00:00
var testfiles = files.test
if (typeof Promise === 'undefined') {
2015-10-05 09:48:32 +00:00
testfiles.concat(['src/polyfills.js'])
2015-10-02 08:01:58 +00:00
}
return gulp.src(testfiles)
2015-09-11 18:35:32 +02:00
.pipe(jasmine({
verbose: true,
includeStuckTrace: true
}))
})
gulp.task('default', ['test'])