8
0

dev-plugin-create.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 {String} workspaceRoot Relative path to workspace root.
  25. * @param {Function} writeln Function for log output.
  26. * @returns {Promise} Returns promise fulfilled after task is done.
  27. */
  28. module.exports = ( ckeditor5Path, workspaceRoot, writeln ) => {
  29. const workspaceAbsolutePath = path.join( ckeditor5Path, 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( `Copying template files to ${ repositoryPath }...` );
  49. tools.copyTemplateFiles( repositoryPath );
  50. writeln( `Updating package.json files...` );
  51. tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
  52. json.name = pluginName;
  53. json.version = pluginVersion;
  54. return json;
  55. } );
  56. tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
  57. if ( !json.dependencies ) {
  58. json.dependencies = {};
  59. }
  60. json.dependencies[ pluginName ] = gitHubUrl;
  61. return json;
  62. } );
  63. writeln( `Creating initial commit...` );
  64. git.initialCommit( pluginName, repositoryPath );
  65. writeln( `Linking ${ pluginName } to node_modules...` );
  66. tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
  67. writeln( `Running npm install in ${ pluginName }.` );
  68. tools.npmInstall( repositoryPath );
  69. writeln( `Installing Git hooks in ${ pluginName }.` );
  70. tools.installGitHooks( repositoryPath );
  71. } );
  72. };