@ianlangs/mathscript 1.4.0 → 1.6.2
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/mpm/mpm.js +119 -0
- package/mpm/mpm.ms +119 -0
- package/package.json +3 -2
- package/src/msc.js +10 -0
- package/src/msnode.js +11 -0
- package/src/transpile.js +1 -1
- package/src/web-t.js +43 -0
package/mpm/mpm.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import path from "path"
|
|
4
|
+
import https from "https"
|
|
5
|
+
import { execSync } from "child_process"
|
|
6
|
+
|
|
7
|
+
if (process.argv[2] === "-v" || process.argv[2] === "--version") {
|
|
8
|
+
(async () => {
|
|
9
|
+
const url = "https://unpkg.com/@ianlangs/mathscript/package.json"
|
|
10
|
+
const res = await fetch(url)
|
|
11
|
+
const pkg = await res.json()
|
|
12
|
+
console.log(`MS versión = ${pkg.version}`)
|
|
13
|
+
process.exit(0)
|
|
14
|
+
})()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2)
|
|
18
|
+
const CWD = process.cwd()
|
|
19
|
+
const MODULES_DIR = path.join(CWD, "ms_modules")
|
|
20
|
+
const DEFAULT_REPO = "https://ianlangs.github.io/mpm-ms/"
|
|
21
|
+
|
|
22
|
+
function ensureDir(dir) {
|
|
23
|
+
if (!fs.existsSync(dir)) {
|
|
24
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function download(url, dest) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const file = fs.createWriteStream(dest)
|
|
31
|
+
https.get(url, res => {
|
|
32
|
+
if (res.statusCode !== 200) {
|
|
33
|
+
reject("HTTP " + res.statusCode)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
res.pipe(file)
|
|
37
|
+
file.on("finish", () => {
|
|
38
|
+
file.close()
|
|
39
|
+
resolve()
|
|
40
|
+
})
|
|
41
|
+
}).on("error", err => {
|
|
42
|
+
fs.unlinkSync(dest)
|
|
43
|
+
reject(err)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function installFromDefault(pkg) {
|
|
49
|
+
const url = DEFAULT_REPO + pkg + ".ms"
|
|
50
|
+
const dest = path.join(MODULES_DIR, pkg + ".ms")
|
|
51
|
+
console.log("Installing", pkg, "from", url)
|
|
52
|
+
return download(url, dest)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function installFromCustom(url) {
|
|
56
|
+
const name = url.split("/").pop()
|
|
57
|
+
const dest = path.join(MODULES_DIR, name)
|
|
58
|
+
console.log("Installing", name, "from", url)
|
|
59
|
+
return download(url, dest)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function installFromNpm(pkg) {
|
|
63
|
+
console.log("Installing from npm:", pkg)
|
|
64
|
+
execSync("npm install " + pkg, { stdio: "inherit" })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function usage() {
|
|
68
|
+
console.log(`
|
|
69
|
+
mpm - MS Package Manager
|
|
70
|
+
|
|
71
|
+
Commands:
|
|
72
|
+
|
|
73
|
+
mpm -i <package> install from default repo
|
|
74
|
+
mpm -i -c <url> install from custom url
|
|
75
|
+
mpm -n <package> install from npm
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
|
|
79
|
+
mpm -i math
|
|
80
|
+
mpm -i -c https://site.com/lib.ms
|
|
81
|
+
mpm -n lodash
|
|
82
|
+
`)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
ensureDir(MODULES_DIR)
|
|
86
|
+
|
|
87
|
+
if (args.length == 0) {
|
|
88
|
+
usage()
|
|
89
|
+
process.exit(0)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
if (args[0] == "-i" || args[0] == "--install") {
|
|
94
|
+
if (args[1] == "-c" || args[1] == "--custom") {
|
|
95
|
+
const url = args[2]
|
|
96
|
+
if (!url) throw "Missing URL"
|
|
97
|
+
await installFromCustom(url)
|
|
98
|
+
} else {
|
|
99
|
+
const pkg = args[1]
|
|
100
|
+
if (!pkg) throw "Missing package name"
|
|
101
|
+
await installFromDefault(pkg)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
else if (args[0] == "-n" || args[0] == "--npm") {
|
|
106
|
+
const pkg = args[1]
|
|
107
|
+
if (!pkg) throw "Missing npm package"
|
|
108
|
+
installFromNpm(pkg)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
else {
|
|
112
|
+
usage()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.log("Done.")
|
|
116
|
+
}
|
|
117
|
+
catch(e) {
|
|
118
|
+
console.error("\n[MPM ERROR]\n", e)
|
|
119
|
+
}
|
package/mpm/mpm.ms
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import path from "path"
|
|
4
|
+
import https from "https"
|
|
5
|
+
import { execSync } from "child_process"
|
|
6
|
+
|
|
7
|
+
if (process.argv[2] === "-v" || process.argv[2] === "--version") {
|
|
8
|
+
(async () => {
|
|
9
|
+
const url = "https://unpkg.com/@ianlangs/mathscript/package.json"
|
|
10
|
+
const res = await fetch(url)
|
|
11
|
+
const pkg = await res.json()
|
|
12
|
+
console.log(`MS versión = ${pkg.version}`)
|
|
13
|
+
process.exit(0)
|
|
14
|
+
})()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2)
|
|
18
|
+
const CWD = process.cwd()
|
|
19
|
+
const MODULES_DIR = path.join(CWD, "ms_modules")
|
|
20
|
+
const DEFAULT_REPO = "https://ianlangs.github.io/mpm-ms/"
|
|
21
|
+
|
|
22
|
+
fn ensureDir(dir) {
|
|
23
|
+
if (!fs.existsSync(dir)) {
|
|
24
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fn download(url, dest) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const file = fs.createWriteStream(dest)
|
|
31
|
+
https.get(url, res => {
|
|
32
|
+
if (res.statusCode !== 200) {
|
|
33
|
+
reject("HTTP " + res.statusCode)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
res.pipe(file)
|
|
37
|
+
file.on("finish", () => {
|
|
38
|
+
file.close()
|
|
39
|
+
resolve()
|
|
40
|
+
})
|
|
41
|
+
}).on("error", err => {
|
|
42
|
+
fs.unlinkSync(dest)
|
|
43
|
+
reject(err)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn installFromDefault(pkg) {
|
|
49
|
+
const url = DEFAULT_REPO + pkg + ".ms"
|
|
50
|
+
const dest = path.join(MODULES_DIR, pkg + ".ms")
|
|
51
|
+
console.log("Installing", pkg, "from", url)
|
|
52
|
+
return download(url, dest)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fn installFromCustom(url) {
|
|
56
|
+
const name = url.split("/").pop()
|
|
57
|
+
const dest = path.join(MODULES_DIR, name)
|
|
58
|
+
console.log("Installing", name, "from", url)
|
|
59
|
+
return download(url, dest)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn installFromNpm(pkg) {
|
|
63
|
+
console.log("Installing from npm:", pkg)
|
|
64
|
+
execSync("npm install " + pkg, { stdio: "inherit" })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fn usage() {
|
|
68
|
+
console.log(`
|
|
69
|
+
mpm - MS Package Manager
|
|
70
|
+
|
|
71
|
+
Commands:
|
|
72
|
+
|
|
73
|
+
mpm -i <package> install from default repo
|
|
74
|
+
mpm -i -c <url> install from custom url
|
|
75
|
+
mpm -n <package> install from npm
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
|
|
79
|
+
mpm -i math
|
|
80
|
+
mpm -i -c https://site.com/lib.ms
|
|
81
|
+
mpm -n lodash
|
|
82
|
+
`)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
ensureDir(MODULES_DIR)
|
|
86
|
+
|
|
87
|
+
if (args.length == 0) {
|
|
88
|
+
usage()
|
|
89
|
+
process.exit(0)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
if (args[0] == "-i" || args[0] == "--install") {
|
|
94
|
+
if (args[1] == "-c" || args[1] == "--custom") {
|
|
95
|
+
const url = args[2]
|
|
96
|
+
if (!url) throw "Missing URL"
|
|
97
|
+
await installFromCustom(url)
|
|
98
|
+
} else {
|
|
99
|
+
const pkg = args[1]
|
|
100
|
+
if (!pkg) throw "Missing package name"
|
|
101
|
+
await installFromDefault(pkg)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
else if (args[0] == "-n" || args[0] == "--npm") {
|
|
106
|
+
const pkg = args[1]
|
|
107
|
+
if (!pkg) throw "Missing npm package"
|
|
108
|
+
installFromNpm(pkg)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
else {
|
|
112
|
+
usage()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.log("Done.")
|
|
116
|
+
}
|
|
117
|
+
catch(e) {
|
|
118
|
+
console.error("\n[MPM ERROR]\n", e)
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@ianlangs/mathscript",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.2",
|
|
5
5
|
"description": "superset de js",
|
|
6
6
|
"main": "src/transpile.js",
|
|
7
7
|
"scripts": {
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"bin": {
|
|
27
27
|
"msc": "./src/msc.js",
|
|
28
|
-
"ms-node": "./src/msnode.js"
|
|
28
|
+
"ms-node": "./src/msnode.js",
|
|
29
|
+
"mpm": "./mpm/mpm.js"
|
|
29
30
|
},
|
|
30
31
|
"homepage": "https://github.com/IanLangs/Mathscript#readme"
|
|
31
32
|
}
|
package/src/msc.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import { transpile } from './transpile.js'
|
|
4
4
|
|
|
5
|
+
if (process.argv[2] === "-v" || process.argv[2] === "--version") {
|
|
6
|
+
(async () => {
|
|
7
|
+
const url = "https://unpkg.com/@ianlangs/mathscript/package.json"
|
|
8
|
+
const res = await fetch(url)
|
|
9
|
+
const pkg = await res.json()
|
|
10
|
+
console.log(`MS versión = ${pkg.version}`)
|
|
11
|
+
process.exit(0)
|
|
12
|
+
})()
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
function init(files) {
|
|
6
16
|
const config = { Files: files }
|
|
7
17
|
fs.writeFileSync('msconfig.json', JSON.stringify(config, null, 4))
|
package/src/msnode.js
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import { transpile } from './transpile.js'
|
|
4
4
|
|
|
5
|
+
if (process.argv[2] === "-v" || process.argv[2] === "--version") {
|
|
6
|
+
(async () => {
|
|
7
|
+
const url = "https://unpkg.com/@ianlangs/mathscript/package.json"
|
|
8
|
+
const res = await fetch(url)
|
|
9
|
+
const pkg = await res.json()
|
|
10
|
+
console.log(`MS versión = ${pkg.version}`)
|
|
11
|
+
process.exit(0)
|
|
12
|
+
})()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
const file = process.argv[2]
|
|
6
17
|
|
|
7
18
|
if (!file) {
|
package/src/transpile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function transpile(code, filename = "<input>") {
|
|
2
|
-
code = code.replace("using(", "require(").replace(
|
|
2
|
+
code = code.replace("using(", "require(").replace(/::[^=\n\(\)]*/g, "").replace(/\bfn\b/g, "function")
|
|
3
3
|
const lines = code.split('\n')
|
|
4
4
|
const vars = new Map()
|
|
5
5
|
const output = []
|
package/src/web-t.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { transpile } from "./web-t.js"
|
|
2
|
+
|
|
3
|
+
const editor = document.getElementById("editor")
|
|
4
|
+
const runButton = document.getElementById("runButton")
|
|
5
|
+
const consoleDiv = document.getElementById("console")
|
|
6
|
+
|
|
7
|
+
function clearConsole() {
|
|
8
|
+
consoleDiv.innerHTML = ""
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function logToConsole(msg) {
|
|
12
|
+
const line = document.createElement("div")
|
|
13
|
+
line.textContent = msg
|
|
14
|
+
consoleDiv.appendChild(line)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
runButton.addEventListener("click", () => {
|
|
18
|
+
clearConsole()
|
|
19
|
+
|
|
20
|
+
const code = editor.value
|
|
21
|
+
|
|
22
|
+
const result = transpile(code, "playground.ms")
|
|
23
|
+
|
|
24
|
+
if (result.errors.length > 0) {
|
|
25
|
+
result.errors.forEach(err => logToConsole(err))
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Capturar console.log
|
|
30
|
+
const originalLog = console.log
|
|
31
|
+
console.log = (...args) => {
|
|
32
|
+
logToConsole(args.join(" "))
|
|
33
|
+
originalLog(...args)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
eval(result.code)
|
|
38
|
+
} catch (e) {
|
|
39
|
+
logToConsole("[RUNTIME ERROR] " + e.message)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log = originalLog
|
|
43
|
+
})
|