autoforce 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sebastian Claros
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Autoforce
2
+
3
+ ## Objetivo
4
+
5
+ La idea de la herramienta era facilitar y automatizar las tareas comunes que realizamos los desarrolladores. A medida que pasa el tiempo tenemos cada vez mas herramientas diarias y especificas, pero las tareas en si son las misma, queremos arrancar a desarrollar algo nuevo (start), terminar el desarrollo(finish), dejarlo a un costado (stop), o bien cancelarlo (cancel).
6
+
7
+ En este repo las tareas buscan automatizar o integrar el siguiente tipo gestiones:
8
+
9
+ - Branching Strategy en Git (Github o Gitlab)
10
+ - Armado de ambiente de desarrollo (Salesforce)
11
+ - Gestion de proyecto (Github projects, Gitlab projects o Jira).
12
+ - Documentacion (Github pages o GitLab pages. Version mejorada con docusaurus)
13
+ - Calidad de codigo (PMD)
14
+ - Uso de IA ( OpenAI, )
15
+
16
+ ## Instalación
17
+
18
+ ```
19
+ yarn add -D
20
+ ```
21
+
22
+ ## Usos
23
+
24
+
25
+ ```
26
+ "@docusaurus/core": "^3.0.1",
27
+ "@docusaurus/preset-classic": "^3.0.1",
28
+ "@docusaurus/theme-mermaid": "^3.0.1",
29
+ "docusaurus-plugin-drawio": "^0.4.0",
30
+ ```
package/lib/auto.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { ConfigArguments } from "./types/auto.js";
2
+ export default function main(): Promise<void>;
3
+ export declare function getConfigFromArgs(processArgs: string[]): ConfigArguments;
package/lib/auto.js ADDED
@@ -0,0 +1,103 @@
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
+ // Comandos validos
11
+ import { createObject, validateTask, getTasks, helpTask, runTask, getTaskFolder } from "./helpers/tasks.js";
12
+ import { logError } from "./helpers/color.js";
13
+ import { createConfigurationFile } from "./helpers/context.js";
14
+ import prompts from "prompts";
15
+ const proxyCommnad = {
16
+ 'help': helpTask,
17
+ 'task': runTask,
18
+ 'new': runTask,
19
+ 'config': createConfigurationFile,
20
+ 'subtask': runTask
21
+ };
22
+ export default function main() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ try {
25
+ const config = getConfigFromArgs(process.argv.slice(2));
26
+ const tasks = getTasks(config.taskFolder);
27
+ const taskName = yield askForTaskName(config.taskName, tasks);
28
+ if (taskName) {
29
+ const task = tasks[taskName];
30
+ const options = config.arguments && task.arguments ? Object.assign(Object.assign({}, config.options), createObject(task.arguments, config.arguments)) : config.options;
31
+ // Valida los json de task y subtask
32
+ if (validateTask(task)) {
33
+ yield proxyCommnad[config.command](task, options);
34
+ }
35
+ else {
36
+ logError('Verifique que los json de task y subtask esten validos');
37
+ }
38
+ }
39
+ }
40
+ catch (error) {
41
+ if (error instanceof Error) {
42
+ console.error(error.message);
43
+ }
44
+ }
45
+ });
46
+ }
47
+ export function getConfigFromArgs(processArgs) {
48
+ const config = { options: {}, taskName: '', command: '', taskFolder: '' };
49
+ const args = [];
50
+ // Divide --xxx como options el resto como args
51
+ for (const argName of processArgs) {
52
+ if (argName.startsWith('--')) {
53
+ const [optionName, optionValue] = argName.substring(2).split('=');
54
+ config.options[optionName] = optionValue || true;
55
+ }
56
+ else {
57
+ args.push(argName);
58
+ }
59
+ }
60
+ // De acuerdo a args separa comando[help, preview, task o subtask] de taskName
61
+ let currentArgument = args.shift();
62
+ const comandosValidos = Object.keys(proxyCommnad);
63
+ if (currentArgument && comandosValidos.includes(currentArgument)) {
64
+ config.command = currentArgument;
65
+ currentArgument = args.shift();
66
+ }
67
+ else {
68
+ config.command = 'task';
69
+ }
70
+ // Setea el taskFolder segun si es un task o subtask
71
+ if ((config.command == 'help' || config.command == 'preview') && (currentArgument == 'subtask' || currentArgument == 'task')) {
72
+ config.taskFolder = getTaskFolder(currentArgument);
73
+ currentArgument = args.shift();
74
+ }
75
+ else {
76
+ config.taskFolder = getTaskFolder(config.command);
77
+ }
78
+ if (typeof currentArgument == 'string') {
79
+ config.taskName = currentArgument;
80
+ }
81
+ config.arguments = args;
82
+ return config;
83
+ }
84
+ function askForTaskName(taskName, tasks) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ // Si exite lo devuelve
87
+ if (tasks[taskName]) {
88
+ return taskName;
89
+ }
90
+ // Sino pregunta
91
+ const response = yield prompts({
92
+ type: "select",
93
+ name: "taskName",
94
+ message: taskName
95
+ ? `${taskName} no es un comando valido`
96
+ : "Seleccione un comando",
97
+ choices: Object.values(tasks).map((task) => {
98
+ return { title: task.name, value: task.name, description: task.description };
99
+ })
100
+ });
101
+ return response.taskName;
102
+ });
103
+ }
@@ -0,0 +1,12 @@
1
+ import { DocumentationModule } from "../types/auto.js";
2
+ export declare function getClasses(files: string[]): string[];
3
+ declare const classModule: DocumentationModule;
4
+ export default classModule;
5
+ /**
6
+ * TODO
7
+ * innerClass
8
+ * annotations
9
+ * locations links
10
+ * complex types Map<Class, Class>
11
+ * relaciones composicion, etc
12
+ */
@@ -0,0 +1,233 @@
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
+ import sf from "./connect.js";
11
+ import templateGenerator from "./template.js";
12
+ const templateEngine = templateGenerator("dictionary", "md");
13
+ import { sortByName, getNamesByExtension, verFecha, splitFilename, DICTIONARY_FOLDER, DOCS_FOLDER } from "./util.js";
14
+ function getMetadata(clases) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ yield sf.connect();
18
+ const classRecords = yield sf.getClasses(clases);
19
+ return Array.isArray(classRecords) ? classRecords : [classRecords];
20
+ }
21
+ catch (e) {
22
+ console.error(e);
23
+ }
24
+ return [];
25
+ });
26
+ }
27
+ export function getClasses(files) {
28
+ const items = new Set();
29
+ for (const file of files) {
30
+ if (file.indexOf("/classes/") > 0) {
31
+ const { filename } = splitFilename(file);
32
+ items.add(filename.split(".")[0]);
33
+ }
34
+ }
35
+ return [...items.values()];
36
+ }
37
+ function classLink() {
38
+ const name = this.Name;
39
+ return `./diccionarios/classes/${name}`;
40
+ }
41
+ function classLinkGraph() {
42
+ const name = this.Name;
43
+ return `./diccionarios/classes/${name}`;
44
+ }
45
+ function linkToType() {
46
+ const dictionaryClasses = getNamesByExtension(DICTIONARY_FOLDER + "/classes", "md");
47
+ const fullType = this.replace("<", "~").replace(">", "~");
48
+ const types = fullType.split("~");
49
+ for (const t in types) {
50
+ if (dictionaryClasses.includes(t)) {
51
+ fullType.replace(t, `[{t}](./diccionarios/classes/{t})`);
52
+ }
53
+ }
54
+ return fullType;
55
+ }
56
+ function filterByPublic() {
57
+ return this.modifiers.includes("public") || this.modifiers.includes("global");
58
+ }
59
+ function scopeModifiers() {
60
+ const modifiers = [];
61
+ if (this.modifiers.includes("public") || this.modifiers.includes("global")) {
62
+ modifiers.push(`+`);
63
+ }
64
+ if (this.modifiers.includes("private")) {
65
+ modifiers.push(`-`);
66
+ }
67
+ if (this.modifiers.includes("protected")) {
68
+ modifiers.push(`#`);
69
+ }
70
+ return modifiers.join(" ");
71
+ }
72
+ function modifiers() {
73
+ const modifiers = [];
74
+ if (this.modifiers.includes("abstract")) {
75
+ modifiers.push(`*`);
76
+ }
77
+ if (this.modifiers.includes("override")) {
78
+ modifiers.push(`o`);
79
+ }
80
+ if (this.modifiers.includes("static") || this.modifiers.includes("final")) {
81
+ modifiers.push(`$`);
82
+ }
83
+ return modifiers.join(" ");
84
+ }
85
+ function classAttributes() {
86
+ const attributes = [];
87
+ // if (this.isValid === "true") {
88
+ // attributes.push(`![Encripted](/img/password_60.png)`);
89
+ // }
90
+ const systemTable = this.SymbolTable;
91
+ if (systemTable.tableDeclaration.modifiers.includes("static")) {
92
+ attributes.push(`$`);
93
+ }
94
+ if (systemTable.tableDeclaration.modifiers.includes("public") ||
95
+ systemTable.tableDeclaration.modifiers.includes("global")) {
96
+ attributes.push(`+`);
97
+ }
98
+ if (systemTable.tableDeclaration.modifiers.includes("private")) {
99
+ attributes.push(`-`);
100
+ }
101
+ if (systemTable.tableDeclaration.modifiers.includes("protected")) {
102
+ attributes.push(`#`);
103
+ }
104
+ if (systemTable.tableDeclaration.modifiers.includes("global")) {
105
+ attributes.push(`G`);
106
+ }
107
+ return attributes.join(" ");
108
+ }
109
+ function getInnerClasses(classes) {
110
+ let ret = [];
111
+ for (const clase of classes) {
112
+ if (clase.SymbolTable && clase.SymbolTable.innerClasses.length > 0) {
113
+ const innerClases = clase.SymbolTable.innerClasses.map((subclase) => {
114
+ subclase.namespace =
115
+ (clase.namespace ? clase.namespace + "." : "") + clase.Name;
116
+ return {
117
+ Name: subclase.Name,
118
+ type: "inner",
119
+ namespace: subclase.namespace,
120
+ SymbolTable: [subclase]
121
+ };
122
+ });
123
+ ret = ret.concat(innerClases);
124
+ const subInner = getInnerClasses(clase.SymbolTable.innerClasses);
125
+ ret = ret.concat(subInner);
126
+ }
127
+ }
128
+ return ret;
129
+ }
130
+ function executeClasses(items, filename, folder) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ if (items.length === 0) {
133
+ return;
134
+ }
135
+ // Busca la metadata
136
+ let contexts = yield getMetadata(items);
137
+ if (!contexts || contexts.length === 0) {
138
+ return;
139
+ }
140
+ // Arma el diccionario de cada Clase
141
+ templateEngine.read("class");
142
+ for (const context of contexts) {
143
+ templateEngine.render(context, {
144
+ helpers: {
145
+ verFecha,
146
+ modifiers,
147
+ linkToType,
148
+ classLinkGraph,
149
+ filterByPublic,
150
+ classAttributes,
151
+ scopeModifiers
152
+ }
153
+ });
154
+ templateEngine.save(context.Name, DICTIONARY_FOLDER + "/classes");
155
+ }
156
+ // Saca las innerClass y las pone como clases con namespace
157
+ const innerClasses = getInnerClasses(contexts);
158
+ const namespaces = {};
159
+ if (innerClasses.length > 0) {
160
+ templateEngine.read("class-inner");
161
+ for (const context of innerClasses) {
162
+ templateEngine.render(context, {
163
+ helpers: { verFecha, modifiers, linkToType }
164
+ });
165
+ templateEngine.save(context.Name, DICTIONARY_FOLDER + "/classes/" + context.namespace);
166
+ // arma un mapa de namespace con el array de sus innerclases
167
+ if (context.namespace) {
168
+ if (namespaces[context.namespace] === undefined) {
169
+ namespaces[context.namespace] = [context.Name];
170
+ }
171
+ else {
172
+ namespaces[context.namespace].push(context.Name);
173
+ }
174
+ }
175
+ }
176
+ contexts = contexts.concat(innerClasses);
177
+ }
178
+ // Arma el documento indice del grupo de clases
179
+ contexts.sort(sortByName);
180
+ templateEngine.read("classes");
181
+ const classContext = { classes: contexts, namespaces };
182
+ templateEngine.render(classContext, {
183
+ helpers: {
184
+ verFecha,
185
+ modifiers,
186
+ linkToType,
187
+ filterByPublic,
188
+ classLinkGraph,
189
+ classLink
190
+ }
191
+ });
192
+ templateEngine.save(filename, DOCS_FOLDER + "/" + folder);
193
+ });
194
+ }
195
+ const classModule = {
196
+ getItems: getClasses,
197
+ execute: executeClasses
198
+ };
199
+ export default classModule;
200
+ /**
201
+ * TODO
202
+ * innerClass
203
+ * annotations
204
+ * locations links
205
+ * complex types Map<Class, Class>
206
+ * relaciones composicion, etc
207
+ */
208
+ /* annotations
209
+ @AuraEnabled
210
+ @TestSetup
211
+ @TestVisible
212
+ @IsTest
213
+ @Future
214
+
215
+ @Deprecated
216
+ @InvocableMethod
217
+ @InvocableVariable
218
+ @JsonAccess
219
+ @NamespaceAccessible
220
+ @ReadOnly
221
+ @RemoteAction
222
+ @SuppressWarnings
223
+
224
+ @ReadOnly
225
+
226
+ REST API
227
+ @RestResource(urlMapping='/nombremiapi')
228
+ @HttpDelete
229
+ @HttpGet
230
+ @HttpPatch
231
+ @HttpPost
232
+ @HttpPut
233
+ */
@@ -0,0 +1,3 @@
1
+ export declare function logError(message: string, tabs?: string): void;
2
+ export declare function logStep(message: string, tabs?: string): void;
3
+ export declare function getColored(text: string, colorName: string): string;
@@ -0,0 +1,47 @@
1
+ const Reset = "\x1b[0m";
2
+ const FgBlack = "\x1b[30m";
3
+ const FgRed = "\x1b[31m";
4
+ const FgGreen = "\x1b[32m";
5
+ const FgYellow = "\x1b[33m";
6
+ const FgBlue = "\x1b[34m";
7
+ const FgMagenta = "\x1b[35m";
8
+ const FgCyan = "\x1b[36m";
9
+ const FgWhite = "\x1b[37m";
10
+ const FgGray = "\x1b[90m";
11
+ // const Bright = "\x1b[1m"
12
+ // const Dim = "\x1b[2m"
13
+ // const Underscore = "\x1b[4m"
14
+ // const Blink = "\x1b[5m"
15
+ // const Reverse = "\x1b[7m"
16
+ // const Hidden = "\x1b[8m"
17
+ // const BgBlack = "\x1b[40m"
18
+ // const BgRed = "\x1b[41m"
19
+ // const BgGreen = "\x1b[42m"
20
+ // const BgYellow = "\x1b[43m"
21
+ // const BgBlue = "\x1b[44m"
22
+ // const BgMagenta = "\x1b[45m"
23
+ // const BgCyan = "\x1b[46m"
24
+ // const BgWhite = "\x1b[47m"
25
+ // const BgGray = "\x1b[100m"
26
+ export function logError(message, tabs = '') {
27
+ console.error(getColored(`[ERROR] ${tabs}${message}`, "red"));
28
+ }
29
+ export function logStep(message, tabs = '') {
30
+ console.info(getColored(`${tabs}${message}`, "green"));
31
+ }
32
+ function getColorName(name) {
33
+ const colors = { "Black": FgBlack,
34
+ "red": FgRed,
35
+ "green": FgGreen,
36
+ "yellow": FgYellow,
37
+ "blue": FgBlue,
38
+ "magenta": FgMagenta,
39
+ "cyan": FgCyan,
40
+ "white": FgWhite,
41
+ "gray": FgGray };
42
+ return colors[name] ? colors[name] : FgBlack;
43
+ }
44
+ export function getColored(text, colorName) {
45
+ const color = getColorName(colorName.toLowerCase());
46
+ return `${color}${text}${Reset}`;
47
+ }
@@ -0,0 +1,16 @@
1
+ import { CustomObject } from "jsforce/lib/api/metadata.js";
2
+ declare function connect(): Promise<void>;
3
+ declare function check(): boolean;
4
+ declare function getDependencies(listOfIds: string[]): Promise<Dependencies>;
5
+ declare function getLwc(fullNames: string[]): Promise<ILwc[]>;
6
+ declare function getClasses(fullNames: string[]): Promise<IApexClass[]>;
7
+ declare function customObjects(fullNames: string[]): Promise<CustomObject[]>;
8
+ declare const _default: {
9
+ connect: typeof connect;
10
+ check: typeof check;
11
+ customObjects: typeof customObjects;
12
+ getDependencies: typeof getDependencies;
13
+ getClasses: typeof getClasses;
14
+ getLwc: typeof getLwc;
15
+ };
16
+ export default _default;