diff --git a/.gitattributes b/.gitattributes index 6ada519..8c565d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ * text=auto eol=lf -*.* linguist-detectable=false -/src/* linguist-detectable=true +* linguist-detectable=false +/src/** linguist-detectable=true diff --git a/.github/README.example.terminal.svg b/.github/README.example.terminal.svg deleted file mode 100644 index 56f56bd..0000000 --- a/.github/README.example.terminal.svg +++ /dev/null @@ -1,336 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -info -: options: - - -info -: { - - -  i:  -'./examples/simple.excalidraw' -, - - -  input:  -'./examples/simple.excalidraw' -, - - -  background:  -true -, - - -  b:  -true -, - - -  embedScene:  -false -, - - -  e:  -false -, - - -  darkMode:  -false -, - - -  d:  -false -, - - -  scale:  -1 -, - - -  s:  -1 -, - - -  format:  -'svg' -, - - -  f:  -'svg' -, - - -  o:  -'./README.example.output.svg' -, - - -  output:  -'./README.example.output.svg' -, - - -  url:  -'' -, - - -  excalidrawVersion:  -'' -, - - -  headless:  -true -, - - -  leaveBrowserRunning:  -false -, - - -  screenshots:  -'' -, - - -  actionSleepTime:  -200 -, - - -  timeout:  --1 - - -} - - -info -: Falling back to environment variable EXCALIDRAW_BRUTE_EXPORT_CLI_URL - - -info -: excalidrawURL: http://localhost:59876 - - -info -: Detecting Excalidraw version... - - -info -: excalidrawVersion: 0.15.0 - - -info -: Clicking: Menu Burger - - -info -: Clicking: Open Menu Item - - -info -: File is chosen! - - -info -: Clicking: Export Menu Item - - -info -: await exportBackgroundSwitch.count(): 1 - - -info -: await exportEmbedSwitch.count(): 1 - - -info -: await exportScaleDiv.count(): 1 - - -info -: await exportScaleElements.count(): 3 - - -info -: Pressing SVG button! - - -info -: File is downloaded! - - -info -: closing... - - - - - \ No newline at end of file diff --git a/.github/README.help.generated.svg b/.github/README.help.generated.svg index 5815f68..8d9c027 100644 --- a/.github/README.help.generated.svg +++ b/.github/README.help.generated.svg @@ -19,545 +19,545 @@ url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bo font-style: bold; font-weight: 700; } -.terminal-1435490868-matrix { +.terminal-4099070515-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } -.terminal-1435490868-title { +.terminal-4099070515-title { font-size: 18px; font-weight: bold; font-family: arial; } -.terminal-1435490868-r1 { fill: #d9d9d9 } -.terminal-1435490868-r2 { fill: #878787 } -.terminal-1435490868-r3 { fill: #d9d9d9;font-weight: bold } -.terminal-1435490868-r4 { fill: #569cd6 } -.terminal-1435490868-r5 { fill: #98e024 } -.terminal-1435490868-r6 { fill: #aaaaaa } -.terminal-1435490868-r7 { fill: #608b1a } +.terminal-4099070515-r1 { fill: #d9d9d9 } +.terminal-4099070515-r2 { fill: #878787 } +.terminal-4099070515-r3 { fill: #d9d9d9;font-weight: bold } +.terminal-4099070515-r4 { fill: #569cd6 } +.terminal-4099070515-r5 { fill: #98e024 } +.terminal-4099070515-r6 { fill: #aaaaaa } +.terminal-4099070515-r7 { fill: #608b1a } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - -$ npx excalidraw-brute-export-cli --help - + +$ npx excalidraw-brute-export-cli --help + - + -  excalidraw-brute-export-cli 0.3.2 —  -Export Excalidraw using a (headless) browser via the command line. - +  excalidraw-brute-export-cli 0.4.0 —  +Export Excalidraw using a (headless) browser via the command line. + - + -USAGE - +USAGE + - + - - excalidraw-brute-export-cli   -<OPTIONS...> - + + excalidraw-brute-export-cli   +<OPTIONS...> + - + - + - + -OPTIONS - +OPTIONS + - + - --action-sleep-time -[action-sleep-t  Time (in milliseconds) for each action to sleep.        - + --action-sleep-time +[action-sleep-t  Time (in milliseconds) for each action to sleep.        + -    ime] -                                 Defaults to 100. Too short and dialogs won't open in    - +    ime] +                                 Defaults to 100. Too short and dialogs won't open in    + -                                         time. Too long and it will take longer to run.          - +                                         time. Too long and it will take longer to run.          + -default: 200 - +default: 200 + - -b -, - --background -<background> -        Should the background be exported, or should it be      - + -b +, + --background +<background> +        Should the background be exported, or should it be      + -                                         transparent. Same option as in the Excalidraw UI when   - +                                         transparent. Same option as in the Excalidraw UI when   + -                                         exporting an image.                                     - +                                         exporting an image.                                     + -boolean - +boolean + - -d -, - --dark-mode -<dark-mode> -          Should the diagram be exported in dark mode, or not.    - + -d +, + --dark-mode +<dark-mode> +          Should the diagram be exported in dark mode, or not.    + -                                         Same option as in the Excalidraw UI when exporting an   - +                                         Same option as in the Excalidraw UI when exporting an   + -                                         image.                                                  - +                                         image.                                                  + -boolean - +boolean + - -e -, - --embed-scene -<embed-scene> -      Should the diagram be exported with the scene embedded  - + -e +, + --embed-scene +<embed-scene> +      Should the diagram be exported with the scene embedded  + -                                         in the image, or not. Tooltip from the UI: 'Scene data  - +                                         in the image, or not. Tooltip from the UI: 'Scene data  + -                                         will be saved into the exported PNG/SVG file so that    - +                                         will be saved into the exported PNG/SVG file so that    + -                                         the scene can be restored from it.                      - +                                         the scene can be restored from it.                      + -                                         Will increase exported file size.' Same option as in    - +                                         Will increase exported file size.' Same option as in    + -                                         the Excalidraw UI when exporting an image.              - +                                         the Excalidraw UI when exporting an image.              + -boolean - +boolean + - --excalidraw-version -[excalidraw-ve  The version of Excalidraw to use. If not specified, it  - + --excalidraw-version +[excalidraw-ve  The version of Excalidraw to use. If not specified, it  + -    rsion] -                               will be detected automatically.                         - +    rsion] +                               will be detected automatically.                         + -one of "0.15.0","0.17.0","", default: "" - +one of "0.15.0","0.17.0","", default: "" + - -f -, - --format -<format> -                The format to export the image in. Either "png" or      - + -f +, + --format +<format> +                The format to export the image in. Either "png" or      + -required -                             "svg".                                                  - +required +                             "svg".                                                  + -one of "png","svg" - +one of "png","svg" + - --headless -[headless] -                Should the browser be headless. Note that file dialogs  - + --headless +[headless] +                Should the browser be headless. Note that file dialogs  + -                                         do not open/work. Can turn this off for debugging.      - +                                         do not open/work. Can turn this off for debugging.      + -boolean, default: true - +boolean, default: true + - -i -, - --input -<excalidaraw-path> -       The path to the excalidraw file                         - + -i +, + --input +<excalidaraw-path> +       The path to the excalidraw file                         + -required - +required + - --leave-browser-running -[leave-brow  Should the browser be left open afterwards (only        - + --leave-browser-running +[leave-brow  Should the browser be left open afterwards (only        + -    ser-running] -                         allowed when headless==false). Can turn this off for    - +    ser-running] +                         allowed when headless==false). Can turn this off for    + -                                         debugging.                                              - +                                         debugging.                                              + -boolean - +boolean + - -o -, - --output -<output-path> -           The path to the output file.                            - + -o +, + --output +<output-path> +           The path to the output file.                            + -required - +required + - -s -, - --scale -<scale> -                  The scale to use when exporting the image. Same option  - + -s +, + --scale +<scale> +                  The scale to use when exporting the image. Same option  + -required -                             as in the Excalidraw UI when exporting an image.        - +required +                             as in the Excalidraw UI when exporting an image.        + -one of 1,2,3 - +one of 1,2,3 + - --screenshots -[screenshots] -          Path to store debug screenshots at each step. Empty     - + --screenshots +[screenshots] +          Path to store debug screenshots at each step. Empty     + -                                         string means no screenshots are recorded. Defaults to   - +                                         string means no screenshots are recorded. Defaults to   + -                                         no screenshots.                                         - +                                         no screenshots.                                         + -default: "" - +default: "" + - --timeout -[timeout] -                  Timeout (in milliseconds) for each action in            - + --timeout +[timeout] +                  Timeout (in milliseconds) for each action in            + -                                         playwright. 0 for infinite timeout. - -1 - for no specific  - +                                         playwright. 0 for infinite timeout. + -1 + for no specific  + -                                         timeout, which uses playwright's default timeout.       - +                                         timeout, which uses playwright's default timeout.       + -                                         Defaults to - -1. - +                                         Defaults to + -1. + -default: - -1 - +default: + -1 + - -u -, - --url -[url] -                      The URL to use for excalidraw website. Falls back to    - + -u +, + --url +[url] +                      The URL to use for excalidraw website. Falls back to    + -                                         environment variable EXCALIDRAW_BRUTE_EXPORT_CLI_URL if - +                                         environment variable EXCALIDRAW_BRUTE_EXPORT_CLI_URL if + -                                         not specified. Falls back to https://excalidraw.com/    - +                                         not specified. Falls back to https://excalidraw.com/    + -                                         otherwise.                                              - +                                         otherwise.                                              + -default: "" - +default: "" + - + -GLOBAL OPTIONS - +GLOBAL OPTIONS + - + - -h -, - --help -                           Display global help or command-related help.            - + -h +, + --help +                           Display global help or command-related help.            + - -V -, - --version -                        Display version.                                        - + -V +, + --version +                        Display version.                                        + - --no-color -                           Disable use of colors in output.                        - + --no-color +                           Disable use of colors in output.                        + - -v -, - --verbose -                        Verbose mode: will also output debug messages.          - + -v +, + --verbose +                        Verbose mode: will also output debug messages.          + - --quiet -                              Quiet mode - only displays warn and error messages.     - + --quiet +                              Quiet mode - only displays warn and error messages.     + - --silent -                             Silent mode: does not output anything, giving no        - + --silent +                             Silent mode: does not output anything, giving no        + -                                         indication of success or failure other than the exit    - +                                         indication of success or failure other than the exit    + -                                         code.                                                   - +                                         code.                                                   + - + diff --git a/.github/README.md.jinja2 b/.github/README.md.jinja2 index bf17408..fe32a8f 100644 --- a/.github/README.md.jinja2 +++ b/.github/README.md.jinja2 @@ -26,8 +26,15 @@ 🎇Features  •  🏠Installation  •  🚜Usage  •  - 💻CLI  •  - ✅Requirements  •  + 💻CLI + +

+

+ + ✅Requirements +  •  + 🐳Docker +  •  🚸Gotchas

@@ -119,33 +126,27 @@ npx playwright install firefox Example: -{% set example_cmd=' -npx excalidraw-brute-export-cli \\ - -i ./examples/simple.excalidraw \\ - --background 1 \\ - --embed-scene 0 \\ - --dark-mode 0 \\ - --scale 1 \\ - --format svg \\ - -o "./README.example.output.svg" -' | trim %} - -```bash -# Use this command: -{{ example_cmd | safe }} -``` - - + + + And the resulting image (svg): -Simple Excalidraw Diagram as a SVG +Simple Excalidraw Diagram as a SVG ## 💻 Command Line Options @@ -223,6 +224,26 @@ npx excalidraw-brute-export-cli \ - WSL2 Ubuntu 20.04, Node `{{rawsnippet('./.nvmrc')|trim}}` using Excalidraw at tag `{{rawsnippet('./.github/.excalidraw-tag')|trim}}`. +## 🐳 Docker Image + +Docker images are published to [ghcr.io/realazthat/{{project_name}}][49] at each +tag. + + + +If you want to build the image yourself, you can use the Dockerfile in the +repository. + + + ## 🚸 Gotchas and Limitations - Sometimes playwright times out. diff --git a/.github/README.remotified.md b/.github/README.remotified.md index c60b4be..9bafb3b 100644 --- a/.github/README.remotified.md +++ b/.github/README.remotified.md @@ -29,8 +29,15 @@ SOURCE: `.github/README.md.jinja2`. 🎇Features  •  🏠Installation  •  🚜Usage  •  - 💻CLI  •  - ✅Requirements  •  + 💻CLI + +

+

+ + ✅Requirements +  •  + 🐳Docker +  •  🚸Gotchas

@@ -57,7 +64,7 @@ exact same export process as Excalidraw itself** -Demo +Demo - ❔ What: Uses [🎭 playwright][2] to run a headless firefox browser to export [Excalidraw][3] diagrams to svg/png files. Using a browser bypasses certain @@ -111,7 +118,7 @@ exact same export process as Excalidraw itself** npm install -g excalidraw-brute-export-cli # Or install globally, direct from GitHub: -npm install -g https://github.com/realazthat/excalidraw-brute-export-cli.git#v0.3.2 +npm install -g https://github.com/realazthat/excalidraw-brute-export-cli.git#v0.4.0 # Might prompt for root. npx playwright install-deps @@ -122,10 +129,9 @@ npx playwright install firefox Example: - - + ```bash -# Use this command: + npx excalidraw-brute-export-cli \ -i ./examples/simple.excalidraw \ --background 1 \ @@ -133,18 +139,24 @@ npx excalidraw-brute-export-cli \ --dark-mode 0 \ --scale 1 \ --format svg \ - -o "./README.example.output.svg" + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + ``` + -Example output + +Output of `bash ./examples/simple_example.sh` + And the resulting image (svg): -Simple Excalidraw Diagram as a SVG +Simple Excalidraw Diagram as a SVG ## 💻 Command Line Options -Output of `npx excalidraw-brute-export-cli --help` +Output of `npx excalidraw-brute-export-cli --help` ## 🐳 Running Excalidraw locally @@ -203,7 +215,7 @@ npx excalidraw-brute-export-cli \ Excalidraw tag `v0.15.0` for more consistent output, and testing. - Supported Node versions: `>=18.0.0 <19.0.0 || >=20.0.0 <21.0.0 || >=21.0.0 <22.0.0 || >=22.0.0 <23.0.0` (See - [./package.json](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/package.json)). These versions were chosen from + [./package.json](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/package.json)). These versions were chosen from current supported and upcoming versions of node, from [Node.js: Previous Releases](https://nodejs.org/en/about/previous-releases). - Tested Node versions on GitHub Actions: `["18.20.2","20.12.1","21.7.3","22.0.0"]`. @@ -213,6 +225,59 @@ npx excalidraw-brute-export-cli \ - WSL2 Ubuntu 20.04, Node `v20.12.1` using Excalidraw at tag `v0.15.0`. +## 🐳 Docker Image + +Docker images are published to [ghcr.io/realazthat/excalidraw-brute-export-cli][49] at each +tag. + + +```bash + +# Use the published images at ghcr.io/realazthat/snipinator. +# /data in the docker image is the working directory, so paths are simpler. +docker run --rm --tty \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}:/data" \ + ghcr.io/realazthat/excalidraw-brute-export-cli:v0.4.0 \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +``` + + +If you want to build the image yourself, you can use the Dockerfile in the +repository. + + +```bash + +docker build -t my-excalidraw-brute-export-cli-image . + +# /data in the docker image is the working directory, so paths are simpler. +docker run --rm --tty \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}:/data" \ + my-excalidraw-brute-export-cli-image \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +``` + + ## 🚸 Gotchas and Limitations - Sometimes playwright times out. @@ -231,7 +296,7 @@ repository. ## 🔑 License This project is licensed under the MIT License - see the -[./LICENSE.md](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/LICENSE.md) file for details. +[./LICENSE.md](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/LICENSE.md) file for details. ## 🫡 Contributions @@ -239,7 +304,7 @@ This project is licensed under the MIT License - see the - For running `pre.sh` (Linux-like environment). - - From [./.github/dependencies.yml](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/.github/dependencies.yml), which is used for + - From [./.github/dependencies.yml](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/.github/dependencies.yml), which is used for the GH Action to do a fresh install of everything: ```yaml @@ -258,13 +323,13 @@ This project is licensed under the MIT License - see the ``` - Requires `pyenv`, or an exact matching version of python as in - [scripts/.python-version](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/scripts/.python-version) (which is currently + [scripts/.python-version](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/scripts/.python-version) (which is currently `3.8.18 `). - `jq`, ([installation](https://jqlang.github.io/jq/)) required for [yq](https://github.com/kislyuk/yq), which is itself required for our - [./README.md](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/README.md) generation, which uses `tomlq` (from the + [./README.md](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/README.md) generation, which uses `tomlq` (from the [yq](https://github.com/kislyuk/yq) package) to include version strings from - [./scripts/pyproject.toml](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/scripts/pyproject.toml). + [./scripts/pyproject.toml](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/scripts/pyproject.toml). - act (to run the GH Action locally): - Requires nodejs. - Requires Go. @@ -277,16 +342,16 @@ This project is licensed under the MIT License - see the ### Commit Process 1. (Optionally) Fork the `develop` branch. -2. If the [.github/demo.gif](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/.github/demo.gif) will change, run +2. If the [.github/demo.gif](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/.github/demo.gif) will change, run `bash ./scripts/generate-animation.sh`, this will generate a new - [.github/demo.gif](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/.github/demo.gif). + [.github/demo.gif](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/.github/demo.gif). - Sanity-check the animation visually! - Unfortunately, every run will make a unique gif, please don't stage this file unless it changes due to some feature change or somesuch. 3. Stage your files: e.g `git add path/to/file.py`. 4. `bash ./scripts/pre.sh`, this will format, lint, and test the code. 5. `git status` check if anything changed (generated - [README.md](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/README.md) for example), if so, `git add` the changes, + [README.md](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/README.md) for example), if so, `git add` the changes, and go back to the previous step. 6. `git commit -m "..."`. 7. Make a PR to `develop` (or push to develop if you have the rights). @@ -298,7 +363,7 @@ These instructions are for maintainers of the project. 1. In the `develop` branch, run `bash ./scripts/pre.sh` to ensure everything is in order. 2. In the `develop` branch, bump the version in - [package.json](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/package.json), following semantic versioning + [package.json](https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/package.json), following semantic versioning principles. Run `bash ./scripts/pre.sh` to ensure everything is in order. - If anything got generated (e.g README or terminal output images), you will have to stage those. @@ -318,7 +383,7 @@ These instructions are for maintainers of the project. `git checkout develop && git merge master`. 9. Push the develop branch to GitHub: `git push origin develop`. -[1]: https://raw.githubusercontent.com/realazthat/excalidraw-brute-export-cli/v0.3.2/.github/logo-exported.svg +[1]: https://raw.githubusercontent.com/realazthat/excalidraw-brute-export-cli/v0.4.0/.github/logo-exported.svg [2]: https://playwright.dev/ [3]: https://excalidraw.com/ @@ -331,7 +396,7 @@ These instructions are for maintainers of the project. [5]: https://img.shields.io/badge/Platform-Node-0A1E1E?style=plastic&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWxhcHRvcC1taW5pbWFsIj48cmVjdCB3aWR0aD0iMTgiIGhlaWdodD0iMTIiIHg9IjMiIHk9IjQiIHJ4PSIyIiByeT0iMiIvPjxsaW5lIHgxPSIyIiB4Mj0iMjIiIHkxPSIyMCIgeTI9IjIwIi8+PC9zdmc+ [6]: https://img.shields.io/github/languages/top/realazthat/excalidraw-brute-export-cli.svg?&cacheSeconds=28800&style=plastic&color=0A1E1E [7]: https://img.shields.io/github/license/realazthat/excalidraw-brute-export-cli?style=plastic&color=0A1E1E -[8]: https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.3.2/LICENSE.md +[8]: https://github.com/realazthat/excalidraw-brute-export-cli/blob/v0.4.0/LICENSE.md [9]: https://img.shields.io/npm/v/excalidraw-brute-export-cli?style=plastic&color=0A1E1E [10]: https://www.npmjs.com/package/excalidraw-brute-export-cli [11]: https://github.com/realazthat/excalidraw-brute-export-cli/tree/master @@ -339,12 +404,12 @@ These instructions are for maintainers of the project. [13]: https://img.shields.io/github/actions/workflow/status/realazthat/excalidraw-brute-export-cli/build-and-test.yml?branch=master&style=plastic [14]: https://img.shields.io/github/actions/workflow/status/realazthat/excalidraw-brute-export-cli/build-and-test.yml?branch=develop&style=plastic [15]: https://github.com/realazthat/excalidraw-brute-export-cli/actions/workflows/build-and-test.yml -[16]: https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.3.2/master?style=plastic -[17]: https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.3.2/develop?style=plastic -[18]: https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.3.2...master -[19]: https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.3.2...develop -[20]: https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.3.2/develop?style=plastic -[21]: https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.3.2...develop +[16]: https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.4.0/master?style=plastic +[17]: https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.4.0/develop?style=plastic +[18]: https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.4.0...master +[19]: https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.4.0...develop +[20]: https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.4.0/develop?style=plastic +[21]: https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.4.0...develop [22]: https://img.shields.io/github/last-commit/realazthat/excalidraw-brute-export-cli/master?style=plastic [23]: https://img.shields.io/github/last-commit/realazthat/excalidraw-brute-export-cli/develop?style=plastic [24]: https://img.shields.io/node/v/excalidraw-brute-export-cli?style=plastic&color=0A1E1E diff --git a/.github/README.simple_example.log.svg b/.github/README.simple_example.log.svg new file mode 100644 index 0000000..f7c05e4 --- /dev/null +++ b/.github/README.simple_example.log.svg @@ -0,0 +1,367 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +npx excalidraw-brute-export-cli -i ./examples/simple.excalidraw --background 1 --embed-scene 0 --dark-mode 0 --scale 1 --format svg -o  + + +./examples/simple_example_output.svg + + +info +: options: + + +info +: { + + +  i:  +'./examples/simple.excalidraw' +, + + +  input:  +'./examples/simple.excalidraw' +, + + +  background:  +true +, + + +  b:  +true +, + + +  embedScene:  +false +, + + +  e:  +false +, + + +  darkMode:  +false +, + + +  d:  +false +, + + +  scale:  +1 +, + + +  s:  +1 +, + + +  format:  +'svg' +, + + +  f:  +'svg' +, + + +  o:  +'./examples/simple_example_output.svg' +, + + +  output:  +'./examples/simple_example_output.svg' +, + + +  url:  +'' +, + + +  excalidrawVersion:  +'' +, + + +  headless:  +true +, + + +  leaveBrowserRunning:  +false +, + + +  screenshots:  +'' +, + + +  actionSleepTime:  +200 +, + + +  timeout:  +-1 + + +} + + +info +: Falling back to environment variable EXCALIDRAW_BRUTE_EXPORT_CLI_URL + + +info +: excalidrawURL: http://localhost:59876 + + +info +: Detecting Excalidraw version... + + +info +: excalidrawVersion: 0.15.0 + + +info +: Clicking: Menu Burger + + +info +: Clicking: Open Menu Item + + +info +: File is chosen! + + +info +: Clicking: Export Menu Item + + +info +: await exportBackgroundSwitch.count(): 1 + + +info +: await exportEmbedSwitch.count(): 1 + + +info +: await exportScaleDiv.count(): 1 + + +info +: await exportScaleElements.count(): 3 + + +info +: Pressing SVG button! + + +info +: File is downloaded! + + +info +: closing... + + + +ls ./examples/simple_example_output.svg + + +./examples/simple_example_output.svg + + + + + \ No newline at end of file diff --git a/.github/simple_example.log b/.github/simple_example.log new file mode 100644 index 0000000..7c950e8 --- /dev/null +++ b/.github/simple_example.log @@ -0,0 +1,53 @@ +$ set -e -x -v -u -o pipefail +set +v +$ set +v +$ GREEN='\033[0;32m' +$ YELLOW='\033[1;33m' +$ NC='\033[0m' +$ PS4='\033[0;32m$ \033[0m' +$ EXCALIDRAW_BRUTE_EXPORT_CLI_URL=http://localhost:59876 +$ [[ -z http://localhost:59876 ]] +$ : ECHO_SNIPPET_START +$ npx excalidraw-brute-export-cli -i ./examples/simple.excalidraw --background 1 --embed-scene 0 --dark-mode 0 --scale 1 --format svg -o ./examples/simple_example_output.svg +info: options: +info: { + i: './examples/simple.excalidraw', + input: './examples/simple.excalidraw', + background: true, + b: true, + embedScene: false, + e: false, + darkMode: false, + d: false, + scale: 1, + s: 1, + format: 'svg', + f: 'svg', + o: './examples/simple_example_output.svg', + output: './examples/simple_example_output.svg', + url: '', + excalidrawVersion: '', + headless: true, + leaveBrowserRunning: false, + screenshots: '', + actionSleepTime: 200, + timeout: -1 +} +info: Falling back to environment variable EXCALIDRAW_BRUTE_EXPORT_CLI_URL +info: excalidrawURL: http://localhost:59876 +info: Detecting Excalidraw version... +info: excalidrawVersion: 0.15.0 +info: Clicking: Menu Burger +info: Clicking: Open Menu Item +info: File is chosen! +info: Clicking: Export Menu Item +info: await exportBackgroundSwitch.count(): 1 +info: await exportEmbedSwitch.count(): 1 +info: await exportScaleDiv.count(): 1 +info: await exportScaleElements.count(): 3 +info: Pressing SVG button! +info: File is downloaded! +info: closing... +$ ls ./examples/simple_example_output.svg +./examples/simple_example_output.svg +$ : ECHO_SNIPPET_END diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b62fee6..7313495 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: detect-private-key - id: double-quote-string-fixer - id: end-of-file-fixer - exclude: ^.*\.(md|svg)$ + exclude: ^.*\.(md|svg|sh)$ - id: fix-byte-order-marker - id: mixed-line-ending - id: name-tests-test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3bbdbed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM node:20.12.1-bullseye-slim + + +WORKDIR /excalidraw-brute-export-cli + +RUN apt-get -y update && apt-get -y --no-install-recommends install bash && \ + apt-get -y clean && \ + apt-get -y autoremove && \ + rm -rf /var/lib/apt/lists/* && \ + mkdir -p /excalidraw-brute-export-cli && \ + chmod -R a+wrX /excalidraw-brute-export-cli && \ + chown -R node:node /excalidraw-brute-export-cli && \ + npx --yes playwright install-deps + + +COPY --chown=node:node . /excalidraw-brute-export-cli + +USER node +# ENV NPM_CONFIG_PREFIX=/home/node/.npm-global +# ENV PATH=/home/node/.npm-global/bin:$PATH +WORKDIR /excalidraw-brute-export-cli +RUN npm install . && npx playwright install + +# This is where the user will mount their data to. +WORKDIR /data + +ENTRYPOINT ["npx", "--prefix", "/excalidraw-brute-export-cli", "excalidraw-brute-export-cli"] +CMD ["--help"] +HEALTHCHECK --interval=30s --timeout=10s --retries=3 \ + CMD npx excalidraw-brute-export-cli --version || exit 1 diff --git a/README.md b/README.md index d3c9a0c..c5e337f 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,15 @@ SOURCE: `.github/README.md.jinja2`. 🎇Features  •  🏠Installation  •  🚜Usage  •  - 💻CLI  •  - ✅Requirements  •  + 💻CLI + +

+

+ + ✅Requirements +  •  + 🐳Docker +  •  🚸Gotchas

@@ -111,7 +118,7 @@ exact same export process as Excalidraw itself** npm install -g excalidraw-brute-export-cli # Or install globally, direct from GitHub: -npm install -g https://github.com/realazthat/excalidraw-brute-export-cli.git#v0.3.2 +npm install -g https://github.com/realazthat/excalidraw-brute-export-cli.git#v0.4.0 # Might prompt for root. npx playwright install-deps @@ -122,10 +129,9 @@ npx playwright install firefox Example: - - + ```bash -# Use this command: + npx excalidraw-brute-export-cli \ -i ./examples/simple.excalidraw \ --background 1 \ @@ -133,14 +139,20 @@ npx excalidraw-brute-export-cli \ --dark-mode 0 \ --scale 1 \ --format svg \ - -o "./README.example.output.svg" + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + ``` + -Example output + +Output of `bash ./examples/simple_example.sh` + And the resulting image (svg): -Simple Excalidraw Diagram as a SVG +Simple Excalidraw Diagram as a SVG ## 💻 Command Line Options @@ -213,6 +225,59 @@ npx excalidraw-brute-export-cli \ - WSL2 Ubuntu 20.04, Node `v20.12.1` using Excalidraw at tag `v0.15.0`. +## 🐳 Docker Image + +Docker images are published to [ghcr.io/realazthat/excalidraw-brute-export-cli][49] at each +tag. + + +```bash + +# Use the published images at ghcr.io/realazthat/snipinator. +# /data in the docker image is the working directory, so paths are simpler. +docker run --rm --tty \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}:/data" \ + ghcr.io/realazthat/excalidraw-brute-export-cli:v0.4.0 \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +``` + + +If you want to build the image yourself, you can use the Dockerfile in the +repository. + + +```bash + +docker build -t my-excalidraw-brute-export-cli-image . + +# /data in the docker image is the working directory, so paths are simpler. +docker run --rm --tty \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}:/data" \ + my-excalidraw-brute-export-cli-image \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +``` + + ## 🚸 Gotchas and Limitations - Sometimes playwright times out. @@ -349,17 +414,17 @@ These instructions are for maintainers of the project. [15]: https://github.com/realazthat/excalidraw-brute-export-cli/actions/workflows/build-and-test.yml [16]: - https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.3.2/master?style=plastic + https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.4.0/master?style=plastic [17]: - https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.3.2/develop?style=plastic + https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.4.0/develop?style=plastic [18]: - https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.3.2...master + https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.4.0...master [19]: - https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.3.2...develop + https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.4.0...develop [20]: - https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.3.2/develop?style=plastic + https://img.shields.io/github/commits-since/realazthat/excalidraw-brute-export-cli/v0.4.0/develop?style=plastic [21]: - https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.3.2...develop + https://github.com/realazthat/excalidraw-brute-export-cli/compare/v0.4.0...develop [22]: https://img.shields.io/github/last-commit/realazthat/excalidraw-brute-export-cli/master?style=plastic [23]: diff --git a/examples/simple-local-docker_example.sh b/examples/simple-local-docker_example.sh new file mode 100755 index 0000000..9219fa8 --- /dev/null +++ b/examples/simple-local-docker_example.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# WARNING: This file is auto-generated by snipinator. Do not edit directly. +# SOURCE: `examples/simple_example.sh.jinja2`. + +#!/bin/bash +# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +set -e -x -v -u -o pipefail +set +v +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +PS4="${GREEN}$ ${NC}" + +EXCALIDRAW_BRUTE_EXPORT_CLI_URL=${EXCALIDRAW_BRUTE_EXPORT_CLI_URL:-} +if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then + echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}" + exit 1 +fi + + + +# Don't run this in act/GH actions because act doesn't play with with nested +# docker; the paths mess up. +if [[ -n "${GITHUB_ACTIONS:-}" ]]; then + echo -e "${YELLOW}This script is not meant to be run in GitHub Actions.${NC}" + exit 0 +fi + +: ECHO_SNIPPET_START +# SNIPPET_START +docker build -t my-excalidraw-brute-export-cli-image . + +# /data in the docker image is the working directory, so paths are simpler. +docker run --rm --tty \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}:/data" \ + my-excalidraw-brute-export-cli-image \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +# SNIPPET_END +: ECHO_SNIPPET_END diff --git a/examples/simple-remote-docker_example-noautorun.sh b/examples/simple-remote-docker_example-noautorun.sh new file mode 100644 index 0000000..254b418 --- /dev/null +++ b/examples/simple-remote-docker_example-noautorun.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# WARNING: This file is auto-generated by snipinator. Do not edit directly. +# SOURCE: `examples/simple_example.sh.jinja2`. + +#!/bin/bash +# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +set -e -x -v -u -o pipefail +set +v +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +PS4="${GREEN}$ ${NC}" + +EXCALIDRAW_BRUTE_EXPORT_CLI_URL=${EXCALIDRAW_BRUTE_EXPORT_CLI_URL:-} +if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then + echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}" + exit 1 +fi + + + +# Don't run this in act/GH actions because act doesn't play with with nested +# docker; the paths mess up. +if [[ -n "${GITHUB_ACTIONS:-}" ]]; then + echo -e "${YELLOW}This script is not meant to be run in GitHub Actions.${NC}" + exit 0 +fi + +: ECHO_SNIPPET_START +# SNIPPET_START +# Use the published images at ghcr.io/realazthat/snipinator. +# /data in the docker image is the working directory, so paths are simpler. +docker run --rm --tty \ + -u "$(id -u):$(id -g)" \ + -v "${PWD}:/data" \ + ghcr.io/realazthat/excalidraw-brute-export-cli:v0.4.0 \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +# SNIPPET_END +: ECHO_SNIPPET_END diff --git a/examples/simple.sh b/examples/simple.sh deleted file mode 100755 index 3af1f80..0000000 --- a/examples/simple.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 -set -e -x -v -u -o pipefail - -mkdir -p "./.deleteme" -rm "./.deleteme/output.png" || true -npx excalidraw-brute-export-cli \ - -i ./examples/simple.excalidraw \ - --background 1 \ - --embed-scene 1 \ - --dark-mode 0 \ - --scale 1 \ - --format png \ - -o "./.deleteme/output.png" - -ls "./.deleteme/output.png" diff --git a/examples/simple_example.sh b/examples/simple_example.sh new file mode 100755 index 0000000..4b877ad --- /dev/null +++ b/examples/simple_example.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# WARNING: This file is auto-generated by snipinator. Do not edit directly. +# SOURCE: `examples/simple_example.sh.jinja2`. + +#!/bin/bash +# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +set -e -x -v -u -o pipefail +set +v +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +PS4="${GREEN}$ ${NC}" + +EXCALIDRAW_BRUTE_EXPORT_CLI_URL=${EXCALIDRAW_BRUTE_EXPORT_CLI_URL:-} +if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then + echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}" + exit 1 +fi + +: ECHO_SNIPPET_START +# SNIPPET_START +npx excalidraw-brute-export-cli \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +# SNIPPET_END +: ECHO_SNIPPET_END diff --git a/examples/simple_example.sh.jinja2 b/examples/simple_example.sh.jinja2 new file mode 100644 index 0000000..823ed2b --- /dev/null +++ b/examples/simple_example.sh.jinja2 @@ -0,0 +1,72 @@ +{%- if True -%} +#!/bin/bash +# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +set -e -x -v -u -o pipefail +set +v +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color +PS4="${GREEN}$ ${NC}" + +EXCALIDRAW_BRUTE_EXPORT_CLI_URL=${EXCALIDRAW_BRUTE_EXPORT_CLI_URL:-} +if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then + echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}" + exit 1 +fi + +{% endif -%} + +{#- example_type: {docker-remote, docker-local, npm-module} -#} +{#- docker_image_name: str -#} +{#- module_name: str -#} +{#- cmd: str -#} + +{%- macro abort(error) -%} + {{ None['[ERROR] ' ~ error][0] }} +{%- endmacro -%} + +{%- if example_type in ['docker-remote', 'docker-local'] -%} + {% set cmd='docker run --rm --tty \\\n -u \"$(id -u):$(id -g)\" \\\n -v \"${PWD}:/data\" \\\n ' ~ docker_image_name %} +{%- elif example_type=='npm-module' -%} + {% set cmd='npx ' ~ module_name %} +{%- else -%} + {{ abort('example_type is unknown value: ' ~ example_type) }} +{%- endif -%} + +{%- if example_type in ['docker-remote', 'docker-local'] %} + +# Don't run this in act/GH actions because act doesn't play with with nested +# docker; the paths mess up. +if [[ -n "${GITHUB_ACTIONS:-}" ]]; then + echo -e "${YELLOW}This script is not meant to be run in GitHub Actions.${NC}" + exit 0 +fi + +{% endif-%} + +: ECHO_SNIPPET_START +# SNIPPET_START +{% if example_type in ['docker-local'] -%} +docker build -t {{docker_image_name|safe}} . + +{% endif -%} + +{% if example_type in ['docker-remote'] -%} +# Use the published images at ghcr.io/realazthat/snipinator. +{% endif -%} +{% if example_type in ['docker-local', 'docker-remote'] -%} +# /data in the docker image is the working directory, so paths are simpler. +{% endif -%} +{{cmd|safe}} \ + -i ./examples/simple.excalidraw \ + --background 1 \ + --embed-scene 0 \ + --dark-mode 0 \ + --scale 1 \ + --format svg \ + -o "./examples/simple_example_output.svg" + +ls "./examples/simple_example_output.svg" + +# SNIPPET_END +: ECHO_SNIPPET_END diff --git a/examples/simple_example_output.svg b/examples/simple_example_output.svg new file mode 100644 index 0000000..52d7eec --- /dev/null +++ b/examples/simple_example_output.svg @@ -0,0 +1,16 @@ + + + + + + + Polygon MeshHeightmap2D Implicit Surface3D Implicit SurfaceVoxel GridMesh GenerationPolygon Rendering PipelineStartRegular SamplingVoxelization(Regular Sampling)Regular SamplingExample: SDFieldRegular SamplingExample: SDFieldIsosurface ExtractionAdaptive Voxel GridAdaptive Sampling(Feature Preservation)Ray Marching/Casting3D MipmapSame data, differentstructureExample: SVOExample: GigaVoxelsAuxiliary Data Structures: Puzzle Pieces2D Height MipmapDownsampling (LOD)Adaptive HeightmapDownsampling(LOD)MeshGenerationExample: GigaVoxelsExample: MinecraftExample: Clipmaps{Toroidal} {Chunked} {Adaptive} SplattingBVHRay Tracing PipelineShear-Warp Volume Rendering{Streaming} Fourier VolumeFFTFourier Volume RenderingExample: BrickMapDownsampling(LOD)Example: SDFieldIsosurface ExtractionSame data, differentstructureExample: Transvoxel Algorithmx \ No newline at end of file diff --git a/lib/version.js b/lib/version.js index 76905bc..5e7afbb 100644 --- a/lib/version.js +++ b/lib/version.js @@ -1,2 +1,2 @@ // Generated by genversion. -export const version = '0.3.2' +export const version = '0.4.0' diff --git a/package-lock.json b/package-lock.json index e9f58aa..39d60a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "excalidraw-brute-export-cli", - "version": "0.3.2", + "version": "0.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "excalidraw-brute-export-cli", - "version": "0.3.2", + "version": "0.4.0", "dependencies": { "@caporal/core": "^2.0.7", "playwright": "^1.43.0" diff --git a/package.json b/package.json index 9eef833..e2b23dd 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,11 @@ "excalidraw-brute-export-cli": "./src/main.js" }, "type": "module", - "version": "0.3.2", + "version": "0.4.0", "scripts": { "format": "npx prettier --write package.json && npx prettier --write src/ && npx prettier --write --parser markdown \"LICENSE.md\" \".github/README.md.jinja2\" --write", "genversion": "genversion --esm lib/version.js", - "prepublishOnly": "git diff --cached --name-only | xargs npm pack --dry-run" + "prepublishOnly": "cp -f .github/README.remotified.md README.md && git diff --cached --name-only | xargs npm pack --dry-run" }, "dependencies": { "@caporal/core": "^2.0.7", diff --git a/scripts/format.sh b/scripts/format.sh index 6af5258..4a8ead3 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -2,4 +2,4 @@ # https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 set -e -x -v -u -o pipefail -npm run format +npm install && npm run format diff --git a/scripts/generate-examples.sh b/scripts/generate-examples.sh new file mode 100755 index 0000000..afc6062 --- /dev/null +++ b/scripts/generate-examples.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425 +set -e -x -v -u -o pipefail + +SCRIPT_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")") +source "${SCRIPT_DIR}/utilities/common.sh" + +################################################################################ +PYTHON_VERSION_PATH=${PWD}/scripts/.python-version \ + VENV_PATH=${PWD}/.cache/scripts/.venv \ + source "${PROJ_PATH}/scripts/utilities/ensure-venv.sh" +PYTHON_VERSION_PATH=${PWD}/scripts/.python-version \ + TOML=${PROJ_PATH}/scripts/pyproject.toml EXTRA=dev \ + DEV_VENV_PATH="${PWD}/.cache/scripts/.venv" \ + TARGET_VENV_PATH="${PWD}/.cache/scripts/.venv" \ + bash "${PROJ_PATH}/scripts/utilities/ensure-reqs.sh" +################################################################################ + + +CUSTOM_WARNING=$(cat << 'EOF' +#!/bin/bash +# WARNING: This file is auto-generated by snipinator. Do not edit directly. +# SOURCE: `{template_file_name}`. + +. +EOF +) + +python -m snipinator.cli \ + -t "${PROJ_PATH}/examples/simple_example.sh.jinja2" \ + --args '{"example_type": "npm-module", "module_name": "excalidraw-brute-export-cli"}' \ + --warning-header "${CUSTOM_WARNING%.}" \ + --rm \ + --force \ + --create \ + -o "${PROJ_PATH}/examples/simple_example.sh" \ + --chmod-ro \ + --skip-unchanged + + +python -m snipinator.cli \ + -t "${PROJ_PATH}/examples/simple_example.sh.jinja2" \ + --args '{"example_type": "docker-local", "docker_image_name": "my-excalidraw-brute-export-cli-image"}' \ + --warning-header "${CUSTOM_WARNING%.}" \ + --rm \ + --force \ + --create \ + -o "${PROJ_PATH}/examples/simple-local-docker_example.sh" \ + --chmod-ro \ + --skip-unchanged + + +LAST_VERSION=$(node -p "require('./package.json').version") +python -m snipinator.cli \ + -t "${PROJ_PATH}/examples/simple_example.sh.jinja2" \ + --args '{"example_type": "docker-remote", "docker_image_name": "ghcr.io/realazthat/excalidraw-brute-export-cli:v'"${LAST_VERSION}"'"}' \ + --warning-header "${CUSTOM_WARNING%.}" \ + --rm \ + --force \ + --create \ + -o "${PROJ_PATH}/examples/simple-remote-docker_example-noautorun.sh" \ + --chmod-ro \ + --skip-unchanged \ No newline at end of file diff --git a/scripts/generate-readme.sh b/scripts/generate-readme.sh index 2ff4a40..a270972 100755 --- a/scripts/generate-readme.sh +++ b/scripts/generate-readme.sh @@ -12,7 +12,6 @@ if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}" exit 1 fi -export EXCALIDRAW_BRUTE_EXPORT_CLI_URL ################################################################################ PYTHON_VERSION_PATH=${PWD}/scripts/.python-version \ VENV_PATH=${PWD}/.cache/scripts/.venv \ @@ -29,6 +28,7 @@ NODE_VERSION_PATH=${PWD}/.nvmrc \ bash scripts/format.sh +( # FORCE_COLOR and TERM are set, to produce consistent results across different # systems. # @@ -56,10 +56,19 @@ export TERM=dumb export CLI_WIDTH=120 export LINES=40 export COLUMNS=120 + + +# Try to make terminal output as consistent as possible. +FORCE_COLOR=3 TERM=dumb CLI_WIDTH=120 COLUMNS=120 LINES=40 \ +PS4="${GREEN}$ ${NC}" unbuffer bash -x ./examples/simple_example.sh \ + > .github/simple_example.log 2>&1 + + python -m snipinator.cli \ -t "${PROJ_PATH}/.github/README.md.jinja2" \ -o "${PROJ_PATH}/README.md" \ - --rm --force --create --chmod-ro + --rm --force --create --chmod-ro --skip-unchanged +) ################################################################################ LAST_VERSION=$(node -p "require('./package.json').version") python -m mdremotifier.cli \ diff --git a/scripts/generate.sh b/scripts/generate.sh index a02992c..efb1125 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -16,7 +16,15 @@ PYTHON_VERSION_PATH=${PWD}/scripts/.python-version \ bash "${PROJ_PATH}/scripts/utilities/ensure-reqs.sh" ################################################################################ +npm install +if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL:-}" ]]; then + source scripts/run-excalidraw.sh +fi + + +npm run genversion bash scripts/format.sh +bash scripts/generate-examples.sh bash scripts/run-all-examples.sh bash scripts/generate-readme.sh ################################################################################ diff --git a/scripts/pre.sh b/scripts/pre.sh index 36a4fbc..e27140d 100755 --- a/scripts/pre.sh +++ b/scripts/pre.sh @@ -18,8 +18,6 @@ IDEAL="0" if [[ "${WANTED_NODE_VERSION}" == "${IDEAL_NODE_VERSION}" && "${EXCALIDRAW_TAG}" == "${IDEAL_EXCALIDRAW_TAG}" ]]; then IDEAL="1" - export EXCALIDRAW_PORT=59876 - export EXCALIDRAW_INSTANCE_NAME="test-excalidraw" fi if [[ -z "${GITHUB_ACTIONS:-}" ]]; then @@ -45,10 +43,8 @@ npm install EXTRA=dev bash scripts/utilities/pin-extra-reqs.sh npm run genversion -source scripts/run-excalidraw.sh -if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL}" ]]; then - echo -e "${RED}EXCALIDRAW_BRUTE_EXPORT_CLI_URL is not set${NC}" - exit 1 +if [[ -z "${EXCALIDRAW_BRUTE_EXPORT_CLI_URL:-}" ]]; then + source scripts/run-excalidraw.sh fi bash scripts/generate.sh diff --git a/scripts/run-all-examples.sh b/scripts/run-all-examples.sh index 5112698..42913d0 100755 --- a/scripts/run-all-examples.sh +++ b/scripts/run-all-examples.sh @@ -19,12 +19,33 @@ NODE_VERSION_PATH=${PWD}/.nvmrc \ # FORCE_COLOR and TERM are set, to produce consistent results across different # systems. # -# See generate-readme.sh for explanation. +# Explanation: +# +# @caporal/core is used for argument parsing. +# +# chalk/chalk, via @caporal/core, uses an internal copy of the supports-color +# library (https://github.com/chalk/supports-color) here: +# . +# +# supports-color is terminal-emulator-dependent. +# +# But we want it to produce consistent results for the README output. +# +# To do this, we set the FORCE_COLOR environment variable to 3. +# +# However, this older version of supports-color does not always listen to +# FORCE_COLOR, so we also have to set TERM to 'dumb'. export FORCE_COLOR=3 export TERM=dumb +# https://www.npmjs.com/package/cli-width, via @caporal/core, detects column +# width, and snipinator's rich_cols isn't cutting it. +export CLI_WIDTH=120 +export LINES=40 +export COLUMNS=120 + # For each sh in examples -find examples -type f -name "*.sh" -print0 | while IFS= read -r -d '' EXAMPLE; do +find examples -type f -name "*_example.sh" -print0 | while IFS= read -r -d '' EXAMPLE; do bash "${EXAMPLE}" echo -e "${GREEN}${EXAMPLE} ran successfully${NC}" done diff --git a/scripts/run-excalidraw.sh b/scripts/run-excalidraw.sh index cf98d11..4b17bef 100755 --- a/scripts/run-excalidraw.sh +++ b/scripts/run-excalidraw.sh @@ -7,12 +7,19 @@ BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' -EXCALIDRAW_TAG=${EXCALIDRAW_TAG:-} +IDEAL_NODE_VERSION="v20.12.1" +WANTED_NODE_VERSION=$(cat .nvmrc) +ACTUAL_NODE_VERSION=$(node --version) + +IDEAL_EXCALIDRAW_TAG=$(cat .github/.excalidraw-tag) +EXCALIDRAW_TAG=${EXCALIDRAW_TAG:-${IDEAL_EXCALIDRAW_TAG}} + EXCALIDRAW_INSTANCE_NAME=${EXCALIDRAW_INSTANCE_NAME:-"test-excalidraw"} EXCALIDRAW_PORT=${EXCALIDRAW_PORT:-} IMAGE_NAME="test-excalidraw" if [[ -z "${EXCALIDRAW_TAG}" ]]; then + echo -e "${RED}EXCALIDRAW_TAG is not set, set it to an excalidraw github tag, or the string 'https://excalidraw.com'.${NC}" exit 1 fi @@ -24,7 +31,11 @@ if [[ "${EXCALIDRAW_TAG}" = "https://excalidraw.com" ]]; then fi if [[ -z "${EXCALIDRAW_PORT}" ]]; then - EXCALIDRAW_PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("",0)); print(s.getsockname()[1]); s.close()') + if [[ "${IDEAL_NODE_VERSION}" == "${WANTED_NODE_VERSION}" && "${WANTED_NODE_VERSION}" == "${ACTUAL_NODE_VERSION}" ]]; then + EXCALIDRAW_PORT=59876 + else + EXCALIDRAW_PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("",0)); print(s.getsockname()[1]); s.close()') + fi fi TMP_DIR=$(mktemp -d) diff --git a/scripts/run-ood-smoke-test.sh b/scripts/run-ood-smoke-test.sh index 60d9a06..1894a35 100755 --- a/scripts/run-ood-smoke-test.sh +++ b/scripts/run-ood-smoke-test.sh @@ -73,7 +73,7 @@ echo -e "${GREEN}Success: excalidraw-brute-export-cli installed successfully${NC npx --no-install excalidraw-brute-export-cli --version npx --no-install excalidraw-brute-export-cli --help -bash examples/simple.sh +bash examples/simple_example.sh echo -e "${GREEN}Success: excalidraw-brute-export-cli smoke test ran successfully${NC}" echo -e "${GREEN}${BASH_SOURCE[0]}: Tests ran successfully${NC}" diff --git a/scripts/utilities/ensure-pyenv.sh b/scripts/utilities/ensure-pyenv.sh index 77f9b0b..485514b 100755 --- a/scripts/utilities/ensure-pyenv.sh +++ b/scripts/utilities/ensure-pyenv.sh @@ -66,9 +66,9 @@ echo -e "${YELLOW}This may take a while${NC}" echo -e "${YELLOW}WANTED_PYTHON_VERSION: ${WANTED_PYTHON_VERSION}${NC}" pyenv install --skip-existing "${WANTED_PYTHON_VERSION}" -ACTUAL_PYTHON_VERSION=$(python --version) +ACTUAL_PYTHON_VERSION=$(python3 --version) echo -e "${YELLOW}ACTUAL_PYTHON_VERSION: ${ACTUAL_PYTHON_VERSION}${NC}" -WHICH_PYTHON=$(command -v python) +WHICH_PYTHON=$(command -v python3) echo -e "${YELLOW}WHICH_PYTHON: ${WHICH_PYTHON}${NC}" ls ~/.pyenv/versions/