dev-plugin-install.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 inquiries = require( './inquiries' );
  7. const git = require( './git' );
  8. const tools = require( './tools' );
  9. const path = require( 'path' );
  10. /**
  11. * 1. Ask for plugin name.
  12. * 2. Ask for GitHub URL.
  13. * 3. Clone repository from provided GitHub URL.
  14. * 4. Checkout repository to provided branch (or master if no branch is provided).
  15. * 5. Update package.json file in CKEditor5 repository.
  16. * 6. Link new plugin.
  17. * 7. Call `npm install` in plugin repository.
  18. * 8. Install Git hooks in plugin repository.
  19. *
  20. * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  21. * @param {String} workspaceRoot Relative path to workspace root.
  22. * @param {Function} writeln Function for log output.
  23. * @returns {Promise} Returns promise fulfilled after task is done.
  24. */
  25. module.exports = ( ckeditor5Path, workspaceRoot, writeln ) => {
  26. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  27. let pluginName;
  28. let repositoryPath;
  29. let gitHubUrl;
  30. return inquiries.getPluginName()
  31. .then( result => {
  32. pluginName = result;
  33. repositoryPath = path.join( workspaceAbsolutePath, pluginName );
  34. return inquiries.getPluginGitHubUrl( pluginName );
  35. } )
  36. .then( result => {
  37. gitHubUrl = result;
  38. let urlInfo = git.parseRepositoryUrl( gitHubUrl );
  39. writeln( `Clonning ${ gitHubUrl }...` );
  40. git.cloneRepository( urlInfo, workspaceAbsolutePath );
  41. writeln( `Checking out ${ gitHubUrl } to ${ urlInfo.branch }...` );
  42. git.checkout( repositoryPath, urlInfo.branch );
  43. writeln( `Updating package.json files...` );
  44. tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
  45. if ( !json.dependencies ) {
  46. json.dependencies = {};
  47. }
  48. json.dependencies[ pluginName ] = gitHubUrl;
  49. return json;
  50. } );
  51. writeln( `Linking ${ pluginName } to node_modules...` );
  52. tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
  53. writeln( `Running npm install in ${ pluginName }.` );
  54. tools.npmInstall( repositoryPath );
  55. writeln( `Installing GIT hooks in ${ pluginName }.` );
  56. tools.installGitHooks( repositoryPath );
  57. } );
  58. };