@iancarlos/mathscript 1.0.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/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@iancarlos/mathscript",
3
+ "version": "1.0.1",
4
+ "description": "ts/js superset",
5
+ "main": "src/transpile.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/IanLangs/Mathscript.git"
13
+ },
14
+ "keywords": [
15
+ "msc",
16
+ "ms",
17
+ "mathscript"
18
+ ],
19
+ "author": "IanLangs",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/IanLangs/Mathscript/issues"
23
+ },
24
+ "dependencies": {
25
+ "typescript": "^5.9.3"
26
+ },
27
+ "bin":{
28
+ "msc":"src/main.js"
29
+ }
30
+ }
package/src/main.js ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+
3
+ import MS from './transpile.js';
4
+ import fs from 'fs';
5
+ import readline from 'readline';
6
+
7
+ // Función para preguntar al usuario
8
+ function ask(question) {
9
+ const rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout
12
+ });
13
+ return new Promise(resolve => {
14
+ rl.question(question, answer => {
15
+ rl.close();
16
+ resolve(answer);
17
+ });
18
+ });
19
+ }
20
+
21
+ async function main() {
22
+ const arg1 = process.argv[2] || "msconfig.json";
23
+
24
+ if (arg1 === "--init") {
25
+ // Preguntar al usuario
26
+ const strictInput = await ask("¿Querés que sea estricto? (sí/no): ");
27
+ const strict = strictInput.toLowerCase().startsWith("s"); // sí → true, no → false
28
+
29
+ const filesInput = await ask("Ingresá los archivos .ms separados por espacios: ");
30
+ const files = filesInput.split(" ").filter(f => f.trim().length > 0);
31
+
32
+ // Crear config
33
+ MS.config = { strict, Files: files };
34
+
35
+ // Guardar config en msconfig.json
36
+ fs.writeFileSync("msconfig.json", JSON.stringify(MS.config, null, 2), 'utf-8');
37
+ console.log("Archivo msconfig.json creado!");
38
+ return;
39
+ }
40
+
41
+ // Si no es --init, asumimos que es un archivo de config
42
+ MS.config = JSON.parse(fs.readFileSync(arg1, 'utf-8'));
43
+
44
+ const strict = MS.config["strict"];
45
+ const files = MS.config["Files"];
46
+
47
+ for (const file of files) {
48
+ const out = file.replace(/\.ms$/, ".js");
49
+ let code = fs.readFileSync(file, 'utf-8');
50
+ code = MS.ms2ts(code);
51
+ code = MS.ts2js(code, strict);
52
+ fs.writeFileSync(out, code, 'utf-8');
53
+ console.log(`Transpilado ${file} → ${out}`);
54
+ }
55
+ }
56
+
57
+ main();
@@ -0,0 +1,51 @@
1
+ #!/bin/env node
2
+
3
+ import * as ts from "typescript"
4
+ import * as fs from "fs"
5
+ import { config } from "process"
6
+ class regex {
7
+
8
+ constructor(p, r) {
9
+ this.p = p
10
+ this.r =r
11
+ }
12
+ replace(s) {
13
+ return s.replace(this.p, this.r)
14
+ }
15
+ }
16
+
17
+ let config = {}
18
+
19
+ const constants = [
20
+ regex(/::/g, ":"),
21
+ regex(/using\((.*?)\)/g, "requiere($1)"),
22
+ regex(/\bstr\b/g, "string"),
23
+ regex(/\bbool\b/g, "boolean"),
24
+ regex(/\bobj\b/g, "object"),
25
+ regex(/\barr\b/g, "Array"),
26
+ regex(/\bfunction\b/g, "Function"),
27
+ regex(/\bfn\b/g, "function")
28
+ ]
29
+
30
+ function ms2ts(code) {
31
+ let result = code;
32
+ for (const r of constants) {
33
+ result = r.replace(result);
34
+ }
35
+ return result;
36
+ }
37
+ function ts2js(code, types) {
38
+ if (types) {
39
+ return ts.transpile(code, { target: ts.ScriptTarget.ES2020, module: ts.ModuleKind.ESNext });
40
+ } else {
41
+ return ts.transpileModule(code, {
42
+ compilerOptions: {
43
+ target: ts.ScriptTarget.ES2020,
44
+ module: ts.ModuleKind.ESNext,
45
+ strict: false
46
+ }
47
+ }).outputText;
48
+ }
49
+ }
50
+
51
+ export default {config, ms2ts, ts2js}