@johnnycubides/catalejo-vue3-desktop-v2 0.3.0 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnnycubides/catalejo-vue3-desktop-v2",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -1,248 +0,0 @@
1
- import type { Config, Project, Result, PluginResult, SerialOptions } from "./types";
2
- import * as request from "./http-request";
3
- import { BLOCKLY_EXTENSION, LANG, PLATFORM, STATUS, TEXT_EXTENSION, TYPE_PLUGIN_RESULT } from "./consts";
4
- import { dialogLabelCommands, getTextFromLang } from "./lang";
5
-
6
- /** Obtener la información relacionada a la configuración del puertoserial */
7
- function getSerialOptions(config: Config): SerialOptions {
8
- const serialOptions: SerialOptions = {}
9
- let atr = config.baudrate;
10
- if (atr != undefined) {
11
- serialOptions.baudRate = parseInt(atr);
12
- }
13
- atr = config.bits;
14
- if (atr != undefined) {
15
- serialOptions.bits = parseInt(atr);
16
- }
17
- atr = config.parity;
18
- if (atr != undefined) {
19
- serialOptions.parity = parseInt(atr);
20
- }
21
- atr = config.stopbits;
22
- if (atr != undefined) {
23
- serialOptions.stopBits = parseInt(atr);
24
- }
25
- atr = config.flowcontrol;
26
- if (atr != undefined) {
27
- serialOptions.flowControl = parseInt(atr);
28
- }
29
- atr = config.dtr;
30
- if (atr != undefined) {
31
- serialOptions.dtr = parseInt(atr);
32
- }
33
- atr = config.rts;
34
- if (atr != undefined) {
35
- serialOptions.rts = parseInt(atr);
36
- }
37
- atr = config.cts;
38
- if (atr != undefined) {
39
- serialOptions.cts = parseInt(atr);
40
- }
41
- return serialOptions;
42
- }
43
-
44
- /** Enviar archivo a través del puerto serial **/
45
- async function nodemcuSend(project: Project, generateCode: Function): Promise<PluginResult> {
46
-
47
- let portName = "";
48
- const options: SerialOptions = getSerialOptions(project.config);
49
- let timeout = 0;
50
- let fileName = "";
51
- let content = "";
52
- let blockSize = 64;
53
-
54
- if (project.config.portname != undefined) {
55
- portName = project.config.portname;
56
- } else {
57
- return {
58
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
59
- data: {
60
- severity: "warn",
61
- summary: "",
62
- detail: "",
63
- life: 3000,
64
- },
65
- }
66
- // return { status: STATUS.FAILED, data: "Require portName" };
67
- }
68
- if (project.config.timeout != undefined) {
69
- timeout = parseInt(project.config.timeout);
70
- }
71
- // El nombre del archivo no es vacío?
72
- if (project.filename != undefined && project.filename != "") {
73
- // Se solicita renombrar el archivo a guardar?
74
- if (project.config.filerename != undefined && project.config.filerename != "") {
75
- // Al renombrar tiene la extensión de texto válida por el nodemcu?
76
- if (project.config.filerename.split(".").pop() == TEXT_EXTENSION) {
77
- fileName = project.config.filerename;
78
- } else {
79
- return {
80
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
81
- data: {
82
- severity: "warn",
83
- summary: "filerename require extension .lua",
84
- detail: "",
85
- life: 3000,
86
- },
87
- }
88
- // return { status: STATUS.FAILED, data: "fileRename require extension .lua" };
89
- }
90
- } else {
91
- // Proviene de un proyecto con extensión de texto válida para nodemcu?
92
- if (project.extension == TEXT_EXTENSION) {
93
- // Guardar directamente.
94
- fileName = project.filename;
95
- } else {
96
- // En cualquier otro caso deberá sustuir la extensión por la soportada por esta plataforma
97
- const index = project.filename.lastIndexOf(".");
98
- fileName = project.filename.substring(0, index) + "." + TEXT_EXTENSION;
99
- }
100
- }
101
- } else {
102
- return {
103
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
104
- data: {
105
- severity: "warn",
106
- summary: "Dont have filename",
107
- detail: "",
108
- life: 3000,
109
- },
110
- }
111
- // return { status: STATUS.FAILED, data: "Dont have fileName" };
112
- }
113
- if (project.content != undefined) {
114
- // El contenido está en lua?
115
- if (project.extension == TEXT_EXTENSION) {
116
- content = project.content;
117
- // El contenido está en blockly ?
118
- } else if (project.extension == BLOCKLY_EXTENSION && project.config.platform == PLATFORM) {
119
- content = generateCode();
120
- } else {
121
- return {
122
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
123
- data: {
124
- severity: "warn",
125
- summary: "Content dont found",
126
- detail: "",
127
- life: 3000,
128
- },
129
- }
130
- // return { status: STATUS.FAILED, data: "Content in other format" };
131
- }
132
- } else {
133
- return {
134
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
135
- data: {
136
- severity: "warn",
137
- summary: "Content dont found",
138
- detail: "",
139
- life: 3000,
140
- },
141
- }
142
- // return { status: STATUS.FAILED, data: "Content dont found" };
143
- }
144
- if (project.config.blocksize != undefined) {
145
- blockSize = parseInt(project.config.blocksize);
146
- }
147
- const result: Result = await request.saveCode(portName, options, timeout, fileName, content, blockSize);
148
- console.log(result.data);
149
- if (result.status == STATUS.OK) {
150
- return {
151
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
152
- data: {
153
- severity: "success",
154
- summary: "Code save OK",
155
- detail: result.data,
156
- life: 3000,
157
- }
158
- }
159
- // return { status: result.status, data: "Save Ok" };
160
- } else {
161
- return {
162
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
163
- data: {
164
- severity: "error",
165
- summary: "Failed to saved",
166
- detail: result.data,
167
- life: 3000,
168
- }
169
- }
170
- // return { status: result.status, data: "FAILED TO SAVED" };
171
- }
172
- }
173
-
174
- /** Traducir blockly code a lua code */
175
- async function nodemcuMagic(project: Project, generateCode: Function): Promise<PluginResult> {
176
- if (project.extension == BLOCKLY_EXTENSION) {
177
- return {
178
- typeResult: TYPE_PLUGIN_RESULT.TEXT_PRINT,
179
- data: {
180
- title: "Lua",
181
- content: generateCode(),
182
- }
183
- };
184
- } else {
185
- return {
186
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
187
- data: {
188
- severity: "warn",
189
- summary: "Opción disponible solo con archivos blockly (json)",
190
- detail: "",
191
- life: 5000,
192
- }
193
- };
194
- }
195
- }
196
-
197
- /** Consultar los puertos seriales disponibles en el sistema **/
198
- async function getSerialPortList(): Promise<PluginResult> {
199
- const result: Result = await request.getSerialPortList();
200
- if (result.status == STATUS.OK) {
201
- // Convertir el resultado de array a un string
202
- let content = "";
203
- for (let index = 0; index < result.data.length; index++) {
204
- content += result.data[index] + "\n";
205
- }
206
- return {
207
- typeResult: TYPE_PLUGIN_RESULT.TEXT_PRINT,
208
- data: {
209
- title: "SerialPortList",
210
- content: content,
211
- }
212
- };
213
- } else {
214
- return {
215
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
216
- data: {
217
- severity: "warn",
218
- summary: "No se pudo obtener información sobre los puertos seriales",
219
- detail: "",
220
- life: 5000,
221
- }
222
- };
223
- }
224
- }
225
-
226
- /** Entregar el enlace para visualizar la documentación */
227
- async function getUrlDocs(lang: LANG): Promise<PluginResult> {
228
- const DOCS = "/plugins/nodemcu/docs/index.html";
229
- const HOST = "http://" + location.hostname;
230
- const PORT = 8080;
231
- // const PORT = location.port;
232
- const URL = HOST + ":" + PORT + DOCS;
233
- return {
234
- typeResult: TYPE_PLUGIN_RESULT.URL_PRINT,
235
- data: {
236
- title: getTextFromLang(dialogLabelCommands.docs.title, lang),
237
- content: URL,
238
- description: "Abre el siguiente enlace para obtener infomación sobre la documentación de nodemcu",
239
- }
240
- }
241
- }
242
-
243
- export {
244
- nodemcuSend,
245
- nodemcuMagic,
246
- getSerialPortList,
247
- getUrlDocs,
248
- }
@@ -1,57 +0,0 @@
1
- import type { ProgLang } from "./types";
2
- export enum STATUS {
3
- OK,
4
- FAILED,
5
- CHANGE,
6
- WITHOUTCHANGE,
7
- REQUEST, // Solicitud para realizar algo
8
- REQUEST_SELECT_FILE_IN_TABVIEW,
9
- EXISTS,
10
- NOEXIST,
11
- FOUND,
12
- NOTFOUND,
13
- ADDED,
14
- SAVED,
15
- UNSAVED,
16
- SET_WS,
17
- ENABLED,
18
- DESABLED,
19
- }
20
-
21
- export enum LANG {
22
- EN,
23
- ES,
24
- }
25
-
26
- /** Tipo de resultados posibles a entrtegar al editor */
27
- export enum TYPE_PLUGIN_RESULT {
28
- TOAST, TEXT_PRINT, TEXT_AREA, URL_PRINT,
29
- }
30
-
31
- export const PYTHON: ProgLang = { name: "Python", extension: "py" };
32
- export const CHUCK: ProgLang = { name: "ChucK", extension: "ck" };
33
- export const LUA: ProgLang = { name: "Lua", extension: "lua" };
34
- export const JAVASCRIPT: ProgLang = { name: "JavaScript", extension: "js" };
35
- export const JSON: ProgLang = { name: "JSON", extension: "json" };
36
-
37
- export const PROG_LANG: ProgLang[] = [
38
- PYTHON,
39
- CHUCK,
40
- LUA,
41
- JAVASCRIPT,
42
- JSON,
43
- ]
44
-
45
- export const TEXT_EXTENSION = "lua"
46
-
47
- export const BLOCKLY_EXTENSION = "json"
48
-
49
- export const PLATFORM = "nodemcu";
50
-
51
- export const BLOCKLY_TEMPLATE = "{\"config\":{\"platform\":\"nodemcu\",\"portname\":\"\",\"baudrate\":\"115200\"},\"blocklycode\":\"<xml xmlns=\\\"https://developers.google.com/blockly/xml\\\"></xml>\"}"
52
-
53
- export const LANG_TEMPLATE =
54
- `-- platform: nodemcu
55
- -- baudrate: 115200
56
- -- portname:
57
- `
@@ -1,72 +0,0 @@
1
-
2
- import { STATUS } from "./consts";
3
- import type { Result, SerialOptions } from "./types";
4
-
5
- const HOST = "http://" + location.hostname;
6
- // const PORT = location.port;
7
- const PORT = "8080"
8
- const MODE = "cors" // cors, no-cors, same-origin
9
- const ROUTE_PREFIX = "nodemcu/"
10
-
11
- async function fecth(url: string, options: any): Promise<Result> {
12
- try {
13
- const response = await fetch(url, options);
14
- const result = await response.json();
15
- // TODO: Quitar o modificar, se ha usado para debug.
16
- if (result.status == STATUS.OK) {
17
- return result;
18
- } else {
19
- return result;
20
- }
21
- } catch (error) {
22
- console.error(error);
23
- return { status: STATUS.FAILED };
24
- }
25
- }
26
-
27
- export async function saveCode(
28
- portName: string,
29
- serialOptions: SerialOptions,
30
- timeout: number,
31
- fileName: string,
32
- content: string,
33
- blockSize: number
34
- ): Promise<Result> {
35
- // TODO: cambiar el ROUTE que councida con el getDirContent
36
- const ROUTE = ROUTE_PREFIX + "savecode"
37
- const url = HOST + ":" + PORT + '/' + ROUTE;
38
-
39
- const body = {
40
- portName: portName,
41
- options: serialOptions,
42
- timeout: timeout,
43
- fileName: fileName,
44
- content: content,
45
- blockSize: blockSize,
46
- }
47
-
48
- const options: RequestInit = {
49
- method: 'PUT',
50
- mode: MODE,
51
- headers: {
52
- 'Content-Type': 'application/json',
53
- },
54
- body: JSON.stringify(body)
55
- };
56
- return await fecth(url, options);
57
- }
58
-
59
- export async function getSerialPortList(): Promise<Result> {
60
- const ROUTE = ROUTE_PREFIX + "getserialportlist"
61
- const url = HOST + ":" + PORT + '/' + ROUTE;
62
- const body = {};
63
- const options: RequestInit = {
64
- method: 'PUT',
65
- mode: MODE,
66
- headers: {
67
- 'Content-Type': 'application/json',
68
- },
69
- body: JSON.stringify(body)
70
- };
71
- return await fecth(url, options);
72
- }
@@ -1,48 +0,0 @@
1
- import { LANG } from "./consts";
2
-
3
- const itemsToolBarLang = {
4
- nodemcuSend: {
5
- en: "Send",
6
- es: "Enviar"
7
- },
8
- magic: {
9
- en: "Translate",
10
- es: "Traducir"
11
- },
12
- getSerialportList: {
13
- en: "Get serial ports",
14
- es: "Listar puertos seriales"
15
- },
16
- docs: {
17
- en: "Documentation",
18
- es: "Documentación"
19
- }
20
- }
21
-
22
- const dialogLabelCommands = {
23
- docs: {
24
- title: {
25
- en: "Nodemcu documentation",
26
- es: "Documentación para Nodemcu"
27
- },
28
- description: {
29
- en: "Open the next link to get information about Nodemcu",
30
- es: " Abre el siguiente enlace para obtener información sobre Nodemcu"
31
- }
32
- }
33
- }
34
-
35
- export function getTextFromLang(object: any, lang: LANG): string {
36
- if (lang == LANG.EN) {
37
- return object.en;
38
- } else if (lang == LANG.ES) {
39
- return object.es;
40
- } else {
41
- return "noname";
42
- }
43
- }
44
-
45
- export {
46
- itemsToolBarLang,
47
- dialogLabelCommands,
48
- }
@@ -1,112 +0,0 @@
1
- import * as nodemcu from '@johnnycubides/nodemcu-blockly-catalejo';
2
- import type { Project, PluginResult } from "./types";
3
- import * as command from "./commands";
4
- import { LANG, PLATFORM, LUA, TYPE_PLUGIN_RESULT, BLOCKLY_TEMPLATE, LANG_TEMPLATE } from "./consts";
5
- import { itemsToolBarLang, getTextFromLang } from "./lang";
6
-
7
- /** Al iniciarse este plugin, debe conservarse las referencia de algunos datos
8
- * que serán usados por este plugin. */
9
- /** Representación del traductor de blockly a un lenguaje base */
10
- let generator: any;
11
- /** Representación del workspace de blockly */
12
- let workspace: any;
13
- /** Variable de las diferentes operaciones y atributos propios de Blockly */
14
- let Blockly: any;
15
-
16
- /** Valor que representa la plataforma para la cual es presentado este plugin */
17
- const platform = PLATFORM;
18
-
19
- /** Lenguaje interpretado con el que opera el plugin (indicar la extension en vez del nombre del lenguaje) */
20
- const platformLang = LUA;
21
-
22
- /** Template para un nuevo proyecto en blockly */
23
- const blockly_template = BLOCKLY_TEMPLATE;
24
-
25
- /** Template para iniciar un proyecto en lenguaje de texto */
26
- const lang_template = LANG_TEMPLATE;
27
-
28
- /** Función para agregar a Blockly las funciones específicas de este plugin */
29
- function initBlockly(blocklyRef: any, generatorRef: any, workspaceRef: any) {
30
- Blockly = blocklyRef;
31
- generator = generatorRef;
32
- workspace = workspaceRef;
33
- nodemcu.addCustomBlocks(Blockly, generator);
34
- }
35
-
36
- /** Función para traducir de blockly al lenguaje principal de operación de este plugin **/
37
- function generateCode() {
38
- return nodemcu.generateCode(generator, workspace);
39
- }
40
-
41
- /** Toolbox Blockly de este plugin */
42
- const toolbox = nodemcu.toolbox;
43
-
44
- /** Items a ser entregados al menubar de la aplicación Catalejo Editor */
45
- function getItemsToolBarOfPlugin(lang: LANG) {
46
- return [
47
- {
48
- label: getTextFromLang(itemsToolBarLang.magic, lang),
49
- icon: "pi pi-sparkles",
50
- command: "nodemcu-magic"
51
- },
52
- {
53
- label: getTextFromLang(itemsToolBarLang.nodemcuSend, lang),
54
- icon: 'pi pi-send',
55
- command: "nodemcu-send",
56
- },
57
- {
58
- label: "nodemcu",
59
- icon: "pi pi-microchip",
60
- items: [
61
- {
62
- label: getTextFromLang(itemsToolBarLang.getSerialportList, lang),
63
- icon: "pi pi-search",
64
- command: "nodemcu-getserialportlist"
65
- },
66
- {
67
- label: getTextFromLang(itemsToolBarLang.docs, lang),
68
- icon: "pi pi-book",
69
- command: "nodemcu-docs"
70
- }
71
- ]
72
-
73
- }
74
- ]
75
- }
76
-
77
- /** Filtro de solicitudes que provienen de la aplicación */
78
- async function commandEmit(project: Project, commandId: string, lang: LANG): Promise<PluginResult> {
79
- // TODO: Convertir en un swutch
80
- if (commandId == "nodemcu-send") {
81
- return await command.nodemcuSend(project, generateCode);
82
- } else if (commandId == "nodemcu-magic") {
83
- return await command.nodemcuMagic(project, generateCode);
84
- } else if (commandId == "nodemcu-getserialportlist") {
85
- return await command.getSerialPortList();
86
- } else if (commandId == "nodemcu-docs") {
87
- return await command.getUrlDocs(lang);
88
- }
89
- else {
90
- return {
91
- typeResult: TYPE_PLUGIN_RESULT.TOAST,
92
- data: {
93
- severity: "error",
94
- summary: "Función no localizada en el plugin",
95
- detail: "",
96
- life: 3000,
97
- }
98
- }
99
- }
100
- }
101
-
102
- export {
103
- platform,
104
- platformLang,
105
- toolbox,
106
- initBlockly,
107
- generateCode,
108
- getItemsToolBarOfPlugin,
109
- commandEmit,
110
- blockly_template,
111
- lang_template,
112
- };
@@ -1,77 +0,0 @@
1
- import type { STATUS, TYPE_PLUGIN_RESULT } from "@/consts";
2
-
3
- // Config es una lista de opciones que se configuran desde el editor.
4
- // Aunque desde el editor es del tipo any y el tamaño no está definido
5
- // Desde el punto de vsita del plugin se restringe las opciones
6
- // de tal maneras que se pueden exponer en la documentación.
7
- export interface Config {
8
- platform?: string, // Nombre de la plataforma
9
- portname?: string, // Puerto serial a usar
10
- timeout?: string, // Timeout del puerto serial
11
- filerename?: string, // Nombre del archivo a guardar
12
- blocksize?: string, // Tamaño de los bloques a enviar por serial
13
- baudrate?: string, // baudRate del puerto serial
14
- bits?: string, // Bits del puerto serial
15
- parity?: string, // Paridad del puerto serial
16
- stopbits?: string, // stopBits del puerto serial
17
- flowcontrol?: string, // flowControl del puerto serial
18
- dtr?: string, // dtr del puerto serial
19
- rts?: string, // rts del puerto serial
20
- cts?: string, // cts del puertoserial
21
- }
22
-
23
- // Estructura de los proyectos a guardar
24
- export interface Project {
25
- path: string,
26
- filename: string,
27
- extension: string, // la extensión está asociada al lenguaje de codemirror
28
- content: string, // Contenido a guardar en el File
29
- blocklycode: string, // compilación dada por ejemplo desde blockly XML
30
- codemirrorCursor: number // Posición del cursor
31
- config: Config,
32
- status: STATUS, // ADDED, SAVED, UNSAVED
33
- }
34
-
35
- // Formato de retorno para funciones
36
- // especialmente como interfaz de vue
37
- export interface Result {
38
- status: STATUS
39
- data?: any
40
- }
41
-
42
- export interface DataToast {
43
- severity: string, /** "error" | "success" | "secondary" | "info" | "contrast" | "warn" */
44
- summary: string,
45
- detail: string,
46
- life: number, /** time in ms */
47
- }
48
-
49
- export interface DataDialog {
50
- title: string,
51
- description?: string,
52
- content: any,
53
- }
54
-
55
- /** Respuesta que debe entregar el plugin para usar en el editor */
56
- export interface PluginResult {
57
- typeResult: TYPE_PLUGIN_RESULT,
58
- data?: DataToast | DataDialog,
59
- }
60
-
61
- export interface SerialOptions {
62
- baudRate?: number,
63
- bits?: number,
64
- parity?: number,
65
- stopBits?: number,
66
- flowControl?: number,
67
- dtr?: number,
68
- rts?: number,
69
- cts?: number,
70
- }
71
-
72
-
73
- /** Lenguajes de programación */
74
- export interface ProgLang {
75
- name: string,
76
- extension: string,
77
- }
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />