gulpfile.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* jshint browser: false, node: true, strict: true */
  6. 'use strict';
  7. const path = require( 'path' );
  8. const gulp = require( 'gulp' );
  9. const runSequence = require( 'run-sequence' );
  10. const compiler = require( '@ckeditor/ckeditor5-dev-compiler' );
  11. const config = {
  12. ROOT_DIR: '.',
  13. MODULE_DIR: {
  14. amd: './build/modules/amd',
  15. cjs: './build/modules/cjs',
  16. esnext: './build/modules/esnext'
  17. },
  18. BUNDLE_DIR: './build/dist',
  19. WORKSPACE_DIR: '..',
  20. // Path to the default configuration file for bundler.
  21. BUNDLE_DEFAULT_CONFIG: './dev/bundles/build-config-standard.js',
  22. DOCUMENTATION: {
  23. // Path to the built editors.
  24. BUNDLE_DIR: './build/docs/assets/scripts/samples',
  25. // Path to the built documentation.
  26. DESTINATION_DIR: './build/docs',
  27. // Glob pattern with samples.
  28. SAMPLES: './docs/samples/**/*.@(md|html|js)'
  29. },
  30. // Files ignored by jshint and jscs tasks. Files from .gitignore will be added automatically during tasks execution.
  31. IGNORED_FILES: [
  32. 'src/lib/**'
  33. ]
  34. };
  35. // Return an array with paths to the CKEditor 5 dependencies.
  36. function getCKEditor5PackagesPaths() {
  37. return compiler.utils.getPackages( config.ROOT_DIR );
  38. }
  39. // Lint tasks. ---------------------------------------------------------------
  40. const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' )( config );
  41. gulp.task( 'lint', ckeditor5Lint.lint );
  42. gulp.task( 'lint-staged', ckeditor5Lint.lintStaged );
  43. gulp.task( 'pre-commit', [ 'lint-staged' ] );
  44. // Development environment tasks. ---------------------------------------------
  45. const ckeditor5DevEnv = require( '@ckeditor/ckeditor5-dev-env' )( config );
  46. gulp.task( 'init', ckeditor5DevEnv.initRepository );
  47. gulp.task( 'create-package', ckeditor5DevEnv.createPackage );
  48. gulp.task( 'update', ckeditor5DevEnv.updateRepositories );
  49. gulp.task( 'pull', ckeditor5DevEnv.updateRepositories );
  50. gulp.task( 'status', ckeditor5DevEnv.checkStatus );
  51. gulp.task( 'st', ckeditor5DevEnv.checkStatus );
  52. gulp.task( 'relink', ckeditor5DevEnv.relink );
  53. gulp.task( 'install', ckeditor5DevEnv.installPackage );
  54. gulp.task( 'exec', ckeditor5DevEnv.execOnRepositories );
  55. // Compilation tasks. ---------------------------------------------------------
  56. gulp.task( 'default', [ 'compile' ] );
  57. gulp.task( 'compile', () => {
  58. const args = compiler.utils.parseArguments();
  59. const formats = {};
  60. for ( const item of args.formats ) {
  61. formats[ item ] = config.MODULE_DIR[ item ];
  62. }
  63. return compiler.tasks.compile( {
  64. formats,
  65. packages: getCKEditor5PackagesPaths(),
  66. watch: args.watch,
  67. es5: args.es5,
  68. samplesGlob: config.DOCUMENTATION.SAMPLES,
  69. verbosity: args.verbosity
  70. } );
  71. } );
  72. // Tasks specific for preparing compiled output with unmodified source files. Used by `gulp docs`.
  73. // TODO: These tasks should be moved directly to ckeditor5-dev-docs.
  74. gulp.task( 'compile:clean:js:esnext', () => {
  75. return compiler.tasks.clean.js( [ config.MODULE_DIR.esnext ] );
  76. } );
  77. gulp.task( 'compile:clean:themes:esnext', () => {
  78. return compiler.tasks.clean.themes( [ config.MODULE_DIR.esnext ] );
  79. } );
  80. gulp.task( 'compile:sass:esnext', () => {
  81. return compiler.tasks.process.sass( {
  82. formats: { esnext: config.MODULE_DIR.esnext },
  83. packages: getCKEditor5PackagesPaths()
  84. } );
  85. } );
  86. gulp.task( 'compile:icons:esnext', () => {
  87. return compiler.tasks.process.icons( {
  88. formats: { esnext: config.MODULE_DIR.esnext },
  89. packages: getCKEditor5PackagesPaths()
  90. } );
  91. } );
  92. gulp.task( 'compile:js:esnext', [ 'compile:clean:js:esnext' ], () => {
  93. return compiler.tasks.process.js( {
  94. formats: { esnext: config.MODULE_DIR.esnext },
  95. packages: getCKEditor5PackagesPaths()
  96. } );
  97. } );
  98. gulp.task( 'compile:themes:esnext', ( callback ) => {
  99. runSequence( 'compile:clean:themes:esnext', 'compile:icons:esnext', 'compile:sass:esnext', callback );
  100. } );
  101. // Building tasks. ------------------------------------------------------------
  102. gulp.task( 'build', () => {
  103. const bundler = require( '@ckeditor/ckeditor5-dev-bundler-rollup' );
  104. return bundler.tasks.build( getBuildOptions() );
  105. } );
  106. function getBuildOptions() {
  107. const minimist = require( 'minimist' );
  108. const pathToConfig = minimist( process.argv.slice( 2 ) ).config || './build-config';
  109. return {
  110. packages: getCKEditor5PackagesPaths(),
  111. buildConfig: require( path.resolve( '.', pathToConfig ) ),
  112. };
  113. }
  114. // Documentation. -------------------------------------------------------------
  115. gulp.task( 'docs', [ 'docs:clean', 'compile:js:esnext', 'compile:themes:esnext' ], ( done ) => {
  116. runSequence( 'docs:build', done );
  117. } );
  118. // Documentation's helpers.
  119. gulp.task( 'docs:clean', () => {
  120. const docsBuilder = require( '@ckeditor/ckeditor5-dev-docs' ).docs( config );
  121. return docsBuilder.clean();
  122. } );
  123. gulp.task( 'docs:build', () => {
  124. const docsBuilder = require( '@ckeditor/ckeditor5-dev-docs' ).docs( config );
  125. return docsBuilder.buildDocs();
  126. } );
  127. // Tests. ---------------------------------------------------------------------
  128. gulp.task( 'test', () => {
  129. return require( '@ckeditor/ckeditor5-dev-tests' )
  130. .runAutomatedTests( getTestOptions() );
  131. } );
  132. gulp.task( 'test:manual', () => {
  133. return require( '@ckeditor/ckeditor5-dev-tests' )
  134. .runManualTests( getTestOptions() );
  135. } );
  136. function getTestOptions() {
  137. return require( '@ckeditor/ckeditor5-dev-tests' ).parseArguments( process.argv.slice( 2 ) );
  138. }