gulpfile.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. config.PACKAGES = ckeditor5DevCompiler.utils.getPackages( config.ROOT_DIR );
  52. const compiler = ckeditor5DevCompiler.compiler( config );
  53. gulp.task( 'default', [ 'compile' ] );
  54. gulp.task( 'compile', callback => {
  55. runSequence( 'compile:clean:all', 'compile:themes', 'compile:js', callback );
  56. } );
  57. gulp.task( 'compile:bundled-sample-tests', [ 'compile:bundled-sample-tests:build-editors' ],
  58. () => compiler.compile.bundledSampleTests() );
  59. // Helpers. ---------------------------
  60. gulp.task( 'compile:clean:all', () => compiler.clean.all() );
  61. gulp.task( 'compile:clean:themes', () => compiler.clean.themes() );
  62. gulp.task( 'compile:clean:js', () => compiler.clean.js() );
  63. gulp.task( 'compile:themes', callback => {
  64. runSequence( 'compile:clean:themes', 'compile:icons', 'compile:sass', callback );
  65. } );
  66. gulp.task( 'compile:sass', () => compiler.compile.sass() );
  67. gulp.task( 'compile:icons', () => compiler.compile.icons() );
  68. gulp.task( 'compile:js', [ 'compile:clean:js' ], () => compiler.compile.js() );
  69. // Tasks specific for preparing compiled output with unmodified source files. Used by `gulp docs` or `gulp build`.
  70. gulp.task( 'compile:clean:js:esnext', () => compiler.clean.js( { formats: [ 'esnext' ] } ) );
  71. gulp.task( 'compile:clean:themes:esnext', () => compiler.clean.themes( { formats: [ 'esnext' ] } ) );
  72. gulp.task( 'compile:sass:esnext', () => compiler.compile.sass( { formats: [ 'esnext' ] } ) );
  73. gulp.task( 'compile:icons:esnext', () => compiler.compile.icons( { formats: [ 'esnext' ] } ) );
  74. gulp.task( 'compile:js:esnext', [ 'compile:clean:js:esnext' ], () => compiler.compile.js( { formats: [ 'esnext' ] } ) );
  75. gulp.task( 'compile:themes:esnext', callback => {
  76. runSequence( 'compile:clean:themes:esnext', 'compile:icons:esnext', 'compile:sass:esnext', callback );
  77. } );
  78. // Building tasks. ------------------------------------------------------------
  79. const ckeditor5DevBundler = require( '@ckeditor/ckeditor5-dev-bundler-rollup' )( config );
  80. gulp.task( 'build', callback => {
  81. runSequence(
  82. 'bundle:generate',
  83. [
  84. 'bundle:minify:js',
  85. 'bundle:minify:css'
  86. ],
  87. () => ckeditor5DevBundler.showSummaryFromConfig( callback )
  88. );
  89. } );
  90. // Helpers. ---------------------------
  91. gulp.task( 'bundle:clean', ckeditor5DevBundler.cleanFromConfig );
  92. gulp.task( 'bundle:minify:js', ckeditor5DevBundler.minify.jsFromConfig );
  93. gulp.task( 'bundle:minify:css', ckeditor5DevBundler.minify.cssFromConfig );
  94. // Generates the bundle without minifying it.
  95. gulp.task( 'bundle:generate',
  96. [
  97. 'bundle:clean',
  98. 'compile:js:esnext',
  99. 'compile:themes:esnext'
  100. ],
  101. ckeditor5DevBundler.generateFromConfig
  102. );
  103. // Documentation. -------------------------------------------------------------
  104. const ckeditor5DevDocs = require( '@ckeditor/ckeditor5-dev-docs' );
  105. const docsBuilder = ckeditor5DevDocs.docs( config );
  106. gulp.task( 'docs', [ 'docs:clean', 'compile:js:esnext' ], ( done ) => {
  107. runSequence( 'docs:editors', 'docs:build', done );
  108. } );
  109. // Documentation's helpers.
  110. gulp.task( 'docs:clean', docsBuilder.clean );
  111. gulp.task( 'docs:build', docsBuilder.buildDocs );
  112. gulp.task( 'docs:editors', [ 'compile:js:esnext', 'compile:themes:esnext' ], docsBuilder.buildEditorsForSamples );