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.

136 lines
4.0 KiB

9 years ago
  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. uglify = require('gulp-uglify'),
  22. // config
  23. config = require('./config/user'),
  24. tasks = require('./config/project/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. stream,
  41. compressedStream,
  42. uncompressedStream
  43. ;
  44. console.info('Building Semantic');
  45. if( !install.isSetup() ) {
  46. console.error('Cannot build files. Run "gulp install" to set-up Semantic');
  47. return;
  48. }
  49. // check for right-to-left language
  50. if(config.rtl === true || config.rtl === 'Yes') {
  51. gulp.start('build-rtl');
  52. return;
  53. }
  54. // unified css stream
  55. stream = gulp.src(source.definitions + '/**/' + globs.components + '.less')
  56. .pipe(plumber())
  57. .pipe(less(settings.less))
  58. .pipe(autoprefixer(settings.prefix))
  59. .pipe(replace(comments.variables.in, comments.variables.out))
  60. .pipe(replace(comments.license.in, comments.license.out))
  61. .pipe(replace(comments.large.in, comments.large.out))
  62. .pipe(replace(comments.small.in, comments.small.out))
  63. .pipe(replace(comments.tiny.in, comments.tiny.out))
  64. .pipe(flatten())
  65. ;
  66. // two concurrent streams from same source to concat release
  67. uncompressedStream = stream.pipe(clone());
  68. compressedStream = stream.pipe(clone());
  69. // uncompressed component css
  70. uncompressedStream
  71. .pipe(plumber())
  72. .pipe(replace(assets.source, assets.uncompressed))
  73. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  74. .pipe(gulp.dest(output.uncompressed))
  75. .pipe(print(log.created))
  76. .on('end', function() {
  77. gulp.start('package uncompressed css');
  78. })
  79. ;
  80. // compressed component css
  81. compressedStream = stream
  82. .pipe(plumber())
  83. .pipe(clone())
  84. .pipe(replace(assets.source, assets.compressed))
  85. .pipe(minifyCSS(settings.minify))
  86. .pipe(rename(settings.rename.minCSS))
  87. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  88. .pipe(gulp.dest(output.compressed))
  89. .pipe(print(log.created))
  90. .on('end', function() {
  91. callback();
  92. gulp.start('package compressed css');
  93. })
  94. ;
  95. // copy assets
  96. gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*')
  97. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  98. .pipe(gulp.dest(output.themes))
  99. ;
  100. // copy source javascript
  101. gulp.src(source.definitions + '/**/' + globs.components + '.js')
  102. .pipe(plumber())
  103. .pipe(flatten())
  104. .pipe(replace(comments.license.in, comments.license.out))
  105. .pipe(gulp.dest(output.uncompressed))
  106. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  107. .pipe(print(log.created))
  108. .pipe(uglify(settings.uglify))
  109. .pipe(rename(settings.rename.minJS))
  110. .pipe(gulp.dest(output.compressed))
  111. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  112. .pipe(print(log.created))
  113. .on('end', function() {
  114. gulp.start('package compressed js');
  115. gulp.start('package uncompressed js');
  116. })
  117. ;
  118. };