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
3.9 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. header = require('gulp-header'),
  16. less = require('gulp-less'),
  17. minifyCSS = require('gulp-minify-css'),
  18. plumber = require('gulp-plumber'),
  19. print = require('gulp-print'),
  20. rename = require('gulp-rename'),
  21. replace = require('gulp-replace'),
  22. uglify = require('gulp-uglify'),
  23. // config
  24. config = require('./config/user'),
  25. tasks = require('./config/project/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. // check for RTL
  51. if(config.rtl) {
  52. gulp.start('build rtl');
  53. return;
  54. }
  55. // unified css stream
  56. stream = gulp.src(source.definitions + '**/' + globs.components + '.less')
  57. .pipe(plumber())
  58. .pipe(less(settings.less))
  59. .pipe(autoprefixer(settings.prefix))
  60. .pipe(flatten())
  61. ;
  62. // two concurrent streams from same source to concat release
  63. uncompressedStream = stream.pipe(clone());
  64. compressedStream = stream.pipe(clone());
  65. uncompressedStream
  66. .pipe(plumber())
  67. .pipe(replace(comments.variables.in, comments.variables.out))
  68. .pipe(replace(comments.large.in, comments.large.out))
  69. .pipe(replace(comments.small.in, comments.small.out))
  70. .pipe(replace(comments.tiny.in, comments.tiny.out))
  71. .pipe(replace(assets.source, assets.uncompressed))
  72. .pipe(header(banner, settings.header))
  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. compressedStream = stream
  81. .pipe(plumber())
  82. .pipe(clone())
  83. .pipe(replace(assets.source, assets.compressed))
  84. .pipe(minifyCSS(settings.minify))
  85. .pipe(rename(settings.rename.minCSS))
  86. .pipe(header(banner, settings.header))
  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(gulp.dest(output.uncompressed))
  105. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  106. .pipe(print(log.created))
  107. .pipe(uglify(settings.uglify))
  108. .pipe(rename(settings.rename.minJS))
  109. .pipe(header(banner, settings.header))
  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. };