tasks.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. const gulp = require( 'gulp' );
  7. const minimist = require( 'minimist' );
  8. const statusTask = require( './tasks/status' );
  9. const initTask = require( './tasks/init' );
  10. const installTask = require( './tasks/install' );
  11. const pluginCreateTask = require( './tasks/create-package' );
  12. const updateTask = require( './tasks/update' );
  13. const relinkTask = require( './tasks/relink' );
  14. const log = require( './utils/log' );
  15. const gutil = require( 'gulp-util' );
  16. module.exports = ( config ) => {
  17. const ckeditor5Path = process.cwd();
  18. const packageJSON = require( '../../../package.json' );
  19. // Configure logging.
  20. log.configure(
  21. ( msg ) => gutil.log( msg ),
  22. ( msg ) => gutil.log( gutil.colors.red( msg ) )
  23. );
  24. const tasks = {
  25. updateRepositories() {
  26. const options = minimist( process.argv.slice( 2 ), {
  27. boolean: [ 'npm-update' ],
  28. default: {
  29. 'npm-update': false
  30. }
  31. } );
  32. return updateTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'npm-update' ] );
  33. },
  34. checkStatus() {
  35. return statusTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
  36. },
  37. initRepository() {
  38. return initTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
  39. },
  40. createPackage( done ) {
  41. return pluginCreateTask( ckeditor5Path, config.WORKSPACE_DIR )
  42. .then( done )
  43. .catch( ( error ) => done( error ) );
  44. },
  45. relink() {
  46. return relinkTask( ckeditor5Path, packageJSON, config.WORKSPACE_DIR );
  47. },
  48. installPackage() {
  49. const options = minimist( process.argv.slice( 2 ), {
  50. string: [ 'package' ],
  51. default: {
  52. plugin: ''
  53. }
  54. } );
  55. if ( options.package ) {
  56. return installTask( ckeditor5Path, config.WORKSPACE_DIR, options.package );
  57. } else {
  58. throw new Error( 'Please provide a package to install: gulp dev-install --plugin <path|GitHub URL|name>' );
  59. }
  60. },
  61. register() {
  62. gulp.task( 'init', tasks.initRepository );
  63. gulp.task( 'create-package', tasks.createPackage );
  64. gulp.task( 'update', tasks.updateRepositories );
  65. gulp.task( 'pull', tasks.updateRepositories );
  66. gulp.task( 'status', tasks.checkStatus );
  67. gulp.task( 'st', tasks.checkStatus );
  68. gulp.task( 'relink', tasks.relink );
  69. gulp.task( 'install', tasks.installPackage );
  70. }
  71. };
  72. return tasks;
  73. };