gulpfile.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 gulp = require( 'gulp' );
  8. const runSequence = require( 'run-sequence' );
  9. const config = {
  10. ROOT_DIR: '.',
  11. MODULE_DIR: {
  12. amd: 'build/modules/amd',
  13. cjs: 'build/modules/cjs',
  14. esnext: 'build/modules/esnext'
  15. },
  16. BUNDLE_DIR: 'build/dist',
  17. WORKSPACE_DIR: '..',
  18. // Path to the default configuration file for bundler.
  19. BUNDLE_DEFAULT_CONFIG: 'dev/bundles/build-config-standard.js',
  20. DOCUMENTATION: {
  21. // Path to the built editors.
  22. BUNDLE_DIR: 'build/docs/assets/scripts/samples',
  23. // Path to the built documentation.
  24. DESTINATION_DIR: 'build/docs',
  25. // Glob pattern with samples.
  26. SAMPLES: 'docs/samples/**/*.@(md|html|js)'
  27. },
  28. // Files ignored by jshint and jscs tasks. Files from .gitignore will be added automatically during tasks execution.
  29. IGNORED_FILES: [
  30. 'src/lib/**'
  31. ]
  32. };
  33. // Lint tasks. ---------------------------------------------------------------
  34. const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' )( config );
  35. gulp.task( 'lint', ckeditor5Lint.lint );
  36. gulp.task( 'lint-staged', ckeditor5Lint.lintStaged );
  37. gulp.task( 'pre-commit', [ 'lint-staged' ] );
  38. // Development environment tasks. ---------------------------------------------
  39. const ckeditor5DevEnv = require( '@ckeditor/ckeditor5-dev-env' )( config );
  40. gulp.task( 'init', ckeditor5DevEnv.initRepository );
  41. gulp.task( 'create-package', ckeditor5DevEnv.createPackage );
  42. gulp.task( 'update', ckeditor5DevEnv.updateRepositories );
  43. gulp.task( 'pull', ckeditor5DevEnv.updateRepositories );
  44. gulp.task( 'status', ckeditor5DevEnv.checkStatus );
  45. gulp.task( 'st', ckeditor5DevEnv.checkStatus );
  46. gulp.task( 'relink', ckeditor5DevEnv.relink );
  47. gulp.task( 'install', ckeditor5DevEnv.installPackage );
  48. gulp.task( 'exec', ckeditor5DevEnv.execOnRepositories );
  49. // Compilation tasks. ---------------------------------------------------------
  50. const ckeditor5DevCompiler = require( '@ckeditor/ckeditor5-dev-compiler' );
  51. // Return an array with paths to the CKEditor 5 dependencies.
  52. function getCKEditorPackagesPaths() {
  53. return ckeditor5DevCompiler.utils.getPackages( config.ROOT_DIR );
  54. }
  55. gulp.task( 'default', [ 'compile' ] );
  56. gulp.task( 'compile', () => {
  57. const args = ckeditor5DevCompiler.utils.parseArguments();
  58. const formats = {};
  59. for ( const item of args.formats ) {
  60. formats[ item ] = config.MODULE_DIR[ item ];
  61. }
  62. return ckeditor5DevCompiler.compiler.compile( {
  63. formats,
  64. packages: getCKEditorPackagesPaths(),
  65. watch: args.watch,
  66. es5: args.es5,
  67. samplesGlob: config.DOCUMENTATION.SAMPLES
  68. } );
  69. } );
  70. // Tasks specific for preparing compiled output with unmodified source files. Used by `gulp docs` or `gulp build`.
  71. // Todo: These tasks should be moved direct to Docs and Bundler.
  72. gulp.task( 'compile:clean:js:esnext', () => {
  73. return ckeditor5DevCompiler.compiler.clean.js( [ config.MODULE_DIR.esnext ] );
  74. } );
  75. gulp.task( 'compile:clean:themes:esnext', () => {
  76. return ckeditor5DevCompiler.compiler.clean.themes( [ config.MODULE_DIR.esnext ] );
  77. } );
  78. gulp.task( 'compile:sass:esnext', () => {
  79. return ckeditor5DevCompiler.compiler.process.sass( {
  80. formats: { esnext: config.MODULE_DIR.esnext },
  81. packages: getCKEditorPackagesPaths()
  82. } );
  83. } );
  84. gulp.task( 'compile:icons:esnext', () => {
  85. return ckeditor5DevCompiler.compiler.process.icons( {
  86. formats: { esnext: config.MODULE_DIR.esnext },
  87. packages: getCKEditorPackagesPaths()
  88. } );
  89. } );
  90. gulp.task( 'compile:js:esnext', [ 'compile:clean:js:esnext' ], () => {
  91. return ckeditor5DevCompiler.compiler.process.js( {
  92. formats: { esnext: config.MODULE_DIR.esnext },
  93. packages: getCKEditorPackagesPaths()
  94. } );
  95. } );
  96. gulp.task( 'compile:themes:esnext', ( callback ) => {
  97. runSequence( 'compile:clean:themes:esnext', 'compile:icons:esnext', 'compile:sass:esnext', callback );
  98. } );
  99. // Building tasks. ------------------------------------------------------------
  100. const ckeditor5DevBundler = require( '@ckeditor/ckeditor5-dev-bundler-rollup' )( config );
  101. gulp.task( 'build', callback => {
  102. runSequence(
  103. 'bundle:generate',
  104. [
  105. 'bundle:minify:js',
  106. 'bundle:minify:css'
  107. ],
  108. () => ckeditor5DevBundler.showSummaryFromConfig( callback )
  109. );
  110. } );
  111. // Helpers. ---------------------------
  112. gulp.task( 'bundle:clean', ckeditor5DevBundler.cleanFromConfig );
  113. gulp.task( 'bundle:minify:js', ckeditor5DevBundler.minify.jsFromConfig );
  114. gulp.task( 'bundle:minify:css', ckeditor5DevBundler.minify.cssFromConfig );
  115. // Generates the bundle without minifying it.
  116. gulp.task( 'bundle:generate',
  117. [
  118. 'bundle:clean',
  119. 'compile:js:esnext',
  120. 'compile:themes:esnext'
  121. ],
  122. ckeditor5DevBundler.generateFromConfig
  123. );
  124. // Documentation. -------------------------------------------------------------
  125. const ckeditor5DevDocs = require( '@ckeditor/ckeditor5-dev-docs' );
  126. const docsBuilder = ckeditor5DevDocs.docs( config );
  127. gulp.task( 'docs', [ 'docs:clean', 'compile:js:esnext' ], ( done ) => {
  128. runSequence( 'docs:editors', 'docs:build', done );
  129. } );
  130. // Documentation's helpers.
  131. gulp.task( 'docs:clean', docsBuilder.clean );
  132. gulp.task( 'docs:build', docsBuilder.buildDocs );
  133. gulp.task( 'docs:editors', [ 'compile:js:esnext', 'compile:themes:esnext' ], docsBuilder.buildEditorsForSamples );