gulpfile.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 temporary documentation files.
  22. TEMPORARY_DIR: 'build/docs/.tmp',
  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. // Glob pattern with guides.
  30. GUIDES: 'docs/guides/**/*.md'
  31. },
  32. // Files ignored by jshint and jscs tasks. Files from .gitignore will be added automatically during tasks execution.
  33. IGNORED_FILES: [
  34. 'src/lib/**'
  35. ]
  36. };
  37. // Lint tasks. ---------------------------------------------------------------
  38. const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' )( config );
  39. gulp.task( 'lint', ckeditor5Lint.lint );
  40. gulp.task( 'lint-staged', ckeditor5Lint.lintStaged );
  41. gulp.task( 'pre-commit', [ 'lint-staged' ] );
  42. // Development environment tasks. ---------------------------------------------
  43. const ckeditor5DevEnv = require( '@ckeditor/ckeditor5-dev-env' )( config );
  44. gulp.task( 'init', ckeditor5DevEnv.initRepository );
  45. gulp.task( 'create-package', ckeditor5DevEnv.createPackage );
  46. gulp.task( 'update', ckeditor5DevEnv.updateRepositories );
  47. gulp.task( 'pull', ckeditor5DevEnv.updateRepositories );
  48. gulp.task( 'status', ckeditor5DevEnv.checkStatus );
  49. gulp.task( 'st', ckeditor5DevEnv.checkStatus );
  50. gulp.task( 'relink', ckeditor5DevEnv.relink );
  51. gulp.task( 'install', ckeditor5DevEnv.installPackage );
  52. gulp.task( 'exec', ckeditor5DevEnv.execOnRepositories );
  53. // Compilation tasks. ---------------------------------------------------------
  54. const ckeditor5DevCompiler = require( '@ckeditor/ckeditor5-dev-compiler' );
  55. const compiler = ckeditor5DevCompiler.compiler( config );
  56. gulp.task( 'default', [ 'compile' ] );
  57. gulp.task( 'compile', callback => {
  58. runSequence( 'compile:clean:all', 'compile:themes', 'compile:js', callback );
  59. } );
  60. gulp.task( 'compile:bundled-sample-tests', [ 'compile:bundled-sample-tests:build-editors' ],
  61. () => compiler.compile.bundledSampleTests() );
  62. // Helpers. ---------------------------
  63. gulp.task( 'compile:clean:all', () => compiler.clean.all() );
  64. gulp.task( 'compile:clean:themes', () => compiler.clean.themes() );
  65. gulp.task( 'compile:clean:js', () => compiler.clean.js() );
  66. gulp.task( 'compile:themes', callback => {
  67. runSequence( 'compile:clean:themes', 'compile:icons', 'compile:sass', callback );
  68. } );
  69. gulp.task( 'compile:sass', () => compiler.compile.sass() );
  70. gulp.task( 'compile:icons', () => compiler.compile.icons() );
  71. gulp.task( 'compile:js', [ 'compile:clean:js' ], () => compiler.compile.js() );
  72. // Tasks specific for preparing compiled output with unmodified source files. Used by `gulp docs` or `gulp build`.
  73. gulp.task( 'compile:clean:js:esnext', () => compiler.clean.js( { formats: [ 'esnext' ] } ) );
  74. gulp.task( 'compile:clean:themes:esnext', () => compiler.clean.themes( { formats: [ 'esnext' ] } ) );
  75. gulp.task( 'compile:sass:esnext', () => compiler.compile.sass( { formats: [ 'esnext' ] } ) );
  76. gulp.task( 'compile:icons:esnext', () => compiler.compile.icons( { formats: [ 'esnext' ] } ) );
  77. gulp.task( 'compile:js:esnext', [ 'compile:clean:js:esnext' ], () => compiler.compile.js( { formats: [ 'esnext' ] } ) );
  78. gulp.task( 'compile:themes:esnext', callback => {
  79. runSequence( 'compile:clean:themes:esnext', 'compile:icons:esnext', 'compile:sass:esnext', callback );
  80. } );
  81. // Building tasks. ------------------------------------------------------------
  82. const ckeditor5DevBundler = require( '@ckeditor/ckeditor5-dev-bundler-rollup' )( config );
  83. gulp.task( 'build', callback => {
  84. runSequence(
  85. 'bundle:generate',
  86. [
  87. 'bundle:minify:js',
  88. 'bundle:minify:css'
  89. ],
  90. () => ckeditor5DevBundler.showSummaryFromConfig( callback )
  91. );
  92. } );
  93. // Helpers. ---------------------------
  94. gulp.task( 'bundle:clean', ckeditor5DevBundler.cleanFromConfig );
  95. gulp.task( 'bundle:minify:js', ckeditor5DevBundler.minify.jsFromConfig );
  96. gulp.task( 'bundle:minify:css', ckeditor5DevBundler.minify.cssFromConfig );
  97. // Generates the bundle without minifying it.
  98. gulp.task( 'bundle:generate',
  99. [
  100. 'bundle:clean',
  101. 'compile:js:esnext',
  102. 'compile:themes:esnext'
  103. ],
  104. ckeditor5DevBundler.generateFromConfig
  105. );
  106. // Documentation. -------------------------------------------------------------
  107. const ckeditor5DevDocs = require( '@ckeditor/ckeditor5-dev-docs' );
  108. const docsBuilder = ckeditor5DevDocs.docs( config );
  109. gulp.task( 'docs', [ 'docs:clean', 'compile:js:esnext' ], ( done ) => {
  110. runSequence( [ 'docs:prepare-files', 'docs:editors' ], 'docs:build', done );
  111. } );
  112. // Documentation's helpers.
  113. gulp.task( 'docs:clean', docsBuilder.clean );
  114. gulp.task( 'docs:build', docsBuilder.buildDocs );
  115. gulp.task( 'docs:prepare-files', docsBuilder.collectDocumentationFiles );
  116. gulp.task( 'docs:editors', [ 'compile:js:esnext', 'compile:themes:esnext' ], docsBuilder.buildEditorsForSamples );