yavascript 0.0.5 → 0.0.7
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/README.md +79 -21
- package/bin/darwin-arm64/yavascript +0 -0
- package/bin/darwin-x86_64/yavascript +0 -0
- package/bin/linux-aarch64/yavascript +0 -0
- package/bin/linux-amd64/yavascript +0 -0
- package/bin/windows-x86_64/yavascript.exe +0 -0
- package/lib/binary-path.js +28 -25
- package/lib/cli.js +1 -1
- package/lib/index.js +4 -2
- package/package.json +2 -2
- package/yavascript.d.ts +1584 -444
- package/bin/darwin/yavascript +0 -0
- package/bin/darwin-arm/yavascript +0 -0
- package/bin/linux/yavascript +0 -0
- package/bin/windows/yavascript.exe +0 -0
package/README.md
CHANGED
|
@@ -1,37 +1,79 @@
|
|
|
1
1
|
# yavascript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
YavaScript is a cross-platform bash-like script runner and repl which is distributed as a single
|
|
4
|
+
statically-linked binary. Scripts can be written in JavaScript, TypeScript, JSX/TSX, or CoffeeScript.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
APIs available for all the things you'd normally want to do in a bash script,
|
|
8
|
-
such as:
|
|
6
|
+
There are APIs available for all the things you'd normally want to do in
|
|
7
|
+
a bash script, such as:
|
|
9
8
|
|
|
10
|
-
- Running programs
|
|
11
|
-
-
|
|
12
|
-
- Reading and writing file contents
|
|
9
|
+
- Running programs and getting their stdout/stderr/status
|
|
10
|
+
- Reading/writing environment variables
|
|
13
11
|
- Checking if files/folders exist
|
|
14
|
-
- Removing files/folders
|
|
12
|
+
- Removing/creating/copying files/folders
|
|
15
13
|
- Reading and changing the current working directory
|
|
14
|
+
- Reading and resolving symbolic links
|
|
16
15
|
- Using globs to get large lists of files
|
|
17
|
-
- Printing stylized text
|
|
16
|
+
- Printing stylized text
|
|
17
|
+
- Clearing the terminal
|
|
18
|
+
- Fetching files from the internet
|
|
18
19
|
|
|
19
|
-
Additionally,
|
|
20
|
-
either not present in bash or are cumbersome to use in bash, namely:
|
|
20
|
+
Additionally, you can do other things that are either not present in bash or are cumbersome to use in bash, namely:
|
|
21
21
|
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
22
|
+
- Serialize and deserialize JSON, CSV, and YAML
|
|
23
|
+
- Removing ANSI control characters from a string
|
|
24
|
+
- Split path strings into a list of segments and rejoin them into a string
|
|
25
|
+
- Check if a path is absolute and resolve relative paths
|
|
26
|
+
- Parse command-line flags
|
|
27
|
+
- Work with Arrays (lists)
|
|
28
|
+
- Work with Objects (key/value dictionaries)
|
|
29
|
+
- Work with Typed Arrays (byte buffers)
|
|
30
|
+
- Reliably get the path to the currently-running file
|
|
31
|
+
- Strongly-typed interfaces and functions (via TypeScript)
|
|
25
32
|
- Cross-file import/export using ECMAScript Modules
|
|
26
|
-
-
|
|
27
|
-
- Pretty-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
33
|
+
- Split strings on delimeters
|
|
34
|
+
- Pretty-print complex structures
|
|
35
|
+
- Call low-level POSIX C APIs like fputs, sprintf, isatty
|
|
36
|
+
- Perform work in threads
|
|
37
|
+
|
|
38
|
+
You'll also find analogues to familiar CLI tools, like:
|
|
39
|
+
|
|
40
|
+
- dirname
|
|
41
|
+
- basename
|
|
42
|
+
- cat
|
|
43
|
+
- ls
|
|
44
|
+
- realpath
|
|
45
|
+
- readlink
|
|
46
|
+
|
|
47
|
+
...and more.
|
|
30
48
|
|
|
31
49
|
To view the APIs, consult the file yavascript.d.ts which was distributed with
|
|
32
50
|
this program, or online at https://github.com/suchipi/yavascript/blob/main/yavascript.d.ts.
|
|
33
51
|
This file contains TypeScript type definitions which can be given to your IDE
|
|
34
|
-
to assist you when writing scripts.
|
|
52
|
+
to assist you when writing scripts, even if you aren't writing your scripts in TypeScript.
|
|
53
|
+
|
|
54
|
+
Here's an example of a script using YavaScript:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
#!/usr/bin/env yavascript
|
|
58
|
+
|
|
59
|
+
// This comment is optional; it tells VS Code to load the specified TypeScript definitions.
|
|
60
|
+
/// <reference path="./yavascript.d.ts" />
|
|
61
|
+
|
|
62
|
+
let isWorkingTreeDirty;
|
|
63
|
+
try {
|
|
64
|
+
exec(`git diff --quiet`);
|
|
65
|
+
isWorkingTreeDirty = false;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
isWorkingTreeDirty = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const branchName = $(`git rev-parse --abbrev-ref HEAD`).stdout.trim();
|
|
71
|
+
|
|
72
|
+
const gitInfo = { branchName, isWorkingTreeDirty };
|
|
73
|
+
echo(gitInfo);
|
|
74
|
+
|
|
75
|
+
writeFile("git-info.yml", YAML.stringify(gitInfo));
|
|
76
|
+
```
|
|
35
77
|
|
|
36
78
|
YavaScript is powered by a fork of the QuickJS JavaScript Engine, originally
|
|
37
79
|
written by Fabrice Bellard. QuickJS is a small, fast JavaScript engine
|
|
@@ -40,4 +82,20 @@ supporting the ES2020 specification.
|
|
|
40
82
|
- Original QuickJS engine: https://bellard.org/quickjs/
|
|
41
83
|
- The fork we use: https://github.com/suchipi/quickjs/
|
|
42
84
|
|
|
43
|
-
|
|
85
|
+
## Compiling
|
|
86
|
+
|
|
87
|
+
### Binaries (all platforms)
|
|
88
|
+
|
|
89
|
+
You will need docker installed, then run `meta/docker/build-all.sh`.
|
|
90
|
+
|
|
91
|
+
### Binaries (just for your machine)
|
|
92
|
+
|
|
93
|
+
You will need node.js and ninja installed, then run `meta/build.sh`.
|
|
94
|
+
|
|
95
|
+
### Docker image
|
|
96
|
+
|
|
97
|
+
You will need docker installed, then run `docker build -t yourusername/yavascript .`.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
YavaScript is written with <3 by Lily Skye.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/binary-path.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
var path = require("path");
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
var binDir = path.resolve(__dirname, "..", "bin");
|
|
4
|
+
|
|
5
|
+
function getBinaryPath(platformAndArch) {
|
|
6
|
+
switch (platformAndArch) {
|
|
7
|
+
case "darwin-arm64": {
|
|
8
|
+
return path.join(binDir, "darwin-arm64", "yavascript");
|
|
9
|
+
}
|
|
10
|
+
case "darwin-x64": {
|
|
11
|
+
return path.join(binDir, "darwin-x86_64", "yavascript");
|
|
12
|
+
}
|
|
13
|
+
case "linux-arm64": {
|
|
14
|
+
return path.join(binDir, "linux-aarch64", "yavascript");
|
|
15
|
+
}
|
|
16
|
+
case "linux-x64": {
|
|
17
|
+
return path.join(binDir, "linux-amd64", "yavascript");
|
|
18
|
+
}
|
|
19
|
+
case "win32-x64": {
|
|
20
|
+
return path.join(binDir, "windows-x86_64", "yavascript.exe");
|
|
21
|
+
}
|
|
22
|
+
default: {
|
|
23
|
+
throw new Error("Unsupported platform: " + platformAndArch);
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
|
-
} else if (process.platform === "linux") {
|
|
25
|
-
binaryPath = path.resolve(__dirname, "..", "bin", "linux", "yavascript");
|
|
26
|
-
} else {
|
|
27
|
-
throw new Error("Unsupported platform: " + process.platform);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
var binaryPath = getBinaryPath(process.platform + "-" + process.arch);
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
getBinaryPath: getBinaryPath,
|
|
32
|
+
binaryPath: binaryPath,
|
|
33
|
+
};
|
package/lib/cli.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var getBinaryPath = require("./binary-path").getBinaryPath;
|
|
2
|
+
var binaryPath = require("./binary-path").binaryPath;
|
|
3
|
+
var version = require("../package.json").version;
|
|
3
4
|
|
|
4
5
|
module.exports = {
|
|
6
|
+
getBinaryPath,
|
|
5
7
|
binaryPath,
|
|
6
8
|
version,
|
|
7
9
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yavascript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"bin": "lib/cli.js",
|
|
6
6
|
"types": "yavascript.d.ts",
|
|
7
|
-
"author": "Lily
|
|
7
|
+
"author": "Lily Skye <me@suchipi.com>",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "suchipi/yavascript"
|
|
10
10
|
}
|