autoforce 0.1.18 → 0.1.20
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 +1 -1
- package/CHANGELOG.md +10 -0
- package/lib/auto.js +47 -61
- package/lib/helpers/class.d.ts +1 -0
- package/lib/helpers/class.js +65 -78
- package/lib/helpers/connect.js +199 -213
- package/lib/helpers/context.d.ts +1 -1
- package/lib/helpers/context.js +275 -220
- 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 +33 -46
- package/lib/helpers/object.js +38 -53
- package/lib/helpers/openai.js +10 -22
- package/lib/helpers/taskFunctions.js +328 -384
- package/lib/helpers/tasks.d.ts +1 -1
- package/lib/helpers/tasks.js +99 -119
- package/lib/helpers/template.js +4 -0
- package/lib/helpers/util.d.ts +2 -3
- package/lib/helpers/util.js +109 -162
- package/package.json +15 -10
package/lib/helpers/tasks.d.ts
CHANGED
@@ -5,5 +5,5 @@ export declare function getTasks(command?: string): Record<string, ITask>;
|
|
5
5
|
export declare function helpTask(task: ITask): Promise<boolean>;
|
6
6
|
export declare function validateTask(task: ITask): boolean;
|
7
7
|
export declare function runTask(task: ITask, taskContext: CommandOptions, tabs?: string): Promise<boolean>;
|
8
|
-
export declare function previewTask(task: ITask, tabs?: string): Promise<
|
8
|
+
export declare function previewTask(task: ITask, taskContext: CommandOptions, tabs?: string): Promise<boolean>;
|
9
9
|
export declare function createObject(fields: ObjectRecord, values: AnyValue[]): ObjectRecord;
|
package/lib/helpers/tasks.js
CHANGED
@@ -1,12 +1,3 @@
|
|
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 context, { initializeContext } from "./context.js";
|
11
2
|
import { logError, logStep } from "./color.js";
|
12
3
|
import { getModelFolders, getFiles, filterJson, readJsonSync } from "./util.js";
|
@@ -40,7 +31,7 @@ export function getTasks(command = 'tasks') {
|
|
40
31
|
}
|
41
32
|
function mergeTask(newTask, oldTask) {
|
42
33
|
const newSteps = newTask.steps ? [...newTask.steps, ...oldTask.steps] : oldTask.steps;
|
43
|
-
const newArguments = newTask.arguments ?
|
34
|
+
const newArguments = newTask.arguments ? { ...newTask.arguments, ...oldTask.arguments } : oldTask.arguments;
|
44
35
|
const newGuards = newTask.guards ? [...newTask.guards, ...oldTask.guards] : oldTask.guards;
|
45
36
|
const newVerbose = newTask.verbose || oldTask.verbose;
|
46
37
|
const newDescription = newTask.description ? newTask.description + ' ' + oldTask.description : oldTask.description;
|
@@ -67,14 +58,12 @@ function isCriteriaMet(criteria) {
|
|
67
58
|
const result = context[field] == value;
|
68
59
|
return result;
|
69
60
|
}
|
70
|
-
export function helpTask(task) {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
return true;
|
77
|
-
});
|
61
|
+
export async function helpTask(task) {
|
62
|
+
console.log('Nombre:', task.name);
|
63
|
+
console.log('Descripcion:', task.description);
|
64
|
+
console.log('Guards:', task.guards);
|
65
|
+
console.log('Argumentos:', task.arguments);
|
66
|
+
return true;
|
78
67
|
}
|
79
68
|
export function validateTask(task) {
|
80
69
|
initializeContext();
|
@@ -113,46 +102,43 @@ export function validateTask(task) {
|
|
113
102
|
}
|
114
103
|
return true;
|
115
104
|
}
|
116
|
-
export function runTask(
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
if (
|
125
|
-
|
126
|
-
context.setObject(taskContext);
|
127
|
-
}
|
128
|
-
yield context.askForArguments(task.arguments);
|
129
|
-
}
|
130
|
-
if (task.verbose) {
|
131
|
-
logStep(`[INICIO] ${task.name}`, tabs);
|
105
|
+
export async function runTask(task, taskContext, tabs = '') {
|
106
|
+
initializeContext();
|
107
|
+
// Valida que este ya esten las variables de enotorno y configuracion
|
108
|
+
if (task.guards) {
|
109
|
+
await context.validate(task.guards);
|
110
|
+
}
|
111
|
+
// Pide datos de entrada y los deja en context
|
112
|
+
if (task.arguments) {
|
113
|
+
if (taskContext) {
|
114
|
+
context.setObject(taskContext);
|
132
115
|
}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
116
|
+
await context.askForArguments(task.arguments);
|
117
|
+
}
|
118
|
+
if (task.verbose) {
|
119
|
+
logStep(`[INICIO] ${task.name}`, tabs);
|
120
|
+
}
|
121
|
+
for (const step of task.steps) {
|
122
|
+
if (isCriteriaMet(step.criteria)) {
|
123
|
+
if (!await executeStep(step, tabs + '\t', task.verbose)) {
|
124
|
+
return false;
|
138
125
|
}
|
139
126
|
}
|
140
|
-
|
141
|
-
|
142
|
-
}
|
143
|
-
|
144
|
-
|
127
|
+
}
|
128
|
+
if (task.verbose) {
|
129
|
+
logStep(`[FIN] ${task.name}`, tabs);
|
130
|
+
}
|
131
|
+
return true;
|
145
132
|
}
|
146
|
-
export function previewTask(
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
});
|
133
|
+
export async function previewTask(task, taskContext, tabs = '') {
|
134
|
+
initializeContext();
|
135
|
+
logStep(`${task.name}: ${task.description}`, tabs);
|
136
|
+
for (const step of task.steps) {
|
137
|
+
previewStep(step, taskContext, tabs);
|
138
|
+
}
|
139
|
+
return true;
|
154
140
|
}
|
155
|
-
function previewStep(step, tabs = '') {
|
141
|
+
function previewStep(step, taskContext, tabs = '') {
|
156
142
|
if (step.criteria) {
|
157
143
|
logStep(`Si ${step.criteria.field} ${step.criteria.operator || '=='} ${step.criteria.value}`, tabs);
|
158
144
|
tabs += '\t';
|
@@ -160,7 +146,7 @@ function previewStep(step, tabs = '') {
|
|
160
146
|
if (step.subtask) {
|
161
147
|
tabs += '\t';
|
162
148
|
const subtask = getTask(step.subtask, 'subtasks');
|
163
|
-
previewTask(subtask, tabs);
|
149
|
+
previewTask(subtask, taskContext, tabs);
|
164
150
|
}
|
165
151
|
else {
|
166
152
|
logStep(`${step.name}`, tabs);
|
@@ -177,83 +163,77 @@ export function createObject(fields, values) {
|
|
177
163
|
}
|
178
164
|
return argsObject;
|
179
165
|
}
|
180
|
-
function runStep(step, tabs) {
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
stepContext = createObject(subtask.arguments, stepContext);
|
193
|
-
}
|
194
|
-
return yield runTask(subtask, stepContext, tabs);
|
166
|
+
async function runStep(step, tabs) {
|
167
|
+
if (typeof step.command === 'string') {
|
168
|
+
return executeCommand(step);
|
169
|
+
}
|
170
|
+
else if (typeof step.function === 'string') {
|
171
|
+
return await executeFunction(step);
|
172
|
+
}
|
173
|
+
else if (typeof step.subtask === 'string' || typeof step.task === 'string') {
|
174
|
+
const subtask = typeof step.subtask === 'string' ? getTask(step.subtask, 'subtask') : getTask(step.task, 'tasks');
|
175
|
+
let stepContext = step.arguments ? context.mergeArgs(step.arguments) : {};
|
176
|
+
if (Array.isArray(stepContext)) {
|
177
|
+
stepContext = createObject(subtask.arguments, stepContext);
|
195
178
|
}
|
196
|
-
|
197
|
-
}
|
179
|
+
return await runTask(subtask, stepContext, tabs);
|
180
|
+
}
|
181
|
+
throw new Error(`No se pudo ejecutar el step ${step.name} porque no tiene command, function o subtasks`);
|
198
182
|
}
|
199
|
-
function askForContinueOrRetry() {
|
200
|
-
|
201
|
-
|
202
|
-
|
183
|
+
async function askForContinueOrRetry() {
|
184
|
+
if (!context.isVerbose) {
|
185
|
+
return 'quit';
|
186
|
+
}
|
187
|
+
const answer = await prompts([
|
188
|
+
{
|
189
|
+
type: "select",
|
190
|
+
name: "continue",
|
191
|
+
message: "No se pudo ejecutar el step, ¿que quiere hacer? ",
|
192
|
+
choices: [{ title: 'Salir', value: 'quit' }, { title: 'Continuar', value: 'continue' }, { title: 'Reintentar', value: 'retry' }],
|
203
193
|
}
|
204
|
-
|
205
|
-
|
206
|
-
type: "select",
|
207
|
-
name: "continue",
|
208
|
-
message: "No se pudo ejecutar el step, ¿que quiere hacer? ",
|
209
|
-
choices: [{ title: 'Salir', value: 'quit' }, { title: 'Continuar', value: 'continue' }, { title: 'Reintentar', value: 'retry' }],
|
210
|
-
}
|
211
|
-
]);
|
212
|
-
return answer.continue;
|
213
|
-
});
|
194
|
+
]);
|
195
|
+
return answer.continue;
|
214
196
|
}
|
215
197
|
function getStepError(step, stepName) {
|
216
198
|
return step.errorMessage ? context.merge(step.errorMessage) : stepName ? `Fallo el step ${stepName}` : '';
|
217
199
|
}
|
218
|
-
function executeStep(
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
success = yield errorHandler();
|
236
|
-
}
|
200
|
+
async function executeStep(step, tabs, verbose = false) {
|
201
|
+
const stepName = step.name ? context.merge(step.name) : undefined;
|
202
|
+
if (verbose && stepName) {
|
203
|
+
logStep(`[INICIO] ${stepName}`, tabs);
|
204
|
+
}
|
205
|
+
let retry = false;
|
206
|
+
let success = false;
|
207
|
+
do {
|
208
|
+
try {
|
209
|
+
success = await runStep(step, tabs);
|
210
|
+
if (!success) {
|
211
|
+
logError(getStepError(step, stepName), tabs);
|
212
|
+
// Si tiene un custom handler cuando hay un error
|
213
|
+
if (step.onError) {
|
214
|
+
const errorHandler = taskFunctions[step.onError];
|
215
|
+
if (typeof errorHandler === 'function') {
|
216
|
+
success = await errorHandler();
|
237
217
|
}
|
238
218
|
}
|
239
219
|
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
}
|
245
|
-
if (!success) {
|
246
|
-
const result = yield askForContinueOrRetry();
|
247
|
-
retry = result == 'retry';
|
248
|
-
success = result == 'continue';
|
220
|
+
}
|
221
|
+
catch (error) {
|
222
|
+
if (error instanceof Error) {
|
223
|
+
logError(error.message, tabs);
|
249
224
|
}
|
250
|
-
} while (!success && retry);
|
251
|
-
if (verbose && stepName) {
|
252
|
-
logStep(`[FIN] ${stepName}`, tabs);
|
253
225
|
}
|
254
226
|
if (!success) {
|
255
|
-
|
227
|
+
const result = await askForContinueOrRetry();
|
228
|
+
retry = result == 'retry';
|
229
|
+
success = result == 'continue';
|
256
230
|
}
|
257
|
-
|
258
|
-
|
231
|
+
} while (!success && retry);
|
232
|
+
if (verbose && stepName) {
|
233
|
+
logStep(`[FIN] ${stepName}`, tabs);
|
234
|
+
}
|
235
|
+
if (!success) {
|
236
|
+
process.exit(!context.isVerbose ? -1 : 0);
|
237
|
+
}
|
238
|
+
return success;
|
259
239
|
}
|
package/lib/helpers/template.js
CHANGED
@@ -23,6 +23,10 @@ function openTemplate(sourceFolder, templateName, extension) {
|
|
23
23
|
return content;
|
24
24
|
}
|
25
25
|
export class TemplateEngine {
|
26
|
+
_template;
|
27
|
+
_rendered;
|
28
|
+
_extension;
|
29
|
+
_sourceFolders;
|
26
30
|
constructor(sources, extension = '*') {
|
27
31
|
this._sourceFolders = sources;
|
28
32
|
this._extension = extension;
|
package/lib/helpers/util.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Choice } from "prompts";
|
2
|
-
import { AnyValue } from "../types/auto.js";
|
2
|
+
import { AnyValue, CommandOptions } from "../types/auto.js";
|
3
3
|
export declare const WORKING_FOLDER: string;
|
4
4
|
export declare const CONFIG_FILE: string;
|
5
5
|
export declare const DICTIONARY_FOLDER: string;
|
@@ -18,11 +18,10 @@ export declare function titlesToChoices(list: string[], titleToValue?: (title: s
|
|
18
18
|
title: string;
|
19
19
|
value: string;
|
20
20
|
}[];
|
21
|
-
export declare function getDataFromPackage(): Record<string, string>;
|
22
21
|
export declare function findChoicesPosition(choices: Choice[], value: string): number;
|
23
22
|
export declare function getFilesInFolders(folders: string[], filter: (fullPath: string) => boolean, recursive?: boolean, ignoreList?: string[]): string[];
|
24
23
|
export declare function getModelFolders(subfolder: string): string[];
|
25
|
-
export declare function createConfigurationFile(taskName?: string): Promise<boolean>;
|
24
|
+
export declare function createConfigurationFile(taskName?: string, options?: CommandOptions): Promise<boolean>;
|
26
25
|
export declare function getConfigFile(file: string, variable: string, defaultValue: AnyValue): any;
|
27
26
|
export declare function getConfig(variable: string, defaultValue: AnyValue): any;
|
28
27
|
export declare function storeConfig(record: Record<string, AnyValue>): void;
|
package/lib/helpers/util.js
CHANGED
@@ -1,12 +1,3 @@
|
|
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 fs from "fs";
|
11
2
|
import { fileURLToPath } from 'url';
|
12
3
|
import prompts from "prompts";
|
@@ -29,48 +20,6 @@ export function valuesToChoices(list, valueToTitle = (value) => value) {
|
|
29
20
|
export function titlesToChoices(list, titleToValue = (title) => title) {
|
30
21
|
return list.map(title => { return { title, value: titleToValue(title) }; });
|
31
22
|
}
|
32
|
-
export function getDataFromPackage() {
|
33
|
-
const data = {};
|
34
|
-
try {
|
35
|
-
const filename = searchInFolderHierarchy("package.json", process.cwd());
|
36
|
-
if (!filename) {
|
37
|
-
throw new Error("No se encontro el package.json en " + process.cwd());
|
38
|
-
}
|
39
|
-
const content = fs.readFileSync(filename, "utf8");
|
40
|
-
const packageJson = JSON.parse(content);
|
41
|
-
if (packageJson.repository) {
|
42
|
-
if (packageJson.repository.url) {
|
43
|
-
data.repositoryUrl = packageJson.repository.url;
|
44
|
-
data.repositoryType = packageJson.repository.type;
|
45
|
-
// Ver de sacar repo y owner
|
46
|
-
if (data.repositoryUrl) {
|
47
|
-
if (data.repositoryUrl.includes("github.com")) {
|
48
|
-
const repositoryArray = data.repositoryUrl.split('github.com/');
|
49
|
-
[data.repositoryOwner, data.repositoryRepo] = repositoryArray[1].split('/');
|
50
|
-
}
|
51
|
-
if (data.repositoryUrl.includes("gitlab.com")) {
|
52
|
-
const repositoryArray = data.repositoryUrl.split('gitlab.com/');
|
53
|
-
[data.repositoryOwner, data.repositoryRepo] = repositoryArray[1].split('/');
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
else if (typeof packageJson.repository === 'string') {
|
58
|
-
data.repositoryUrl = packageJson.repository;
|
59
|
-
const repositoryArray = data.repositoryUrl.split(':');
|
60
|
-
data.repositoryType = repositoryArray[0];
|
61
|
-
[data.repositoryOwner, data.repositoryRepo] = repositoryArray[1].split('/');
|
62
|
-
}
|
63
|
-
if (data.repositoryRepo && data.repositoryRepo.endsWith('.git')) {
|
64
|
-
data.repositoryRepo = data.repositoryRepo.replace('.git', '');
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
catch (error) {
|
69
|
-
console.log(error);
|
70
|
-
throw new Error(`Verifique que exista y sea valido el package.json`);
|
71
|
-
}
|
72
|
-
return data;
|
73
|
-
}
|
74
23
|
export function findChoicesPosition(choices, value) {
|
75
24
|
const index = choices.findIndex(choice => choice.value === value);
|
76
25
|
return index === -1 ? 0 : index;
|
@@ -96,127 +45,125 @@ export function getModelFolders(subfolder) {
|
|
96
45
|
function getTemplates(filter) {
|
97
46
|
return getFilesInFolders(getModelFolders('templates'), filter);
|
98
47
|
}
|
99
|
-
function getTaskConfig(config) {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
48
|
+
async function getTaskConfig(config) {
|
49
|
+
// TODO: Ver si esto se mueve a un config list
|
50
|
+
// List Command settings
|
51
|
+
const filters = context.listFilters();
|
52
|
+
const listFilter = await prompts([
|
53
|
+
{
|
54
|
+
message: 'Elija un filtro, o bien lo puede dejar fijo en autoforce como listFilter',
|
55
|
+
name: 'filter',
|
56
|
+
type: 'select',
|
57
|
+
initial: findChoicesPosition(filters, config.listFilter),
|
58
|
+
choices: filters
|
59
|
+
}
|
60
|
+
]);
|
61
|
+
if (listFilter.filter === undefined)
|
62
|
+
return;
|
63
|
+
config.listFilter = listFilter.filter;
|
64
|
+
const files = getTemplates(filterBash).map(filename => filename.split(".")[0]);
|
65
|
+
if (files.length > 0) {
|
66
|
+
const templates = valuesToChoices(files);
|
67
|
+
const template = await prompts([
|
105
68
|
{
|
106
|
-
message: 'Elija un
|
107
|
-
name: '
|
69
|
+
message: 'Elija un template, o bien lo puede dejar en autoforce como listTemplate',
|
70
|
+
name: 'template',
|
108
71
|
type: 'select',
|
109
|
-
initial: findChoicesPosition(
|
110
|
-
choices:
|
72
|
+
initial: findChoicesPosition(templates, config.listTemplate),
|
73
|
+
choices: templates
|
111
74
|
}
|
112
75
|
]);
|
113
|
-
if (
|
76
|
+
if (template.template === undefined)
|
114
77
|
return;
|
115
|
-
config.
|
116
|
-
|
117
|
-
|
118
|
-
const templates = valuesToChoices(files);
|
119
|
-
const template = yield prompts([
|
120
|
-
{
|
121
|
-
message: 'Elija un template, o bien lo puede dejar en autoforce como listTemplate',
|
122
|
-
name: 'template',
|
123
|
-
type: 'select',
|
124
|
-
initial: findChoicesPosition(templates, config.listTemplate),
|
125
|
-
choices: templates
|
126
|
-
}
|
127
|
-
]);
|
128
|
-
if (template.template === undefined)
|
129
|
-
return;
|
130
|
-
config.listTemplate = template.template;
|
131
|
-
}
|
132
|
-
return config;
|
133
|
-
});
|
78
|
+
config.listTemplate = template.template;
|
79
|
+
}
|
80
|
+
return config;
|
134
81
|
}
|
135
|
-
function getBaseConfig(config) {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
const automationModel = yield prompts([{
|
162
|
-
type: "select",
|
163
|
-
name: "model",
|
164
|
-
message: `Elija un modelo de automatizacion para ${prefix}`,
|
165
|
-
initial: findChoicesPosition(models, config[contextProperty]),
|
166
|
-
choices: models
|
167
|
-
}]);
|
168
|
-
if (automationModel.model === undefined)
|
169
|
-
return;
|
170
|
-
config[contextProperty] = automationModel.model;
|
171
|
-
}
|
172
|
-
// Gestion del Proyecto
|
173
|
-
const projectChoices = [{ title: 'Github Projects', value: ProjectServices.GitHub }, { title: 'GitLab Projects', value: ProjectServices.GitLab }, { title: 'Jira', value: ProjectServices.Jira }, { title: 'None', value: ProjectServices.None }];
|
174
|
-
const projectServices = yield prompts([{
|
82
|
+
async function getBaseConfig(config) {
|
83
|
+
// Todo: Chequear el repoOwner y repo
|
84
|
+
const gitChoices = [{ title: 'Github', value: GitServices.GitHub }, { title: 'Gitlab', value: GitServices.GitLab }];
|
85
|
+
// Preguntar por GitHub o GitLab
|
86
|
+
const gitServices = await prompts([{
|
87
|
+
type: "select",
|
88
|
+
name: "git",
|
89
|
+
message: "Elija un servicio de Git",
|
90
|
+
initial: findChoicesPosition(gitChoices, config.gitServices),
|
91
|
+
choices: gitChoices
|
92
|
+
}]);
|
93
|
+
if (gitServices.git === undefined)
|
94
|
+
process.exit(0);
|
95
|
+
config.gitServices = gitServices.git;
|
96
|
+
// Chequear las variables de entorno
|
97
|
+
if (gitServices.git === GitServices.GitHub && !process.env.GITHUB_TOKEN) {
|
98
|
+
logWarning('A fin de que la herramienta funcione debe configurar una variable de entorno GITHUB_TOKEN');
|
99
|
+
}
|
100
|
+
if (gitServices.git === GitServices.GitLab && !process.env.GITLAB_TOKEN) {
|
101
|
+
logWarning('A fin de que la herramienta funcione debe configurar una variable de entorno GITLAB_TOKEN');
|
102
|
+
}
|
103
|
+
// Selecciona los modelos de automatizacion
|
104
|
+
for (const prefix of ['dev', 'git', 'doc', 'project']) {
|
105
|
+
const contextProperty = prefix + 'Model';
|
106
|
+
const models = readJsonSync(`${MODELS_FOLDER}/${prefix}/models.json`);
|
107
|
+
const automationModel = await prompts([{
|
175
108
|
type: "select",
|
176
|
-
name: "
|
177
|
-
message:
|
178
|
-
initial: findChoicesPosition(
|
179
|
-
choices:
|
109
|
+
name: "model",
|
110
|
+
message: `Elija un modelo de automatizacion para ${prefix}`,
|
111
|
+
initial: findChoicesPosition(models, config[contextProperty]),
|
112
|
+
choices: models
|
180
113
|
}]);
|
181
|
-
if (
|
114
|
+
if (automationModel.model === undefined)
|
182
115
|
return;
|
183
|
-
config
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
//
|
199
|
-
const
|
116
|
+
config[contextProperty] = automationModel.model;
|
117
|
+
}
|
118
|
+
// Gestion del Proyecto
|
119
|
+
const projectChoices = [{ title: 'Github Projects', value: ProjectServices.GitHub }, { title: 'GitLab Projects', value: ProjectServices.GitLab }, { title: 'Jira', value: ProjectServices.Jira }, { title: 'None', value: ProjectServices.None }];
|
120
|
+
const projectServices = await prompts([{
|
121
|
+
type: "select",
|
122
|
+
name: "project",
|
123
|
+
message: "Gestion de proyecto",
|
124
|
+
initial: findChoicesPosition(projectChoices, config.projectServices),
|
125
|
+
choices: projectChoices
|
126
|
+
}]);
|
127
|
+
if (projectServices.project === undefined)
|
128
|
+
return;
|
129
|
+
config.projectServices = projectServices.project;
|
130
|
+
if (projectServices.project === ProjectServices.GitHub || projectServices.project === ProjectServices.GitLab) {
|
131
|
+
// Gestion del Proyecto
|
132
|
+
const backlogColumn = await prompts([{
|
200
133
|
type: "text",
|
201
|
-
name: "
|
202
|
-
initial: config.
|
203
|
-
message: "
|
134
|
+
name: "backlogColumn",
|
135
|
+
initial: config.backlogColumn,
|
136
|
+
message: "Nombre de la columna donde se crean nuevos issues"
|
204
137
|
}]);
|
205
|
-
if (
|
138
|
+
if (backlogColumn.backlogColumn === undefined)
|
206
139
|
return;
|
207
|
-
config.
|
208
|
-
|
209
|
-
}
|
140
|
+
config.backlogColumn = backlogColumn.backlogColumn;
|
141
|
+
logInfo(`Por omision ser utilizan proyectos dentro de ${context.repositoryOwner} y ${context.repositoryRepo} `);
|
142
|
+
}
|
143
|
+
// Id de Projecto
|
144
|
+
const projectId = await prompts([{
|
145
|
+
type: "text",
|
146
|
+
name: "projectId",
|
147
|
+
initial: config.projectId,
|
148
|
+
message: "Id del proyecto"
|
149
|
+
}]);
|
150
|
+
if (projectId.projectId === undefined)
|
151
|
+
return;
|
152
|
+
config.projectId = projectId.projectId;
|
153
|
+
return config;
|
210
154
|
}
|
211
|
-
export function createConfigurationFile(taskName) {
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
if (!config)
|
216
|
-
return false;
|
217
|
-
storeConfig(config);
|
155
|
+
export async function createConfigurationFile(taskName, options) {
|
156
|
+
if (options?.noprompt) {
|
157
|
+
delete options.noprompt;
|
158
|
+
storeConfig(options);
|
218
159
|
return true;
|
219
|
-
}
|
160
|
+
}
|
161
|
+
const baseConfig = { backlogColumn: options?.backlogColumn || context.backlogColumn, devModel: options?.devModel || context.devModel, docModel: options?.docModel || context.docModel, projectModel: options?.projectModel || context.projectModel, gitModel: options?.gitModel || context.gitModel, gitServices: options?.gitServices || context.gitServices, projectServices: options?.projectServices || context.projectServices, projectId: options?.projectId || context.projectId, listFilter: options?.listFilter || context.listFilter, listTemplate: options?.listTemplate || context.listTemplate };
|
162
|
+
const config = taskName ? await getTaskConfig(baseConfig) : await getBaseConfig(baseConfig);
|
163
|
+
if (!config)
|
164
|
+
return false;
|
165
|
+
storeConfig(config);
|
166
|
+
return true;
|
220
167
|
}
|
221
168
|
export function getConfigFile(file, variable, defaultValue) {
|
222
169
|
if (fs.existsSync(file)) {
|
@@ -227,7 +174,7 @@ export function getConfigFile(file, variable, defaultValue) {
|
|
227
174
|
return config[variable];
|
228
175
|
}
|
229
176
|
}
|
230
|
-
catch
|
177
|
+
catch {
|
231
178
|
return defaultValue;
|
232
179
|
}
|
233
180
|
}
|
@@ -243,7 +190,7 @@ export function storeConfig(record) {
|
|
243
190
|
try {
|
244
191
|
config = JSON.parse(content);
|
245
192
|
}
|
246
|
-
catch
|
193
|
+
catch {
|
247
194
|
throw new Error(`Verifique que el ${CONFIG_FILE} sea json valido`);
|
248
195
|
}
|
249
196
|
}
|
@@ -253,7 +200,7 @@ export function storeConfig(record) {
|
|
253
200
|
try {
|
254
201
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
255
202
|
}
|
256
|
-
catch
|
203
|
+
catch {
|
257
204
|
throw new Error(`No se pudo guardar la configuracion en ${CONFIG_FILE}`);
|
258
205
|
}
|
259
206
|
}
|
@@ -355,7 +302,7 @@ export function readJsonSync(filename) {
|
|
355
302
|
try {
|
356
303
|
return JSON.parse(content);
|
357
304
|
}
|
358
|
-
catch
|
305
|
+
catch {
|
359
306
|
throw new Error(`Verifique que el ${filename} sea json valido`);
|
360
307
|
}
|
361
308
|
}
|