build-docs.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env node
  2. /**
  3. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  4. * For licensing, see LICENSE.md.
  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. buildDocs();
  14. function buildDocs() {
  15. if ( skipApi ) {
  16. const fs = require( 'fs' );
  17. const apiJsonPath = './docs/api/output.json';
  18. if ( fs.existsSync( apiJsonPath ) ) {
  19. fs.unlinkSync( apiJsonPath );
  20. }
  21. runUmberto( {
  22. skipLiveSnippets,
  23. skipApi,
  24. skipValidation,
  25. production
  26. } ).then( () => process.exit() );
  27. return;
  28. }
  29. // Simple way to reuse existing api/output.json:
  30. // return Promise.resolve()
  31. buildApiDocs()
  32. .then( () => {
  33. return runUmberto( {
  34. skipLiveSnippets,
  35. skipValidation,
  36. production
  37. } );
  38. } );
  39. }
  40. function runUmberto( options ) {
  41. const umberto = require( 'umberto' );
  42. return umberto.buildSingleProject( {
  43. configDir: 'docs',
  44. clean: true,
  45. skipLiveSnippets: options.skipLiveSnippets,
  46. skipValidation: options.skipValidation,
  47. snippetOptions: {
  48. production: options.production
  49. },
  50. skipApi: options.skipApi
  51. } );
  52. }