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.

113 lines
3.2 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. runSequence = require('run-sequence'),
  22. // config
  23. config = require('../config/user'),
  24. tasks = require('../config/tasks'),
  25. install = require('../config/project/install'),
  26. // shorthand
  27. globs = config.globs,
  28. assets = config.paths.assets,
  29. output = config.paths.output,
  30. source = config.paths.source,
  31. banner = tasks.banner,
  32. comments = tasks.regExp.comments,
  33. log = tasks.log,
  34. settings = tasks.settings
  35. ;
  36. // add internal tasks (concat release)
  37. require('../collections/internal')(gulp);
  38. module.exports = function(callback) {
  39. var
  40. tasksCompleted = 0,
  41. maybeCallback = function() {
  42. tasksCompleted++;
  43. if(tasksCompleted === 2) {
  44. callback();
  45. }
  46. },
  47. stream,
  48. compressedStream,
  49. uncompressedStream
  50. ;
  51. console.info('Building CSS');
  52. if( !install.isSetup() ) {
  53. console.error('Cannot build files. Run "gulp install" to set-up Semantic');
  54. return;
  55. }
  56. // unified css stream
  57. stream = gulp.src(source.definitions + '/**/' + globs.components + '.less')
  58. .pipe(plumber(settings.plumber.less))
  59. .pipe(less(settings.less))
  60. .pipe(autoprefixer(settings.prefix))
  61. .pipe(replace(comments.variables.in, comments.variables.out))
  62. .pipe(replace(comments.license.in, comments.license.out))
  63. .pipe(replace(comments.large.in, comments.large.out))
  64. .pipe(replace(comments.small.in, comments.small.out))
  65. .pipe(replace(comments.tiny.in, comments.tiny.out))
  66. .pipe(flatten())
  67. ;
  68. // two concurrent streams from same source to concat release
  69. uncompressedStream = stream.pipe(clone());
  70. compressedStream = stream.pipe(clone());
  71. // uncompressed component css
  72. uncompressedStream
  73. .pipe(plumber())
  74. .pipe(replace(assets.source, assets.uncompressed))
  75. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  76. .pipe(gulp.dest(output.uncompressed))
  77. .pipe(print(log.created))
  78. .on('end', function() {
  79. runSequence('package uncompressed css', maybeCallback);
  80. })
  81. ;
  82. // compressed component css
  83. compressedStream = stream
  84. .pipe(plumber())
  85. .pipe(clone())
  86. .pipe(replace(assets.source, assets.compressed))
  87. .pipe(minifyCSS(settings.minify))
  88. .pipe(rename(settings.rename.minCSS))
  89. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  90. .pipe(gulp.dest(output.compressed))
  91. .pipe(print(log.created))
  92. .on('end', function() {
  93. runSequence('package compressed css', maybeCallback);
  94. })
  95. ;
  96. };