dat.gui/gulpfile.js

238 lines
6.2 KiB
JavaScript
Raw Normal View History

/*
2014-09-08 02:43:10 +00:00
Main Gulp tasks
-----------------
2014-08-27 00:01:15 +00:00
* default - dev
2014-09-15 20:22:54 +00:00
* build - create a vulcanized compiled version after linting and formatting
* dev - launch server, watch for code changes, lint, format
* docs - compile the docs and update gh-pages
* release - build js and docs and update version tag
* test - run the tests
* watch - watch for code changes and update styles but serve it yourself
2014-09-03 00:44:37 +00:00
Gulp tasks used by the main gulp tasks
--------------------------------------
2014-08-27 00:01:15 +00:00
* clean - remove build files
* style - convert stylus to css
* fmt - format the js with esformater
* lint - lint the js with jshint
* readme - convert the readme.md into interactive html doc
* reload - reload the webserver
* serve - start the webserver
* shim - create the shim loader
* vulcanize - vulcanize the into one file
*/
2014-09-02 16:00:08 +00:00
var gulp = require( 'gulp' );
gulp.task( 'default', [ 'dev' ] );
2014-09-15 20:15:34 +00:00
gulp.task( 'build', [ 'readme', 'vulcanize', 'shim' ], function() {
return gulp.src( 'build/dat-gui.html' )
.pipe( $.replace( /\\/g, '\\\\' ) )
.pipe( $.replace( /'/g, '\\\'' ) )
.pipe( $.replace( /^(.*)$/gm, '\'$1\',' ) )
.pipe( $.insert.wrap( 'document.write([', '].join("\\n"))' ) )
.pipe( $.rename( 'dat-gui.js' ) )
.pipe( gulp.dest( 'build' ) );
2014-09-02 16:00:08 +00:00
2014-09-08 01:31:51 +00:00
} );
2014-08-27 00:01:15 +00:00
2014-09-15 20:15:34 +00:00
gulp.task( 'dev', [ 'watch', 'serve' ] );
gulp.task( 'docs', [ 'style', 'readme' ] );
gulp.task( 'release', function() {
console.log( 'Task not yet implemented.' );
2014-09-09 20:56:24 +00:00
} );
gulp.task( 'test', function() {
2014-09-09 20:56:24 +00:00
karma.server.start( {
frameworks: [ 'jasmine' ],
files: paths.test
} );
} );
2014-09-15 20:22:54 +00:00
gulp.task( 'watch', [ 'lint', 'build', 'test' ], function() {
// watches and builds all tasks
2014-09-09 20:56:13 +00:00
2014-09-15 20:15:34 +00:00
gulp.watch( paths.build, [ 'build' ] );
gulp.watch( paths.docs, [ 'readme' ] );
gulp.watch( paths.styl, [ 'style' ] );
2014-08-27 00:01:15 +00:00
2014-09-15 20:15:34 +00:00
// gulp.watch( paths.html.concat( paths.styl )
// .concat( paths.js ).concat( paths.shim )
// .concat( paths.docs ), [ 'reload' ] );
2014-08-27 00:01:15 +00:00
// fmt
$.watch( paths.js, {
base: './'
} )
.pipe( $.esformatter( formattingOptions ) )
2014-09-15 20:22:54 +00:00
.pipe( gulp.dest( './' ) )
.pipe( $.jshint( '.jshintrc' ) )
2014-09-15 22:39:43 +00:00
.pipe( $.jshint.reporter( 'default' ) )
2014-09-15 20:22:54 +00:00
.pipe( $.jshint.reporter( 'fail' ) );
2014-09-15 20:15:34 +00:00
2014-09-08 01:31:51 +00:00
} );
2014-08-27 00:01:15 +00:00
////////////////////////////////////////////////
2014-08-27 00:01:15 +00:00
gulp.task( 'clean', function() {
return gulp.src( 'build/*' )
.pipe( $.rimraf() );
} );
gulp.task( 'style', function() {
return gulp.src( paths.styl, {
base: './'
} )
.pipe( $.stylus( {
use: [ nib() ]
2014-09-08 03:36:20 +00:00
} ) )
.pipe( gulp.dest( './' ) )
.pipe( $.filter( '**/*.css' ) )
.pipe( $.if( browserSync.active, browserSync.reload( {
stream: true
} ) ) );
2014-08-27 00:01:15 +00:00
2014-09-08 01:31:51 +00:00
} );
2014-08-27 00:01:15 +00:00
gulp.task( 'fmt', function() {
2014-08-27 00:01:15 +00:00
return gulp.src( paths.js, {
base: './'
} )
.pipe( $.esformatter( formattingOptions ) )
.pipe( gulp.dest( './' ) );
2014-08-27 00:01:15 +00:00
2014-09-08 01:31:51 +00:00
} );
2014-09-02 22:34:12 +00:00
gulp.task( 'lint', [ 'fmt' ], function() {
2014-09-02 22:34:12 +00:00
return gulp.src( paths.js )
.pipe( browserSync.reload( {
stream: true,
once: true
} ) )
2014-09-08 03:36:20 +00:00
.pipe( $.jshint( '.jshintrc' ) )
2014-09-15 22:39:43 +00:00
.pipe( $.jshint.reporter( 'default' ) )
2014-09-08 03:36:20 +00:00
.pipe( $.if( !browserSync.active, $.jshint.reporter( 'fail' ) ) );
2014-09-02 22:34:12 +00:00
2014-09-08 01:31:51 +00:00
} );
2014-09-02 22:34:12 +00:00
gulp.task( 'readme', function() {
return gulp.src( 'README.md' )
.pipe( $.marked( { // convert the markdown
gfm: true, // use github flavor markdown
highlight: function( code ) { // highlight the code
return highlight.highlightAuto( code ).value;
}
} ) )
.pipe( $.wrap( {
src: 'docs/template.html'
} ) )
.pipe( $.rename( 'index.html' ) )
.pipe( gulp.dest( './' ) );
2014-08-27 00:01:15 +00:00
} );
2014-09-03 00:14:37 +00:00
gulp.task( 'reload', function() {
if ( browserSync.active ) {
browserSync.reload();
}
} );
gulp.task( 'serve', function() {
browserSync.init( null, {
browser: [ 'google-chrome', 'google chrome' ], // linux uses the -
server: {
baseDir: [ '..' ]
},
startPath: '/dat.gui/'
} );
2014-09-08 01:31:51 +00:00
} );
2014-09-03 00:14:37 +00:00
2014-09-08 22:01:13 +00:00
gulp.task( 'shim', function() {
2014-09-09 20:56:13 +00:00
2014-09-08 22:01:13 +00:00
return gulp.src( paths.shim )
.pipe( $.uglify() )
.pipe( $.rename( 'dat-gui.shim.js' ) )
2014-09-08 22:01:13 +00:00
.pipe( gulp.dest( 'build' ) );
} );
gulp.task( 'vulcanize', [ 'style' ], function() {
2014-09-03 23:14:14 +00:00
return gulp.src( 'dat-gui.html' )
// must use the latest version of gulp-vulcanize otherwise it grabs the file from disk
.pipe( $.insert.prepend( '<script src="../platform/platform.js"></script>\n' ) )
.pipe( $.vulcanize( {
dest: 'build',
inline: true,
strip: true
} ) )
// clean up some vulcanize ...
.pipe( $.replace( /\n\n/gm, '' ) )
.pipe( $.replace( /<!-- .* -->/gm, '' ) )
.pipe( $.replace( /^<div hidden>undefined<\/div>\n/gm, '' ) )
.pipe( gulp.dest( 'build' ) );
2014-09-08 01:31:51 +00:00
} );
var nib = require( 'nib' ),
highlight = require( 'highlight.js' ),
karma = require( 'karma' ),
browserSync = require( 'browser-sync' ),
$ = require( 'gulp-load-plugins' )();
2014-09-08 01:31:51 +00:00
var paths = {
docs: [ 'README.md', 'docs/template.html' ],
js: [ 'gulpfile.js', 'elements/**/*.js' ],
html: [ 'dat-gui.html', 'elements/**/*.html' ],
shim: [ 'elements/shim.js' ],
styl: [ 'docs/*.styl', 'elements/**/*.styl' ],
test: [ 'build/dat-gui.js', 'tests/*.js' ]
};
2014-09-08 01:31:51 +00:00
2014-09-15 20:15:34 +00:00
paths.build = []
.concat( paths.html )
.concat( paths.styl )
.concat( paths.js )
.concat( paths.shim );
var formattingOptions = {
'preset': 'jquery',
'plugins': [
'esformatter-quotes',
'esformatter-semicolons',
'esformatter-braces'
],
'quotes': {
'type': 'single',
'avoidEscape': false
},
'indent': {
'value': ' '
},
'whiteSpace': {
'before': {
'ArgumentListObjectExpression': 1,
'ArgumentListFunctionExpression': 1,
'ArgumentListArrayExpression': 1
},
'after': {
'ArgumentListObjectExpression': 1,
'ArgumentListFunctionExpression': 1,
'ArgumentListArrayExpression': 1
}
}
};
2014-09-03 23:14:14 +00:00