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.

139 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. less = require('gulp-less'),
  15. minifyCSS = require('gulp-clean-css'),
  16. plumber = require('gulp-plumber'),
  17. print = require('gulp-print').default,
  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. buildRTL
  37. ;
  38. // add internal tasks (concat release)
  39. require('../collections/internal')(gulp);
  40. buildRTL = 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(replace(comments.variables.in, comments.variables.out))
  58. .pipe(replace(comments.license.in, comments.license.out))
  59. .pipe(replace(comments.large.in, comments.large.out))
  60. .pipe(replace(comments.small.in, comments.small.out))
  61. .pipe(replace(comments.tiny.in, comments.tiny.out))
  62. .pipe(flatten())
  63. ;
  64. // two concurrent streams from same source to concat release
  65. uncompressedStream = stream.pipe(clone());
  66. compressedStream = stream.pipe(clone());
  67. uncompressedStream
  68. .pipe(plumber())
  69. .pipe(replace(assets.source, assets.uncompressed))
  70. .pipe(rename(settings.rename.rtlCSS))
  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
  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(gulpif(config.hasPermission, chmod(config.permission)))
  85. .pipe(gulp.dest(output.compressed))
  86. .pipe(print(log.created))
  87. .on('end', function() {
  88. callback();
  89. gulp.start('package compressed rtl css');
  90. })
  91. ;
  92. // copy assets
  93. gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*')
  94. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  95. .pipe(gulp.dest(output.themes))
  96. ;
  97. // copy source javascript
  98. gulp.src(source.definitions + '/**/' + globs.components + '.js')
  99. .pipe(plumber())
  100. .pipe(flatten())
  101. .pipe(replace(comments.license.in, comments.license.out))
  102. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  103. .pipe(gulp.dest(output.uncompressed))
  104. .pipe(print(log.created))
  105. .pipe(uglify(settings.uglify))
  106. .pipe(rename(settings.rename.minJS))
  107. .pipe(gulp.dest(output.compressed))
  108. .pipe(print(log.created))
  109. .on('end', function() {
  110. gulp.start('package compressed js');
  111. gulp.start('package uncompressed js');
  112. })
  113. ;
  114. };
  115. /* Export with Metadata */
  116. buildRTL.displayName = 'build-rtl';
  117. buildRTL.description = 'Build files as RTL';
  118. module.exports = buildRTL;