You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.0 KiB

  1. /*******************************
  2. Build Task
  3. *******************************/
  4. var
  5. gulp = require('gulp'),
  6. // node dependencies
  7. console = require('better-console'),
  8. fs = require('fs'),
  9. // gulp dependencies
  10. autoprefixer = require('gulp-autoprefixer'),
  11. chmod = require('gulp-chmod'),
  12. clone = require('gulp-clone'),
  13. flatten = require('gulp-flatten'),
  14. gulpif = require('gulp-if'),
  15. less = require('gulp-less'),
  16. minifyCSS = require('gulp-minify-css'),
  17. plumber = require('gulp-plumber'),
  18. print = require('gulp-print'),
  19. rename = require('gulp-rename'),
  20. replace = require('gulp-replace'),
  21. // config
  22. config = require('../config/user'),
  23. tasks = require('../config/tasks'),
  24. install = require('../config/project/install'),
  25. // shorthand
  26. globs = config.globs,
  27. assets = config.paths.assets,
  28. output = config.paths.output,
  29. source = config.paths.source,
  30. banner = tasks.banner,
  31. comments = tasks.regExp.comments,
  32. log = tasks.log,
  33. settings = tasks.settings
  34. ;
  35. // add internal tasks (concat release)
  36. require('../collections/internal')(gulp);
  37. module.exports = function(callback) {
  38. var
  39. stream,
  40. compressedStream,
  41. uncompressedStream
  42. ;
  43. console.info('Building CSS');
  44. if( !install.isSetup() ) {
  45. console.error('Cannot build files. Run "gulp install" to set-up Semantic');
  46. return;
  47. }
  48. // unified css stream
  49. stream = gulp.src(source.definitions + '/**/' + globs.components + '.less')
  50. .pipe(plumber(settings.plumber.less))
  51. .pipe(less(settings.less))
  52. .pipe(autoprefixer(settings.prefix))
  53. .pipe(replace(comments.variables.in, comments.variables.out))
  54. .pipe(replace(comments.license.in, comments.license.out))
  55. .pipe(replace(comments.large.in, comments.large.out))
  56. .pipe(replace(comments.small.in, comments.small.out))
  57. .pipe(replace(comments.tiny.in, comments.tiny.out))
  58. .pipe(flatten())
  59. ;
  60. // two concurrent streams from same source to concat release
  61. uncompressedStream = stream.pipe(clone());
  62. compressedStream = stream.pipe(clone());
  63. // uncompressed component css
  64. uncompressedStream
  65. .pipe(plumber())
  66. .pipe(replace(assets.source, assets.uncompressed))
  67. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  68. .pipe(gulp.dest(output.uncompressed))
  69. .pipe(print(log.created))
  70. .on('end', function() {
  71. gulp.start('package uncompressed css');
  72. })
  73. ;
  74. // compressed component css
  75. compressedStream = stream
  76. .pipe(plumber())
  77. .pipe(clone())
  78. .pipe(replace(assets.source, assets.compressed))
  79. .pipe(minifyCSS(settings.minify))
  80. .pipe(rename(settings.rename.minCSS))
  81. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  82. .pipe(gulp.dest(output.compressed))
  83. .pipe(print(log.created))
  84. .on('end', function() {
  85. gulp.start('package compressed css');
  86. callback();
  87. })
  88. ;
  89. };