build-docs.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  4. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  5. */
  6. /* eslint-env node */
  7. 'use strict';
  8. const buildApiDocs = require( './buildapi' );
  9. const skipLiveSnippets = process.argv.includes( '--skip-snippets' );
  10. const skipApi = process.argv.includes( '--skip-api' );
  11. const skipValidation = process.argv.includes( '--skip-validation' );
  12. const production = process.argv.includes( '--production' );
  13. const watch = process.argv.includes( '--watch' );
  14. const verbose = process.argv.includes( '--verbose' );
  15. const allowedSnippets = process.argv.find( item => item.startsWith( '--snippets=' ) );
  16. buildDocs();
  17. function buildDocs() {
  18. let promise;
  19. if ( skipApi ) {
  20. promise = Promise.resolve();
  21. } else {
  22. promise = buildApiDocs();
  23. }
  24. promise
  25. .then( () => {
  26. return runUmberto( {
  27. skipLiveSnippets,
  28. skipApi,
  29. skipValidation,
  30. production,
  31. watch,
  32. verbose
  33. } );
  34. } )
  35. .catch( err => {
  36. console.error( err );
  37. process.exitCode = 1;
  38. } );
  39. }
  40. function runUmberto( options ) {
  41. const umberto = require( 'umberto' );
  42. return umberto.buildSingleProject( {
  43. configDir: 'docs',
  44. clean: true,
  45. dev: !options.production,
  46. skipLiveSnippets: options.skipLiveSnippets,
  47. skipValidation: options.skipValidation,
  48. snippetOptions: {
  49. production: options.production,
  50. allowedSnippets: allowedSnippets ? allowedSnippets.replace( '--snippets=', '' ).split( ',' ) : []
  51. },
  52. skipApi: options.skipApi,
  53. verbose: options.verbose,
  54. watch: options.watch
  55. } );
  56. }