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.

199 lines
5.3 KiB

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