gulpfile.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. // Simple way to reuse existing api/output.json:
  45. // return Promise.resolve()
  46. return buildApiDocs()
  47. .then( () => {
  48. return runUmberto( {
  49. skipLiveSnippets,
  50. production
  51. } );
  52. } );
  53. } );
  54. gulp.task( 'docs:api', buildApiDocs );
  55. function buildApiDocs() {
  56. assertIsInstalled( '@ckeditor/ckeditor5-dev-docs' );
  57. const ckeditor5Docs = require( '@ckeditor/ckeditor5-dev-docs' );
  58. return ckeditor5Docs
  59. .build( {
  60. readmePath: path.join( process.cwd(), 'README.md' ),
  61. sourceFiles: [
  62. process.cwd() + '/packages/ckeditor5-*/src/**/*.@(js|jsdoc)',
  63. '!' + process.cwd() + '/packages/ckeditor5-*/src/lib/**/*.js',
  64. '!' + process.cwd() + '/packages/ckeditor5-build-*/src/**/*.js'
  65. ],
  66. validateOnly: process.argv[ 3 ] == '--validate-only'
  67. } );
  68. }
  69. function runUmberto( options ) {
  70. assertIsInstalled( 'umberto' );
  71. const umberto = require( 'umberto' );
  72. return umberto.buildSingleProject( {
  73. configDir: 'docs',
  74. clean: true,
  75. skipLiveSnippets: options.skipLiveSnippets,
  76. snippetOptions: {
  77. production: options.production
  78. },
  79. skipApi: options.skipApi
  80. } );
  81. }
  82. // Translations. --------------------------------------------------------------
  83. gulp.task( 'translations:collect', () => {
  84. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  85. return require( '@ckeditor/ckeditor5-dev-env' ).collectTranslations();
  86. } );
  87. gulp.task( 'translations:upload', () => {
  88. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  89. return require( '@ckeditor/ckeditor5-dev-env' ).uploadTranslations();
  90. } );
  91. gulp.task( 'translations:download', () => {
  92. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  93. return require( '@ckeditor/ckeditor5-dev-env' ).downloadTranslations();
  94. } );
  95. // Releasing. -----------------------------------------------------------------
  96. gulp.task( 'changelog:dependencies', () => {
  97. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  98. return require( '@ckeditor/ckeditor5-dev-env' )
  99. .generateChangelogForSubRepositories( {
  100. cwd: process.cwd(),
  101. packages: 'packages'
  102. } );
  103. } );
  104. gulp.task( 'release:dependencies', () => {
  105. assertIsInstalled( '@ckeditor/ckeditor5-dev-env' );
  106. return require( '@ckeditor/ckeditor5-dev-env' )
  107. .releaseSubRepositories( {
  108. cwd: process.cwd(),
  109. packages: 'packages'
  110. } );
  111. } );
  112. // Utils. ---------------------------------------------------------------------
  113. function assertIsInstalled( packageName ) {
  114. try {
  115. require( packageName + '/package.json' );
  116. } catch ( err ) {
  117. console.error( `Error: Cannot find package '${ packageName }'.\n` );
  118. console.error( 'You need to install optional dependencies.' );
  119. console.error( 'Run: \'npm run install-optional-dependencies\'.' );
  120. process.exit( 1 );
  121. }
  122. }