Home Manual Reference Source

src/services/cli/cliSHTranspile.js

  1. const { provider } = require('jimple');
  2. const CLICommand = require('../../abstracts/cliCommand');
  3. /**
  4. * This is a private command the shell script executes in order to transpile a target.
  5. * @extends {CLICommand}
  6. */
  7. class CLISHTranspileCommand extends CLICommand {
  8. /**
  9. * Class constructor.
  10. * @param {Builder} builder To copy the target files.
  11. */
  12. constructor(builder) {
  13. super();
  14. /**
  15. * A local reference for the `builder` service.
  16. * @type {Builder}
  17. */
  18. this.builder = builder;
  19. /**
  20. * The instruction needed to trigger the command.
  21. * @type {string}
  22. */
  23. this.command = 'sh-transpile-target [target]';
  24. /**
  25. * A description of the command, just to follow the interface as the command won't show up on
  26. * the help interface.
  27. * @type {string}
  28. */
  29. this.description = 'Transpile a target code if needed';
  30. this.addOption(
  31. 'type',
  32. '-t, --type [type]',
  33. 'Which build type: development (default) or production',
  34. 'development'
  35. );
  36. /**
  37. * Hide the command from the help interface.
  38. * @type {boolean}
  39. */
  40. this.hidden = true;
  41. }
  42. /**
  43. * Handle the execution of the command and copies a target files.
  44. * @param {string} target The name of the target.
  45. * @param {Command} command The executed command (sent by `commander`).
  46. * @param {Object} options The command options.
  47. * @param {string} options.type The type of build.
  48. */
  49. handle(target, command, options) {
  50. return this.builder.transpileTarget(target, options.type);
  51. }
  52. }
  53. /**
  54. * The service provider that once registered on the app container will set an instance of
  55. * `CLISHTranspileCommand` as the `cliSHTranspileCommand` service.
  56. * @example
  57. * // Register it on the container
  58. * container.register(cliSHTranspileCommand);
  59. * // Getting access to the service instance
  60. * const cliSHTranspileCommand = container.get('cliSHTranspileCommand');
  61. * @type {Provider}
  62. */
  63. const cliSHTranspileCommand = provider((app) => {
  64. app.set('cliSHTranspileCommand', () => new CLISHTranspileCommand(app.get('builder')));
  65. });
  66.  
  67. module.exports = {
  68. CLISHTranspileCommand,
  69. cliSHTranspileCommand,
  70. };