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.
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import fs from "fs";
11
11
  import { fileURLToPath } from 'url';
12
12
  import prompts from "prompts";
13
- import { ProjectServices, GitServices } from "./context.js";
13
+ import context, { ProjectServices, GitServices } from "./context.js";
14
14
  import { logInfo, logWarning } from "./color.js";
15
15
  const COMMAND_FOLDER = searchInFolderHierarchy('commands', fileURLToPath(import.meta.url));
16
16
  export const CONFIG_FILE = process.cwd() + '/.autoforce.json';
@@ -21,6 +21,7 @@ export const WORKING_FOLDER = process.env.INIT_CWD || ".";
21
21
  export const filterJson = (fullPath) => fullPath.endsWith(".json");
22
22
  export const filterDirectory = (fullPath) => fs.lstatSync(fullPath).isDirectory();
23
23
  export const filterFiles = (fullPath) => !fs.lstatSync(fullPath).isDirectory();
24
+ export const filterBash = (fullPath) => fullPath.endsWith(".bash");
24
25
  export const camelToText = (s) => s.replace(/[A-Z]/g, x => ' ' + x);
25
26
  export const kebabToText = (s) => s.replace(/-./g, x => ' ' + x[1].toUpperCase());
26
27
  export const snakeToText = (s) => s.replace(/_./g, x => ' ' + x[1].toUpperCase());
@@ -69,23 +70,61 @@ export function getDataFromPackage() {
69
70
  }
70
71
  return data;
71
72
  }
72
- export function createConfigurationFile() {
73
+ export function findChoicesPosition(choices, value) {
74
+ const index = choices.findIndex(choice => choice.value === value);
75
+ return index === -1 ? 0 : index;
76
+ }
77
+ function getTaskConfig(config) {
73
78
  return __awaiter(this, void 0, void 0, function* () {
74
- // Todo: Chequear el repoOwner y repo
75
- const data = getDataFromPackage();
76
- const optionals = {};
77
- if (!data.repositoryOwner || !data.repositoryRepo) {
78
- throw new Error('No se encontro repository en el package.json ! Por favor agreguelo y vuelva a intentar');
79
+ // TODO: Ver si esto se mueve a un config list
80
+ // List Command settings
81
+ const filters = context.listFilters();
82
+ const listFilter = yield prompts([
83
+ {
84
+ message: 'Elija un filtro, o bien lo puede dejar fijo en autoforce como listFilter',
85
+ name: 'filter',
86
+ type: 'select',
87
+ initial: findChoicesPosition(filters, config.listFilter),
88
+ choices: filters
89
+ }
90
+ ]);
91
+ if (listFilter.filter === undefined)
92
+ return;
93
+ config.listFilter = listFilter.filter;
94
+ const files = getFiles(`${TEMPLATES_FOLDER}/${config.modelTemplates}`, filterBash).map(filename => filename.split(".")[0]);
95
+ if (files.length > 0) {
96
+ const templates = valuesToChoices(files);
97
+ const template = yield prompts([
98
+ {
99
+ message: 'Elija un template, o bien lo puede dejar en autoforce como listTemplate',
100
+ name: 'template',
101
+ type: 'select',
102
+ initial: findChoicesPosition(templates, config.listTemplate),
103
+ choices: templates
104
+ }
105
+ ]);
106
+ if (template.template === undefined)
107
+ return;
108
+ config.listTemplate = template.template;
79
109
  }
80
- const initialServices = data.repositoryUrl.includes("github.com") ? 0 : 1;
110
+ return config;
111
+ });
112
+ }
113
+ function getBaseConfig(config) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ // Todo: Chequear el repoOwner y repo
116
+ const gitChoices = [{ title: 'Github', value: GitServices.GitHub }, { title: 'Gitlab', value: GitServices.GitLab }];
81
117
  // Preguntar por GitHub o GitLab
82
118
  const gitServices = yield prompts([{
83
119
  type: "select",
84
120
  name: "git",
85
- initial: initialServices,
86
121
  message: "Elija un servicio de Git",
87
- choices: [{ title: 'Github', value: GitServices.GitHub }, { title: 'Gitlab', value: GitServices.GitLab }]
122
+ initial: findChoicesPosition(gitChoices, config.gitServices),
123
+ choices: gitChoices
88
124
  }]);
125
+ if (gitServices.git === undefined)
126
+ process.exit(0);
127
+ config.gitServices = gitServices.git;
89
128
  // Chequear las variables de entorno
90
129
  if (gitServices.git === GitServices.GitHub && !process.env.GITHUB_TOKEN) {
91
130
  logWarning('A fin de que la herramienta funcione debe configurar una variable de entorno GITHUB_TOKEN');
@@ -93,13 +132,19 @@ export function createConfigurationFile() {
93
132
  if (gitServices.git === GitServices.GitLab && !process.env.GITLAB_TOKEN) {
94
133
  logWarning('A fin de que la herramienta funcione debe configurar una variable de entorno GITLAB_TOKEN');
95
134
  }
135
+ // Selecciona el modelo de automatizacion
96
136
  const models = readJsonSync(`${COMMAND_FOLDER}/models.json`);
137
+ models.push({ title: 'Personalizado', value: 'custom', description: 'En este caso los comandos son configurados fuera de la herramienta y los lee de la carpeta commands en el root del repo' });
97
138
  const automationModel = yield prompts([{
98
139
  type: "select",
99
140
  name: "model",
100
141
  message: "Elija un modelo de automatizacion",
101
- choices: models.concat([{ title: 'Personalizado', value: 'custom', description: 'En este caso los comandos son configurados fuera de la herramienta y los lee de la carpeta commands en el root del repo' }])
142
+ initial: findChoicesPosition(models, config.model),
143
+ choices: models
102
144
  }]);
145
+ if (automationModel.model === undefined)
146
+ return;
147
+ config.model = automationModel.model;
103
148
  // Si es custom pregunta si quiere tomar de base alguno existente
104
149
  if (automationModel.model === 'custom') {
105
150
  const baseModel = yield prompts([{
@@ -113,45 +158,63 @@ export function createConfigurationFile() {
113
158
  }
114
159
  }
115
160
  // Gestion del Proyecto
161
+ const projectChoices = [{ title: 'Github Projects', value: ProjectServices.GitHub }, { title: 'GitLab Projects', value: ProjectServices.GitLab }, { title: 'Jira', value: ProjectServices.Jira }, { title: 'None', value: ProjectServices.None }];
116
162
  const projectServices = yield prompts([{
117
163
  type: "select",
118
164
  name: "project",
119
- initial: initialServices,
120
165
  message: "Gestion de proyecto",
121
- choices: [{ title: 'Github Projects', value: ProjectServices.GitHub }, { title: 'GitLab Projects', value: ProjectServices.GitLab }, { title: 'Jira', value: ProjectServices.Jira }, { title: 'None', value: ProjectServices.None }]
166
+ initial: findChoicesPosition(projectChoices, config.projectServices),
167
+ choices: projectChoices
122
168
  }]);
169
+ if (projectServices.project === undefined)
170
+ return;
171
+ config.projectServices = projectServices.project;
172
+ ;
123
173
  if (projectServices.project === ProjectServices.GitHub || projectServices.project === ProjectServices.GitLab) {
124
174
  // Gestion del Proyecto
125
175
  const backlogColumn = yield prompts([{
126
176
  type: "text",
127
177
  name: "backlogColumn",
128
- initial: 'Todo',
178
+ initial: config.backlogColumn,
129
179
  message: "Nombre de la columna donde se crean nuevos issues"
130
180
  }]);
131
- optionals['backlogColumn'] = backlogColumn.backlogColumn;
132
- logInfo(`Por omision ser utilizan proyectos dentro de ${data.repositoryOwner} y ${data.repositoryRepo} `);
181
+ if (backlogColumn.backlogColumn === undefined)
182
+ return;
183
+ config.backlogColumn = backlogColumn.backlogColumn;
184
+ logInfo(`Por omision ser utilizan proyectos dentro de ${context.repositoryOwner} y ${context.repositoryRepo} `);
133
185
  }
186
+ // Id de Projecto
134
187
  const projectId = yield prompts([{
135
188
  type: "text",
136
189
  name: "projectId",
190
+ initial: config.projectId,
137
191
  message: "Id del proyecto"
138
192
  }]);
193
+ if (projectId.projectId === undefined)
194
+ return;
195
+ config.projectId = projectId.projectId;
139
196
  // Modelo de Dcumentacion
140
197
  const modelsTemplates = readJsonSync(`${TEMPLATES_FOLDER}/models.json`);
141
198
  const modelTemplates = yield prompts([{
142
199
  type: "select",
143
200
  name: "model",
144
201
  message: "Elija un modelo de documentacion",
202
+ initial: findChoicesPosition(modelsTemplates, config.modelTemplates),
145
203
  choices: modelsTemplates
146
204
  }]);
147
- // console.log('Genera documentacion');
148
- const config = Object.assign({ model: automationModel.model, modelTemplates: modelTemplates.model, gitServices: gitServices.git, projectServices: projectServices.project, projectId: projectId.projectId }, optionals);
149
- try {
150
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
151
- }
152
- catch (_a) {
153
- throw new Error(`No se pudo guardar la configuracion en ${CONFIG_FILE}`);
154
- }
205
+ if (modelTemplates.model === undefined)
206
+ return;
207
+ config.modelTemplates = modelTemplates.model;
208
+ return config;
209
+ });
210
+ }
211
+ export function createConfigurationFile(taskName) {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ const baseConfig = { backlogColumn: context.backlogColumn, model: context.model, modelTemplates: context.modelTemplates, gitServices: context.gitServices, projectServices: context.projectServices, projectId: context.projectId, listFilter: context.listFilter, listTemplate: context.listTemplate };
214
+ let config = taskName ? yield getTaskConfig(baseConfig) : yield getBaseConfig(baseConfig);
215
+ if (!config)
216
+ return false;
217
+ storeConfig(config);
155
218
  return true;
156
219
  });
157
220
  }
@@ -170,7 +233,7 @@ export function getConfig(variable, defaultValue) {
170
233
  }
171
234
  return defaultValue;
172
235
  }
173
- export function storeConfig(variable, value) {
236
+ export function storeConfig(record) {
174
237
  let config = {};
175
238
  if (fs.existsSync(CONFIG_FILE)) {
176
239
  const content = fs.readFileSync(CONFIG_FILE, "utf8");
@@ -181,8 +244,15 @@ export function storeConfig(variable, value) {
181
244
  throw new Error(`Verifique que el ${CONFIG_FILE} sea json valido`);
182
245
  }
183
246
  }
184
- config[variable] = value;
185
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
247
+ for (const [variable, value] of Object.entries(record)) {
248
+ config[variable] = value;
249
+ }
250
+ try {
251
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
252
+ }
253
+ catch (_b) {
254
+ throw new Error(`No se pudo guardar la configuracion en ${CONFIG_FILE}`);
255
+ }
186
256
  }
187
257
  export function sortByName(objA, objB) {
188
258
  return objA.Name > objB.Name ? 1 : objA.Name < objB.Name ? -1 : 0;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "autoforce",
3
3
  "homepage": "https://sebastianclaros.github.io/autoforce",
4
4
  "private": false,
5
- "version": "0.1.10",
5
+ "version": "0.1.12",
6
6
  "keywords": [
7
7
  "Salesforce",
8
8
  "Automation",
@@ -1,4 +1,8 @@
1
-
2
- {{#each issues}}
3
- * {{title}}
4
- {{/each}}
1
+ ## Version {{context.version}}
2
+ - Fecha: {{hoy}}
3
+ - Paquete: [Descargar](https://www.npmjs.com/package/autoforce/v/{{context.version}})
4
+ - Cambios:
5
+ {{#each issues}}
6
+ * {{title}}
7
+ - {{url}}
8
+ {{/each}}
@@ -0,0 +1,4 @@
1
+ {{#each issues}}
2
+ * #{{number}}: {{title}}
3
+ {{milestone.title}}
4
+ {{/each}}
@@ -0,0 +1,8 @@
1
+ {{#with issue}}
2
+ #{{number}}: {{title}}
3
+ {{state}}
4
+ {{#each labels}}{{this}}{{/each}}
5
+ {{url}}
6
+ {{milestone.title}}
7
+ {{body}}
8
+ {{/with}}
@@ -2,12 +2,11 @@
2
2
  {
3
3
  "title": "Procesos de Negocio en Salesforce",
4
4
  "value": "modelA",
5
- "description": "Documenta Clases, Objetos y LWC a traves de procesos de negocios. Se basa en docusaurus"0
5
+ "description": "Documenta Clases, Objetos y LWC a traves de procesos de negocios. Se basa en docusaurus"
6
6
  },
7
7
  {
8
8
  "title": "Proyecto simple en Github Docs",
9
9
  "value": "modelB",
10
10
  "description": "Github pages con changelog, readme y carpeta docs de Markdowns"
11
11
  }
12
- ]
13
-
12
+ ]
File without changes