@ianlangs/mathscript 1.4.0 → 1.6.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/mpm/mpm.js ADDED
@@ -0,0 +1,109 @@
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
+ const args = process.argv.slice(2)
8
+ const CWD = process.cwd()
9
+ const MODULES_DIR = path.join(CWD, "ms_modules")
10
+ const DEFAULT_REPO = "https://ianlangs.github.io/mpm-ms/"
11
+
12
+ function ensureDir(dir) {
13
+ if (!fs.existsSync(dir)) {
14
+ fs.mkdirSync(dir, { recursive: true })
15
+ }
16
+ }
17
+
18
+ function download(url, dest) {
19
+ return new Promise((resolve, reject) => {
20
+ const file = fs.createWriteStream(dest)
21
+ https.get(url, res => {
22
+ if (res.statusCode !== 200) {
23
+ reject("HTTP " + res.statusCode)
24
+ return
25
+ }
26
+ res.pipe(file)
27
+ file.on("finish", () => {
28
+ file.close()
29
+ resolve()
30
+ })
31
+ }).on("error", err => {
32
+ fs.unlinkSync(dest)
33
+ reject(err)
34
+ })
35
+ })
36
+ }
37
+
38
+ function installFromDefault(pkg) {
39
+ const url = DEFAULT_REPO + pkg + ".ms"
40
+ const dest = path.join(MODULES_DIR, pkg + ".ms")
41
+ console.log("Installing", pkg, "from", url)
42
+ return download(url, dest)
43
+ }
44
+
45
+ function installFromCustom(url) {
46
+ const name = url.split("/").pop()
47
+ const dest = path.join(MODULES_DIR, name)
48
+ console.log("Installing", name, "from", url)
49
+ return download(url, dest)
50
+ }
51
+
52
+ function installFromNpm(pkg) {
53
+ console.log("Installing from npm:", pkg)
54
+ execSync("npm install " + pkg, { stdio: "inherit" })
55
+ }
56
+
57
+ function usage() {
58
+ console.log(`
59
+ mpm - MS Package Manager
60
+
61
+ Commands:
62
+
63
+ mpm -i <package> install from default repo
64
+ mpm -i -c <url> install from custom url
65
+ mpm -n <package> install from npm
66
+
67
+ Examples:
68
+
69
+ mpm -i math
70
+ mpm -i -c https://site.com/lib.ms
71
+ mpm -n lodash
72
+ `)
73
+ }
74
+
75
+ ensureDir(MODULES_DIR)
76
+
77
+ if (args.length == 0) {
78
+ usage()
79
+ process.exit(0)
80
+ }
81
+
82
+ try {
83
+ if (args[0] == "-i" || args[0] == "--install") {
84
+ if (args[1] == "-c" || args[1] == "--custom") {
85
+ const url = args[2]
86
+ if (!url) throw "Missing URL"
87
+ await installFromCustom(url)
88
+ } else {
89
+ const pkg = args[1]
90
+ if (!pkg) throw "Missing package name"
91
+ await installFromDefault(pkg)
92
+ }
93
+ }
94
+
95
+ else if (args[0] == "-n" || args[0] == "--npm") {
96
+ const pkg = args[1]
97
+ if (!pkg) throw "Missing npm package"
98
+ installFromNpm(pkg)
99
+ }
100
+
101
+ else {
102
+ usage()
103
+ }
104
+
105
+ console.log("Done.")
106
+ }
107
+ catch(e) {
108
+ console.error("\n[MPM ERROR]\n", e)
109
+ }
package/mpm/mpm.ms ADDED
@@ -0,0 +1,109 @@
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
+ const args = process.argv.slice(2)
8
+ const CWD = process.cwd()
9
+ const MODULES_DIR = path.join(CWD, "ms_modules")
10
+ const DEFAULT_REPO = "https://ianlangs.github.io/mpm-ms/"
11
+
12
+ fn ensureDir(dir) {
13
+ if (!fs.existsSync(dir)) {
14
+ fs.mkdirSync(dir, { recursive: true })
15
+ }
16
+ }
17
+
18
+ fn download(url, dest) {
19
+ return new Promise((resolve, reject) => {
20
+ const file = fs.createWriteStream(dest)
21
+ https.get(url, res => {
22
+ if (res.statusCode !== 200) {
23
+ reject("HTTP " + res.statusCode)
24
+ return
25
+ }
26
+ res.pipe(file)
27
+ file.on("finish", () => {
28
+ file.close()
29
+ resolve()
30
+ })
31
+ }).on("error", err => {
32
+ fs.unlinkSync(dest)
33
+ reject(err)
34
+ })
35
+ })
36
+ }
37
+
38
+ fn installFromDefault(pkg) {
39
+ const url = DEFAULT_REPO + pkg + ".ms"
40
+ const dest = path.join(MODULES_DIR, pkg + ".ms")
41
+ console.log("Installing", pkg, "from", url)
42
+ return download(url, dest)
43
+ }
44
+
45
+ fn installFromCustom(url) {
46
+ const name = url.split("/").pop()
47
+ const dest = path.join(MODULES_DIR, name)
48
+ console.log("Installing", name, "from", url)
49
+ return download(url, dest)
50
+ }
51
+
52
+ fn installFromNpm(pkg) {
53
+ console.log("Installing from npm:", pkg)
54
+ execSync("npm install " + pkg, { stdio: "inherit" })
55
+ }
56
+
57
+ fn usage() {
58
+ console.log(`
59
+ mpm - MS Package Manager
60
+
61
+ Commands:
62
+
63
+ mpm -i <package> install from default repo
64
+ mpm -i -c <url> install from custom url
65
+ mpm -n <package> install from npm
66
+
67
+ Examples:
68
+
69
+ mpm -i math
70
+ mpm -i -c https://site.com/lib.ms
71
+ mpm -n lodash
72
+ `)
73
+ }
74
+
75
+ ensureDir(MODULES_DIR)
76
+
77
+ if (args.length == 0) {
78
+ usage()
79
+ process.exit(0)
80
+ }
81
+
82
+ try {
83
+ if (args[0] == "-i" || args[0] == "--install") {
84
+ if (args[1] == "-c" || args[1] == "--custom") {
85
+ const url = args[2]
86
+ if (!url) throw "Missing URL"
87
+ await installFromCustom(url)
88
+ } else {
89
+ const pkg = args[1]
90
+ if (!pkg) throw "Missing package name"
91
+ await installFromDefault(pkg)
92
+ }
93
+ }
94
+
95
+ else if (args[0] == "-n" || args[0] == "--npm") {
96
+ const pkg = args[1]
97
+ if (!pkg) throw "Missing npm package"
98
+ installFromNpm(pkg)
99
+ }
100
+
101
+ else {
102
+ usage()
103
+ }
104
+
105
+ console.log("Done.")
106
+ }
107
+ catch(e) {
108
+ console.error("\n[MPM ERROR]\n", e)
109
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@ianlangs/mathscript",
4
- "version": "1.4.0",
4
+ "version": "1.6.0",
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/transpile.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function transpile(code, filename = "<input>") {
2
- code = code.replace("using(", "require(").replace(/::?[^=\n\(\)]*/g, "").replace(/\bfn\b/g, "function")
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
File without changes