2014-09-08 02:43:10 +00:00
|
|
|
var gulp = require( 'gulp' ),
|
|
|
|
nib = require( 'nib' ),
|
|
|
|
fs = require( 'fs' ),
|
|
|
|
marked = require( 'marked' ),
|
|
|
|
karma = require( 'karma' ),
|
2014-09-08 01:31:51 +00:00
|
|
|
browserSync = require( 'browser-sync' ),
|
2014-09-08 02:43:10 +00:00
|
|
|
$ = require( 'gulp-load-plugins' )();
|
|
|
|
|
|
|
|
var paths = {
|
|
|
|
build: [ 'elements/**/*.styl', 'elements/**/*.html', 'elements/**/*.js' , 'gui.html' ],
|
|
|
|
lint: [ 'gulpfile.js', 'elements/**/*.js' ],
|
|
|
|
test: [ 'build/gui.js', 'tests/*.js' ],
|
|
|
|
clean: [ 'build/*', '**/*.css' ],
|
2014-09-08 22:01:13 +00:00
|
|
|
docs: [ 'README.md', 'docs/*' ],
|
|
|
|
shim: [ 'elements/shim.js' ]
|
2014-09-08 02:43:10 +00:00
|
|
|
};
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 22:01:13 +00:00
|
|
|
gulp.task( 'default', [ 'docs', 'lint', 'shim', 'build' ] );
|
2014-09-03 00:44:37 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
gulp.task( 'watch', [ 'default' ], function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
karma.server.start( {
|
2014-09-08 01:38:29 +00:00
|
|
|
frameworks: [ 'jasmine' ],
|
2014-09-08 02:43:10 +00:00
|
|
|
files: paths.test
|
2014-09-08 01:31:51 +00:00
|
|
|
} );
|
2014-09-02 16:00:08 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
gulp.watch( paths.docs, [ 'docs' ] );
|
|
|
|
gulp.watch( paths.lint, [ 'lint' ] );
|
|
|
|
gulp.watch( paths.build, [ 'build' ] );
|
2014-09-08 22:01:13 +00:00
|
|
|
gulp.watch( paths.shim, [ 'shim' ] );
|
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-09 20:56:13 +00:00
|
|
|
gulp.task( 'serve', [], function() {
|
|
|
|
browserSync.init( null, {
|
|
|
|
browser: [ 'google-chrome', 'google chrome' ], // linux uses the -
|
|
|
|
server: {
|
|
|
|
baseDir: [ '..' ]
|
|
|
|
},
|
|
|
|
startPath: '/dat.gui/'
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
gulp.task( 'build', [ 'vulcanize' ], function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return gulp.src( 'build/gui.html' )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.replace( /\\/g, '\\\\' ) )
|
|
|
|
.pipe( $.replace( /'/g, '\\\'' ) )
|
|
|
|
.pipe( $.replace( /^(.*)$/gm, '\'$1\',' ) )
|
|
|
|
.pipe( $.insert.wrap( 'document.write([', '].join("\\n"))' ) )
|
|
|
|
.pipe( $.rename( 'gui.js' ) )
|
|
|
|
.pipe( gulp.dest( 'build' ) );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
} );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
gulp.task( 'vulcanize', [ 'css' ], function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return gulp.src( 'gui.html' )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.vulcanize( {
|
|
|
|
dest: 'build',
|
|
|
|
inline: true,
|
|
|
|
strip: true
|
|
|
|
} ) )
|
2014-09-09 20:56:13 +00:00
|
|
|
// clean up some vulcanize ...
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.replace( /\n\n/gm, '' ) )
|
|
|
|
.pipe( $.replace( /<!-- .* -->/gm, '' ) )
|
|
|
|
.pipe( $.replace( /^<div hidden>undefined<\/div>\n/gm, '' ) )
|
|
|
|
.pipe( gulp.dest( 'build' ) );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
} );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
gulp.task( 'lint', [ 'jscs', 'jshint' ] );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
gulp.task( 'jscs', function() {
|
2014-09-04 23:53:27 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
return gulp.src( paths.lint )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.jscs() );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
} );
|
2014-09-02 22:34:12 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
gulp.task( 'jshint', function() {
|
2014-09-02 22:34:12 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
return gulp.src( paths.lint )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( browserSync.reload( { stream: true, once: true } ) )
|
|
|
|
.pipe( $.jshint( '.jshintrc' ) )
|
|
|
|
.pipe( $.jshint.reporter( 'jshint-stylish' ) )
|
|
|
|
.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
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
gulp.task( 'css', function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return css( 'elements/**/*.styl', 'elements' );
|
2014-09-03 00:14:37 +00:00
|
|
|
|
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( 'gui.shim.js' ) )
|
|
|
|
.pipe( gulp.dest( 'build' ) );
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
gulp.task( 'docs', function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
css( 'docs/*.styl', 'docs' );
|
2014-09-03 23:14:14 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
var content = {
|
|
|
|
readme: marked( fs.readFileSync( 'README.md', 'utf8' ) )
|
|
|
|
};
|
2014-09-03 23:14:14 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return gulp.src( 'docs/template.html' )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.plates( content ) )
|
|
|
|
.pipe( $.rename( 'index.html' ) )
|
|
|
|
.pipe( gulp.dest( './' ) );
|
2014-09-08 01:31:51 +00:00
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
gulp.task( 'clean', function() {
|
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
return gulp.src( paths.clean )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.rimraf() );
|
2014-09-08 01:31:51 +00:00
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
function css( src, dest ) {
|
|
|
|
|
|
|
|
return gulp.src( src )
|
2014-09-08 03:36:20 +00:00
|
|
|
.pipe( $.stylus( { use: [ nib() ] } ) )
|
|
|
|
.pipe( gulp.dest( dest ) );
|
2014-09-03 23:14:14 +00:00
|
|
|
|
|
|
|
}
|