dev-update.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 {Boolean} runNpmUpdate When set to true `npm update` will be executed inside each plugin repository
  19. * and inside CKEditor 5 repository.
  20. */
  21. module.exports = ( ckeditor5Path, packageJSON, workspaceRoot, writeln, runNpmUpdate ) => {
  22. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  23. // Get all CKEditor dependencies from package.json.
  24. const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
  25. if ( dependencies ) {
  26. const directories = tools.getCKE5Directories( workspaceAbsolutePath );
  27. if ( directories.length ) {
  28. for ( let dependency in dependencies ) {
  29. const repositoryURL = dependencies[ dependency ];
  30. const urlInfo = git.parseRepositoryUrl( repositoryURL );
  31. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  32. // Check if repository's directory already exists.
  33. if ( directories.indexOf( urlInfo.name ) > -1 ) {
  34. writeln( `Checking out ${ urlInfo.name } to ${ urlInfo.branch }...` );
  35. git.checkout( repositoryAbsolutePath, urlInfo.branch );
  36. writeln( `Pulling changes to ${ urlInfo.name }...` );
  37. git.pull( repositoryAbsolutePath, urlInfo.branch );
  38. if ( runNpmUpdate ) {
  39. writeln( `Running "npm update" in ${ urlInfo.name }...` );
  40. tools.npmUpdate( repositoryAbsolutePath );
  41. }
  42. }
  43. }
  44. if ( runNpmUpdate ) {
  45. writeln( `Running "npm update" in CKEditor5 repository...` );
  46. tools.npmUpdate( ckeditor5Path );
  47. }
  48. } else {
  49. writeln( 'No CKEditor5 plugins in development mode.' );
  50. }
  51. } else {
  52. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  53. }
  54. };