gulpfile.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. const production = process.argv.includes( '--production' );
  32. if ( skipApi ) {
  33. const fs = require( 'fs' );
  34. const apiJsonPath = './docs/api/output.json';
  35. if ( fs.existsSync( apiJsonPath ) ) {
  36. fs.unlinkSync( apiJsonPath );
  37. }
  38. return runUmberto( {
  39. skipLiveSnippets,
  40. production
  41. } );
  42. }
  43. return buildApiDocs()
  44. .then( () => {
  45. return runUmberto( {
  46. skipLiveSnippets,
  47. production
  48. } );
  49. } );
  50. } );
  51. gulp.task( 'docs:api', buildApiDocs );
  52. function buildApiDocs() {
  53. assertIsInstalled( '@ckeditor/ckeditor5-dev-docs' );
  54. const ckeditor5Docs = require( '@ckeditor/ckeditor5-dev-docs' );
  55. return ckeditor5Docs
  56. .build( {
  57. readmePath: path.join( process.cwd(), 'README.md' ),
  58. sourceFiles: [
  59. process.cwd() + '/packages/ckeditor5-*/src/**/*.@(js|jsdoc)',
  60. '!' + process.cwd() + '/packages/ckeditor5-*/src/lib/**/*.js'
  61. ],
  62. validateOnly: process.argv[ 3 ] == '--validate-only'
  63. } );
  64. }
  65. function runUmberto( options ) {
  66. assertIsInstalled( 'umberto' );
  67. const umberto = require( 'umberto' );
  68. return umberto.buildSingleProject( {
  69. configDir: 'docs',
  70. clean: true,
  71. skipLiveSnippets: options.skipLiveSnippets,
  72. snippetOptions: {
  73. production: options.production
  74. }
  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:dependencies', () => {
  92. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  93. return require( '@ckeditor/ckeditor5-dev-env' )
  94. .generateChangelogForSubRepositories( {
  95. cwd: process.cwd(),
  96. packages: 'packages'
  97. } );
  98. } );
  99. gulp.task( 'release:dependencies', () => {
  100. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  101. return require( '@ckeditor/ckeditor5-dev-env' )
  102. .releaseSubRepositories( {
  103. cwd: process.cwd(),
  104. packages: 'packages'
  105. } );
  106. } );
  107. // Utils. ---------------------------------------------------------------------
  108. function assertIsInstalled( packageName ) {
  109. try {
  110. require( packageName + '/package.json' );
  111. } catch ( err ) {
  112. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  113. console.error( 'You need to install optional dependencies.' );
  114. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  115. process.exit( 1 );
  116. }
  117. }