dev-relink.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. for ( let dependency in dependencies ) {
  26. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  27. const repositoryURL = dependencies[ dependency ];
  28. // Check if repository's directory exists.
  29. if ( directories.indexOf( dependency ) > -1 ) {
  30. try {
  31. writeln( `Linking ${ repositoryURL }...` );
  32. tools.linkDirectories( repositoryAbsolutePath, path.join( ckeditor5Path, 'node_modules' , dependency ) );
  33. } catch ( error ) {
  34. writeError( error );
  35. }
  36. }
  37. }
  38. } else {
  39. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  40. }
  41. };