gulpfile.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. SOURCE_DIR: '.docs',
  23. DESTINATION_DIR: 'build/docs',
  24. SAMPLES: {
  25. EXTENSIONS: [ 'md', 'html', 'js' ],
  26. DIRECTORY: 'samples'
  27. },
  28. GUIDES: {
  29. EXTENSIONS: [ 'md' ],
  30. DIRECTORY: 'guides'
  31. }
  32. },
  33. // Files ignored by jshint and jscs tasks. Files from .gitignore will be added automatically during tasks execution.
  34. IGNORED_FILES: [
  35. 'src/lib/**'
  36. ]
  37. };
  38. require( './dev/tasks/test/tasks' )( config ).register();
  39. // Lint tasks.
  40. const ckeditor5Lint = require( 'ckeditor5-dev-lint' )( config );
  41. gulp.task( 'lint', ckeditor5Lint.lint );
  42. gulp.task( 'lint-staged', ckeditor5Lint.lintStaged );
  43. gulp.task( 'default', [ 'compile' ] );
  44. gulp.task( 'pre-commit', [ 'lint-staged' ] );
  45. // Development environment tasks.
  46. const ckeditor5DevEnv = require( 'ckeditor5-dev-env' )( config );
  47. gulp.task( 'init', ckeditor5DevEnv.initRepository );
  48. gulp.task( 'create-package', ckeditor5DevEnv.createPackage );
  49. gulp.task( 'update', ckeditor5DevEnv.updateRepositories );
  50. gulp.task( 'pull', ckeditor5DevEnv.updateRepositories );
  51. gulp.task( 'status', ckeditor5DevEnv.checkStatus );
  52. gulp.task( 'st', ckeditor5DevEnv.checkStatus );
  53. gulp.task( 'relink', ckeditor5DevEnv.relink );
  54. gulp.task( 'install', ckeditor5DevEnv.installPackage );
  55. gulp.task( 'exec', ckeditor5DevEnv.execOnRepositories );
  56. // Bundling and building tasks.
  57. const ckeditor5DevBundle = require( 'ckeditor5-dev-bundler-rollup' )( config );
  58. gulp.task( 'bundle:clean', ckeditor5DevBundle.cleanFromConfig );
  59. gulp.task( 'bundle:minify:js', ckeditor5DevBundle.minify.jsFromConfig );
  60. gulp.task( 'bundle:minify:css', ckeditor5DevBundle.minify.cssFromConfig );
  61. gulp.task( 'build:generate',
  62. [
  63. 'bundle:clean',
  64. 'compile:js:esnext',
  65. 'compile:themes:esnext'
  66. ],
  67. ckeditor5DevBundle.generateFromConfig
  68. );
  69. gulp.task( 'build', ( callback ) => {
  70. runSequence( 'build:generate',
  71. [
  72. 'bundle:minify:js',
  73. 'bundle:minify:css'
  74. ],
  75. () => ckeditor5DevBundle.showSummaryFromConfig( callback )
  76. );
  77. } );
  78. // Compile tasks.
  79. const ckeditor5DevCompiler = require( 'ckeditor5-dev-compiler' )( config );
  80. const compiler = ckeditor5DevCompiler.compiler;
  81. gulp.task( 'compile', callback => {
  82. runSequence( 'compile:clean:all', 'compile:themes', 'compile:js', callback );
  83. } );
  84. // Clean tasks.
  85. gulp.task( 'compile:clean:all', () => compiler.clean.all() );
  86. gulp.task( 'compile:clean:themes', () => compiler.clean.themes() );
  87. gulp.task( 'compile:clean:js', () => compiler.clean.js() );
  88. gulp.task( 'compile:themes', ( callback ) => {
  89. runSequence( 'compile:clean:themes', 'compile:icons', 'compile:sass', callback );
  90. } );
  91. gulp.task( 'compile:sass', () => compiler.compile.sass() );
  92. gulp.task( 'compile:icons', () => compiler.compile.icons() );
  93. gulp.task( 'compile:js', [ 'compile:clean:js' ], () => compiler.compile.js() );
  94. // Tasks specific for preparing compiled output with unmodified source files. Uses by `gulp docs` or `gulp bundle`.
  95. gulp.task( 'compile:clean:js:esnext', () => compiler.clean.js( { formats: [ 'esnext' ] } ) );
  96. gulp.task( 'compile:clean:themes:esnext', () => compiler.clean.themes( { formats: [ 'esnext' ] } ) );
  97. gulp.task( 'compile:sass:esnext', () => compiler.compile.sass( { formats: [ 'esnext' ] } ) );
  98. gulp.task( 'compile:icons:esnext', () => compiler.compile.icons( { formats: [ 'esnext' ] } ) );
  99. gulp.task( 'compile:js:esnext', [ 'compile:clean:js:esnext' ], () => compiler.compile.js( { formats: [ 'esnext' ] } ) );
  100. gulp.task( 'compile:themes:esnext', ( callback ) => {
  101. runSequence( 'compile:clean:themes:esnext', 'compile:icons:esnext', 'compile:sass:esnext', callback );
  102. } );
  103. // Tasks specific for testing under node.
  104. gulp.task( 'compile:clean:js:cjs', () => compiler.clean.js( { formats: [ 'cjs' ] } ) );
  105. gulp.task( 'compile:js:cjs', [ 'compile:clean:js:cjs' ], () => compiler.compile.js( { formats: [ 'cjs' ] } ) );
  106. // Tasks specific for testing releases.
  107. gulp.task( 'test:samples:local', () => compiler.compile.tests.local() );
  108. gulp.task( 'test:samples:bundled', [ 'compile:samples' ], () => compiler.compile.tests.bundled() );
  109. gulp.task( 'test:samples', [ 'test:samples:local', 'test:samples:bundled' ] );
  110. // Tasks specific for building editors for testing releases.
  111. gulp.task( 'compile:samples:clean', ckeditor5DevBundle.cleanSamples );
  112. gulp.task( 'compile:samples',
  113. [
  114. 'compile:samples:clean',
  115. 'compile:js:esnext',
  116. 'compile:themes:esnext'
  117. ],
  118. ckeditor5DevBundle.buildEditorsForSamples
  119. );
  120. // Docs.
  121. const docsBuilder = ckeditor5DevCompiler.docs;
  122. gulp.task( 'docs', [ 'compile:js:esnext' ], docsBuilder.buildDocs );