8
0

inquiries.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';
  2. var inquirer = require( 'inquirer' );
  3. var path = require( 'path' );
  4. var fs = require( 'fs' );
  5. var DEFAULT_PLUGIN_NAME_PREFIX = 'ckeditor5-plugin-';
  6. var DEFAULT_GITHUB_URL_PREFIX = 'ckeditor/';
  7. module.exports = {
  8. getPluginName: function( data ) {
  9. return new Promise( function( resolve ) {
  10. inquirer.prompt( [ {
  11. name: 'pluginName',
  12. message: 'Enter plugin name without ' + DEFAULT_PLUGIN_NAME_PREFIX + ' prefix:',
  13. validate: function( input ) {
  14. var regexp = /^[a-zA-Z0-9-_]+$/;
  15. return regexp.test( input ) ? true : 'Please provide a valid plugin name.';
  16. },
  17. default: data.pluginName ? data.pluginName : null
  18. } ], function( answers ) {
  19. data.pluginName = DEFAULT_PLUGIN_NAME_PREFIX + answers.pluginName
  20. resolve( data );
  21. } );
  22. } );
  23. },
  24. // Ask for initial version of the plugin.
  25. getPluginVersion: function( data ) {
  26. return new Promise( function( resolve ) {
  27. inquirer.prompt( [ {
  28. name: 'version',
  29. message: 'Enter plugin\'s initial version:',
  30. default: data.version ? data.version : ''
  31. } ], function( answers ) {
  32. data.version = answers.version;
  33. resolve( data );
  34. } );
  35. } );
  36. },
  37. // Ask for the location of the repository.
  38. getRepositoryLocation: function( data ) {
  39. var defaultLocation = path.join( data.cwd, '..', data.pluginName );
  40. return new Promise( function( resolve ) {
  41. inquirer.prompt( [ {
  42. name: 'path',
  43. message: 'Enter repository location:',
  44. default: defaultLocation,
  45. validate: function( input ) {
  46. var status;
  47. try {
  48. status = fs.statSync( input );
  49. } catch ( e ) {}
  50. return status && ( status.isFile() || status.isDirectory() ) ? 'Repository location already exists.' : true;
  51. }
  52. } ], function( answers ) {
  53. data.repositoryLocation = answers.path;
  54. resolve( data );
  55. } );
  56. } );
  57. },
  58. // Ask for GitHub Url.
  59. getPluginGitHubUrl: function( data ) {
  60. var defaultGitHubUrl = DEFAULT_GITHUB_URL_PREFIX + data.pluginName;
  61. return new Promise( function( resolve ) {
  62. inquirer.prompt( [ {
  63. name: 'gitHubUrl',
  64. message: 'Enter plugin\'s GitHub URL:',
  65. default: defaultGitHubUrl
  66. } ], function( answers ) {
  67. data.gitHubUrl = answers.gitHubUrl;
  68. resolve( data );
  69. } );
  70. } );
  71. }
  72. };