brsh 3.0.0 → 3.1.1

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/bin/Readme.md CHANGED
@@ -1,33 +1,79 @@
1
- # Export File System
1
+ # CLI Utilities (`bin/`)
2
2
 
3
- the export file system command can be used to export a local folder structure for use as a filesystem in Shell.js
3
+ This directory contains the command-line utilities for building virtual filesystems and running `brsh` in Node.js.
4
4
 
5
- ## What Will it Do?
5
+ ---
6
6
 
7
- it will travers the directory structure from the provided base path, and import all files based on the following rules:
7
+ ## 1. `exportFileSystem`
8
8
 
9
- * Javascript files (.js): imported as node modules, whatever they export will be available to Shell JS, this is really useful for adding new commands just make sure you set module.exports to your Command class
10
- * WebAssembly files (.wasm): automatically wrapped as executable `WasmCommand` binaries (especially when placed in `/bin`) or stored as raw binary files
11
- * Binary files (.jpg, .png, .bmp, .pdf, .zip, etc.): stored as `BinaryFile` instances (or raw zero-overhead byte slices when using `--binary` / `.brfs`)
12
- * all other files: imported as UTF-8 string representations of the data inside (preserving Unix file permissions and symlinks)
9
+ `exportFileSystem` converts a local directory structure into a virtual filesystem bundle or `.brfs` binary container for use in `brsh`.
13
10
 
14
- ## CLI options
11
+ ### How Files Are Imported
15
12
 
16
- | name | alias | variable | description |
17
- | ---- | ----- | -------- | ----------- |
18
- | root | | `String` path | also the default option, this is the path to the root of your file system |
19
- | variable | v | `String` name | final variable output name for instance if set to `filesystem` when this file is loaded in a browser it will be accessible at `window.filesystem` |
20
- | output | o | `String` path | path for the output file (`.js` bundle or standalone `.brfs` binary container; if not set will output to stdout) |
21
- | binary | b | | emit an indexed `BRFS` binary container (`.brfs`) with raw binary payloads, permissions, and symlinks instead of base64-in-JS |
22
- | compress | c | | emit a gzip-compressed bundle alongside a browser decompression loader (legacy `.brsh` / `.brfs` mode) |
23
- | pretty | p | | if pretty is set we will disable code uglification and pretify the json directory structure |
24
- | hyperlinks | h | | enable experimental hyperlink support for application (this will pass through an environment variable to your filesystem FORCE_HYPERLINK some libraries will pick up on this and pass back ansi links) |
13
+ `exportFileSystem` traverses the directory structure from the provided root path and imports files according to the following rules:
25
14
 
26
- ## how does it work
15
+ * **JavaScript files (`.js`)**: Bundled via `esbuild` as CommonJS/ESM modules. Whatever they export is available directly to `brsh` — useful for adding custom `Command` classes (`module.exports = MyCommand`).
16
+ * **WebAssembly files (`.wasm`)**: Automatically wrapped as executable `WasmCommand` binaries (when placed in `/bin`) or stored as raw binary files.
17
+ * **Binary files (`.jpg`, `.png`, `.gif`, `.bmp`, `.webp`, `.ico`, `.pdf`, `.zip`, etc.)**: Stored as `BinaryFile` (`Uint8Array`) instances (or zero-overhead byte slices when using `--binary` / `.brfs`).
18
+ * **All other files**: Imported as UTF-8 strings, preserving Unix file permissions (`mode`) and symbolic links (`SymlinkRef`).
27
19
 
28
- most of the heavy lifting is done by [browserify](http://browserify.org/) and the following awesome plugins:
20
+ ### CLI Options
29
21
 
30
- * [Stringify](http://johnpostlethwait.github.io/stringify/)
31
- * [Imgurify](https://github.com/asbjornenge/imgurify)
32
- * [Bundle Collapser](https://github.com/substack/bundle-collapser)
33
- * [Uglifyify](https://github.com/hughsk/uglifyify)
22
+ | Option | Alias | Type | Description |
23
+ | ------ | ----- | ---- | ----------- |
24
+ | `root` | | `String` path | *(Default positional option, required)* Path to the root directory of your filesystem |
25
+ | `variable` | `-v` | `String` name | Global variable name (`globalThis.<variable>`) assigned when outputting a `.js` bundle (`{ filesystem, permissions }`). Not required when `-o` ends with `.brfs` |
26
+ | `output` | `-o` | `String` path | Output file path (`.js` bundle or standalone `.brfs` binary container) |
27
+ | `binary` | `-b` | `Boolean` | Emit an indexed `BRFS` binary container (`.brfs`) with raw binary payloads, permissions, symlinks, and bundled JS commands instead of base64-in-JS |
28
+ | `compress` | `-c` | `Boolean` | Gzip-compress the emitted `.brfs` container (or JS bundle) and generate a browser `DecompressionStream` loader when outputting `.js` |
29
+ | `pretty` | `-p` | `Boolean` | Disable minification and pretty-print the JSON directory structure |
30
+ | `hyperlinks` | `-h` | `Boolean` | Set `process.env.FORCE_HYPERLINK="true"` in bundled JS commands so libraries emit ANSI OSC 8 hyperlinks |
31
+
32
+ ### Examples
33
+
34
+ ```shell
35
+ # Standard JS bundle (sets globalThis.fs = { filesystem, permissions })
36
+ exportFileSystem ./demo/filesystem -o ./demo/fs.js -v fs
37
+
38
+ # Standalone .brfs binary container (pass URL or Uint8Array directly to new Shell({ filesystem: '/fs.brfs' }))
39
+ exportFileSystem ./demo/filesystem -o ./demo/fs.brfs
40
+
41
+ # Binary .brfs container + tiny JS loader (sets globalThis.fs = Promise<{ filesystem, permissions }>)
42
+ exportFileSystem ./demo/filesystem -o ./demo/fs.js -v fs --binary --compress
43
+ ```
44
+
45
+ ### How It Works
46
+
47
+ `exportFileSystem` uses [`lib/buildFilesystemStructure.js`](../lib/buildFilesystemStructure.js) to walk the directory tree and record file contents, permissions, and symlinks, [`esbuild`](https://esbuild.github.io/) with `esbuild-plugin-polyfill-node` to bundle any `.js` command modules for the browser, and [`lib/BinaryContainer.js`](../lib/BinaryContainer.js) to serialize `.brfs` binary containers.
48
+
49
+ ---
50
+
51
+ ## 2. `brsh` (`bin/brsh-shell.js`)
52
+
53
+ Interactive Node.js REPL and non-interactive script/command runner backed by `brsh` (with `wbt` and `pico` pre-registered).
54
+
55
+ ```shell
56
+ # Interactive REPL against the real Node.js filesystem
57
+ brsh
58
+
59
+ # Interactive REPL against the virtual demo filesystem
60
+ brsh --demo
61
+
62
+ # Run a single command string and exit
63
+ brsh -c "ls -la | grep Readme"
64
+
65
+ # Run a script file with arguments and shell flags (-e, -x)
66
+ brsh -e -x ./myscript.sh arg1 arg2
67
+ ```
68
+
69
+ ---
70
+
71
+ ## 3. `bin/brsh-cmd.js`
72
+
73
+ Multi-call CLI wrapper used by the BusyBox compatibility test suite. Can be invoked directly (`node bin/brsh-cmd.js grep foo file.txt`) or symlinked under a command's name (`cat`, `cp`, `grep`, `ls`, `mv`, `rm`, `busybox`, etc.) to run any `brsh` command against the real Node.js filesystem.
74
+
75
+ ---
76
+
77
+ ## 4. `bin/zsh-server.js`
78
+
79
+ Zero-dependency HTTP + WebSocket server (`npm run demo:zsh`) that spawns a real OS shell (`$SHELL` / `/bin/zsh`) via [`lib/terminal/PtyBridge.js`](../lib/terminal/PtyBridge.js) and attaches it to `brsh/terminal` in the browser at `http://127.0.0.1:3080`.