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.
- package/.autoforce.json +8 -4
- package/CHANGELOG.md +20 -1
- package/lib/auto.js +50 -64
- package/lib/helpers/class.d.ts +1 -0
- package/lib/helpers/class.js +74 -80
- package/lib/helpers/connect.js +199 -213
- package/lib/helpers/context.d.ts +6 -3
- package/lib/helpers/context.js +279 -225
- package/lib/helpers/github-graphql.js +90 -113
- package/lib/helpers/github-project-graphql.js +100 -132
- package/lib/helpers/gitlab-graphql.js +68 -104
- package/lib/helpers/lwc.js +42 -48
- package/lib/helpers/metadata.js +1 -2
- package/lib/helpers/object.js +47 -55
- package/lib/helpers/openai.js +10 -22
- package/lib/helpers/taskFunctions.js +330 -386
- package/lib/helpers/tasks.d.ts +3 -6
- package/lib/helpers/tasks.js +132 -147
- package/lib/helpers/template.d.ts +9 -5
- package/lib/helpers/template.js +31 -18
- package/lib/helpers/util.d.ts +5 -6
- package/lib/helpers/util.js +131 -187
- package/models/dev/models.json +19 -0
- package/models/doc/models.json +9 -0
- package/models/git/models.json +9 -0
- package/models/project/models.json +9 -0
- package/package.json +16 -12
- package/commands/modelC/new/issue.json +0 -24
- package/commands/models.json +0 -18
- package/templates/modelB/openIssues.bash +0 -4
- package/templates/modelB/viewIssue.bash +0 -8
- package/templates/models.json +0 -12
- /package/{commands/modelA → models/dev/npm}/subtasks/checkout-branch.json +0 -0
- /package/{commands/modelA → models/dev/npm}/subtasks/create-pull.json +0 -0
- /package/{commands/modelC → models/dev/npm}/subtasks/pack.json +0 -0
- /package/{commands/modelA → models/dev/npm}/subtasks/publish-branch.json +0 -0
- /package/{commands/modelA → models/dev/npm}/tasks/cancel.json +0 -0
- /package/{commands/modelA → models/dev/npm}/tasks/finish.json +0 -0
- /package/{commands/modelC → models/dev/npm}/tasks/list.json +0 -0
- /package/{commands/modelC → models/dev/npm}/tasks/publish.json +0 -0
- /package/{commands/modelC → models/dev/npm}/tasks/start.json +0 -0
- /package/{commands/modelA → models/dev/npm}/tasks/stop.json +0 -0
- /package/{commands/modelA → models/dev/npm}/tasks/switch.json +0 -0
- /package/{commands/modelA → models/dev/npm}/tasks/view.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/subtasks/create-scratch.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/subtasks/deploy-code.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/subtasks/drop-scratch.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/subtasks/package-code.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/subtasks/validate-code.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/subtasks/validate-scratch.json +0 -0
- /package/{commands/modelC → models/dev/scratchs}/tasks/cancel.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/tasks/deploy.json +0 -0
- /package/{commands/modelC → models/dev/scratchs}/tasks/finish.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/tasks/rollback.json +0 -0
- /package/{commands/modelA → models/dev/scratchs}/tasks/start.json +0 -0
- /package/{commands/modelC → models/dev/scratchs}/tasks/stop.json +0 -0
- /package/{commands/modelC → models/dev/scratchs}/tasks/switch.json +0 -0
- /package/{commands/modelA → models/doc/processes}/new/process.json +0 -0
- /package/{commands/modelA/subtasks → models/doc/processes/subtask}/update-documentation.json +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-all.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-diagrama.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-inner.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-metodos.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-public.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class-referencias.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/class.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/classes.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/object.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/dictionary/objects.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/intro.md +0 -0
- /package/{templates/modelA → models/doc/processes/templates}/process.md +0 -0
- /package/{commands/modelC/subtasks → models/git/githubflow/subtask}/checkout-branch.json +0 -0
- /package/{commands/modelC/subtasks → models/git/githubflow/subtask}/create-pull.json +0 -0
- /package/{commands/modelC/subtasks → models/git/githubflow/subtask}/publish-branch.json +0 -0
- /package/{commands/modelA → models/project/github-releases}/new/issue.json +0 -0
- /package/{commands/modelA/tasks → models/project/github-releases/task}/list.json +0 -0
- /package/{commands/modelC/tasks → models/project/github-releases/task}/view.json +0 -0
- /package/{templates/modelB → models/project/github-releases/templates}/changelog.md +0 -0
- /package/{templates/modelA → models/project/github-releases/templates}/openIssues.bash +0 -0
- /package/{templates/modelA → models/project/github-releases/templates}/viewIssue.bash +0 -0
package/lib/helpers/context.js
CHANGED
@@ -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
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
197
|
-
|
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
|
-
|
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
|
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(
|
321
|
+
const folders = getFiles(this.dictionaryFolder, filterDirectory, true, ['diccionarios']);
|
257
322
|
for (const folder of folders) {
|
258
|
-
const fullpath = `${
|
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] =
|
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(
|
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(
|
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(
|
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
|
-
|
304
|
-
|
305
|
-
|
306
|
-
if (guard
|
307
|
-
|
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
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
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
|
-
|
372
|
-
if (!this.
|
373
|
-
|
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
|
-
|
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
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
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
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
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
|
-
|
429
|
-
|
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
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
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
|
-
|
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
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
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
|
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
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
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
|
-
|
553
|
-
|
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
|