gulpfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. } );
  47. }
  48. function runUmberto() {
  49. assertIsInstalled( 'umberto' );
  50. const umberto = require( 'umberto' );
  51. return umberto.buildSingleProject( {
  52. configDir: 'docs',
  53. clean: true
  54. } );
  55. }
  56. // Translations. --------------------------------------------------------------
  57. gulp.task( 'translations:collect', () => {
  58. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  59. return require( '@ckeditor/ckeditor5-dev-env' ).collectTranslations();
  60. } );
  61. gulp.task( 'translations:upload', () => {
  62. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  63. return require( '@ckeditor/ckeditor5-dev-env' ).uploadTranslations();
  64. } );
  65. gulp.task( 'translations:download', () => {
  66. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  67. return require( '@ckeditor/ckeditor5-dev-env' ).downloadTranslations();
  68. } );
  69. // Releasing. -----------------------------------------------------------------
  70. gulp.task( 'changelog:dependencies', () => {
  71. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  72. return require( '@ckeditor/ckeditor5-dev-env' )
  73. .generateChangelogForSubRepositories( {
  74. cwd: process.cwd(),
  75. packages: 'packages'
  76. } );
  77. } );
  78. gulp.task( 'release:dependencies', () => {
  79. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  80. return require( '@ckeditor/ckeditor5-dev-env' )
  81. .releaseSubRepositories( {
  82. cwd: process.cwd(),
  83. packages: 'packages'
  84. } );
  85. } );
  86. // Utils. ---------------------------------------------------------------------
  87. function assertIsInstalled( packageName ) {
  88. try {
  89. require( packageName + '/package.json' );
  90. } catch ( err ) {
  91. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  92. console.error( 'You need to install optional dependencies.' );
  93. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  94. process.exit( 1 );
  95. }
  96. }