You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-60
Original file line number
Diff line number
Diff line change
@@ -1,65 +1,39 @@
1
-
# yavascript
1
+
# 
2
2
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](https://en.wikipedia.org/wiki/JavaScript), [TypeScript](https://www.typescriptlang.org/), [JSX/TSX](https://react.dev/learn/writing-markup-with-jsx), [CoffeeScript](https://coffeescript.org/) or [Civet](https://civet.dev/).
3
+
YavaScript is a cross-platform bash-like script runner and repl which is distributed as a single statically-linked program, weighing in at about 4MB. Scripts can be written in [JavaScript](https://en.wikipedia.org/wiki/JavaScript) or [JS-related languages](#languages).
5
4
6
5
> YavaScript is the name of the program. YavaScript is not a new language. YavaScript uses normal JavaScript.
7
6
8
-
There are APIs available for all the things you'd normally want to do in
9
-
a bash script, such as:
7
+
## Why?
10
8
11
-
- Running programs and getting their stdout/stderr/status
12
-
- Reading/writing environment variables
13
-
- Checking if files/folders exist
14
-
- Removing/creating/copying files/folders
15
-
- Reading and changing the current working directory
16
-
- Reading and resolving symbolic links
17
-
- Using globs to get large lists of files
18
-
- Printing stylized text
19
-
- Clearing the terminal
20
-
- Fetching files from the internet
21
-
22
-
Additionally, you can do other things that are either not present in bash or are cumbersome to use in bash, namely:
23
-
24
-
- Serialize and deserialize JSON, CSV, YAML, and TOML
25
-
- Removing ANSI control characters from a string
26
-
- Split path strings into a list of segments and rejoin them into a string
27
-
- Check if a path is absolute and resolve relative paths
28
-
- Parse command-line flags
29
-
- Work with Arrays (lists)
30
-
- Work with Objects (key/value dictionaries)
31
-
- Work with Typed Arrays (byte buffers)
32
-
- Reliably get the path to the currently-running file
33
-
- Strongly-typed interfaces and functions (via TypeScript)
34
-
- Cross-file import/export using ECMAScript Modules
35
-
- Split strings on delimeters
36
-
- Pretty-print complex structures
37
-
- Call low-level POSIX C APIs like fputs, sprintf, isatty
38
-
- Perform work in threads
39
-
- Import packages from npm (via "npm:" imports) or local node_modules
40
-
41
-
You'll also find analogues to familiar CLI tools, like:
9
+
YavaScript exists as an alternative to bash scripts. Instead of writing scripts using shell syntax and running them with bash, you write them in JavaScript and run them with YavaScript.
42
10
43
-
- dirname
44
-
- basename
45
-
- cat
46
-
- ls
47
-
- realpath
48
-
- readlink
11
+
At only ~4MB and with no dependencies, YavaScript is easy to install or include in a Docker image. As such, it's suitable for use in all the places you would use shell scripts now. It's a great fit for those sort of "environment-level infrastructure" scripts that every Git repo ends up needing, like "build the app", "pull the latest docker images", "install/use the correct versions of languages and tools", etc.
49
12
50
-
...and more.
13
+
YavaScript has built-in APIs for all the things you'd normally want to do in a bash script, such as:
51
14
52
-
## API Documentation
15
+
- Running programs
16
+
- Using environment variables
17
+
- Working with files/folders
18
+
- Resolving globs into lists of paths
19
+
- Printing stylized text
53
20
54
-
See [here](/meta/generated-docs/README.md).
21
+
As well as APIs for things which are difficult or cumbersome in bash, like:
55
22
56
-
## TypeScript Types
23
+
- (De)serialize JSON, CSV, YAML, and TOML
24
+
- Parse command-line flags into a structured object
25
+
- Safely manipulate and resolve path strings
26
+
- Work with raw byte buffers (typed arrays)
27
+
- Reliably get the path to the currently-running script
28
+
- Strongly-typed interfaces and functions (via TypeScript)
29
+
- Cross-file import/export using ECMAScript Modules
30
+
- Call low-level POSIX C APIs like fputs, sprintf, isatty
57
31
58
-
YavaScript comes with a TypeScript type definition (`.d.ts`) file.
32
+
You'll also find cross-platform analogues to familiar CLI tools, like `mkdir`, `rm`, `chmod`, `dirname`, `which`, and more.
59
33
60
-
The `.d.ts` file contains documented TypeScript type definitions which can be given to your IDE to assist you when writing scripts, even if you aren't writing your scripts in TypeScript.
34
+
## APIs
61
35
62
-
You can [view the `.d.ts` file online](./yavascript.d.ts), but if you have YavaScript installed, you should instead run `yavascript --print-types` to obtain the `.d.ts` file for your specific release.
36
+
**For the full API documentation, see [here](/meta/generated-docs/README.md).**
There are several other projects that bring a shell-like environment to JS, such as [zx](https://github.com/google/zx), [ShellJS](https://www.npmjs.com/package/shelljs), and [Bun Shell](https://bun.sh/docs/runtime/shell). The main difference between those and YavaScript is that YavaScript is very small, fully cross-platform, and brings its own JavaScript engine. The effect of those differences is that you can rely on YavaScript in places where you couldn't always rely on zx/shelljs/bun, like in your bootstrapping script that installs Node, or your smallest Docker containers. Or even on tiny constrained systems, like your router!
104
+
105
+
## Supported Platforms
106
+
107
+
- macOS (10.16 or higher)
108
+
- Intel Processors (x86_64)
109
+
- Apple Silicon (aarch64)
110
+
- Linux
111
+
- aarch64 or x86_64
112
+
- glibc, muslc, or statically-linked
113
+
- Windows (MinGW)
114
+
- x86_64
115
+
116
+
## Installation
117
+
118
+
You can find the binary for your platform on [the releases page](https://github.com/suchipi/yavascript/releases). As YavaScript is fully self-contained in one small file, it's trivial to install and uninstall; simply place it somewhere specified in your [`PATH`](https://superuser.com/a/284351).
119
+
120
+
## Languages
121
+
122
+
YavaScript can load and run any of these languages with no ahead-of-time compilation step needed:
YavaScript comes with a TypeScript type definition (`.d.ts`) file.
133
+
134
+
The `.d.ts` file contains documented TypeScript type definitions which can be given to your IDE to assist you when writing scripts, even if you aren't writing your scripts in TypeScript.
135
+
136
+
You can [view the `.d.ts` file online](./yavascript.d.ts), but if you have YavaScript installed, you should instead run `yavascript --print-types` to obtain the `.d.ts` file for your specific release.
137
+
127
138
## QuickJS
128
139
129
140
YavaScript is powered by a fork of the QuickJS JavaScript Engine, originally
@@ -133,17 +144,7 @@ supporting the ES2020 specification.
133
144
- Original QuickJS engine: https://bellard.org/quickjs/
134
145
- The fork we use: https://github.com/suchipi/quickjs/
135
146
136
-
## Installation
137
-
138
-
You can find the binary for your platform on [the releases page](https://github.com/suchipi/yavascript/releases). As YavaScript is fully self-contained in one small file, it's trivial to install and uninstall; simply place it somewhere specified in your [`PATH`](https://superuser.com/a/284351). Supported platforms are:
139
-
140
-
- macOS 10.16 or higher, either Intel or Apple Silicon (M1, M2, etc)
141
-
- Linux (gnu), either aarch64 or x86_64
142
-
- Linux (musl), either aarch64 or x86_64
143
-
- Linux (with musl libc statically linked into the binary), either aarch64 or x86_64
0 commit comments