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.

134 lines
3.9 KiB

  1. /*******************************
  2. Build Task
  3. *******************************/
  4. var
  5. gulp = require('gulp'),
  6. // node dependencies
  7. fs = require('fs'),
  8. // gulp dependencies
  9. autoprefixer = require('gulp-autoprefixer'),
  10. chmod = require('gulp-chmod'),
  11. clone = require('gulp-clone'),
  12. flatten = require('gulp-flatten'),
  13. gulpif = require('gulp-if'),
  14. header = require('gulp-header'),
  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. rtlcss = require('gulp-rtlcss'),
  22. uglify = require('gulp-uglify'),
  23. // user config
  24. config = require('../config/user'),
  25. // install config
  26. tasks = require('../config/project/tasks'),
  27. install = require('../config/project/install'),
  28. // shorthand
  29. globs = config.globs,
  30. assets = config.paths.assets,
  31. output = config.paths.output,
  32. source = config.paths.source,
  33. banner = tasks.banner,
  34. comments = tasks.regExp.comments,
  35. log = tasks.log,
  36. settings = tasks.settings
  37. ;
  38. // add internal tasks (concat release)
  39. require('../collections/internal')(gulp);
  40. module.exports = function(callback) {
  41. var
  42. stream,
  43. compressedStream,
  44. uncompressedStream
  45. ;
  46. console.info('Building Semantic');
  47. if( !install.isSetup() ) {
  48. console.error('Cannot build files. Run "gulp install" to set-up Semantic');
  49. return;
  50. }
  51. // unified css stream
  52. stream = gulp.src(source.definitions + '/**/' + globs.components + '.less')
  53. .pipe(plumber())
  54. .pipe(less(settings.less))
  55. .pipe(autoprefixer(settings.prefix))
  56. .pipe(rtlcss())
  57. .pipe(flatten())
  58. ;
  59. // two concurrent streams from same source to concat release
  60. uncompressedStream = stream.pipe(clone());
  61. compressedStream = stream.pipe(clone());
  62. uncompressedStream
  63. .pipe(plumber())
  64. .pipe(replace(comments.variables.in, comments.variables.out))
  65. .pipe(replace(comments.large.in, comments.large.out))
  66. .pipe(replace(comments.small.in, comments.small.out))
  67. .pipe(replace(comments.tiny.in, comments.tiny.out))
  68. .pipe(replace(assets.source, assets.uncompressed))
  69. .pipe(rename(settings.rename.rtlCSS))
  70. .pipe(header(banner, settings.header))
  71. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  72. .pipe(gulp.dest(output.uncompressed))
  73. .pipe(print(log.created))
  74. .on('end', function() {
  75. gulp.start('package uncompressed rtl css');
  76. })
  77. ;
  78. compressedStream = stream
  79. .pipe(plumber())
  80. .pipe(clone())
  81. .pipe(replace(assets.source, assets.compressed))
  82. .pipe(minifyCSS(settings.minify))
  83. .pipe(rename(settings.rename.rtlMinCSS))
  84. .pipe(header(banner, settings.header))
  85. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  86. .pipe(gulp.dest(output.compressed))
  87. .pipe(print(log.created))
  88. .on('end', function() {
  89. callback();
  90. gulp.start('package compressed rtl css');
  91. })
  92. ;
  93. // copy assets
  94. gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*')
  95. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  96. .pipe(gulp.dest(output.themes))
  97. ;
  98. // copy source javascript
  99. gulp.src(source.definitions + '/**/' + globs.components + '.js')
  100. .pipe(plumber())
  101. .pipe(flatten())
  102. .pipe(gulp.dest(output.uncompressed))
  103. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  104. .pipe(print(log.created))
  105. .pipe(uglify(settings.uglify))
  106. .pipe(rename(settings.rename.minJS))
  107. .pipe(header(banner, settings.header))
  108. .pipe(gulp.dest(output.compressed))
  109. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  110. .pipe(print(log.created))
  111. .on('end', function() {
  112. gulp.start('package compressed js');
  113. gulp.start('package uncompressed js');
  114. })
  115. ;
  116. };