dev-relink.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 path = require( 'path' );
  8. /**
  9. * 1. Get CKEditor5 dependencies from package.json file.
  10. * 2. Scan workspace for repositories that match dependencies from package.json file.
  11. * 3. Link repositories to node_modules in CKEditor5 repository.
  12. *
  13. * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  14. * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
  15. * @param {String} workspaceRoot Relative path to workspace root.
  16. * @param {Function} writeln Function for log output.
  17. * @param {Function} writeError Function of error output
  18. */
  19. module.exports = ( ckeditor5Path, packageJSON, workspaceRoot, writeln, writeError ) => {
  20. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  21. // Get all CKEditor dependencies from package.json.
  22. const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
  23. if ( dependencies ) {
  24. const directories = tools.getCKE5Directories( workspaceAbsolutePath );
  25. if ( directories.length ) {
  26. for ( let dependency in dependencies ) {
  27. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  28. const repositoryURL = dependencies[ dependency ];
  29. // Check if repository's directory exists.
  30. if ( directories.indexOf( dependency ) > -1 ) {
  31. try {
  32. writeln( `Linking ${ repositoryURL }...` );
  33. tools.linkDirectories( repositoryAbsolutePath, path.join( ckeditor5Path, 'node_modules', dependency ) );
  34. } catch ( error ) {
  35. writeError( error );
  36. }
  37. }
  38. }
  39. } else {
  40. writeln( 'No CKEditor5 plugins in development mode.' );
  41. }
  42. } else {
  43. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  44. }
  45. };