autoforce 0.1.10 → 0.1.12
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/CHANGELOG.md +49 -3
- package/README.md +0 -13
- package/commands/modelA/tasks/list.json +1 -1
- package/commands/modelC/new/issue.json +6 -23
- package/commands/modelC/tasks/list.json +3 -1
- package/commands/modelC/tasks/publish.json +2 -1
- package/lib/auto.js +3 -3
- package/lib/helpers/context.d.ts +16 -2
- package/lib/helpers/context.js +103 -38
- package/lib/helpers/github-graphql.d.ts +3 -34
- package/lib/helpers/github-graphql.js +51 -51
- package/lib/helpers/github-project-graphql.d.ts +37 -5
- package/lib/helpers/github-project-graphql.js +83 -17
- package/lib/helpers/gitlab-graphql.d.ts +4 -2
- package/lib/helpers/gitlab-graphql.js +12 -2
- package/lib/helpers/openai.js +1 -1
- package/lib/helpers/taskFunctions.js +114 -36
- package/lib/helpers/tasks.js +12 -8
- package/lib/helpers/template.d.ts +3 -2
- package/lib/helpers/template.js +23 -3
- package/lib/helpers/util.d.ts +5 -3
- package/lib/helpers/util.js +97 -27
- package/package.json +1 -1
- package/templates/modelB/changelog.md +8 -4
- package/templates/modelB/openIssues.bash +4 -0
- package/templates/modelB/viewIssue.bash +8 -0
- package/templates/models.json +2 -3
- package/templates/modelB/openIssues.md +0 -0
@@ -42,24 +42,24 @@ export class GitHubProjectApi extends GitHubApi {
|
|
42
42
|
return mapValues;
|
43
43
|
});
|
44
44
|
}
|
45
|
-
createIssue(title, state, label, body,
|
46
|
-
var _a;
|
45
|
+
createIssue(title, state, label, body, milestoneId) {
|
47
46
|
return __awaiter(this, void 0, void 0, function* () {
|
47
|
+
var _a;
|
48
48
|
const user = yield this.getUser();
|
49
49
|
const repository = yield this.getRepository(label);
|
50
50
|
const repositoryId = repository.id;
|
51
51
|
const labelId = (_a = repository.label) === null || _a === void 0 ? void 0 : _a.id;
|
52
52
|
const projectId = repository.projectV2.id;
|
53
53
|
const mutationIssue = `
|
54
|
-
mutation createIssue($repositoryId: ID!, $assignId: ID!, $title: String!, $body: String, ${labelId ? '$labelId: ID!' : ''}
|
54
|
+
mutation createIssue($repositoryId: ID!, $assignId: ID!, $title: String!, $body: String, $milestoneId: ID ${labelId ? ', $labelId: ID!' : ''} ) {
|
55
55
|
createIssue(
|
56
56
|
input: {
|
57
57
|
repositoryId: $repositoryId,
|
58
58
|
assigneeIds: [$assignId],
|
59
|
-
${labelId ? 'labelIds: [$labelId],' : ''}
|
60
59
|
title: $title,
|
61
60
|
milestoneId: $milestoneId,
|
62
61
|
body: $body
|
62
|
+
${labelId ? ',labelIds: [$labelId]' : ''}
|
63
63
|
}
|
64
64
|
) {
|
65
65
|
issue {
|
@@ -68,7 +68,7 @@ export class GitHubProjectApi extends GitHubApi {
|
|
68
68
|
}
|
69
69
|
}
|
70
70
|
}`;
|
71
|
-
const { createIssue } = yield this.graphqlAuth(mutationIssue, { labelId, body, assignId: user.id, projectId, repositoryId, title, label: label ? [label] : null });
|
71
|
+
const { createIssue } = yield this.graphqlAuth(mutationIssue, { labelId, body, assignId: user.id, projectId, repositoryId, title, milestoneId: milestoneId ? milestoneId : null, label: label ? [label] : null });
|
72
72
|
const issue = createIssue.issue;
|
73
73
|
if (!state || !issue.number) {
|
74
74
|
return issue.number;
|
@@ -115,19 +115,71 @@ export class GitHubProjectApi extends GitHubApi {
|
|
115
115
|
});
|
116
116
|
}
|
117
117
|
getIssueState(issueNumber) {
|
118
|
-
var _a, _b, _c;
|
119
118
|
return __awaiter(this, void 0, void 0, function* () {
|
120
|
-
|
119
|
+
var _a, _b, _c;
|
120
|
+
const issue = yield this._getIssue(issueNumber);
|
121
121
|
return (_c = (_b = (_a = issue.projectItems) === null || _a === void 0 ? void 0 : _a.nodes[0]) === null || _b === void 0 ? void 0 : _b.fieldValueByName) === null || _c === void 0 ? void 0 : _c.name;
|
122
122
|
});
|
123
123
|
}
|
124
124
|
getIssueName(title) {
|
125
125
|
return title.toLowerCase().replaceAll(' ', '-');
|
126
126
|
}
|
127
|
-
|
127
|
+
_getIssue(issueNumber) {
|
128
128
|
return __awaiter(this, void 0, void 0, function* () {
|
129
|
-
const
|
130
|
-
|
129
|
+
const query = `
|
130
|
+
query getIssue($owner:String!, $repo: String!, $issueNumber: Int!) {
|
131
|
+
repository(owner: $owner, name: $repo) {
|
132
|
+
issue(number: $issueNumber) {
|
133
|
+
title
|
134
|
+
number,
|
135
|
+
id
|
136
|
+
url
|
137
|
+
body
|
138
|
+
labels(first:3, orderBy: { field: CREATED_AT, direction: DESC}) {
|
139
|
+
nodes {
|
140
|
+
color
|
141
|
+
name
|
142
|
+
}
|
143
|
+
}
|
144
|
+
projectItems(last: 1) {
|
145
|
+
nodes{
|
146
|
+
id,
|
147
|
+
project {
|
148
|
+
id
|
149
|
+
}
|
150
|
+
fieldValueByName(name: "Status"){
|
151
|
+
... on ProjectV2ItemFieldSingleSelectValue {
|
152
|
+
name
|
153
|
+
id
|
154
|
+
field {
|
155
|
+
... on ProjectV2SingleSelectField {
|
156
|
+
id
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
linkedBranches(last:1){
|
164
|
+
nodes {
|
165
|
+
ref {
|
166
|
+
id
|
167
|
+
name
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
`;
|
175
|
+
const { repository } = yield this.graphqlAuth(query, Object.assign({ issueNumber: Number.parseInt(issueNumber) }, this.repoVar));
|
176
|
+
return repository.issue;
|
177
|
+
});
|
178
|
+
}
|
179
|
+
getIssue(issueNumber) {
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
181
|
+
const issue = yield this._getIssue(issueNumber);
|
182
|
+
const issueObject = { number: issue.number, title: issue.title, id: issue.id, url: issue.url, body: issue.body };
|
131
183
|
issueObject.name = this.getIssueName(issue.title);
|
132
184
|
if (issue.linkedBranches.nodes.length > 0) {
|
133
185
|
issueObject.branch = issue.linkedBranches.nodes[0].ref.name;
|
@@ -149,11 +201,6 @@ export class GitHubProjectApi extends GitHubApi {
|
|
149
201
|
return yield this.getIssuesWithFilter(`{ states: OPEN }`);
|
150
202
|
});
|
151
203
|
}
|
152
|
-
getIssuesByMilestone(milestone) {
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
154
|
-
return yield this.getIssuesWithFilter(`{ milestone: ${milestone} }`);
|
155
|
-
});
|
156
|
-
}
|
157
204
|
getIssuesWithFilter(filterBy) {
|
158
205
|
return __awaiter(this, void 0, void 0, function* () {
|
159
206
|
const query = `
|
@@ -161,7 +208,26 @@ export class GitHubProjectApi extends GitHubApi {
|
|
161
208
|
repository(owner: $owner, name: $repo) {
|
162
209
|
issues(last: 10, filterBy: ${filterBy} ) {
|
163
210
|
nodes {
|
211
|
+
number
|
164
212
|
title
|
213
|
+
body
|
214
|
+
state
|
215
|
+
url
|
216
|
+
milestone {
|
217
|
+
dueOn
|
218
|
+
title
|
219
|
+
}
|
220
|
+
labels ( last: 3, orderBy: { field: CREATED_AT, direction: DESC} ) {
|
221
|
+
nodes {
|
222
|
+
color
|
223
|
+
name
|
224
|
+
}
|
225
|
+
}
|
226
|
+
assignees ( last: 3 ) {
|
227
|
+
nodes {
|
228
|
+
login
|
229
|
+
}
|
230
|
+
}
|
165
231
|
id
|
166
232
|
}
|
167
233
|
}
|
@@ -174,7 +240,7 @@ export class GitHubProjectApi extends GitHubApi {
|
|
174
240
|
}
|
175
241
|
moveIssue(issueNumber, state) {
|
176
242
|
return __awaiter(this, void 0, void 0, function* () {
|
177
|
-
const issue = yield this.
|
243
|
+
const issue = yield this._getIssue(issueNumber);
|
178
244
|
const itemId = issue.projectItems.nodes[0].id;
|
179
245
|
const projectId = issue.projectItems.nodes[0].project.id;
|
180
246
|
const fieldId = issue.projectItems.nodes[0].fieldValueByName.field.id;
|
@@ -202,7 +268,7 @@ export class GitHubProjectApi extends GitHubApi {
|
|
202
268
|
assignIssueToMe(issueNumber) {
|
203
269
|
return __awaiter(this, void 0, void 0, function* () {
|
204
270
|
const user = yield this.getUser();
|
205
|
-
const issue = yield this.
|
271
|
+
const issue = yield this._getIssue(issueNumber);
|
206
272
|
const mutation = `
|
207
273
|
mutation assignUser( $issueId: ID!, $userId: ID!) {
|
208
274
|
addAssigneesToAssignable(input: {
|
@@ -8,9 +8,11 @@ export declare class GitLabApi implements IGitApi, IProjectApi {
|
|
8
8
|
projectNumber: number | undefined;
|
9
9
|
graphqlAuth: GraphQLClient;
|
10
10
|
constructor(token: string, owner: string, repo: string, projectNumber?: number);
|
11
|
-
|
11
|
+
getLabels(): Promise<never[]>;
|
12
|
+
getMilestones(): Promise<never[]>;
|
13
|
+
getIssue(issueNumber: string): Promise<{}>;
|
12
14
|
getIssues(): Promise<never[]>;
|
13
|
-
|
15
|
+
getIssuesWithFilter(filter: string): Promise<never[]>;
|
14
16
|
createIssue(title: string, state?: string, label?: string, body?: string, milestone?: string): Promise<number>;
|
15
17
|
moveIssue(issueNumber: string, state: string): Promise<boolean>;
|
16
18
|
assignIssueToMe(issueNumber: string): Promise<boolean>;
|
@@ -16,7 +16,17 @@ export class GitLabApi {
|
|
16
16
|
this.projectNumber = projectNumber;
|
17
17
|
this.graphqlAuth.setHeaders({ authorization: `Bearer ${token}` });
|
18
18
|
}
|
19
|
-
|
19
|
+
getLabels() {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
return [];
|
22
|
+
});
|
23
|
+
}
|
24
|
+
getMilestones() {
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
26
|
+
return [];
|
27
|
+
});
|
28
|
+
}
|
29
|
+
getIssue(issueNumber) {
|
20
30
|
return __awaiter(this, void 0, void 0, function* () {
|
21
31
|
console.log(issueNumber);
|
22
32
|
return {};
|
@@ -27,7 +37,7 @@ export class GitLabApi {
|
|
27
37
|
return [];
|
28
38
|
});
|
29
39
|
}
|
30
|
-
|
40
|
+
getIssuesWithFilter(filter) {
|
31
41
|
return __awaiter(this, void 0, void 0, function* () {
|
32
42
|
return [];
|
33
43
|
});
|
package/lib/helpers/openai.js
CHANGED
@@ -12,8 +12,8 @@ const client = new OpenAI({
|
|
12
12
|
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
|
13
13
|
});
|
14
14
|
export function getCommitMessage() {
|
15
|
-
var _a;
|
16
15
|
return __awaiter(this, void 0, void 0, function* () {
|
16
|
+
var _a;
|
17
17
|
if (process.env['OPENAI_API_KEY']) {
|
18
18
|
const params = {
|
19
19
|
messages: [{ role: 'user', content: 'Say this is a test' }],
|
@@ -8,13 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
});
|
9
9
|
};
|
10
10
|
import { execSync } from "child_process";
|
11
|
-
import context from "./context.js";
|
11
|
+
import context, { ListFilters } from "./context.js";
|
12
12
|
import { logError, logInfo } from "./color.js";
|
13
13
|
import metadata from './metadata.js';
|
14
14
|
import prompts from "prompts";
|
15
15
|
import templateGenerator from "./template.js";
|
16
|
-
import {
|
17
|
-
|
16
|
+
import { filterBash, getFiles, storeConfig, TEMPLATE_MODEL_FOLDER, valuesToChoices } from "./util.js";
|
17
|
+
function generateTemplate(templateFolder, templateExtension, template, context) {
|
18
|
+
if (!template || !templateFolder || !templateExtension) {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
const templateEngine = templateGenerator(templateFolder, templateExtension);
|
22
|
+
const formulas = {
|
23
|
+
today: Date.now(),
|
24
|
+
};
|
25
|
+
const view = Object.assign(Object.assign({}, formulas), context);
|
26
|
+
templateEngine.read(template);
|
27
|
+
templateEngine.render(view);
|
28
|
+
return templateEngine.rendered;
|
29
|
+
}
|
18
30
|
function createTemplate(templateFolder, templateExtension, template, filename, folder, context) {
|
19
31
|
if (!template || !filename || !templateFolder || !templateExtension) {
|
20
32
|
return;
|
@@ -225,7 +237,7 @@ export const taskFunctions = {
|
|
225
237
|
return true;
|
226
238
|
},
|
227
239
|
storeConfig(variable, value) {
|
228
|
-
storeConfig(variable
|
240
|
+
storeConfig({ [variable]: value });
|
229
241
|
return true;
|
230
242
|
},
|
231
243
|
docProcess() {
|
@@ -321,12 +333,12 @@ export const taskFunctions = {
|
|
321
333
|
console.log('Not implemented');
|
322
334
|
return false;
|
323
335
|
},
|
324
|
-
createIssue(title, label, body) {
|
336
|
+
createIssue(title, label, body, milestone) {
|
325
337
|
return __awaiter(this, void 0, void 0, function* () {
|
326
338
|
if (context.projectApi === undefined) {
|
327
339
|
return false;
|
328
340
|
}
|
329
|
-
const issueNumber = yield context.projectApi.createIssue(title, context.backlogColumn, label, body);
|
341
|
+
const issueNumber = yield context.projectApi.createIssue(title, context.backlogColumn, label, body, milestone);
|
330
342
|
if (issueNumber) {
|
331
343
|
console.log(`Se creo el issue ${issueNumber}`);
|
332
344
|
return true;
|
@@ -346,7 +358,7 @@ export const taskFunctions = {
|
|
346
358
|
if (context.projectApi === undefined) {
|
347
359
|
return false;
|
348
360
|
}
|
349
|
-
const issue = yield context.projectApi.
|
361
|
+
const issue = yield context.projectApi.getIssue(issueNumber);
|
350
362
|
if (!issue.state) {
|
351
363
|
return false;
|
352
364
|
}
|
@@ -428,53 +440,119 @@ export const taskFunctions = {
|
|
428
440
|
return result;
|
429
441
|
});
|
430
442
|
},
|
431
|
-
viewIssue(
|
432
|
-
return __awaiter(this,
|
443
|
+
viewIssue(issueNumber_1) {
|
444
|
+
return __awaiter(this, arguments, void 0, function* (issueNumber, template = 'viewIssue') {
|
433
445
|
if (!context.projectApi) {
|
434
446
|
return false;
|
435
447
|
}
|
436
|
-
const result = yield context.projectApi.
|
437
|
-
|
438
|
-
|
439
|
-
console.log(result.branch);
|
440
|
-
}
|
441
|
-
else {
|
442
|
-
console.log('sin branch');
|
443
|
-
}
|
444
|
-
// Labels
|
445
|
-
if (result.labels) {
|
446
|
-
const labels = [];
|
447
|
-
for (const label of result.labels) {
|
448
|
-
labels.push(getColored(label, 'cyan'));
|
449
|
-
}
|
450
|
-
console.log(labels.join(' '));
|
451
|
-
}
|
452
|
-
// Body
|
453
|
-
if (result.body) {
|
454
|
-
console.log(result.body);
|
455
|
-
}
|
448
|
+
const result = yield context.projectApi.getIssue(issueNumber);
|
449
|
+
const rendered = generateTemplate(TEMPLATE_MODEL_FOLDER, 'bash', template, Object.assign({ issue: result }, context));
|
450
|
+
console.log(rendered);
|
456
451
|
return true;
|
457
452
|
});
|
458
453
|
},
|
459
|
-
listIssues() {
|
454
|
+
listIssues(listFilter, listTemplate) {
|
460
455
|
return __awaiter(this, void 0, void 0, function* () {
|
461
|
-
|
456
|
+
let filter = '{states: OPEN}';
|
457
|
+
const extension = '*';
|
458
|
+
if (!listFilter) {
|
459
|
+
listFilter = context.options.filter || context.listFilter;
|
460
|
+
}
|
461
|
+
if (!listTemplate) {
|
462
|
+
listTemplate = context.options.template || context.listTemplate;
|
463
|
+
}
|
464
|
+
if (!context.projectApi || !context.gitApi) {
|
462
465
|
return false;
|
463
466
|
}
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
+
if (!listFilter) {
|
468
|
+
const answer = yield prompts([
|
469
|
+
{
|
470
|
+
message: 'Elija un filtro, o bien lo puede dejar fijo en autoforce como listFilter',
|
471
|
+
name: 'filter',
|
472
|
+
type: 'select',
|
473
|
+
initial: 0,
|
474
|
+
choices: context.listFilters
|
475
|
+
}
|
476
|
+
]);
|
477
|
+
listFilter = answer.filter;
|
478
|
+
}
|
479
|
+
if (listFilter === ListFilters.PorMilestone) {
|
480
|
+
if (context.options.milestone) {
|
481
|
+
const milestoneFilter = (yield context.gitApi.getMilestones()).filter(milestone => milestone.title == context.options.milestone);
|
482
|
+
if (milestoneFilter.length === 0) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
filter = `{ milestoneNumber: "${milestoneFilter[0].number}"}`;
|
486
|
+
}
|
487
|
+
else {
|
488
|
+
const choices = (yield context.gitApi.getMilestones()).map(milestone => { return { value: milestone.number, title: milestone.title }; });
|
489
|
+
choices.push({ value: '', title: 'Issues sin Milestone' });
|
490
|
+
choices.push({ value: '*', title: 'Issues con Milestone' });
|
491
|
+
const answer = yield prompts([
|
492
|
+
{
|
493
|
+
message: 'Elija un milestone',
|
494
|
+
name: 'filterValue',
|
495
|
+
type: 'select',
|
496
|
+
initial: 0,
|
497
|
+
choices
|
498
|
+
}
|
499
|
+
]);
|
500
|
+
filter = `{ milestoneNumber: "${answer.filterValue}"}`;
|
501
|
+
if (answer.filterValue === undefined)
|
502
|
+
return false;
|
503
|
+
}
|
504
|
+
}
|
505
|
+
if (listFilter === ListFilters.PorLabel) {
|
506
|
+
if (context.options.label) {
|
507
|
+
filter = `{labels: "${context.options.label}"}`;
|
508
|
+
}
|
509
|
+
else {
|
510
|
+
const labels = (yield context.gitApi.getLabels()).map(label => label.name);
|
511
|
+
const choices = valuesToChoices(labels);
|
512
|
+
const answer = yield prompts([
|
513
|
+
{
|
514
|
+
message: 'Elija un label',
|
515
|
+
name: 'filterValue',
|
516
|
+
type: 'select',
|
517
|
+
initial: 0,
|
518
|
+
choices
|
519
|
+
}
|
520
|
+
]);
|
521
|
+
if (answer.filterValue === undefined)
|
522
|
+
return false;
|
523
|
+
filter = `{labels: "${answer.filterValue}"}`;
|
524
|
+
}
|
467
525
|
}
|
526
|
+
if (!listTemplate) {
|
527
|
+
const files = getFiles(TEMPLATE_MODEL_FOLDER, filterBash).map(filename => filename.split(".")[0]);
|
528
|
+
const templates = valuesToChoices(files);
|
529
|
+
const answer = yield prompts([
|
530
|
+
{
|
531
|
+
message: 'Elija un template, o bien lo puede dejar en autoforce como listTemplate',
|
532
|
+
name: 'template',
|
533
|
+
type: 'select',
|
534
|
+
initial: 0,
|
535
|
+
choices: templates
|
536
|
+
}
|
537
|
+
]);
|
538
|
+
listTemplate = answer.template;
|
539
|
+
if (listTemplate === undefined)
|
540
|
+
return false;
|
541
|
+
}
|
542
|
+
const result = yield context.projectApi.getIssuesWithFilter(filter);
|
543
|
+
console.log(context.version);
|
544
|
+
const rendered = generateTemplate(TEMPLATE_MODEL_FOLDER, extension, listTemplate, { issues: result, context });
|
545
|
+
console.log(rendered);
|
468
546
|
return true;
|
469
547
|
});
|
470
548
|
},
|
471
549
|
checkIssueType(issueNumber) {
|
472
|
-
var _a;
|
473
550
|
return __awaiter(this, void 0, void 0, function* () {
|
551
|
+
var _a;
|
474
552
|
if (!context.projectApi) {
|
475
553
|
return false;
|
476
554
|
}
|
477
|
-
const issue = yield context.projectApi.
|
555
|
+
const issue = yield context.projectApi.getIssue(issueNumber);
|
478
556
|
// Setea el issueType segun el issue
|
479
557
|
try {
|
480
558
|
let newIssueType = 'feature';
|
package/lib/helpers/tasks.js
CHANGED
@@ -95,6 +95,10 @@ export function validateTask(task) {
|
|
95
95
|
const subtask = getTask(step.subtask, SUBTASKS_FOLDER);
|
96
96
|
validateStep = validateTask(subtask);
|
97
97
|
}
|
98
|
+
else if (typeof step.task === 'string') {
|
99
|
+
const subtask = getTask(step.task, TASKS_FOLDER);
|
100
|
+
validateStep = validateTask(subtask);
|
101
|
+
}
|
98
102
|
else {
|
99
103
|
console.log('Step no tiene command ni function ni subtask');
|
100
104
|
}
|
@@ -104,8 +108,8 @@ export function validateTask(task) {
|
|
104
108
|
}
|
105
109
|
return true;
|
106
110
|
}
|
107
|
-
export function runTask(
|
108
|
-
return __awaiter(this,
|
111
|
+
export function runTask(task_1, taskContext_1) {
|
112
|
+
return __awaiter(this, arguments, void 0, function* (task, taskContext, tabs = '') {
|
109
113
|
initializeContext();
|
110
114
|
// Valida que este ya esten las variables de enotorno y configuracion
|
111
115
|
if (task.guards) {
|
@@ -134,8 +138,8 @@ export function runTask(task, taskContext, tabs = '') {
|
|
134
138
|
return true;
|
135
139
|
});
|
136
140
|
}
|
137
|
-
export function previewTask(
|
138
|
-
return __awaiter(this,
|
141
|
+
export function previewTask(task_1) {
|
142
|
+
return __awaiter(this, arguments, void 0, function* (task, tabs = '') {
|
139
143
|
initializeContext();
|
140
144
|
logStep(`${task.name}: ${task.description}`, tabs);
|
141
145
|
for (const step of task.steps) {
|
@@ -176,8 +180,8 @@ function runStep(step, tabs) {
|
|
176
180
|
else if (typeof step.function === 'string') {
|
177
181
|
return yield executeFunction(step);
|
178
182
|
}
|
179
|
-
else if (typeof step.subtask === 'string') {
|
180
|
-
const subtask = getTask(step.subtask, SUBTASKS_FOLDER);
|
183
|
+
else if (typeof step.subtask === 'string' || typeof step.task === 'string') {
|
184
|
+
const subtask = typeof step.subtask === 'string' ? getTask(step.subtask, SUBTASKS_FOLDER) : getTask(step.task, TASKS_FOLDER);
|
181
185
|
let stepContext = step.arguments ? context.mergeArgs(step.arguments) : {};
|
182
186
|
if (Array.isArray(stepContext)) {
|
183
187
|
stepContext = createObject(subtask.arguments, stepContext);
|
@@ -206,8 +210,8 @@ function askForContinueOrRetry() {
|
|
206
210
|
function getStepError(step, stepName) {
|
207
211
|
return step.errorMessage ? context.merge(step.errorMessage) : stepName ? `Fallo el step ${stepName}` : '';
|
208
212
|
}
|
209
|
-
function executeStep(
|
210
|
-
return __awaiter(this,
|
213
|
+
function executeStep(step_1, tabs_1) {
|
214
|
+
return __awaiter(this, arguments, void 0, function* (step, tabs, verbose = false) {
|
211
215
|
const stepName = step.name ? context.merge(step.name) : undefined;
|
212
216
|
if (verbose && stepName) {
|
213
217
|
logStep(`[INICIO] ${stepName}`, tabs);
|
@@ -1,13 +1,14 @@
|
|
1
|
-
/// <reference types="handlebars" />
|
2
1
|
declare class TemplateEngine {
|
3
2
|
_template: HandlebarsTemplateDelegate | undefined;
|
4
3
|
_rendered: string | undefined;
|
5
4
|
_extension: string;
|
6
5
|
_sourceFolder: string;
|
7
|
-
constructor(source: string, extension
|
6
|
+
constructor(source: string, extension?: string);
|
8
7
|
getTemplates(): string[];
|
8
|
+
getNameAndExtension(templateName: string): string[];
|
9
9
|
read(templateName: string): void;
|
10
10
|
render(context: object, options?: RuntimeOptions): void;
|
11
|
+
get rendered(): string | undefined;
|
11
12
|
save(filename: string, folder: string, options?: SaveTemplateOptions): void;
|
12
13
|
}
|
13
14
|
declare const _default: (source: string, extension: string) => TemplateEngine;
|
package/lib/helpers/template.js
CHANGED
@@ -23,7 +23,7 @@ function openTemplate(sourceFolder, templateName, extension) {
|
|
23
23
|
return content;
|
24
24
|
}
|
25
25
|
class TemplateEngine {
|
26
|
-
constructor(source, extension) {
|
26
|
+
constructor(source, extension = '*') {
|
27
27
|
this._sourceFolder = source;
|
28
28
|
if (!fs.existsSync(this._sourceFolder)) {
|
29
29
|
throw new Error(`La carpeta source ${this._sourceFolder} no existe!`);
|
@@ -32,7 +32,7 @@ class TemplateEngine {
|
|
32
32
|
}
|
33
33
|
;
|
34
34
|
getTemplates() {
|
35
|
-
const filterThisExtension = (file) => file.endsWith(`.${this._extension}`);
|
35
|
+
const filterThisExtension = (file) => file.endsWith(`.${this._extension}`) || this._extension === '*';
|
36
36
|
const templates = [];
|
37
37
|
const files = getFiles(this._sourceFolder, filterThisExtension, true, ['dictionary']);
|
38
38
|
for (const filename of files) {
|
@@ -41,8 +41,25 @@ class TemplateEngine {
|
|
41
41
|
}
|
42
42
|
return templates;
|
43
43
|
}
|
44
|
+
getNameAndExtension(templateName) {
|
45
|
+
// Si viene la extension en el nombre la extrae
|
46
|
+
if (templateName.split(".").length > 1) {
|
47
|
+
return templateName.split(".");
|
48
|
+
}
|
49
|
+
// Si viene la extension * busca cual puede ser en el directorio
|
50
|
+
if (this._extension === '*' || this._extension === '') {
|
51
|
+
const fileNames = getFiles(this._sourceFolder, fileName => fileName.split(".")[0].endsWith(templateName));
|
52
|
+
if (fileNames.length > 0) {
|
53
|
+
return fileNames[0].split(".");
|
54
|
+
}
|
55
|
+
}
|
56
|
+
// Por defecto usa el templateName como nombre y la extension
|
57
|
+
return [templateName, this._extension];
|
58
|
+
}
|
44
59
|
read(templateName) {
|
45
|
-
|
60
|
+
// Por defecto usa el templateName como nombre y la extension
|
61
|
+
const [name, extension] = this.getNameAndExtension(templateName);
|
62
|
+
const rawTemplate = openTemplate(this._sourceFolder, name, extension);
|
46
63
|
this._template = Handlebars.compile(rawTemplate);
|
47
64
|
}
|
48
65
|
render(context, options = {}) {
|
@@ -51,6 +68,9 @@ class TemplateEngine {
|
|
51
68
|
}
|
52
69
|
this._rendered = this._template(context, options);
|
53
70
|
}
|
71
|
+
get rendered() {
|
72
|
+
return this._rendered;
|
73
|
+
}
|
54
74
|
save(filename, folder, options = { create: true, overwrite: true }) {
|
55
75
|
let accion = "creo";
|
56
76
|
if (folder && !fs.existsSync(folder)) {
|
package/lib/helpers/util.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import prompts from "prompts";
|
1
|
+
import prompts, { Choice } from "prompts";
|
2
2
|
import { AnyValue } from "../types/auto.js";
|
3
3
|
export declare const CONFIG_FILE: string;
|
4
4
|
export declare const TEMPLATES_FOLDER: string;
|
@@ -8,6 +8,7 @@ export declare const WORKING_FOLDER: string;
|
|
8
8
|
export declare const filterJson: (fullPath: string) => boolean;
|
9
9
|
export declare const filterDirectory: (fullPath: string) => boolean;
|
10
10
|
export declare const filterFiles: (fullPath: string) => boolean;
|
11
|
+
export declare const filterBash: (fullPath: string) => boolean;
|
11
12
|
export declare const camelToText: (s: string) => string;
|
12
13
|
export declare const kebabToText: (s: string) => string;
|
13
14
|
export declare const snakeToText: (s: string) => string;
|
@@ -20,9 +21,10 @@ export declare function titlesToChoices(list: string[], titleToValue?: (title: s
|
|
20
21
|
value: string;
|
21
22
|
}[];
|
22
23
|
export declare function getDataFromPackage(): Record<string, string>;
|
23
|
-
export declare function
|
24
|
+
export declare function findChoicesPosition(choices: Choice[], value: string): number;
|
25
|
+
export declare function createConfigurationFile(taskName?: string): Promise<boolean>;
|
24
26
|
export declare function getConfig(variable: string, defaultValue: AnyValue): any;
|
25
|
-
export declare function storeConfig(
|
27
|
+
export declare function storeConfig(record: Record<string, AnyValue>): void;
|
26
28
|
export declare function sortByName(objA: {
|
27
29
|
Name: string;
|
28
30
|
}, objB: {
|