gulpfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* eslint-env node */
  6. 'use strict';
  7. const path = require( 'path' );
  8. const gulp = require( 'gulp' );
  9. // Documentation. -------------------------------------------------------------
  10. gulp.task( 'docs', () => {
  11. const skipLiveSnippets = process.argv.includes( '--skip-snippets' );
  12. const skipApi = process.argv.includes( '--skip-api' );
  13. const production = process.argv.includes( '--production' );
  14. if ( skipApi ) {
  15. const fs = require( 'fs' );
  16. const apiJsonPath = './docs/api/output.json';
  17. if ( fs.existsSync( apiJsonPath ) ) {
  18. fs.unlinkSync( apiJsonPath );
  19. }
  20. return runUmberto( {
  21. skipLiveSnippets,
  22. skipApi,
  23. production
  24. } );
  25. }
  26. // Simple way to reuse existing api/output.json:
  27. // return Promise.resolve()
  28. return buildApiDocs()
  29. .then( () => {
  30. return runUmberto( {
  31. skipLiveSnippets,
  32. production
  33. } );
  34. } );
  35. } );
  36. gulp.task( 'docs:api', buildApiDocs );
  37. function buildApiDocs() {
  38. assertIsInstalled( '@ckeditor/ckeditor5-dev-docs' );
  39. const ckeditor5Docs = require( '@ckeditor/ckeditor5-dev-docs' );
  40. return ckeditor5Docs
  41. .build( {
  42. readmePath: path.join( process.cwd(), 'README.md' ),
  43. sourceFiles: [
  44. process.cwd() + '/packages/ckeditor5-*/src/**/*.@(js|jsdoc)',
  45. '!' + process.cwd() + '/packages/ckeditor5-*/src/lib/**/*.js',
  46. '!' + process.cwd() + '/packages/ckeditor5-build-*/src/**/*.js'
  47. ],
  48. validateOnly: process.argv[ 3 ] == '--validate-only'
  49. } );
  50. }
  51. function runUmberto( options ) {
  52. assertIsInstalled( 'umberto' );
  53. const umberto = require( 'umberto' );
  54. return umberto.buildSingleProject( {
  55. configDir: 'docs',
  56. clean: true,
  57. skipLiveSnippets: options.skipLiveSnippets,
  58. snippetOptions: {
  59. production: options.production
  60. },
  61. skipApi: options.skipApi
  62. } );
  63. }
  64. // Translations. --------------------------------------------------------------
  65. gulp.task( 'translations:collect', () => {
  66. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  67. return require( '@ckeditor/ckeditor5-dev-env' ).collectTranslations();
  68. } );
  69. gulp.task( 'translations:upload', () => {
  70. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  71. return require( '@ckeditor/ckeditor5-dev-env' ).uploadTranslations();
  72. } );
  73. gulp.task( 'translations:download', () => {
  74. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  75. return require( '@ckeditor/ckeditor5-dev-env' ).downloadTranslations();
  76. } );
  77. // Releasing. -----------------------------------------------------------------
  78. gulp.task( 'changelog:dependencies', () => {
  79. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  80. return require( '@ckeditor/ckeditor5-dev-env' )
  81. .generateChangelogForSubRepositories( {
  82. cwd: process.cwd(),
  83. packages: 'packages'
  84. } );
  85. } );
  86. gulp.task( 'release:dependencies', () => {
  87. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  88. return require( '@ckeditor/ckeditor5-dev-env' )
  89. .releaseSubRepositories( {
  90. cwd: process.cwd(),
  91. packages: 'packages'
  92. } );
  93. } );
  94. // Utils. ---------------------------------------------------------------------
  95. function assertIsInstalled( packageName ) {
  96. try {
  97. require( packageName + '/package.json' );
  98. } catch ( err ) {
  99. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  100. console.error( 'You need to install optional dependencies.' );
  101. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  102. process.exit( 1 );
  103. }
  104. }