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.

178 lines
4.9 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. map = require('map-stream'),
  10. // gulp dependencies
  11. autoprefixer = require('gulp-autoprefixer'),
  12. chmod = require('gulp-chmod'),
  13. clone = require('gulp-clone'),
  14. flatten = require('gulp-flatten'),
  15. gulpif = require('gulp-if'),
  16. header = require('gulp-header'),
  17. less = require('gulp-less'),
  18. minifyCSS = require('gulp-minify-css'),
  19. plumber = require('gulp-plumber'),
  20. print = require('gulp-print'),
  21. rename = require('gulp-rename'),
  22. replace = require('gulp-replace'),
  23. uglify = require('gulp-uglify'),
  24. // user config
  25. config = require('../config/docs'),
  26. // install config
  27. tasks = require('../config/tasks'),
  28. configSetup = require('../config/project/config'),
  29. install = require('../config/project/install'),
  30. // metadata parsing
  31. metadata = require('./metadata'),
  32. // shorthand
  33. globs,
  34. assets,
  35. output,
  36. source,
  37. banner = tasks.banner,
  38. comments = tasks.regExp.comments,
  39. log = tasks.log,
  40. settings = tasks.settings
  41. ;
  42. // add internal tasks (concat release)
  43. require('../collections/internal')(gulp);
  44. module.exports = function(callback) {
  45. var
  46. stream,
  47. compressedStream,
  48. uncompressedStream
  49. ;
  50. // use a different config
  51. config = configSetup.addDerivedValues(config);
  52. // shorthand
  53. globs = config.globs;
  54. assets = config.paths.assets;
  55. output = config.paths.output;
  56. source = config.paths.source;
  57. /*--------------
  58. Parse metadata
  59. ---------------*/
  60. // parse all *.html.eco in docs repo, data will end up in
  61. // metadata.result object. Note this assumes that the docs
  62. // repository is present and in proper directory location as
  63. // specified by docs.json.
  64. console.info('Building Metadata');
  65. gulp.src(config.paths.template.eco + globs.eco)
  66. .pipe(map(metadata.parser))
  67. .on('end', function() {
  68. fs.writeFile(output.metadata + '/metadata.json', JSON.stringify(metadata.result, null, 2));
  69. })
  70. ;
  71. /*--------------
  72. Copy Source
  73. ---------------*/
  74. console.info('Copying LESS source');
  75. // copy src/ to server
  76. gulp.src('src/**/*.*')
  77. .pipe(gulp.dest(output.less))
  78. .pipe(print(log.created))
  79. ;
  80. /*--------------
  81. Build
  82. ---------------*/
  83. console.info('Building Semantic for docs');
  84. if( !install.isSetup() ) {
  85. console.error('Cannot build files. Run "gulp install" to set-up Semantic');
  86. return;
  87. }
  88. // unified css stream
  89. stream = gulp.src(source.definitions + '/**/' + globs.components + '.less')
  90. .pipe(plumber())
  91. .pipe(less(settings.less))
  92. .pipe(autoprefixer(settings.prefix))
  93. .pipe(flatten())
  94. ;
  95. // two concurrent streams from same source to concat release
  96. uncompressedStream = stream.pipe(clone());
  97. compressedStream = stream.pipe(clone());
  98. uncompressedStream
  99. .pipe(plumber())
  100. .pipe(replace(comments.variables.in, comments.variables.out))
  101. .pipe(replace(comments.large.in, comments.large.out))
  102. .pipe(replace(comments.small.in, comments.small.out))
  103. .pipe(replace(comments.tiny.in, comments.tiny.out))
  104. .pipe(replace(assets.source, assets.uncompressed))
  105. .pipe(header(banner, settings.header))
  106. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  107. .pipe(gulp.dest(output.uncompressed))
  108. .pipe(print(log.created))
  109. .on('end', function() {
  110. gulp.start('package uncompressed docs css');
  111. })
  112. ;
  113. compressedStream = stream
  114. .pipe(plumber())
  115. .pipe(clone())
  116. .pipe(replace(assets.source, assets.compressed))
  117. .pipe(minifyCSS(settings.minify))
  118. .pipe(rename(settings.rename.minCSS))
  119. .pipe(header(banner, settings.header))
  120. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  121. .pipe(gulp.dest(output.compressed))
  122. .pipe(print(log.created))
  123. .on('end', function() {
  124. callback();
  125. gulp.start('package compressed docs css');
  126. })
  127. ;
  128. // copy assets
  129. gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*')
  130. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  131. .pipe(gulp.dest(output.themes))
  132. ;
  133. // copy source javascript
  134. gulp.src(source.definitions + '/**/' + globs.components + '.js')
  135. .pipe(plumber())
  136. .pipe(flatten())
  137. .pipe(gulp.dest(output.uncompressed))
  138. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  139. .pipe(print(log.created))
  140. .pipe(uglify(settings.uglify))
  141. .pipe(rename(settings.rename.minJS))
  142. .pipe(header(banner, settings.header))
  143. .pipe(gulp.dest(output.compressed))
  144. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  145. .pipe(print(log.created))
  146. .on('end', function() {
  147. gulp.start('package compressed docs js');
  148. gulp.start('package uncompressed docs js');
  149. })
  150. ;
  151. };