@mlightcad/cad-simple-viewer-cli 1.6.3 → 1.7.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 mlightcad
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mlightcad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,139 +1,140 @@
1
- # @mlightcad/cad-simple-viewer-cli
2
-
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
- [![npm version](https://img.shields.io/npm/v/@mlightcad/cad-simple-viewer-cli.svg)](https://www.npmjs.com/package/@mlightcad/cad-simple-viewer-cli)
5
-
6
- AcCoreConsole-style **headless** CLI for MLight CAD Viewer. Install from npm, open a DXF/DWG (or start blank), run an AutoCAD-like **`.scr` command script**, and save exports (`pngout`, `-chtml`, `cdxf`, …) to disk.
7
-
8
- Requires **Node.js 20+**. The CLI uses headless Chromium via Playwright; on first use you must install the browser once.
9
-
10
- ## Install
11
-
12
- ```bash
13
- npm install -g @mlightcad/cad-simple-viewer-cli
14
- npx playwright install chromium
15
- ```
16
-
17
- Or as a project dependency:
18
-
19
- ```bash
20
- npm install -D @mlightcad/cad-simple-viewer-cli
21
- npx playwright install chromium
22
- ```
23
-
24
- ## Quick start
25
-
26
- ```bash
27
- # Export a drawing to PNG (sample script shipped with the package)
28
- cad-simple-viewer-cli \
29
- -i ./drawing.dwg \
30
- -s node_modules/@mlightcad/cad-simple-viewer-cli/examples/export-png.scr \
31
- -o ./out
32
-
33
- # Global install: same, with your own script
34
- cad-simple-viewer-cli -i ./drawing.dxf -s ./export-png.scr -o ./out
35
-
36
- # Open from URL
37
- cad-simple-viewer-cli \
38
- -i https://cdn.jsdelivr.net/gh/mlightcad/cad-data@main/data/canteen.dwg \
39
- -s ./export-png.scr \
40
- -o ./out
41
-
42
- # No input file: start from a blank ISO drawing (write mode)
43
- cad-simple-viewer-cli -s ./create-drawing-dxf.scr -o ./out --mode write
44
- ```
45
-
46
- With a local install, use `npx`:
47
-
48
- ```bash
49
- npx cad-simple-viewer-cli -i ./drawing.dwg -s ./export-png.scr -o ./out
50
- ```
51
-
52
- ## Options
53
-
54
- | Option | Description |
55
- |--------|-------------|
56
- | `-i, --input <file-or-url>` | Local `.dxf` / `.dwg` path or `http(s)` URL. Omit to start from a blank ISO template |
57
- | `-s, --script <file>` | `.scr` command script (**required**) |
58
- | `-o, --output <dir>` | Directory for downloaded exports (default: input file’s directory, or cwd when no `-i`) |
59
- | `--mode <read\|write>` | Document open mode (default: `read` with `-i`, `write` without `-i`) |
60
- | `--locale <code>` | Prompt/keyword locale (`en`, `zh`, …) |
61
- | `--logfile <path>` | Append start / finish / download log lines |
62
-
63
- ## AcCoreConsole mapping
64
-
65
- | AcCoreConsole | cad-simple-viewer-cli |
66
- |---------------|------------------------|
67
- | `accoreconsole /i drawing.dwg /s script.scr` | `cad-simple-viewer-cli -i drawing.dwg -s script.scr` |
68
- | `/i` | `-i, --input` (optional path or URL) |
69
- | `/s` | `-s, --script` |
70
- | plot / export path | `-o, --output` (download directory) |
71
-
72
- ## Script format
73
-
74
- 1. First non-blank line of each command is the **command name**
75
- 2. Following lines answer prompts (empty line = Enter / default / None)
76
- 3. Full-line `;` comments are ignored
77
- 4. `QUIT` / `EXIT` ends the script
78
-
79
- Example — zoom extents, then PNG (long side 2048):
80
-
81
- ```
82
- ; export-png.scr
83
- zoom
84
- e
85
- pngout
86
-
87
- 2048
88
- quit
89
- ```
90
-
91
- Useful commands (non-exhaustive): `zoom`, `pngout`, `cdxf`, `-chtml`, `chtml`, `cpdf`, `csvg`, `-layer`, `qnew`, `line`, `circle`, …
92
-
93
- Layer edits need `--mode write`. Export commands write files via browser download; the CLI captures them into `-o`.
94
-
95
- ## Sample scripts
96
-
97
- After install, examples live under `node_modules/@mlightcad/cad-simple-viewer-cli/examples/` (or the global package folder):
98
-
99
- | Script | Purpose |
100
- |--------|---------|
101
- | `export-png.scr` | Zoom extents → PNG |
102
- | `export-html.scr` | Offline HTML (`-chtml`) |
103
- | `export-dxf.scr` | DXF download (`cdxf`) |
104
- | `create-drawing-dxf.scr` | Blank drawing + LINE → DXF (no `-i`) |
105
- | `create-shapes-dxf.scr` | Blank drawing + LINE + CIRCLE → DXF |
106
- | `create-drawing-png.scr` | Blank drawing → PNG |
107
- | `freeze-layer-png.scr` | `-layer` Off then PNG (`--mode write`; edit `LAYER_NAME`) |
108
- | `batch-export-png.mjs` | Scan a folder of drawings PNG |
109
- | `batch-export-html.mjs` | Scan a folder → HTML |
110
-
111
- Batch helpers (from your project after `npm install -D`):
112
-
113
- ```bash
114
- node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-png.mjs ./drawings ./out-png
115
- node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html.mjs ./drawings ./out-html
116
- ```
117
-
118
- ## Programmatic API
119
-
120
- ```js
121
- import { runHeadless } from '@mlightcad/cad-simple-viewer-cli'
122
-
123
- const { outputDir, savedFiles } = await runHeadless({
124
- inputPath: './drawing.dwg', // optional; omit for blank drawing
125
- scriptPath: './export-png.scr',
126
- outputDir: './out',
127
- mode: 'read', // optional
128
- locale: 'en', // optional
129
- logfile: './cli.log' // optional
130
- })
131
-
132
- console.log(outputDir, savedFiles)
133
- ```
134
-
135
- ## How it works
136
-
137
- 1. The published package includes a prebuilt Playwright runner (`dist-runner/`).
138
- 2. The CLI starts headless Chromium, opens the drawing (or a blank template), waits for entity convert / deferred text geometry, then runs `AcApDocManager.runScript()`.
139
- 3. Export commands trigger downloads; the CLI writes captured files under `-o`.
1
+ # @mlightcad/cad-simple-viewer-cli
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/@mlightcad/cad-simple-viewer-cli.svg)](https://www.npmjs.com/package/@mlightcad/cad-simple-viewer-cli)
5
+
6
+ AcCoreConsole-style **headless** CLI for MLight CAD Viewer. Install from npm, open a DXF/DWG (or start blank), run an AutoCAD-like **`.scr` command script**, and save exports (`pngout`, `-chtml`, `cdxf`, …) to disk.
7
+
8
+ Requires **Node.js 20+**. The CLI uses headless Chromium via Playwright; on first use you must install the browser once.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install -g @mlightcad/cad-simple-viewer-cli
14
+ npx playwright install chromium
15
+ ```
16
+
17
+ Or as a project dependency:
18
+
19
+ ```bash
20
+ npm install -D @mlightcad/cad-simple-viewer-cli
21
+ npx playwright install chromium
22
+ ```
23
+
24
+ ## Quick start
25
+
26
+ ```bash
27
+ # Export a drawing to PNG (sample script shipped with the package)
28
+ cad-simple-viewer-cli \
29
+ -i ./drawing.dwg \
30
+ -s node_modules/@mlightcad/cad-simple-viewer-cli/examples/export-png.scr \
31
+ -o ./out
32
+
33
+ # Global install: same, with your own script
34
+ cad-simple-viewer-cli -i ./drawing.dxf -s ./export-png.scr -o ./out
35
+
36
+ # Open from URL
37
+ cad-simple-viewer-cli \
38
+ -i https://cdn.jsdelivr.net/gh/mlightcad/cad-data@main/data/canteen.dwg \
39
+ -s ./export-png.scr \
40
+ -o ./out
41
+
42
+ # No input file: start from a blank ISO drawing (write mode)
43
+ cad-simple-viewer-cli -s ./create-drawing-dxf.scr -o ./out --mode write
44
+ ```
45
+
46
+ With a local install, use `npx`:
47
+
48
+ ```bash
49
+ npx cad-simple-viewer-cli -i ./drawing.dwg -s ./export-png.scr -o ./out
50
+ ```
51
+
52
+ ## Options
53
+
54
+ | Option | Description |
55
+ |--------|-------------|
56
+ | `-i, --input <file-or-url>` | Local `.dxf` / `.dwg` path or `http(s)` URL. Omit to start from a blank ISO template |
57
+ | `-s, --script <file>` | `.scr` command script (**required**) |
58
+ | `-o, --output <dir>` | Directory for downloaded exports (default: input file’s directory, or cwd when no `-i`) |
59
+ | `--mode <read\|write>` | Document open mode (default: `read` with `-i`, `write` without `-i`) |
60
+ | `--locale <code>` | Prompt/keyword locale (`en`, `zh`, …) |
61
+ | `--logfile <path>` | Append start / finish / download log lines |
62
+
63
+ ## AcCoreConsole mapping
64
+
65
+ | AcCoreConsole | cad-simple-viewer-cli |
66
+ |---------------|------------------------|
67
+ | `accoreconsole /i drawing.dwg /s script.scr` | `cad-simple-viewer-cli -i drawing.dwg -s script.scr` |
68
+ | `/i` | `-i, --input` (optional path or URL) |
69
+ | `/s` | `-s, --script` |
70
+ | plot / export path | `-o, --output` (download directory) |
71
+
72
+ ## Script format
73
+
74
+ 1. First non-blank line of each command is the **command name**
75
+ 2. Following lines answer prompts (empty line = Enter / default / None)
76
+ 3. Full-line `;` comments are ignored
77
+ 4. `QUIT` / `EXIT` ends the script
78
+
79
+ Example — zoom extents, then PNG (long side 2048):
80
+
81
+ ```
82
+ ; export-png.scr
83
+ zoom
84
+ e
85
+ pngout
86
+
87
+ 2048
88
+ quit
89
+ ```
90
+
91
+ Useful commands (non-exhaustive): `zoom`, `pngout`, `cdxf`, `-chtml`, `chtml`, `cpdf`, `csvg`, `-layer`, `qnew`, `line`, `circle`, …
92
+
93
+ Layer edits need `--mode write`. Export commands write files via browser download; the CLI captures them into `-o`.
94
+
95
+ ## Sample scripts
96
+
97
+ After install, examples live under `node_modules/@mlightcad/cad-simple-viewer-cli/examples/` (or the global package folder):
98
+
99
+ | Script | Purpose |
100
+ |--------|---------|
101
+ | `export-png.scr` | Zoom extents → PNG |
102
+ | `export-html.scr` | Offline HTML (`-chtml`) |
103
+ | `export-html-multi.scr` | Multi-file ACEX package zip (`-chtml` Multi) |
104
+ | `export-dxf.scr` | DXF download (`cdxf`) |
105
+ | `create-drawing-dxf.scr` | Blank drawing + LINE → DXF (no `-i`) |
106
+ | `create-shapes-dxf.scr` | Blank drawing + LINE + CIRCLE DXF |
107
+ | `create-drawing-png.scr` | Blank drawing PNG |
108
+ | `freeze-layer-png.scr` | `-layer` Off then PNG (`--mode write`; edit `LAYER_NAME`) |
109
+ | `batch-export-png.mjs` | Scan a folder of drawings PNG |
110
+ | `batch-export-html.mjs` | Scan a folder → HTML |
111
+
112
+ Batch helpers (from your project after `npm install -D`):
113
+
114
+ ```bash
115
+ node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-png.mjs ./drawings ./out-png
116
+ node node_modules/@mlightcad/cad-simple-viewer-cli/examples/batch-export-html.mjs ./drawings ./out-html
117
+ ```
118
+
119
+ ## Programmatic API
120
+
121
+ ```js
122
+ import { runHeadless } from '@mlightcad/cad-simple-viewer-cli'
123
+
124
+ const { outputDir, savedFiles } = await runHeadless({
125
+ inputPath: './drawing.dwg', // optional; omit for blank drawing
126
+ scriptPath: './export-png.scr',
127
+ outputDir: './out',
128
+ mode: 'read', // optional
129
+ locale: 'en', // optional
130
+ logfile: './cli.log' // optional
131
+ })
132
+
133
+ console.log(outputDir, savedFiles)
134
+ ```
135
+
136
+ ## How it works
137
+
138
+ 1. The published package includes a prebuilt Playwright runner (`dist-runner/`).
139
+ 2. The CLI starts headless Chromium, opens the drawing (or a blank template), waits for entity convert / deferred text geometry, then runs `AcApDocManager.runScript()`.
140
+ 3. Export commands trigger downloads; the CLI writes captured files under `-o`.