gulpfile.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. skipApi,
  41. production
  42. } );
  43. }
  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. ],
  63. validateOnly: process.argv[ 3 ] == '--validate-only'
  64. } );
  65. }
  66. function runUmberto( options ) {
  67. assertIsInstalled( 'umberto' );
  68. const umberto = require( 'umberto' );
  69. return umberto.buildSingleProject( {
  70. configDir: 'docs',
  71. clean: true,
  72. skipLiveSnippets: options.skipLiveSnippets,
  73. snippetOptions: {
  74. production: options.production
  75. },
  76. skipApi: options.skipApi
  77. } );
  78. }
  79. // Translations. --------------------------------------------------------------
  80. gulp.task( 'translations:collect', () => {
  81. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  82. return require( '@ckeditor/ckeditor5-dev-env' ).collectTranslations();
  83. } );
  84. gulp.task( 'translations:upload', () => {
  85. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  86. return require( '@ckeditor/ckeditor5-dev-env' ).uploadTranslations();
  87. } );
  88. gulp.task( 'translations:download', () => {
  89. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  90. return require( '@ckeditor/ckeditor5-dev-env' ).downloadTranslations();
  91. } );
  92. // Releasing. -----------------------------------------------------------------
  93. gulp.task( 'changelog:dependencies', () => {
  94. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  95. return require( '@ckeditor/ckeditor5-dev-env' )
  96. .generateChangelogForSubRepositories( {
  97. cwd: process.cwd(),
  98. packages: 'packages'
  99. } );
  100. } );
  101. gulp.task( 'release:dependencies', () => {
  102. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  103. return require( '@ckeditor/ckeditor5-dev-env' )
  104. .releaseSubRepositories( {
  105. cwd: process.cwd(),
  106. packages: 'packages'
  107. } );
  108. } );
  109. // Utils. ---------------------------------------------------------------------
  110. function assertIsInstalled( packageName ) {
  111. try {
  112. require( packageName + '/package.json' );
  113. } catch ( err ) {
  114. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  115. console.error( 'You need to install optional dependencies.' );
  116. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  117. process.exit( 1 );
  118. }
  119. }