8
0

gulpfile.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. // Tests. ---------------------------------------------------------------------
  10. gulp.task( 'test', () => {
  11. return require( '@ckeditor/ckeditor5-dev-tests' )
  12. .runAutomatedTests( getTestOptions() );
  13. } );
  14. gulp.task( 'test:manual', () => {
  15. return require( '@ckeditor/ckeditor5-dev-tests' )
  16. .runManualTests( getTestOptions() );
  17. } );
  18. function getTestOptions() {
  19. return require( '@ckeditor/ckeditor5-dev-tests' )
  20. .parseArguments( process.argv.slice( 2 ) );
  21. }
  22. // Documentation. -------------------------------------------------------------
  23. gulp.task( 'docs', () => {
  24. const skipLiveSnippets = process.argv.includes( '--skip-snippets' );
  25. const skipApi = process.argv.includes( '--skip-api' );
  26. const production = process.argv.includes( '--production' );
  27. if ( skipApi ) {
  28. const fs = require( 'fs' );
  29. const apiJsonPath = './docs/api/output.json';
  30. if ( fs.existsSync( apiJsonPath ) ) {
  31. fs.unlinkSync( apiJsonPath );
  32. }
  33. return runUmberto( {
  34. skipLiveSnippets,
  35. skipApi,
  36. production
  37. } );
  38. }
  39. // Simple way to reuse existing api/output.json:
  40. // return Promise.resolve()
  41. return buildApiDocs()
  42. .then( () => {
  43. return runUmberto( {
  44. skipLiveSnippets,
  45. production
  46. } );
  47. } );
  48. } );
  49. gulp.task( 'docs:api', buildApiDocs );
  50. function buildApiDocs() {
  51. assertIsInstalled( '@ckeditor/ckeditor5-dev-docs' );
  52. const ckeditor5Docs = require( '@ckeditor/ckeditor5-dev-docs' );
  53. return ckeditor5Docs
  54. .build( {
  55. readmePath: path.join( process.cwd(), 'README.md' ),
  56. sourceFiles: [
  57. process.cwd() + '/packages/ckeditor5-*/src/**/*.@(js|jsdoc)',
  58. '!' + process.cwd() + '/packages/ckeditor5-*/src/lib/**/*.js',
  59. '!' + process.cwd() + '/packages/ckeditor5-build-*/src/**/*.js'
  60. ],
  61. validateOnly: process.argv[ 3 ] == '--validate-only'
  62. } );
  63. }
  64. function runUmberto( options ) {
  65. assertIsInstalled( 'umberto' );
  66. const umberto = require( 'umberto' );
  67. return umberto.buildSingleProject( {
  68. configDir: 'docs',
  69. clean: true,
  70. skipLiveSnippets: options.skipLiveSnippets,
  71. snippetOptions: {
  72. production: options.production
  73. },
  74. skipApi: options.skipApi
  75. } );
  76. }
  77. // Translations. --------------------------------------------------------------
  78. gulp.task( 'translations:collect', () => {
  79. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  80. return require( '@ckeditor/ckeditor5-dev-env' ).collectTranslations();
  81. } );
  82. gulp.task( 'translations:upload', () => {
  83. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  84. return require( '@ckeditor/ckeditor5-dev-env' ).uploadTranslations();
  85. } );
  86. gulp.task( 'translations:download', () => {
  87. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  88. return require( '@ckeditor/ckeditor5-dev-env' ).downloadTranslations();
  89. } );
  90. // Releasing. -----------------------------------------------------------------
  91. gulp.task( 'changelog', () => {
  92. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  93. const devEnv = require( '@ckeditor/ckeditor5-dev-env' );
  94. const commonOptions = {
  95. cwd: process.cwd(),
  96. packages: 'packages'
  97. };
  98. const editorBuildsGlob = '@ckeditor/ckeditor5-build-*';
  99. const optionsForDependencies = Object.assign( {}, commonOptions, {
  100. skipPackages: editorBuildsGlob
  101. } );
  102. const optionsForBuilds = Object.assign( {}, commonOptions, {
  103. scope: editorBuildsGlob
  104. } );
  105. return Promise.resolve()
  106. .then( () => devEnv.generateChangelogForSubRepositories( optionsForDependencies ) )
  107. .then( () => devEnv.generateSummaryChangelog( optionsForBuilds ) );
  108. } );
  109. gulp.task( 'release:dependencies', () => {
  110. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  111. return require( '@ckeditor/ckeditor5-dev-env' )
  112. .releaseSubRepositories( {
  113. cwd: process.cwd(),
  114. packages: 'packages'
  115. } );
  116. } );
  117. // Utils. ---------------------------------------------------------------------
  118. function assertIsInstalled( packageName ) {
  119. try {
  120. require( packageName + '/package.json' );
  121. } catch ( err ) {
  122. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  123. console.error( 'You need to install optional dependencies.' );
  124. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  125. process.exit( 1 );
  126. }
  127. }