dev-update.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. const tools = require( './tools' );
  7. const git = require( './git' );
  8. const path = require( 'path' );
  9. /**
  10. * 1. Get CKEditor5 dependencies from package.json file.
  11. * 2. Scan workspace for repositories that match dependencies from package.json file.
  12. * 3. Run GIT pull command on each repository found.
  13. *
  14. * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  15. * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
  16. * @param {String} workspaceRoot Relative path to workspace root.
  17. * @param {Function} writeln Function for log output.
  18. * @param {Function} writeError Function of error output
  19. */
  20. module.exports = ( ckeditor5Path, packageJSON, workspaceRoot, writeln, writeError ) => {
  21. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  22. // Get all CKEditor dependencies from package.json.
  23. const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
  24. if ( dependencies ) {
  25. const directories = tools.getCKE5Directories( workspaceAbsolutePath );
  26. if ( directories.length ) {
  27. for ( let dependency in dependencies ) {
  28. const repositoryURL = dependencies[ dependency ];
  29. const urlInfo = git.parseRepositoryUrl( repositoryURL );
  30. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  31. // Check if repository's directory already exists.
  32. if ( directories.indexOf( dependency ) > -1 ) {
  33. try {
  34. writeln( `Updating ${ repositoryURL }...` );
  35. git.pull( repositoryAbsolutePath, urlInfo.branch );
  36. } catch ( error ) {
  37. writeError( error );
  38. }
  39. }
  40. }
  41. } else {
  42. writeln( 'No CKEditor5 plugins in development mode.' );
  43. }
  44. } else {
  45. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  46. }
  47. };