gulpfile.js 3.8 KB

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