gulpfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. if ( process.argv[ 3 ] == '--no-api' ) {
  30. return runUmberto();
  31. }
  32. return buildApiDocs()
  33. .then( runUmberto );
  34. } );
  35. gulp.task( 'docs:api-json', buildApiDocs );
  36. function buildApiDocs() {
  37. assertIsInstalled( '@ckeditor/ckeditor5-dev-docs' );
  38. const ckeditor5Docs = require( '@ckeditor/ckeditor5-dev-docs' );
  39. return ckeditor5Docs
  40. .build( {
  41. readmePath: path.join( process.cwd(), 'README.md' ),
  42. sourceFiles: [
  43. process.cwd() + '/packages/ckeditor5-*/src/**/*.@(js|jsdoc)',
  44. '!' + process.cwd() + '/packages/ckeditor5-*/src/lib/**/*.js'
  45. ],
  46. validationOnly: process.argv[ 3 ] == '--validate-only'
  47. } );
  48. }
  49. function runUmberto() {
  50. assertIsInstalled( 'umberto' );
  51. const umberto = require( 'umberto' );
  52. return umberto.buildSingleProject( {
  53. configDir: 'docs',
  54. clean: true
  55. } );
  56. }
  57. // Translations. --------------------------------------------------------------
  58. gulp.task( 'translations:collect', () => {
  59. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  60. return require( '@ckeditor/ckeditor5-dev-env' ).collectTranslations();
  61. } );
  62. gulp.task( 'translations:upload', () => {
  63. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  64. return require( '@ckeditor/ckeditor5-dev-env' ).uploadTranslations();
  65. } );
  66. gulp.task( 'translations:download', () => {
  67. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  68. return require( '@ckeditor/ckeditor5-dev-env' ).downloadTranslations();
  69. } );
  70. // Releasing. -----------------------------------------------------------------
  71. gulp.task( 'changelog:dependencies', () => {
  72. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  73. return require( '@ckeditor/ckeditor5-dev-env' )
  74. .generateChangelogForSubRepositories( {
  75. cwd: process.cwd(),
  76. packages: 'packages'
  77. } );
  78. } );
  79. gulp.task( 'release:dependencies', () => {
  80. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  81. return require( '@ckeditor/ckeditor5-dev-env' )
  82. .releaseSubRepositories( {
  83. cwd: process.cwd(),
  84. packages: 'packages'
  85. } );
  86. } );
  87. // Utils. ---------------------------------------------------------------------
  88. function assertIsInstalled( packageName ) {
  89. try {
  90. require( packageName + '/package.json' );
  91. } catch ( err ) {
  92. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  93. console.error( 'You need to install optional dependencies.' );
  94. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  95. process.exit( 1 );
  96. }
  97. }