8
0

dev-plugin-create.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 new plugin name.
  12. * 2. Ask for initial version.
  13. * 3. Ask for GitHub URL.
  14. * 4. Initialize repository
  15. * 4.1. Initialize GIT repository.
  16. * 4.2. Fetch and merge boilerplate project.
  17. * 5. Update package.json file in new plugin's repository.
  18. * 6. Update package.json file in CKEditor5 repository.
  19. * 7. Link new plugin.
  20. * 8. Call `npm install` in plugin repository.
  21. * 9. Install Git hooks in plugin repository.
  22. *
  23. * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  24. * @param {Object} options grunt options.
  25. * @param {Function} writeln Function for log output.
  26. * @returns {Promise} Returns promise fulfilled after task is done.
  27. */
  28. module.exports = ( ckeditor5Path, options, writeln ) => {
  29. const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
  30. let pluginName;
  31. let repositoryPath;
  32. let pluginVersion;
  33. let gitHubUrl;
  34. return inquiries.getPluginName()
  35. .then( result => {
  36. pluginName = result;
  37. repositoryPath = path.join( workspaceAbsolutePath, pluginName );
  38. return inquiries.getPluginVersion();
  39. } )
  40. .then( result => {
  41. pluginVersion = result;
  42. return inquiries.getPluginGitHubUrl( pluginName );
  43. } )
  44. .then( result => {
  45. gitHubUrl = result;
  46. writeln( `Initializing repository ${ repositoryPath }...` );
  47. git.initializeRepository( repositoryPath );
  48. writeln( `Updating package.json files...` );
  49. tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
  50. json.name = pluginName;
  51. json.version = pluginVersion;
  52. return json;
  53. } );
  54. tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
  55. if ( !json.dependencies ) {
  56. json.dependencies = {};
  57. }
  58. json.dependencies[ pluginName ] = gitHubUrl;
  59. return json;
  60. } );
  61. writeln( `Linking ${ pluginName } to node_modules...` );
  62. tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
  63. writeln( `Running npm install in ${ pluginName }.` );
  64. tools.npmInstall( repositoryPath );
  65. writeln( `Installing GIT hooks in ${ pluginName }.` );
  66. tools.installGitHooks( repositoryPath );
  67. } );
  68. };