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 CHANGED
@@ -1,37 +1,79 @@
1
1
  # yavascript
2
2
 
3
- <!-- NOTE: this file is also used as help text by the CLI. Don't use markdown syntax below this line unless said syntax would also be clearly readable as plain text. -->
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
- YavaScript is a bash-like script runner which is distributed as a single
6
- statically-linked binary. Scripts are written in JavaScript. There are global
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
- - Accessing environment variables
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 to the terminal
16
+ - Printing stylized text
17
+ - Clearing the terminal
18
+ - Fetching files from the internet
18
19
 
19
- Additionally, since it's JavaScript, you get some other features that are
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
- - Arrays (lists) and Objects (key/value dictionaries)
23
- - Working with path strings
24
- - Working with JSON
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
- - Splitting strings on delimeters
27
- - Pretty-printing of objects
28
- - Getting the path to the currently-running script (via import.meta.url or `__filename`)
29
- - Getting the absolute path to the root folder of the current git/mercurial repo (repoRoot function)
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
- YavaScript is written with <3 by Lily Scott.
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
@@ -1,30 +1,33 @@
1
1
  var path = require("path");
2
2
 
3
- var binaryPath;
4
- if (process.platform === "win32") {
5
- binaryPath = path.resolve(
6
- __dirname,
7
- "..",
8
- "bin",
9
- "windows",
10
- "yavascript.exe"
11
- );
12
- } else if (process.platform === "darwin") {
13
- if (process.arch.startsWith("arm")) {
14
- binaryPath = path.resolve(
15
- __dirname,
16
- "..",
17
- "bin",
18
- "darwin-arm",
19
- "yavascript"
20
- );
21
- } else {
22
- binaryPath = path.resolve(__dirname, "..", "bin", "darwin", "yavascript");
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
- module.exports = binaryPath;
28
+ var binaryPath = getBinaryPath(process.platform + "-" + process.arch);
29
+
30
+ module.exports = {
31
+ getBinaryPath: getBinaryPath,
32
+ binaryPath: binaryPath,
33
+ };
package/lib/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  var child_process = require("child_process");
3
- var binaryPath = require("./binary-path");
3
+ var binaryPath = require("./binary-path").binaryPath;
4
4
 
5
5
  try {
6
6
  child_process.execFileSync(binaryPath, process.argv.slice(2), {
package/lib/index.js CHANGED
@@ -1,7 +1,9 @@
1
- const binaryPath = require("./binary-path");
2
- const version = require("./package.json").version;
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.5",
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 Scott <me@suchipi.com>",
7
+ "author": "Lily Skye <me@suchipi.com>",
8
8
  "license": "MIT",
9
9
  "repository": "suchipi/yavascript"
10
10
  }