8
0

build.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* jshint node: true, esnext: true */
  2. 'use strict';
  3. const KNOWN_OPTIONS = {
  4. build: {
  5. string: [
  6. 'formats'
  7. ],
  8. boolean: [
  9. 'watch'
  10. ],
  11. default: {
  12. formats: 'amd',
  13. watch: false
  14. }
  15. }
  16. };
  17. const path = require( 'path' );
  18. const gulp = require( 'gulp' );
  19. const del = require( 'del' );
  20. const merge = require( 'merge-stream' );
  21. const gulpMirror = require( 'gulp-mirror' );
  22. const gutil = require( 'gulp-util' );
  23. const minimist = require( 'minimist' );
  24. const utils = require( './utils' );
  25. const sep = path.sep;
  26. const options = minimist( process.argv.slice( 2 ), KNOWN_OPTIONS[ process.argv[ 2 ] ] );
  27. module.exports = ( config ) => {
  28. const distDir = path.join( config.ROOT_DIR, config.DIST_DIR );
  29. const tasks = {
  30. clean() {
  31. return del( distDir );
  32. },
  33. src: {
  34. all( watch ) {
  35. return merge( tasks.src.main( watch ), tasks.src.ckeditor5( watch ), tasks.src.modules( watch ) );
  36. },
  37. main( watch ) {
  38. return utils.src( config.ROOT_DIR, 'ckeditor.js', watch );
  39. },
  40. ckeditor5( watch ) {
  41. return utils.src( config.ROOT_DIR, 'src/**/*.js', watch )
  42. .pipe( utils.wrapCKEditor5Module() );
  43. },
  44. modules( watch ) {
  45. const modulePathPattern = new RegExp( `node_modules${ sep }(ckeditor5-[^${ sep }]+)${ sep }src` );
  46. return utils.src( config.ROOT_DIR, 'node_modules/ckeditor5-*/src/**/*.js', watch )
  47. .pipe( utils.unpackModules( modulePathPattern ) );
  48. }
  49. }
  50. };
  51. gulp.task( 'build:clean', tasks.clean );
  52. gulp.task( 'build', [ 'build:clean' ], () => {
  53. const formats = options.formats.split( ',' );
  54. const codeStream = tasks.src.all( options.watch )
  55. .on( 'data', ( file ) => {
  56. gutil.log( `Processing '${ gutil.colors.cyan( file.path ) }'...` );
  57. } );
  58. const formatPipes = formats.reduce( utils.addFormat( distDir ), [] );
  59. return codeStream
  60. .pipe( gulpMirror.apply( null, formatPipes ) );
  61. } );
  62. return tasks;
  63. };