yavascript 0.0.6 → 0.0.8

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,35 +1,80 @@
1
1
  # yavascript
2
2
 
3
- YavaScript is a bash-like script runner which is distributed as a single
4
- statically-linked binary. Scripts are written in JavaScript or CoffeeScript.
5
- There are global APIs available for all the things you'd normally want to do in
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.
5
+
6
+ There are APIs available for all the things you'd normally want to do in
6
7
  a bash script, such as:
7
8
 
8
- - Running programs
9
- - Accessing environment variables
10
- - Reading and writing file contents
9
+ - Running programs and getting their stdout/stderr/status
10
+ - Reading/writing environment variables
11
11
  - Checking if files/folders exist
12
- - Removing files/folders
12
+ - Removing/creating/copying files/folders
13
13
  - Reading and changing the current working directory
14
+ - Reading and resolving symbolic links
14
15
  - Using globs to get large lists of files
15
- - Printing stylized text to the terminal
16
+ - Printing stylized text
17
+ - Clearing the terminal
18
+ - Fetching files from the internet
16
19
 
17
- Additionally, since it's JavaScript, you get some other features that are
18
- 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:
19
21
 
20
- - Arrays (lists) and Objects (key/value dictionaries)
21
- - Working with path strings
22
- - 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)
23
32
  - Cross-file import/export using ECMAScript Modules
24
- - Splitting strings on delimeters
25
- - Pretty-printing of objects
26
- - Getting the path to the currently-running script (via import.meta.url or `__filename`)
27
- - 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
+ - Import packages from npm (via "npm:" imports) or local node_modules
38
+
39
+ You'll also find analogues to familiar CLI tools, like:
40
+
41
+ - dirname
42
+ - basename
43
+ - cat
44
+ - ls
45
+ - realpath
46
+ - readlink
47
+
48
+ ...and more.
28
49
 
29
50
  To view the APIs, consult the file yavascript.d.ts which was distributed with
30
51
  this program, or online at https://github.com/suchipi/yavascript/blob/main/yavascript.d.ts.
31
52
  This file contains TypeScript type definitions which can be given to your IDE
32
- to assist you when writing scripts.
53
+ to assist you when writing scripts, even if you aren't writing your scripts in TypeScript.
54
+
55
+ Here's an example of a script using YavaScript:
56
+
57
+ ```js
58
+ #!/usr/bin/env yavascript
59
+
60
+ // This comment is optional; it tells VS Code to load the specified TypeScript definitions.
61
+ /// <reference path="./yavascript.d.ts" />
62
+
63
+ let isWorkingTreeDirty;
64
+ try {
65
+ exec(`git diff --quiet`);
66
+ isWorkingTreeDirty = false;
67
+ } catch (error) {
68
+ isWorkingTreeDirty = true;
69
+ }
70
+
71
+ const branchName = $(`git rev-parse --abbrev-ref HEAD`).stdout.trim();
72
+
73
+ const gitInfo = { branchName, isWorkingTreeDirty };
74
+ echo(gitInfo);
75
+
76
+ writeFile("git-info.yml", YAML.stringify(gitInfo));
77
+ ```
33
78
 
34
79
  YavaScript is powered by a fork of the QuickJS JavaScript Engine, originally
35
80
  written by Fabrice Bellard. QuickJS is a small, fast JavaScript engine
@@ -42,7 +87,11 @@ supporting the ES2020 specification.
42
87
 
43
88
  ### Binaries (all platforms)
44
89
 
45
- You will need docker installed, then run `./scripts/build.sh`.
90
+ You will need docker installed, then run `meta/docker/build-all.sh`.
91
+
92
+ ### Binaries (just for your machine)
93
+
94
+ You will need node.js and ninja installed, then run `meta/build.sh`.
46
95
 
47
96
  ### Docker image
48
97
 
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,6 +1,6 @@
1
1
  {
2
2
  "name": "yavascript",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "lib/index.js",
5
5
  "bin": "lib/cli.js",
6
6
  "types": "yavascript.d.ts",