gulpfile.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. DOCS_DIR: 'build/docs',
  17. BUNDLE_DIR: 'build/dist',
  18. WORKSPACE_DIR: '..',
  19. // Path to the default configuration file for bundler.
  20. BUNDLE_DEFAULT_CONFIG: 'dev/bundles/build-config-standard.js',
  21. DOCUMENTATION: {
  22. // Glob pattern with samples.
  23. SAMPLES: 'docs/samples/**/*.@(md|html|js)',
  24. // Glob pattern with guides.
  25. GUIDES: 'docs/guides/**/*.md'
  26. },
  27. // Files ignored by jshint and jscs tasks. Files from .gitignore will be added automatically during tasks execution.
  28. IGNORED_FILES: [
  29. 'src/lib/**'
  30. ]
  31. };
  32. // Lint tasks.
  33. const ckeditor5Lint = require( 'ckeditor5-dev-lint' )( config );
  34. gulp.task( 'lint', ckeditor5Lint.lint );
  35. gulp.task( 'lint-staged', ckeditor5Lint.lintStaged );
  36. gulp.task( 'default', [ 'compile' ] );
  37. gulp.task( 'pre-commit', [ 'lint-staged' ] );
  38. // Development environment tasks.
  39. const ckeditor5DevEnv = require( '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. // Bundling and building tasks.
  50. const ckeditor5DevBundle = require( 'ckeditor5-dev-bundler-rollup' )( config );
  51. gulp.task( 'bundle:clean', ckeditor5DevBundle.cleanFromConfig );
  52. gulp.task( 'bundle:minify:js', ckeditor5DevBundle.minify.jsFromConfig );
  53. gulp.task( 'bundle:minify:css', ckeditor5DevBundle.minify.cssFromConfig );
  54. gulp.task( 'build:generate',
  55. [
  56. 'bundle:clean',
  57. 'compile:js:esnext',
  58. 'compile:themes:esnext'
  59. ],
  60. ckeditor5DevBundle.generateFromConfig
  61. );
  62. gulp.task( 'build', ( callback ) => {
  63. runSequence( 'build:generate',
  64. [
  65. 'bundle:minify:js',
  66. 'bundle:minify:css'
  67. ],
  68. () => ckeditor5DevBundle.showSummaryFromConfig( callback )
  69. );
  70. } );
  71. // Compile tasks.
  72. const ckeditor5DevCompiler = require( 'ckeditor5-dev-compiler' )( config );
  73. const compiler = ckeditor5DevCompiler.compiler;
  74. gulp.task( 'compile', callback => {
  75. runSequence( 'compile:clean:all', 'compile:themes', 'compile:js', callback );
  76. } );
  77. // Clean tasks.
  78. gulp.task( 'compile:clean:all', () => compiler.clean.all() );
  79. gulp.task( 'compile:clean:themes', () => compiler.clean.themes() );
  80. gulp.task( 'compile:clean:js', () => compiler.clean.js() );
  81. gulp.task( 'compile:themes', ( callback ) => {
  82. runSequence( 'compile:clean:themes', 'compile:icons', 'compile:sass', callback );
  83. } );
  84. gulp.task( 'compile:sass', () => compiler.compile.sass() );
  85. gulp.task( 'compile:icons', () => compiler.compile.icons() );
  86. gulp.task( 'compile:js', [ 'compile:clean:js' ], () => compiler.compile.js() );
  87. // Tasks specific for preparing compiled output with unmodified source files. Uses by `gulp docs` or `gulp bundle`.
  88. gulp.task( 'compile:clean:js:esnext', () => compiler.clean.js( { formats: [ 'esnext' ] } ) );
  89. gulp.task( 'compile:clean:themes:esnext', () => compiler.clean.themes( { formats: [ 'esnext' ] } ) );
  90. gulp.task( 'compile:sass:esnext', () => compiler.compile.sass( { formats: [ 'esnext' ] } ) );
  91. gulp.task( 'compile:icons:esnext', () => compiler.compile.icons( { formats: [ 'esnext' ] } ) );
  92. gulp.task( 'compile:js:esnext', [ 'compile:clean:js:esnext' ], () => compiler.compile.js( { formats: [ 'esnext' ] } ) );
  93. gulp.task( 'compile:themes:esnext', ( callback ) => {
  94. runSequence( 'compile:clean:themes:esnext', 'compile:icons:esnext', 'compile:sass:esnext', callback );
  95. } );
  96. // Tasks specific for testing under node.
  97. gulp.task( 'compile:clean:js:cjs', () => compiler.clean.js( { formats: [ 'cjs' ] } ) );
  98. gulp.task( 'compile:js:cjs', [ 'compile:clean:js:cjs' ], () => compiler.compile.js( { formats: [ 'cjs' ] } ) );
  99. // Tasks specific for testing releases.
  100. gulp.task( 'test:samples:local', [ 'compile' ], () => compiler.compile.tests.local() );
  101. gulp.task( 'test:samples:bundled', [ 'compile:samples' ], () => compiler.compile.tests.bundled() );
  102. gulp.task( 'test:samples', [ 'test:samples:local', 'test:samples:bundled' ] );
  103. // Tasks specific for building editors for testing releases.
  104. gulp.task( 'compile:samples',
  105. [
  106. 'compile:js:esnext',
  107. 'compile:themes:esnext'
  108. ],
  109. ckeditor5DevBundle.buildEditorsForSamples
  110. );
  111. // Docs.
  112. const docsBuilder = ckeditor5DevCompiler.docs;
  113. gulp.task( 'docs', [ 'compile:js:esnext' ], docsBuilder.buildDocs );