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.

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