create.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. var inquiries = require( './inquiries' );
  3. var common = require( './common' );
  4. var path = require( 'path' );
  5. var tools = require( '../utils/tools' );
  6. module.exports = function( grunt, done ) {
  7. var data = {
  8. grunt: grunt,
  9. cwd: process.cwd(),
  10. pluginName: '',
  11. repositoryLocation: '',
  12. gitHubUrl: '',
  13. version: '0.0.1'
  14. };
  15. inquiries.getPluginName( data )
  16. .then( inquiries.getRepositoryLocation )
  17. .then( inquiries.getPluginVersion )
  18. .then( inquiries.getPluginGitHubUrl )
  19. .then( createRepository )
  20. .then( updatePluginPackageJSON )
  21. .then( common.updatePackageJson )
  22. .then( common.linkPlugin )
  23. .then( common.commitNewPlugin )
  24. .then( function() {
  25. done();
  26. } ).catch( function( e ) {
  27. done( e );
  28. } );
  29. };
  30. // Updates plugin package.json by adding name of the plugin and version.
  31. function updatePluginPackageJSON( data ) {
  32. var packageJSONPath = path.join( data.repositoryLocation, 'package.json' );
  33. data.grunt.log.writeln( 'Updating plugin\'s package.json...' );
  34. return new Promise( function( resolve ) {
  35. common.updateJSONFile( packageJSONPath, function( json ) {
  36. json.name = data.pluginName;
  37. json.version = data.version;
  38. return json;
  39. } ).then( function() {
  40. resolve( data );
  41. } );
  42. } );
  43. }
  44. // Initializes git repository and merges ckeditor5 boilerplate into master branch.
  45. function createRepository( data ) {
  46. data.grunt.log.writeln( 'Initializing plugin repository...' );
  47. return new Promise( function( resolve ) {
  48. var repositoryLocation = data.repositoryLocation;
  49. var initializeRepoCommands = [
  50. 'git init ' + repositoryLocation,
  51. 'cd ' + repositoryLocation,
  52. 'git remote add boilerplate git@github.com:ckeditor/ckeditor-boilerplate.git',
  53. 'git fetch boilerplate ckeditor5',
  54. 'git merge boilerplate/ckeditor5'
  55. ];
  56. tools.shExec( initializeRepoCommands.join( ' && ' ) );
  57. resolve( data );
  58. } );
  59. }