diff --git a/.gitignore b/.gitignore
index 93a7c6e..c61e353 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,4 +23,5 @@ root_h/
root_i/
root_j/
Primate/
-cmd/gtree/gtree
\ No newline at end of file
+cmd/gtree/gtree
+gtree.wasm
\ No newline at end of file
diff --git a/Makefile b/Makefile
index fa848b7..8bd413f 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,10 @@
hotreload:
air
+# sudo GOOS=wasip1 GOARCH=wasm go build -o gtree.wasm ./cmd/gtree
+wasi:
+ GOOS=wasip1 GOARCH=wasm go build -o gtree.wasm ./cmd/gtree
+
sweep:
rm -rf ./root/ ./root1/ ./root2/ ./root3/ ./root4/ ./root5/ ./root6/ ./root7/ ./root8/ Primate/ gtree/
rm -rf ./root_a/ ./root_b/ ./root_c/ ./root_d/ ./root_e/ ./root_f/ ./root_g/ ./root_h/ ./root_i/ ./root_j/
diff --git a/README.md b/README.md
index f677a8a..e26c918 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,11 @@ $ gtree web
# CLI
+> **Note**
+> WASM binary with WASI support are also available.
+> Basically, the usage is the same as the CLI built with Go.
+> Please refer [here](README_wasi_wasm.md) for usage.
+
## Installation
@@ -78,6 +83,9 @@ $ port install gtree aqua +WASI +$ Go to GitHub releases and Download `gtree.wasm` + Docker $ docker pull ghcr.io/ddddddo/gtree:latest $ docker run ghcr.io/ddddddo/gtree:latest template | docker run -i ghcr.io/ddddddo/gtree:latest output diff --git a/README_wasi_wasm.md b/README_wasi_wasm.md new file mode 100644 index 0000000..9730554 --- /dev/null +++ b/README_wasi_wasm.md @@ -0,0 +1,139 @@ +## 1. Install WASM runtime +- https://wasmtime.dev/ + +## 2. Download *`gtree.wasm`* +- https://github.com/ddddddO/gtree/releases + +## 3. Use in console! +### *Help* +```console +$ wasmtime gtree.wasm help +NAME: + gtree - This CLI uses Markdown to generate directory trees and directories itself, and also verifies directories. + The symbols that can be used in Markdown are '-', '+', '*', and '#'. + +USAGE: + gtree [global options] command [command options] [arguments...] + +VERSION: + 1.9.6 / revision xxx + +COMMANDS: + output, o, out Outputs tree from markdown. + Let's try 'gtree template | gtree output'. + mkdir, m Makes directories and files from markdown. It is possible to dry run. + Let's try 'gtree template | gtree mkdir -e .go -e .md -e Makefile'. + verify, vf Verifies tree structure represented in markdown by comparing it with existing directories. + Let's try 'gtree template | gtree verify'. + template, t, tmpl Outputs markdown template. Use it to try out gtree CLI. + web, w, www Opens "Tree Maker" in your browser and shows the URL in terminal. + gocode, gc, code Outputs a sample Go program calling "gtree" package. + version, v Prints the version. + help, h Shows a list of commands or help for one command + +GLOBAL OPTIONS: + --help, -h show help + --version, -v print the version +``` + +### *Template* +```console +$ wasmtime gtree.wasm template +- gtree + - cmd + - gtree + - main.go + - testdata + - sample1.md + - sample2.md + - Makefile + - tree.go +``` + +### *Output* +```console +$ wasmtime gtree.wasm template | wasmtime gtree.wasm output +gtree +├── cmd +│ └── gtree +│ └── main.go +├── testdata +│ ├── sample1.md +│ └── sample2.md +├── Makefile +└── tree.go +``` + +### *Mkdir* +```console +$ wasmtime gtree.wasm template | wasmtime gtree.wasm mkdir --dry-run -e .go -e .md -e Makefile +gtree +├── cmd +│ └── gtree +│ └── main.go +├── testdata +│ ├── sample1.md +│ └── sample2.md +├── Makefile +└── tree.go + +4 directories, 5 files +$ tree gtree +gtree [error opening dir] + +0 directories, 0 files +$ wasmtime gtree.wasm template | wasmtime --dir=$PWD gtree.wasm mkdir -e .go -e .md -e Makefile +$ tree gtree +gtree +├── Makefile +├── cmd +│ └── gtree +│ └── main.go +├── testdata +│ ├── sample1.md +│ └── sample2.md +└── tree.go + +3 directories, 5 files +``` + +### *Verify* +```console +$ tree example +example +├── find_pipe_programmable-gtree +│ └── main.go +├── go-list_pipe_programmable-gtree +│ └── main.go +├── like_cli +│ ├── adapter +│ │ ├── executor.go +│ │ └── indentation.go +│ └── main.go +├── noexist +│ └── xxx +└── programmable + └── main.go + +6 directories, 7 files +$ cat testdata/sample9.md +- example + - find_pipe_programmable-gtree + - main.go + - go-list_pipe_programmable-gtree + - main.go + - like_cli + - adapter + - executor.go + - indentation.go + - main.go + - kkk + - programmable + - main.go +$ cat testdata/sample9.md | wasmtime --dir=$PWD gtree.wasm verify --strict +Extra paths exist: + example/noexist + example/noexist/xxx +Required paths does not exist: + example/like_cli/kkk +``` \ No newline at end of file diff --git a/cmd/gtree-wasm/Makefile b/cmd/gtree-wasm/Makefile index d7ff07b..003b2b9 100644 --- a/cmd/gtree-wasm/Makefile +++ b/cmd/gtree-wasm/Makefile @@ -17,7 +17,7 @@ confirm: # -> gzip圧縮で268KBだった。 # ただ、goのwasm_exec.jsではなく、tinygo/targets/wasm_exec.js を使用する。ref: https://tinygo.org/docs/guides/webassembly/#how-it-works tinybuild: - tinygo build -o main.wasm -target wasm -tags wasm main.go + tinygo build -o main.wasm -target wasm -tags tinywasm main.go deploy: confirm tinybuild cleancss -o ../../docs/main.css main.css diff --git a/pipeline_tree.go b/pipeline_tree.go index b43ee63..201b920 100644 --- a/pipeline_tree.go +++ b/pipeline_tree.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/pipeline_tree_grower.go b/pipeline_tree_grower.go index 3d888f2..09d292c 100644 --- a/pipeline_tree_grower.go +++ b/pipeline_tree_grower.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/pipeline_tree_mkdirer.go b/pipeline_tree_mkdirer.go index f5ce5d6..0098c81 100644 --- a/pipeline_tree_mkdirer.go +++ b/pipeline_tree_mkdirer.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/pipeline_tree_spreader.go b/pipeline_tree_spreader.go index b4a72a1..22cc28a 100644 --- a/pipeline_tree_spreader.go +++ b/pipeline_tree_spreader.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/pipeline_tree_verifier.go b/pipeline_tree_verifier.go index 39bd963..2f054d0 100644 --- a/pipeline_tree_verifier.go +++ b/pipeline_tree_verifier.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/root_generator.go b/root_generator.go index aa0862d..cf5a809 100644 --- a/root_generator.go +++ b/root_generator.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/simple_tree.go b/simple_tree.go index 78720d8..d2bd5b7 100644 --- a/simple_tree.go +++ b/simple_tree.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/simple_tree_grower.go b/simple_tree_grower.go index 16bb32b..0030427 100644 --- a/simple_tree_grower.go +++ b/simple_tree_grower.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/simple_tree_mkdirer.go b/simple_tree_mkdirer.go index 24c5c06..5995cf8 100644 --- a/simple_tree_mkdirer.go +++ b/simple_tree_mkdirer.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/simple_tree_spreader.go b/simple_tree_spreader.go index 46caa19..12eba0a 100644 --- a/simple_tree_spreader.go +++ b/simple_tree_spreader.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/simple_tree_verifier.go b/simple_tree_verifier.go index 79b7eda..bbba97d 100644 --- a/simple_tree_verifier.go +++ b/simple_tree_verifier.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/tree.go b/tree.go index d4f5a48..08d9128 100644 --- a/tree.go +++ b/tree.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/tree_handler.go b/tree_handler.go index ff07d70..ae0316e 100644 --- a/tree_handler.go +++ b/tree_handler.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/tree_handler_programmably.go b/tree_handler_programmably.go index 166d787..f976d3a 100644 --- a/tree_handler_programmably.go +++ b/tree_handler_programmably.go @@ -1,4 +1,4 @@ -//go:build !wasm +//go:build !tinywasm package gtree diff --git a/wasm_root_generator.go b/wasm_root_generator.go index 5282c12..6f39615 100644 --- a/wasm_root_generator.go +++ b/wasm_root_generator.go @@ -1,4 +1,4 @@ -//go:build wasm +//go:build tinywasm package gtree diff --git a/wasm_tree.go b/wasm_tree.go index 98b0203..0a8f37d 100644 --- a/wasm_tree.go +++ b/wasm_tree.go @@ -1,4 +1,4 @@ -//go:build wasm +//go:build tinywasm package gtree diff --git a/wasm_tree_grower.go b/wasm_tree_grower.go index 348e873..955ee05 100644 --- a/wasm_tree_grower.go +++ b/wasm_tree_grower.go @@ -1,4 +1,4 @@ -//go:build wasm +//go:build tinywasm package gtree diff --git a/wasm_tree_handler.go b/wasm_tree_handler.go index a186062..d25f29e 100644 --- a/wasm_tree_handler.go +++ b/wasm_tree_handler.go @@ -1,4 +1,4 @@ -//go:build wasm +//go:build tinywasm package gtree diff --git a/wasm_tree_spreader.go b/wasm_tree_spreader.go index d57cbcf..ee180cc 100644 --- a/wasm_tree_spreader.go +++ b/wasm_tree_spreader.go @@ -1,4 +1,4 @@ -//go:build wasm +//go:build tinywasm package gtree