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.

157 lines
4.3 KiB

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