8
0

dev-init.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. var tools = require( './tools' );
  7. var git = require( './git' );
  8. var path = require( 'path' );
  9. /**
  10. * 1. Get CKEditor5 dependencies from package.json file.
  11. * 2. Check if any of the repositories are already present in the workspace.
  12. * 2.1. If repository is present in the workspace, check it out to desired branch if one is provided.
  13. * 2.2. If repository is not present in the workspace, clone it and checkout to desired branch if one is provided.
  14. * 3. Link new repository to node_modules. (do not use npm link, use standard linking instead)
  15. */
  16. module.exports = ( ckeditor5Path, packageJSON, options, writeln, writeError ) => {
  17. const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
  18. // Get all CKEditor dependencies from package.json.
  19. const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
  20. if ( dependencies ) {
  21. const directories = tools.getCKE5Directories( workspaceAbsolutePath );
  22. for ( let dependency in dependencies ) {
  23. const repositoryURL = dependencies[ dependency ];
  24. const urlInfo = git.parseRepositoryUrl( repositoryURL );
  25. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  26. // Check if repository's directory already exists.
  27. if ( directories.indexOf( dependency ) === -1 ) {
  28. try {
  29. writeln( `Clonning ${ repositoryURL }...` );
  30. git.cloneRepository( urlInfo, workspaceAbsolutePath );
  31. } catch ( error ) {
  32. writeError( error );
  33. }
  34. }
  35. // Check out proper branch.
  36. try {
  37. writeln( `Checking out ${ repositoryURL } to ${ urlInfo.branch }...` );
  38. git.checkout( repositoryAbsolutePath, urlInfo.branch );
  39. } catch ( error ) {
  40. writeError( error );
  41. }
  42. // Link plugin.
  43. try {
  44. writeln( `Linking ${ repositoryURL }...` );
  45. tools.linkDirectories( repositoryAbsolutePath, path.join( ckeditor5Path, 'node_modules' , dependency ) );
  46. } catch ( error ) {
  47. writeError( error );
  48. }
  49. }
  50. } else {
  51. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  52. }
  53. };