From 2457ca65ad657646b9828d318e841d9b2a7f9c10 Mon Sep 17 00:00:00 2001 From: jlukic Date: Mon, 30 Mar 2015 16:05:19 -0400 Subject: [PATCH] Related #2014, separate css and javascript into separate tasks --- tasks/build.js | 111 ++------------------------------------ tasks/build/assets.js | 35 ++++++++++++ tasks/build/css.js | 105 ++++++++++++++++++++++++++++++++++++ tasks/build/javascript.js | 77 ++++++++++++++++++++++++++ 4 files changed, 221 insertions(+), 107 deletions(-) create mode 100644 tasks/build/assets.js create mode 100644 tasks/build/css.js create mode 100644 tasks/build/javascript.js diff --git a/tasks/build.js b/tasks/build.js index 4def7c9b5..50b4af1b4 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -5,52 +5,14 @@ var gulp = require('gulp'), - // node dependencies - console = require('better-console'), - fs = require('fs'), - - // gulp dependencies - autoprefixer = require('gulp-autoprefixer'), - chmod = require('gulp-chmod'), - clone = require('gulp-clone'), - flatten = require('gulp-flatten'), - gulpif = require('gulp-if'), - less = require('gulp-less'), - minifyCSS = require('gulp-minify-css'), - plumber = require('gulp-plumber'), - print = require('gulp-print'), - rename = require('gulp-rename'), - replace = require('gulp-replace'), - uglify = require('gulp-uglify'), - // config config = require('./config/user'), - tasks = require('./config/project/tasks'), - install = require('./config/project/install'), - - // shorthand - globs = config.globs, - assets = config.paths.assets, - output = config.paths.output, - source = config.paths.source, + install = require('./config/project/install') - banner = tasks.banner, - comments = tasks.regExp.comments, - log = tasks.log, - settings = tasks.settings ; -// add internal tasks (concat release) -require('./collections/internal')(gulp); - module.exports = function(callback) { - var - stream, - compressedStream, - uncompressedStream - ; - console.info('Building Semantic'); if( !install.isSetup() ) { @@ -64,74 +26,9 @@ module.exports = function(callback) { return; } - // unified css stream - stream = gulp.src(source.definitions + '/**/' + globs.components + '.less') - .pipe(plumber(settings.plumber.less)) - .pipe(less(settings.less)) - .pipe(autoprefixer(settings.prefix)) - .pipe(replace(comments.variables.in, comments.variables.out)) - .pipe(replace(comments.license.in, comments.license.out)) - .pipe(replace(comments.large.in, comments.large.out)) - .pipe(replace(comments.small.in, comments.small.out)) - .pipe(replace(comments.tiny.in, comments.tiny.out)) - .pipe(flatten()) - ; - - // two concurrent streams from same source to concat release - uncompressedStream = stream.pipe(clone()); - compressedStream = stream.pipe(clone()); - - // uncompressed component css - uncompressedStream - .pipe(plumber()) - .pipe(replace(assets.source, assets.uncompressed)) - .pipe(gulpif(config.hasPermission, chmod(config.permission))) - .pipe(gulp.dest(output.uncompressed)) - .pipe(print(log.created)) - .on('end', function() { - gulp.start('package uncompressed css'); - }) - ; - - // compressed component css - compressedStream = stream - .pipe(plumber()) - .pipe(clone()) - .pipe(replace(assets.source, assets.compressed)) - .pipe(minifyCSS(settings.minify)) - .pipe(rename(settings.rename.minCSS)) - .pipe(gulpif(config.hasPermission, chmod(config.permission))) - .pipe(gulp.dest(output.compressed)) - .pipe(print(log.created)) - .on('end', function() { - callback(); - gulp.start('package compressed css'); - }) - ; - - // copy assets - gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*') - .pipe(gulpif(config.hasPermission, chmod(config.permission))) - .pipe(gulp.dest(output.themes)) - ; + gulp.start('build-javascript'); + gulp.start('build-css'); + gulp.start('build-assets'); - // copy source javascript - gulp.src(source.definitions + '/**/' + globs.components + '.js') - .pipe(plumber()) - .pipe(flatten()) - .pipe(replace(comments.license.in, comments.license.out)) - .pipe(gulp.dest(output.uncompressed)) - .pipe(gulpif(config.hasPermission, chmod(config.permission))) - .pipe(print(log.created)) - .pipe(uglify(settings.uglify)) - .pipe(rename(settings.rename.minJS)) - .pipe(gulp.dest(output.compressed)) - .pipe(gulpif(config.hasPermission, chmod(config.permission))) - .pipe(print(log.created)) - .on('end', function() { - gulp.start('package compressed js'); - gulp.start('package uncompressed js'); - }) - ; }; \ No newline at end of file diff --git a/tasks/build/assets.js b/tasks/build/assets.js new file mode 100644 index 000000000..d843387ac --- /dev/null +++ b/tasks/build/assets.js @@ -0,0 +1,35 @@ +/******************************* + Build Task +*******************************/ + +var + gulp = require('gulp'), + + // gulp dependencies + chmod = require('gulp-chmod'), + gulpif = require('gulp-if'), + + // config + config = require('../config/user'), + tasks = require('../config/project/tasks'), + + // shorthand + globs = config.globs, + assets = config.paths.assets, + output = config.paths.output, + source = config.paths.source, + + log = tasks.log +; + +module.exports = function(callback) { + + console.info('Building assets'); + + // copy assets + return gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*') + .pipe(gulpif(config.hasPermission, chmod(config.permission))) + .pipe(gulp.dest(output.themes)) + ; + +}; \ No newline at end of file diff --git a/tasks/build/css.js b/tasks/build/css.js new file mode 100644 index 000000000..86a3c4c78 --- /dev/null +++ b/tasks/build/css.js @@ -0,0 +1,105 @@ +/******************************* + Build Task +*******************************/ + +var + gulp = require('gulp'), + + // node dependencies + console = require('better-console'), + fs = require('fs'), + + // gulp dependencies + autoprefixer = require('gulp-autoprefixer'), + chmod = require('gulp-chmod'), + clone = require('gulp-clone'), + flatten = require('gulp-flatten'), + gulpif = require('gulp-if'), + less = require('gulp-less'), + minifyCSS = require('gulp-minify-css'), + plumber = require('gulp-plumber'), + print = require('gulp-print'), + rename = require('gulp-rename'), + replace = require('gulp-replace'), + + // config + config = require('../config/user'), + tasks = require('../config/project/tasks'), + install = require('../config/project/install'), + + // shorthand + globs = config.globs, + assets = config.paths.assets, + output = config.paths.output, + source = config.paths.source, + + banner = tasks.banner, + comments = tasks.regExp.comments, + log = tasks.log, + settings = tasks.settings +; + +// add internal tasks (concat release) +require('../collections/internal')(gulp); + +module.exports = function(callback) { + + var + stream, + compressedStream, + uncompressedStream + ; + + console.info('Building CSS'); + + if( !install.isSetup() ) { + console.error('Cannot build files. Run "gulp install" to set-up Semantic'); + return; + } + + // unified css stream + stream = gulp.src(source.definitions + '/**/' + globs.components + '.less') + .pipe(plumber(settings.plumber.less)) + .pipe(less(settings.less)) + .pipe(autoprefixer(settings.prefix)) + .pipe(replace(comments.variables.in, comments.variables.out)) + .pipe(replace(comments.license.in, comments.license.out)) + .pipe(replace(comments.large.in, comments.large.out)) + .pipe(replace(comments.small.in, comments.small.out)) + .pipe(replace(comments.tiny.in, comments.tiny.out)) + .pipe(flatten()) + ; + + // two concurrent streams from same source to concat release + uncompressedStream = stream.pipe(clone()); + compressedStream = stream.pipe(clone()); + + // uncompressed component css + uncompressedStream + .pipe(plumber()) + .pipe(replace(assets.source, assets.uncompressed)) + .pipe(gulpif(config.hasPermission, chmod(config.permission))) + .pipe(gulp.dest(output.uncompressed)) + .pipe(print(log.created)) + .on('end', function() { + gulp.start('package uncompressed css'); + }) + ; + + // compressed component css + compressedStream = stream + .pipe(plumber()) + .pipe(clone()) + .pipe(replace(assets.source, assets.compressed)) + .pipe(minifyCSS(settings.minify)) + .pipe(rename(settings.rename.minCSS)) + .pipe(gulpif(config.hasPermission, chmod(config.permission))) + .pipe(gulp.dest(output.compressed)) + .pipe(print(log.created)) + .on('end', function() { + gulp.start('package compressed css'); + callback(); + }) + ; + +}; \ No newline at end of file diff --git a/tasks/build/javascript.js b/tasks/build/javascript.js new file mode 100644 index 000000000..6ddf4d098 --- /dev/null +++ b/tasks/build/javascript.js @@ -0,0 +1,77 @@ +/******************************* + Build Task +*******************************/ + +var + gulp = require('gulp'), + + // node dependencies + console = require('better-console'), + fs = require('fs'), + + // gulp dependencies + chmod = require('gulp-chmod'), + flatten = require('gulp-flatten'), + gulpif = require('gulp-if'), + plumber = require('gulp-plumber'), + print = require('gulp-print'), + rename = require('gulp-rename'), + replace = require('gulp-replace'), + uglify = require('gulp-uglify'), + + // config + config = require('../config/user'), + tasks = require('../config/project/tasks'), + install = require('../config/project/install'), + + // shorthand + globs = config.globs, + assets = config.paths.assets, + output = config.paths.output, + source = config.paths.source, + + banner = tasks.banner, + comments = tasks.regExp.comments, + log = tasks.log, + settings = tasks.settings +; + +// add internal tasks (concat release) +require('../collections/internal')(gulp); + +module.exports = function(callback) { + + var + stream, + compressedStream, + uncompressedStream + ; + + console.info('Building Javascript'); + + if( !install.isSetup() ) { + console.error('Cannot build files. Run "gulp install" to set-up Semantic'); + return; + } + + // copy source javascript + gulp.src(source.definitions + '/**/' + globs.components + '.js') + .pipe(plumber()) + .pipe(flatten()) + .pipe(replace(comments.license.in, comments.license.out)) + .pipe(gulp.dest(output.uncompressed)) + .pipe(gulpif(config.hasPermission, chmod(config.permission))) + .pipe(print(log.created)) + .pipe(uglify(settings.uglify)) + .pipe(rename(settings.rename.minJS)) + .pipe(gulp.dest(output.compressed)) + .pipe(gulpif(config.hasPermission, chmod(config.permission))) + .pipe(print(log.created)) + .on('end', function() { + gulp.start('package compressed js'); + gulp.start('package uncompressed js'); + callback(); + }) + ; + +}; \ No newline at end of file