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.

189 lines
5.1 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 Examples
  73. ---------------*/
  74. console.info('Copying examples');
  75. // copy src/ to server
  76. gulp.src('examples/**/*.*')
  77. .pipe(gulp.dest(output.examples))
  78. .pipe(print(log.created))
  79. ;
  80. /*--------------
  81. Copy Source
  82. ---------------*/
  83. console.info('Copying LESS source');
  84. // copy src/ to server
  85. gulp.src('src/**/*.*')
  86. .pipe(gulp.dest(output.less))
  87. .pipe(print(log.created))
  88. ;
  89. /*--------------
  90. Build
  91. ---------------*/
  92. console.info('Building Semantic for docs');
  93. if( !install.isSetup() ) {
  94. console.error('Cannot build files. Run "gulp install" to set-up Semantic');
  95. return;
  96. }
  97. // unified css stream
  98. stream = gulp.src(source.definitions + '/**/' + globs.components + '.less')
  99. .pipe(plumber())
  100. .pipe(less(settings.less))
  101. .pipe(autoprefixer(settings.prefix))
  102. .pipe(flatten())
  103. ;
  104. // two concurrent streams from same source to concat release
  105. uncompressedStream = stream.pipe(clone());
  106. compressedStream = stream.pipe(clone());
  107. uncompressedStream
  108. .pipe(plumber())
  109. .pipe(replace(comments.variables.in, comments.variables.out))
  110. .pipe(replace(comments.large.in, comments.large.out))
  111. .pipe(replace(comments.small.in, comments.small.out))
  112. .pipe(replace(comments.tiny.in, comments.tiny.out))
  113. .pipe(replace(assets.source, assets.uncompressed))
  114. .pipe(header(banner, settings.header))
  115. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  116. .pipe(gulp.dest(output.uncompressed))
  117. .pipe(print(log.created))
  118. .on('end', function() {
  119. gulp.start('package uncompressed docs css');
  120. })
  121. ;
  122. compressedStream = stream
  123. .pipe(plumber())
  124. .pipe(clone())
  125. .pipe(replace(assets.source, assets.compressed))
  126. .pipe(minifyCSS(settings.minify))
  127. .pipe(rename(settings.rename.minCSS))
  128. .pipe(header(banner, settings.header))
  129. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  130. .pipe(gulp.dest(output.compressed))
  131. .pipe(print(log.created))
  132. .on('end', function() {
  133. callback();
  134. gulp.start('package compressed docs css');
  135. })
  136. ;
  137. // copy assets
  138. gulp.src(source.themes + '/**/assets/**/' + globs.components + '?(s).*')
  139. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  140. .pipe(gulp.dest(output.themes))
  141. ;
  142. // copy source javascript
  143. gulp.src(source.definitions + '/**/' + globs.components + '.js')
  144. .pipe(plumber())
  145. .pipe(flatten())
  146. .pipe(gulp.dest(output.uncompressed))
  147. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  148. .pipe(print(log.created))
  149. .pipe(uglify(settings.uglify))
  150. .pipe(rename(settings.rename.minJS))
  151. .pipe(header(banner, settings.header))
  152. .pipe(gulp.dest(output.compressed))
  153. .pipe(gulpif(config.hasPermission, chmod(config.permission)))
  154. .pipe(print(log.created))
  155. .on('end', function() {
  156. gulp.start('package compressed docs js');
  157. gulp.start('package uncompressed docs js');
  158. })
  159. ;
  160. };