8
0

gulpfile.js 4.4 KB

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