autoforce 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.autoforce.json +8 -4
  2. package/CHANGELOG.md +20 -1
  3. package/lib/auto.js +50 -64
  4. package/lib/helpers/class.d.ts +1 -0
  5. package/lib/helpers/class.js +74 -80
  6. package/lib/helpers/connect.js +199 -213
  7. package/lib/helpers/context.d.ts +6 -3
  8. package/lib/helpers/context.js +279 -225
  9. package/lib/helpers/github-graphql.js +90 -113
  10. package/lib/helpers/github-project-graphql.js +100 -132
  11. package/lib/helpers/gitlab-graphql.js +68 -104
  12. package/lib/helpers/lwc.js +42 -48
  13. package/lib/helpers/metadata.js +1 -2
  14. package/lib/helpers/object.js +47 -55
  15. package/lib/helpers/openai.js +10 -22
  16. package/lib/helpers/taskFunctions.js +330 -386
  17. package/lib/helpers/tasks.d.ts +3 -6
  18. package/lib/helpers/tasks.js +132 -147
  19. package/lib/helpers/template.d.ts +9 -5
  20. package/lib/helpers/template.js +31 -18
  21. package/lib/helpers/util.d.ts +5 -6
  22. package/lib/helpers/util.js +131 -187
  23. package/models/dev/models.json +19 -0
  24. package/models/doc/models.json +9 -0
  25. package/models/git/models.json +9 -0
  26. package/models/project/models.json +9 -0
  27. package/package.json +16 -12
  28. package/commands/modelC/new/issue.json +0 -24
  29. package/commands/models.json +0 -18
  30. package/templates/modelB/openIssues.bash +0 -4
  31. package/templates/modelB/viewIssue.bash +0 -8
  32. package/templates/models.json +0 -12
  33. /package/{commands/modelA → models/dev/npm}/subtasks/checkout-branch.json +0 -0
  34. /package/{commands/modelA → models/dev/npm}/subtasks/create-pull.json +0 -0
  35. /package/{commands/modelC → models/dev/npm}/subtasks/pack.json +0 -0
  36. /package/{commands/modelA → models/dev/npm}/subtasks/publish-branch.json +0 -0
  37. /package/{commands/modelA → models/dev/npm}/tasks/cancel.json +0 -0
  38. /package/{commands/modelA → models/dev/npm}/tasks/finish.json +0 -0
  39. /package/{commands/modelC → models/dev/npm}/tasks/list.json +0 -0
  40. /package/{commands/modelC → models/dev/npm}/tasks/publish.json +0 -0
  41. /package/{commands/modelC → models/dev/npm}/tasks/start.json +0 -0
  42. /package/{commands/modelA → models/dev/npm}/tasks/stop.json +0 -0
  43. /package/{commands/modelA → models/dev/npm}/tasks/switch.json +0 -0
  44. /package/{commands/modelA → models/dev/npm}/tasks/view.json +0 -0
  45. /package/{commands/modelA → models/dev/scratchs}/subtasks/create-scratch.json +0 -0
  46. /package/{commands/modelA → models/dev/scratchs}/subtasks/deploy-code.json +0 -0
  47. /package/{commands/modelA → models/dev/scratchs}/subtasks/drop-scratch.json +0 -0
  48. /package/{commands/modelA → models/dev/scratchs}/subtasks/package-code.json +0 -0
  49. /package/{commands/modelA → models/dev/scratchs}/subtasks/validate-code.json +0 -0
  50. /package/{commands/modelA → models/dev/scratchs}/subtasks/validate-scratch.json +0 -0
  51. /package/{commands/modelC → models/dev/scratchs}/tasks/cancel.json +0 -0
  52. /package/{commands/modelA → models/dev/scratchs}/tasks/deploy.json +0 -0
  53. /package/{commands/modelC → models/dev/scratchs}/tasks/finish.json +0 -0
  54. /package/{commands/modelA → models/dev/scratchs}/tasks/rollback.json +0 -0
  55. /package/{commands/modelA → models/dev/scratchs}/tasks/start.json +0 -0
  56. /package/{commands/modelC → models/dev/scratchs}/tasks/stop.json +0 -0
  57. /package/{commands/modelC → models/dev/scratchs}/tasks/switch.json +0 -0
  58. /package/{commands/modelA → models/doc/processes}/new/process.json +0 -0
  59. /package/{commands/modelA/subtasks → models/doc/processes/subtask}/update-documentation.json +0 -0
  60. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-all.md +0 -0
  61. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-diagrama.md +0 -0
  62. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-inner.md +0 -0
  63. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-metodos.md +0 -0
  64. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-public.md +0 -0
  65. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-referencias.md +0 -0
  66. /package/{templates/modelA → models/doc/processes/templates}/dictionary/class.md +0 -0
  67. /package/{templates/modelA → models/doc/processes/templates}/dictionary/classes.md +0 -0
  68. /package/{templates/modelA → models/doc/processes/templates}/dictionary/object.md +0 -0
  69. /package/{templates/modelA → models/doc/processes/templates}/dictionary/objects.md +0 -0
  70. /package/{templates/modelA → models/doc/processes/templates}/intro.md +0 -0
  71. /package/{templates/modelA → models/doc/processes/templates}/process.md +0 -0
  72. /package/{commands/modelC/subtasks → models/git/githubflow/subtask}/checkout-branch.json +0 -0
  73. /package/{commands/modelC/subtasks → models/git/githubflow/subtask}/create-pull.json +0 -0
  74. /package/{commands/modelC/subtasks → models/git/githubflow/subtask}/publish-branch.json +0 -0
  75. /package/{commands/modelA → models/project/github-releases}/new/issue.json +0 -0
  76. /package/{commands/modelA/tasks → models/project/github-releases/task}/list.json +0 -0
  77. /package/{commands/modelC/tasks → models/project/github-releases/task}/view.json +0 -0
  78. /package/{templates/modelB → models/project/github-releases/templates}/changelog.md +0 -0
  79. /package/{templates/modelA → models/project/github-releases/templates}/openIssues.bash +0 -0
  80. /package/{templates/modelA → models/project/github-releases/templates}/viewIssue.bash +0 -0
@@ -1,14 +1,5 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { executeShell, getOrganizationObject, getCurrentOrganization, getBranchName, getTargetOrg } from "./taskFunctions.js";
11
- import { convertNameToKey, convertKeyToName, getFiles, filterDirectory, addNewItems, CONFIG_FILE, createConfigurationFile, getDataFromPackage } from "./util.js";
2
+ import { convertNameToKey, convertKeyToName, getFiles, filterDirectory, addNewItems, CONFIG_FILE, createConfigurationFile } from "./util.js";
12
3
  import { GitHubApi } from "./github-graphql.js";
13
4
  import { GitHubProjectApi } from "./github-project-graphql.js";
14
5
  import { GitLabApi } from "./gitlab-graphql.js";
@@ -37,65 +28,141 @@ export var ProjectServices;
37
28
  })(ProjectServices || (ProjectServices = {}));
38
29
  const filterProcesses = (fullPath) => fullPath.endsWith(".md"); // && !fullPath.endsWith("intro.md")
39
30
  const ISSUES_TYPES = [{ value: 'feature', title: 'feature' }, { value: 'bug', title: 'bug' }, { value: 'documentation', title: 'documentation' }, { value: 'automation', title: 'automation' }];
31
+ function searchInFolderHierarchy(element, parentFolder) {
32
+ if (fs.existsSync(`${parentFolder}/${element}`)) {
33
+ return `${parentFolder}/${element}`;
34
+ }
35
+ else {
36
+ const lastIndex = parentFolder.lastIndexOf('/');
37
+ if (lastIndex !== -1) {
38
+ const newParentFolder = parentFolder.substring(0, lastIndex);
39
+ if (newParentFolder !== '') {
40
+ return searchInFolderHierarchy(element, newParentFolder);
41
+ }
42
+ }
43
+ }
44
+ return '';
45
+ }
46
+ function getDataFromPackage() {
47
+ const data = {};
48
+ try {
49
+ const filename = searchInFolderHierarchy("package.json", process.cwd());
50
+ if (!filename) {
51
+ throw new Error("No se encontro el package.json en " + process.cwd());
52
+ }
53
+ const content = fs.readFileSync(filename, "utf8");
54
+ const packageJson = JSON.parse(content);
55
+ if (packageJson.repository) {
56
+ if (packageJson.repository.url) {
57
+ data.repositoryUrl = packageJson.repository.url;
58
+ data.repositoryType = packageJson.repository.type;
59
+ // Ver de sacar repo y owner
60
+ if (data.repositoryUrl) {
61
+ if (data.repositoryUrl.includes("github.com")) {
62
+ const repositoryArray = data.repositoryUrl.split('github.com/');
63
+ [data.repositoryOwner, data.repositoryRepo] = repositoryArray[1].split('/');
64
+ }
65
+ if (data.repositoryUrl.includes("gitlab.com")) {
66
+ const repositoryArray = data.repositoryUrl.split('gitlab.com/');
67
+ [data.repositoryOwner, data.repositoryRepo] = repositoryArray[1].split('/');
68
+ }
69
+ }
70
+ }
71
+ else if (typeof packageJson.repository === 'string') {
72
+ data.repositoryUrl = packageJson.repository;
73
+ const repositoryArray = data.repositoryUrl.split(':');
74
+ data.repositoryType = repositoryArray[0];
75
+ [data.repositoryOwner, data.repositoryRepo] = repositoryArray[1].split('/');
76
+ }
77
+ if (data.repositoryRepo && data.repositoryRepo.endsWith('.git')) {
78
+ data.repositoryRepo = data.repositoryRepo.replace('.git', '');
79
+ }
80
+ }
81
+ }
82
+ catch (error) {
83
+ console.log(error);
84
+ throw new Error(`Verifique que exista y sea valido el package.json`);
85
+ }
86
+ return data;
87
+ }
40
88
  class Context {
89
+ devModel; // Default Model de commands
90
+ gitModel;
91
+ docModel;
92
+ projectModel;
93
+ gitServices = GitServices.None;
94
+ isGitApi = false;
95
+ gitApi;
96
+ version;
97
+ dictionaryFolder = process.cwd() + "/docs";
98
+ options = {};
99
+ projectServices = ProjectServices.None;
100
+ isProjectApi = false;
101
+ projectApi;
102
+ sfInstalled = true;
103
+ sfToken = true;
104
+ branchName;
105
+ issueNumber;
106
+ issueType;
107
+ _process;
108
+ _processesHeader;
109
+ _newIssueNumber;
110
+ _newIssueType;
111
+ newBranchName;
112
+ defaultDias = 7;
113
+ permissionSet;
114
+ issueTitle;
115
+ isVerbose = false;
116
+ _scratch;
117
+ _branchScratch;
118
+ existNewBranch = false;
119
+ _targetOrg;
120
+ // Documentacion
121
+ processes;
122
+ // Ultima salida del shell
123
+ salida = '';
124
+ // Git Repository
125
+ repositoryUrl;
126
+ repositoryType;
127
+ repositoryOwner;
128
+ repositoryRepo;
129
+ // Project Reference
130
+ projectId;
131
+ backlogColumn = 'Todo';
132
+ //Templates especiales
133
+ listFilter = ListFilters.Mios;
134
+ listTemplate = 'openIssues';
41
135
  constructor() {
42
- this.model = 'modelA'; // Default Model de commands
43
- this.modelTemplates = 'modelA'; // Default Model de templates
44
- this.gitServices = GitServices.None;
45
- this.isGitApi = false;
46
- this.options = {};
47
- this.projectServices = ProjectServices.None;
48
- this.isProjectApi = false;
49
- this.sfInstalled = true;
50
- this.sfToken = true;
51
- this.defaultDias = 7;
52
- this.isVerbose = false;
53
- this.existNewBranch = false;
54
- // Ultima salida del shell
55
- this.salida = '';
56
- this.backlogColumn = 'Todo';
57
- //Templates especiales
58
- this.listFilter = ListFilters.Mios;
59
- this.listTemplate = 'openIssues';
60
136
  this.loadConfig();
61
137
  this.loadPackage();
62
138
  }
63
- labels() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- var _a;
66
- const choices = [{ value: '', title: 'Ninguno' }, { value: 'new', title: 'Nuevo' }];
67
- const labels = yield ((_a = this.gitApi) === null || _a === void 0 ? void 0 : _a.getLabels());
68
- if (labels) {
69
- labels.forEach(label => choices.push({ value: label.name, title: label.name }));
70
- }
71
- return choices;
72
- });
139
+ async labels() {
140
+ const choices = [{ value: '', title: 'Ninguno' }, { value: 'new', title: 'Nuevo' }];
141
+ const labels = await this.gitApi?.getLabels();
142
+ if (labels) {
143
+ labels.forEach(label => choices.push({ value: label.name, title: label.name }));
144
+ }
145
+ return choices;
73
146
  }
74
147
  listFilters() {
75
148
  const filters = [{ title: 'Solo mios abiertos', value: ListFilters.Mios, description: 'Busca los issues donde este asignado y esten en state Open' }, { title: 'Por Milestone', value: ListFilters.PorMilestone, description: 'Busca los issues de un deterinado milestone' }, { title: 'Por Label', value: ListFilters.PorLabel, description: 'Busca los issues de un deterinado label' }];
76
149
  return filters;
77
150
  }
78
- milestoneNumbers() {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- var _a;
81
- const choices = [{ value: '', title: 'Ninguno' }];
82
- const milestones = yield ((_a = this.gitApi) === null || _a === void 0 ? void 0 : _a.getMilestones());
83
- if (milestones) {
84
- milestones.forEach(milestone => choices.push({ value: milestone.number, title: milestone.title }));
85
- }
86
- return choices;
87
- });
151
+ async milestoneNumbers() {
152
+ const choices = [{ value: '', title: 'Ninguno' }];
153
+ const milestones = await this.gitApi?.getMilestones();
154
+ if (milestones) {
155
+ milestones.forEach(milestone => choices.push({ value: milestone.number, title: milestone.title }));
156
+ }
157
+ return choices;
88
158
  }
89
- milestones() {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- var _a;
92
- const choices = [{ value: '', title: 'Ninguno' }, { value: 'new', title: 'Nuevo' }];
93
- const milestones = yield ((_a = this.gitApi) === null || _a === void 0 ? void 0 : _a.getMilestones());
94
- if (milestones) {
95
- milestones.forEach(milestone => choices.push({ value: milestone.id, title: milestone.title }));
96
- }
97
- return choices;
98
- });
159
+ async milestones() {
160
+ const choices = [{ value: '', title: 'Ninguno' }, { value: 'new', title: 'Nuevo' }];
161
+ const milestones = await this.gitApi?.getMilestones();
162
+ if (milestones) {
163
+ milestones.forEach(milestone => choices.push({ value: milestone.id, title: milestone.title }));
164
+ }
165
+ return choices;
99
166
  }
100
167
  loadProjectApi() {
101
168
  if (!this.isProjectApi) {
@@ -167,37 +234,35 @@ class Context {
167
234
  this.repositoryOwner = data.repositoryOwner;
168
235
  this.repositoryRepo = data.repositoryRepo;
169
236
  }
170
- loadConfig() {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- if (!fs.existsSync(CONFIG_FILE)) {
173
- logWarning('Bienvenido! La herramienta Autoforce necesita un primer paso de configuracion antes de usarla.');
174
- logWarning('- Podes usar el asistente ejecutando npx autoforce config');
175
- logWarning('- Podes hacerlo manualmente leyendo la documentacion y creando .autoforce.json manualmente en el root del proyecto (https://sebastianclaros.github.io/autoforce/docs/configuracion)');
176
- const answer = yield prompts([
177
- {
178
- type: "confirm",
179
- name: "asistente",
180
- message: "Queres ejecutar el asistente ahora?"
181
- }
182
- ]);
183
- if (answer.asistente) {
184
- yield createConfigurationFile();
185
- return true;
186
- }
187
- return false;
188
- }
189
- const content = fs.readFileSync(CONFIG_FILE, "utf8");
190
- try {
191
- const config = JSON.parse(content);
192
- for (const key in config) {
193
- this.set(key, config[key]);
237
+ async loadConfig() {
238
+ if (!fs.existsSync(CONFIG_FILE)) {
239
+ logWarning('Bienvenido! La herramienta Autoforce necesita un primer paso de configuracion antes de usarla.');
240
+ logWarning('- Podes usar el asistente ejecutando npx autoforce config');
241
+ logWarning('- Podes hacerlo manualmente leyendo la documentacion y creando .autoforce.json manualmente en el root del proyecto (https://sebastianclaros.github.io/autoforce/docs/configuracion)');
242
+ const answer = await prompts([
243
+ {
244
+ type: "confirm",
245
+ name: "asistente",
246
+ message: "Queres ejecutar el asistente ahora?"
194
247
  }
248
+ ]);
249
+ if (answer.asistente) {
250
+ await createConfigurationFile();
251
+ return true;
195
252
  }
196
- catch (_a) {
197
- throw new Error(`Verifique que el ${CONFIG_FILE} sea json valido`);
253
+ return false;
254
+ }
255
+ const content = fs.readFileSync(CONFIG_FILE, "utf8");
256
+ try {
257
+ const config = JSON.parse(content);
258
+ for (const key in config) {
259
+ this.set(key, config[key]);
198
260
  }
199
- return true;
200
- });
261
+ }
262
+ catch {
263
+ throw new Error(`Verifique que el ${CONFIG_FILE} sea json valido`);
264
+ }
265
+ return true;
201
266
  }
202
267
  init() {
203
268
  this.loadProjectApi();
@@ -246,21 +311,21 @@ class Context {
246
311
  config.processes = processes;
247
312
  fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
248
313
  }
249
- catch (_a) {
314
+ catch {
250
315
  throw new Error(`No se pudo guardar la metadata`);
251
316
  }
252
317
  }
253
318
  get processesHeader() {
254
319
  if (!this._processesHeader) {
255
320
  this._processesHeader = {};
256
- const folders = getFiles(process.cwd() + "/docs", filterDirectory, true, ['diccionarios']);
321
+ const folders = getFiles(this.dictionaryFolder, filterDirectory, true, ['diccionarios']);
257
322
  for (const folder of folders) {
258
- const fullpath = `${process.cwd()}/docs/${folder}`;
323
+ const fullpath = `${this.dictionaryFolder}/${folder}`;
259
324
  const filenames = getFiles(fullpath, filterProcesses);
260
325
  for (const filename of filenames) {
261
326
  const header = this.getProcessHeader(fullpath + "/" + filename);
262
327
  if (header.process) {
263
- this._processesHeader[header.process] = Object.assign(Object.assign({}, header), { folder: fullpath, filename });
328
+ this._processesHeader[header.process] = { ...header, folder: fullpath, filename };
264
329
  }
265
330
  }
266
331
  }
@@ -269,7 +334,7 @@ class Context {
269
334
  }
270
335
  // TODO: merge con getProcessFromDocs
271
336
  getProcessMetadata() {
272
- const folders = getFiles(process.cwd() + "/docs", filterDirectory, true, ['diccionarios']);
337
+ const folders = getFiles(this.dictionaryFolder, filterDirectory, true, ['diccionarios']);
273
338
  const retArray = [];
274
339
  for (const folder of folders) {
275
340
  const fullpath = `${process.cwd()}/docs/${folder}`;
@@ -278,14 +343,18 @@ class Context {
278
343
  const header = this.getProcessHeader(fullpath + "/" + process);
279
344
  const processKey = convertNameToKey(header.slug || header.title || process);
280
345
  if (this.processes && this.processes[processKey]) {
281
- retArray.push(Object.assign({ folder, name: convertKeyToName(processKey) }, this.processes[processKey]));
346
+ retArray.push({
347
+ folder,
348
+ name: convertKeyToName(processKey),
349
+ ...this.processes[processKey]
350
+ });
282
351
  }
283
352
  }
284
353
  }
285
354
  return retArray;
286
355
  }
287
356
  getModules() {
288
- return getFiles(process.cwd() + "/docs", filterDirectory, false, ['diccionarios']);
357
+ return getFiles(this.dictionaryFolder, filterDirectory, false, ['diccionarios']);
289
358
  }
290
359
  get modules() {
291
360
  return this.getModules().map(module => { return { value: module, title: module }; });
@@ -299,23 +368,21 @@ class Context {
299
368
  }
300
369
  return this._scratch;
301
370
  }
302
- validate(guards) {
303
- return __awaiter(this, void 0, void 0, function* () {
304
- for (const guard of guards) {
305
- // Chequeo de variables de entorno
306
- if (guard[0] === '$') {
307
- if (!process.env[guard.substring(1)]) {
308
- throw new Error(`La variable de entorno ${guard} no esta configurada.`);
309
- }
371
+ async validate(guards) {
372
+ for (const guard of guards) {
373
+ // Chequeo de variables de entorno
374
+ if (guard[0] === '$') {
375
+ if (!process.env[guard.substring(1)]) {
376
+ throw new Error(`La variable de entorno ${guard} no esta configurada.`);
310
377
  }
311
- else {
312
- const value = yield this.get(guard);
313
- if (!value) {
314
- throw new Error(`No se encontro la variable ${guard} en el contexto. Ejecute yarn auto config o lea el index.md para mas informacion.`);
315
- }
378
+ }
379
+ else {
380
+ const value = await this.get(guard);
381
+ if (!value) {
382
+ throw new Error(`No se encontro la variable ${guard} en el contexto. Ejecute yarn auto config o lea el index.md para mas informacion.`);
316
383
  }
317
384
  }
318
- });
385
+ }
319
386
  }
320
387
  issueFromBranch(branchName) {
321
388
  const branchSplit = branchName.split("/");
@@ -367,31 +434,27 @@ class Context {
367
434
  this.existNewBranch = typeof salida === 'string' && (salida.includes(this.newBranchName));
368
435
  }
369
436
  }
370
- askFornewBranchName() {
371
- return __awaiter(this, void 0, void 0, function* () {
372
- if (!this.newBranchName) {
373
- if (!this.newIssueType) {
374
- this.newIssueType = yield this.askFornewIssueType();
375
- }
376
- if (!this.newIssueNumber) {
377
- this.newIssueNumber = yield this.askFornewIssueNumber();
378
- }
379
- this.setNewBranchName();
437
+ async askFornewBranchName() {
438
+ if (!this.newBranchName) {
439
+ if (!this.newIssueType) {
440
+ this.newIssueType = await this.askFornewIssueType();
380
441
  }
381
- return this.newBranchName;
382
- });
442
+ if (!this.newIssueNumber) {
443
+ this.newIssueNumber = await this.askFornewIssueNumber();
444
+ }
445
+ this.setNewBranchName();
446
+ }
447
+ return this.newBranchName;
383
448
  }
384
- askFornewIssueNumber() {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- const answer = yield prompts([
387
- {
388
- type: "text",
389
- name: "newIssueNumber",
390
- message: "Por favor ingrese el nuevo issueNumber?"
391
- }
392
- ]);
393
- return answer.newIssueNumber;
394
- });
449
+ async askFornewIssueNumber() {
450
+ const answer = await prompts([
451
+ {
452
+ type: "text",
453
+ name: "newIssueNumber",
454
+ message: "Por favor ingrese el nuevo issueNumber?"
455
+ }
456
+ ]);
457
+ return answer.newIssueNumber;
395
458
  }
396
459
  set process(value) {
397
460
  this._process = value;
@@ -413,83 +476,78 @@ class Context {
413
476
  }
414
477
  return this._process;
415
478
  }
416
- askForprocess() {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- if (this.projectApi && !this.issueTitle && this.issueNumber) {
419
- const issue = yield this.projectApi.getIssue(this.issueNumber);
420
- this.issueTitle = issue.title;
421
- }
422
- if (this.issueTitle) {
423
- const process = this.getProcessFromTitle(this.issueTitle);
424
- if (process && this.processesHeader[process]) {
425
- return process;
426
- }
479
+ async askForprocess() {
480
+ if (this.projectApi && !this.issueTitle && this.issueNumber) {
481
+ const issue = await this.projectApi.getIssue(this.issueNumber);
482
+ this.issueTitle = issue.title;
483
+ }
484
+ if (this.issueTitle) {
485
+ const process = this.getProcessFromTitle(this.issueTitle);
486
+ if (process && this.processesHeader[process]) {
487
+ return process;
427
488
  }
428
- const choices = Object.values(this.processesHeader).map(header => {
429
- return { value: header.process, title: header.title };
430
- });
431
- const answer = yield prompts([{
432
- type: "select",
433
- name: "process",
434
- message: "Por favor seleccione el proceso",
435
- choices
436
- }]);
437
- return answer.process;
489
+ }
490
+ const choices = Object.values(this.processesHeader).map(header => {
491
+ return { value: header.process, title: header.title };
438
492
  });
439
- }
440
- askFornewIssueType() {
441
- return __awaiter(this, void 0, void 0, function* () {
442
- const answer = yield prompts([
443
- {
444
- type: "list",
445
- name: "newIssueType",
446
- initial: "feature",
447
- message: "Por favor ingrese el type del issue?",
448
- choices: ISSUES_TYPES
493
+ const answer = await prompts([{
494
+ type: "select",
495
+ name: "process",
496
+ message: "Por favor seleccione el proceso",
497
+ choices
498
+ }]);
499
+ return answer.process;
500
+ }
501
+ async askFornewIssueType() {
502
+ const answer = await prompts([
503
+ {
504
+ type: "list",
505
+ name: "newIssueType",
506
+ initial: "feature",
507
+ message: "Por favor ingrese el type del issue?",
508
+ choices: ISSUES_TYPES
509
+ }
510
+ ]);
511
+ return answer.newIssueType;
512
+ }
513
+ async convertToArrayOfInputs(inputs) {
514
+ let inputsArray = [];
515
+ if (Array.isArray(inputs)) {
516
+ // Si viene los args como ['name1', 'names] lo convierte a [{name: 'name1'}, {name: 'name2'}]
517
+ inputsArray = inputs.map(input => { return { name: input, type: 'text', message: `Por favor ingrese ${input}?` }; });
518
+ }
519
+ else {
520
+ // Si viene args como objeto { name1: {...}, name2: {...}} lo convierte a [{name: name1...}, {name: name2...}]
521
+ for (const key in inputs) {
522
+ if (typeof inputs[key].default === 'string') {
523
+ inputs[key].initial = this.merge(inputs[key].default);
449
524
  }
450
- ]);
451
- return answer.newIssueType;
452
- });
453
- }
454
- convertToArrayOfInputs(inputs) {
455
- return __awaiter(this, void 0, void 0, function* () {
456
- let inputsArray = [];
457
- if (Array.isArray(inputs)) {
458
- // Si viene los args como ['name1', 'names] lo convierte a [{name: 'name1'}, {name: 'name2'}]
459
- inputsArray = inputs.map(input => { return { name: input, type: 'text', message: `Por favor ingrese ${input}?` }; });
460
- }
461
- else {
462
- // Si viene args como objeto { name1: {...}, name2: {...}} lo convierte a [{name: name1...}, {name: name2...}]
463
- for (const key in inputs) {
464
- if (typeof inputs[key].default == 'string') {
465
- inputs[key].initial = this.merge(inputs[key].default);
466
- }
467
- if (typeof inputs[key].values == 'string' && typeof this[inputs[key].values] == 'function') {
468
- const choices = yield this[inputs[key].values]();
525
+ if (typeof inputs[key].values === 'string') {
526
+ const methodName = inputs[key].values;
527
+ if (typeof this[methodName] === 'function') {
528
+ const choices = await this[methodName]();
469
529
  if (Array.isArray(choices)) {
470
530
  inputs[key].choices = choices;
471
531
  }
472
532
  }
473
- inputsArray.push(Object.assign({ name: key, type: 'text', message: `Por favor ingrese ${key}?` }, inputs[key]));
474
- }
475
- }
476
- return inputsArray;
477
- });
478
- }
479
- askForExit() {
480
- return __awaiter(this, void 0, void 0, function* () {
481
- const answer = yield prompts([
482
- {
483
- type: "confirm",
484
- name: "exit",
485
- initial: true,
486
- message: "Desea salir?"
487
533
  }
488
- ]);
489
- if (answer.exit) {
490
- process.exit(-1);
534
+ inputsArray.push({ ...{ name: key, type: 'text', message: `Por favor ingrese ${key}?` }, ...inputs[key] });
491
535
  }
492
- });
536
+ }
537
+ return inputsArray;
538
+ }
539
+ async askForExit() {
540
+ const answer = await prompts([
541
+ {
542
+ type: "confirm",
543
+ name: "exit",
544
+ initial: true,
545
+ message: "Desea salir?"
546
+ }
547
+ ]);
548
+ if (answer.exit) {
549
+ process.exit(-1);
550
+ }
493
551
  }
494
552
  mergeArgs(args) {
495
553
  if (Array.isArray(args)) {
@@ -510,18 +568,16 @@ class Context {
510
568
  }
511
569
  throw new Error(`Los argumentos ${args} son incompatibles para el merge`);
512
570
  }
513
- askForArguments(inputs) {
514
- return __awaiter(this, void 0, void 0, function* () {
515
- // unifica los dos tipos de inputs (array y objeto) en un array de inputs
516
- const inputsArray = yield this.convertToArrayOfInputs(inputs);
517
- for (const input of inputsArray) {
518
- const hasValue = yield this.get(input.name);
519
- if (!hasValue) {
520
- const answer = yield prompts([input], { onCancel: this.askForExit });
521
- this[input.name] = answer[input.name];
522
- }
571
+ async askForArguments(inputs) {
572
+ // unifica los dos tipos de inputs (array y objeto) en un array de inputs
573
+ const inputsArray = await this.convertToArrayOfInputs(inputs);
574
+ for (const input of inputsArray) {
575
+ const hasValue = await this.get(input.name);
576
+ if (!hasValue) {
577
+ const answer = await prompts([input], { onCancel: this.askForExit });
578
+ this[input.name] = answer[input.name];
523
579
  }
524
- });
580
+ }
525
581
  }
526
582
  setObject(obj) {
527
583
  for (const field in obj) {
@@ -532,31 +588,29 @@ class Context {
532
588
  try {
533
589
  this[key] = value;
534
590
  }
535
- catch (_a) {
591
+ catch {
536
592
  throw new Error(`No se puede setear el ${key} con el valor ${value} en context`);
537
593
  }
538
594
  }
539
595
  // Devuelve el valor o hace un askFor si esta vacio
540
- get(key) {
541
- return __awaiter(this, void 0, void 0, function* () {
542
- try {
543
- const value = this[key];
544
- if (!value) {
545
- const askForMethod = 'askFor' + key;
546
- if (this[askForMethod] && typeof this[askForMethod] == 'function') {
547
- this[key] = yield this[askForMethod]();
548
- }
596
+ async get(key) {
597
+ try {
598
+ const value = this[key];
599
+ if (!value) {
600
+ const askForMethod = 'askFor' + key;
601
+ if (this[askForMethod] && typeof this[askForMethod] == 'function') {
602
+ this[key] = await this[askForMethod]();
549
603
  }
550
- return this[key];
551
604
  }
552
- catch (_a) {
553
- throw new Error(`No se puedo obtener la propiedad ${key} en context`);
554
- }
555
- });
605
+ return this[key];
606
+ }
607
+ catch {
608
+ throw new Error(`No se puedo obtener la propiedad ${key} en context`);
609
+ }
556
610
  }
557
611
  merge(text) {
558
612
  if (typeof text != 'string' || text.indexOf('${') === -1) {
559
- return text;
613
+ return text || '';
560
614
  }
561
615
  const matches = text.matchAll(/\$\{([^}]+)}/g);
562
616
  // si no tiene para merge