8
0

dev-plugin-create.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @license Copyright (c) 2003-2016, 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. Copy template files.
  18. * 6. Update package.json file in new plugin's repository.
  19. * 7. Update package.json file in CKEditor5 repository.
  20. * 8. Create initial commit.
  21. * 9. Link new plugin.
  22. * 10. Call `npm install` in plugin repository.
  23. * 11. Install Git hooks in plugin repository.
  24. *
  25. * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  26. * @param {String} workspaceRoot Relative path to workspace root.
  27. * @param {Function} writeln Function for log output.
  28. * @returns {Promise} Returns promise fulfilled after task is done.
  29. */
  30. module.exports = ( ckeditor5Path, workspaceRoot, writeln ) => {
  31. const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
  32. let pluginName;
  33. let repositoryPath;
  34. let pluginVersion;
  35. let gitHubUrl;
  36. return inquiries.getPluginName()
  37. .then( result => {
  38. pluginName = result;
  39. repositoryPath = path.join( workspaceAbsolutePath, pluginName );
  40. return inquiries.getPluginVersion();
  41. } )
  42. .then( result => {
  43. pluginVersion = result;
  44. return inquiries.getPluginGitHubUrl( pluginName );
  45. } )
  46. .then( result => {
  47. gitHubUrl = result;
  48. writeln( `Initializing repository ${ repositoryPath }...` );
  49. git.initializeRepository( repositoryPath );
  50. writeln( `Copying template files to ${ repositoryPath }...` );
  51. tools.copyTemplateFiles( repositoryPath );
  52. writeln( `Updating package.json files...` );
  53. tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
  54. json.name = pluginName;
  55. json.version = pluginVersion;
  56. return json;
  57. } );
  58. tools.updateJSONFile( path.join( ckeditor5Path, 'package.json' ), ( json ) => {
  59. if ( !json.dependencies ) {
  60. json.dependencies = {};
  61. }
  62. json.dependencies[ pluginName ] = gitHubUrl;
  63. return json;
  64. } );
  65. writeln( `Creating initial commit...` );
  66. git.initialCommit( pluginName, repositoryPath );
  67. writeln( `Linking ${ pluginName } to node_modules...` );
  68. tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
  69. writeln( `Running npm install in ${ pluginName }.` );
  70. tools.npmInstall( repositoryPath );
  71. writeln( `Installing Git hooks in ${ pluginName }.` );
  72. tools.installGitHooks( repositoryPath );
  73. } );
  74. };