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

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.
@@ -1,105 +1,105 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Recursively scan a directory for .dwg / .dxf files and export each to HTML
4
- * via cad-simple-viewer-cli + export-html.scr.
5
- *
6
- * Usage (from packages/cad-simple-viewer-cli after build):
7
- * node examples/batch-export-html.mjs <inputDir> [outputDir]
8
- */
9
- import { spawn } from 'node:child_process'
10
- import { existsSync } from 'node:fs'
11
- import { mkdir, readdir } from 'node:fs/promises'
12
- import path from 'node:path'
13
- import { fileURLToPath } from 'node:url'
14
-
15
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
16
- const packageRoot = path.resolve(__dirname, '..')
17
- const cliJs = path.join(packageRoot, 'dist', 'cli.js')
18
- const scriptPath = path.join(__dirname, 'export-html.scr')
19
-
20
- const DRAWING_EXT = new Set(['.dwg', '.dxf'])
21
-
22
- async function collectDrawings(dir, out = []) {
23
- const entries = await readdir(dir, { withFileTypes: true })
24
- for (const entry of entries) {
25
- const full = path.join(dir, entry.name)
26
- if (entry.isDirectory()) {
27
- await collectDrawings(full, out)
28
- } else if (DRAWING_EXT.has(path.extname(entry.name).toLowerCase())) {
29
- out.push(full)
30
- }
31
- }
32
- return out
33
- }
34
-
35
- function runCli(input, outputDir) {
36
- return new Promise((resolve, reject) => {
37
- const child = spawn(
38
- process.execPath,
39
- [
40
- cliJs,
41
- '-i',
42
- input,
43
- '-s',
44
- scriptPath,
45
- '-o',
46
- outputDir,
47
- '--mode',
48
- 'read'
49
- ],
50
- { stdio: 'inherit' }
51
- )
52
- child.on('error', reject)
53
- child.on('exit', code => {
54
- if (code === 0) resolve()
55
- else reject(new Error(`cad-simple-viewer-cli exited with code ${code} for ${input}`))
56
- })
57
- })
58
- }
59
-
60
- async function main() {
61
- const inputDir = path.resolve(process.argv[2] ?? '')
62
- const outputDir = path.resolve(
63
- process.argv[3] ?? path.join(inputDir, 'html-out')
64
- )
65
-
66
- if (!process.argv[2] || !existsSync(inputDir)) {
67
- console.error(
68
- 'Usage: node examples/batch-export-html.mjs <inputDir> [outputDir]'
69
- )
70
- process.exitCode = 1
71
- return
72
- }
73
- if (!existsSync(cliJs)) {
74
- console.error(
75
- 'CLI not built. Run: pnpm --filter @mlightcad/cad-simple-viewer-cli build'
76
- )
77
- process.exitCode = 1
78
- return
79
- }
80
-
81
- await mkdir(outputDir, { recursive: true })
82
- const drawings = await collectDrawings(inputDir)
83
- if (!drawings.length) {
84
- console.error(`No .dwg/.dxf files found under ${inputDir}`)
85
- process.exitCode = 1
86
- return
87
- }
88
-
89
- console.log(`Found ${drawings.length} drawing(s). Output: ${outputDir}`)
90
- let failed = 0
91
- for (const drawing of drawings) {
92
- console.log(`\n=== ${drawing} ===`)
93
- try {
94
- await runCli(drawing, outputDir)
95
- } catch (error) {
96
- failed++
97
- console.error(error instanceof Error ? error.message : String(error))
98
- }
99
- }
100
-
101
- console.log(`\nDone. success=${drawings.length - failed} failed=${failed}`)
102
- if (failed) process.exitCode = 1
103
- }
104
-
105
- await main()
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Recursively scan a directory for .dwg / .dxf files and export each to HTML
4
+ * via cad-simple-viewer-cli + export-html.scr.
5
+ *
6
+ * Usage (from packages/cad-simple-viewer-cli after build):
7
+ * node examples/batch-export-html.mjs <inputDir> [outputDir]
8
+ */
9
+ import { spawn } from 'node:child_process'
10
+ import { existsSync } from 'node:fs'
11
+ import { mkdir, readdir } from 'node:fs/promises'
12
+ import path from 'node:path'
13
+ import { fileURLToPath } from 'node:url'
14
+
15
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
16
+ const packageRoot = path.resolve(__dirname, '..')
17
+ const cliJs = path.join(packageRoot, 'dist', 'cli.js')
18
+ const scriptPath = path.join(__dirname, 'export-html.scr')
19
+
20
+ const DRAWING_EXT = new Set(['.dwg', '.dxf'])
21
+
22
+ async function collectDrawings(dir, out = []) {
23
+ const entries = await readdir(dir, { withFileTypes: true })
24
+ for (const entry of entries) {
25
+ const full = path.join(dir, entry.name)
26
+ if (entry.isDirectory()) {
27
+ await collectDrawings(full, out)
28
+ } else if (DRAWING_EXT.has(path.extname(entry.name).toLowerCase())) {
29
+ out.push(full)
30
+ }
31
+ }
32
+ return out
33
+ }
34
+
35
+ function runCli(input, outputDir) {
36
+ return new Promise((resolve, reject) => {
37
+ const child = spawn(
38
+ process.execPath,
39
+ [
40
+ cliJs,
41
+ '-i',
42
+ input,
43
+ '-s',
44
+ scriptPath,
45
+ '-o',
46
+ outputDir,
47
+ '--mode',
48
+ 'read'
49
+ ],
50
+ { stdio: 'inherit' }
51
+ )
52
+ child.on('error', reject)
53
+ child.on('exit', code => {
54
+ if (code === 0) resolve()
55
+ else reject(new Error(`cad-simple-viewer-cli exited with code ${code} for ${input}`))
56
+ })
57
+ })
58
+ }
59
+
60
+ async function main() {
61
+ const inputDir = path.resolve(process.argv[2] ?? '')
62
+ const outputDir = path.resolve(
63
+ process.argv[3] ?? path.join(inputDir, 'html-out')
64
+ )
65
+
66
+ if (!process.argv[2] || !existsSync(inputDir)) {
67
+ console.error(
68
+ 'Usage: node examples/batch-export-html.mjs <inputDir> [outputDir]'
69
+ )
70
+ process.exitCode = 1
71
+ return
72
+ }
73
+ if (!existsSync(cliJs)) {
74
+ console.error(
75
+ 'CLI not built. Run: pnpm --filter @mlightcad/cad-simple-viewer-cli build'
76
+ )
77
+ process.exitCode = 1
78
+ return
79
+ }
80
+
81
+ await mkdir(outputDir, { recursive: true })
82
+ const drawings = await collectDrawings(inputDir)
83
+ if (!drawings.length) {
84
+ console.error(`No .dwg/.dxf files found under ${inputDir}`)
85
+ process.exitCode = 1
86
+ return
87
+ }
88
+
89
+ console.log(`Found ${drawings.length} drawing(s). Output: ${outputDir}`)
90
+ let failed = 0
91
+ for (const drawing of drawings) {
92
+ console.log(`\n=== ${drawing} ===`)
93
+ try {
94
+ await runCli(drawing, outputDir)
95
+ } catch (error) {
96
+ failed++
97
+ console.error(error instanceof Error ? error.message : String(error))
98
+ }
99
+ }
100
+
101
+ console.log(`\nDone. success=${drawings.length - failed} failed=${failed}`)
102
+ if (failed) process.exitCode = 1
103
+ }
104
+
105
+ await main()
@@ -1,103 +1,103 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Recursively scan a directory for .dwg / .dxf files and export each to PNG
4
- * via cad-simple-viewer-cli + export-png.scr.
5
- *
6
- * Usage (from packages/cad-simple-viewer-cli after build):
7
- * node examples/batch-export-png.mjs <inputDir> [outputDir]
8
- */
9
- import { spawn } from 'node:child_process'
10
- import { existsSync } from 'node:fs'
11
- import { mkdir, readdir } from 'node:fs/promises'
12
- import path from 'node:path'
13
- import { fileURLToPath } from 'node:url'
14
-
15
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
16
- const packageRoot = path.resolve(__dirname, '..')
17
- const cliJs = path.join(packageRoot, 'dist', 'cli.js')
18
- const scriptPath = path.join(__dirname, 'export-png.scr')
19
-
20
- const DRAWING_EXT = new Set(['.dwg', '.dxf'])
21
-
22
- async function collectDrawings(dir, out = []) {
23
- const entries = await readdir(dir, { withFileTypes: true })
24
- for (const entry of entries) {
25
- const full = path.join(dir, entry.name)
26
- if (entry.isDirectory()) {
27
- await collectDrawings(full, out)
28
- } else if (DRAWING_EXT.has(path.extname(entry.name).toLowerCase())) {
29
- out.push(full)
30
- }
31
- }
32
- return out
33
- }
34
-
35
- function runCli(input, outputDir) {
36
- return new Promise((resolve, reject) => {
37
- const child = spawn(
38
- process.execPath,
39
- [
40
- cliJs,
41
- '-i',
42
- input,
43
- '-s',
44
- scriptPath,
45
- '-o',
46
- outputDir,
47
- '--mode',
48
- 'read'
49
- ],
50
- { stdio: 'inherit' }
51
- )
52
- child.on('error', reject)
53
- child.on('exit', code => {
54
- if (code === 0) resolve()
55
- else reject(new Error(`cad-simple-viewer-cli exited with code ${code} for ${input}`))
56
- })
57
- })
58
- }
59
-
60
- async function main() {
61
- const inputDir = path.resolve(process.argv[2] ?? '')
62
- const outputDir = path.resolve(process.argv[3] ?? path.join(inputDir, 'png-out'))
63
-
64
- if (!process.argv[2] || !existsSync(inputDir)) {
65
- console.error(
66
- 'Usage: node examples/batch-export-png.mjs <inputDir> [outputDir]'
67
- )
68
- process.exitCode = 1
69
- return
70
- }
71
- if (!existsSync(cliJs)) {
72
- console.error(
73
- 'CLI not built. Run: pnpm --filter @mlightcad/cad-simple-viewer-cli build'
74
- )
75
- process.exitCode = 1
76
- return
77
- }
78
-
79
- await mkdir(outputDir, { recursive: true })
80
- const drawings = await collectDrawings(inputDir)
81
- if (!drawings.length) {
82
- console.error(`No .dwg/.dxf files found under ${inputDir}`)
83
- process.exitCode = 1
84
- return
85
- }
86
-
87
- console.log(`Found ${drawings.length} drawing(s). Output: ${outputDir}`)
88
- let failed = 0
89
- for (const drawing of drawings) {
90
- console.log(`\n=== ${drawing} ===`)
91
- try {
92
- await runCli(drawing, outputDir)
93
- } catch (error) {
94
- failed++
95
- console.error(error instanceof Error ? error.message : String(error))
96
- }
97
- }
98
-
99
- console.log(`\nDone. success=${drawings.length - failed} failed=${failed}`)
100
- if (failed) process.exitCode = 1
101
- }
102
-
103
- await main()
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Recursively scan a directory for .dwg / .dxf files and export each to PNG
4
+ * via cad-simple-viewer-cli + export-png.scr.
5
+ *
6
+ * Usage (from packages/cad-simple-viewer-cli after build):
7
+ * node examples/batch-export-png.mjs <inputDir> [outputDir]
8
+ */
9
+ import { spawn } from 'node:child_process'
10
+ import { existsSync } from 'node:fs'
11
+ import { mkdir, readdir } from 'node:fs/promises'
12
+ import path from 'node:path'
13
+ import { fileURLToPath } from 'node:url'
14
+
15
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
16
+ const packageRoot = path.resolve(__dirname, '..')
17
+ const cliJs = path.join(packageRoot, 'dist', 'cli.js')
18
+ const scriptPath = path.join(__dirname, 'export-png.scr')
19
+
20
+ const DRAWING_EXT = new Set(['.dwg', '.dxf'])
21
+
22
+ async function collectDrawings(dir, out = []) {
23
+ const entries = await readdir(dir, { withFileTypes: true })
24
+ for (const entry of entries) {
25
+ const full = path.join(dir, entry.name)
26
+ if (entry.isDirectory()) {
27
+ await collectDrawings(full, out)
28
+ } else if (DRAWING_EXT.has(path.extname(entry.name).toLowerCase())) {
29
+ out.push(full)
30
+ }
31
+ }
32
+ return out
33
+ }
34
+
35
+ function runCli(input, outputDir) {
36
+ return new Promise((resolve, reject) => {
37
+ const child = spawn(
38
+ process.execPath,
39
+ [
40
+ cliJs,
41
+ '-i',
42
+ input,
43
+ '-s',
44
+ scriptPath,
45
+ '-o',
46
+ outputDir,
47
+ '--mode',
48
+ 'read'
49
+ ],
50
+ { stdio: 'inherit' }
51
+ )
52
+ child.on('error', reject)
53
+ child.on('exit', code => {
54
+ if (code === 0) resolve()
55
+ else reject(new Error(`cad-simple-viewer-cli exited with code ${code} for ${input}`))
56
+ })
57
+ })
58
+ }
59
+
60
+ async function main() {
61
+ const inputDir = path.resolve(process.argv[2] ?? '')
62
+ const outputDir = path.resolve(process.argv[3] ?? path.join(inputDir, 'png-out'))
63
+
64
+ if (!process.argv[2] || !existsSync(inputDir)) {
65
+ console.error(
66
+ 'Usage: node examples/batch-export-png.mjs <inputDir> [outputDir]'
67
+ )
68
+ process.exitCode = 1
69
+ return
70
+ }
71
+ if (!existsSync(cliJs)) {
72
+ console.error(
73
+ 'CLI not built. Run: pnpm --filter @mlightcad/cad-simple-viewer-cli build'
74
+ )
75
+ process.exitCode = 1
76
+ return
77
+ }
78
+
79
+ await mkdir(outputDir, { recursive: true })
80
+ const drawings = await collectDrawings(inputDir)
81
+ if (!drawings.length) {
82
+ console.error(`No .dwg/.dxf files found under ${inputDir}`)
83
+ process.exitCode = 1
84
+ return
85
+ }
86
+
87
+ console.log(`Found ${drawings.length} drawing(s). Output: ${outputDir}`)
88
+ let failed = 0
89
+ for (const drawing of drawings) {
90
+ console.log(`\n=== ${drawing} ===`)
91
+ try {
92
+ await runCli(drawing, outputDir)
93
+ } catch (error) {
94
+ failed++
95
+ console.error(error instanceof Error ? error.message : String(error))
96
+ }
97
+ }
98
+
99
+ console.log(`\nDone. success=${drawings.length - failed} failed=${failed}`)
100
+ if (failed) process.exitCode = 1
101
+ }
102
+
103
+ await main()
@@ -1,15 +1,15 @@
1
- ; Create a new ISO drawing, draw a closed rectangle with LINE, then export DXF.
2
- ; No -i needed (CLI starts from a blank template; qnew refreshes from ISO).
3
- ; Usage:
4
- ; cad-simple-viewer-cli -s examples/create-drawing-dxf.scr -o ./out --mode write
5
- qnew
6
- line
7
- 0,0
8
- 100,0
9
- 100,60
10
- 0,60
11
- c
12
- zoom
13
- e
14
- cdxf
15
- quit
1
+ ; Create a new ISO drawing, draw a closed rectangle with LINE, then export DXF.
2
+ ; No -i needed (CLI starts from a blank template; qnew refreshes from ISO).
3
+ ; Usage:
4
+ ; cad-simple-viewer-cli -s examples/create-drawing-dxf.scr -o ./out --mode write
5
+ qnew
6
+ line
7
+ 0,0
8
+ 100,0
9
+ 100,60
10
+ 0,60
11
+ c
12
+ zoom
13
+ e
14
+ cdxf
15
+ quit
@@ -1,19 +1,19 @@
1
- ; Create a new drawing, then export PNG (no input file).
2
- ; Usage:
3
- ; cad-simple-viewer-cli -s examples/create-drawing-png.scr -o ./out --mode write
4
- qnew
5
- line
6
- 0,0
7
- 80,0
8
- 80,50
9
- 0,50
10
- c
11
- circle
12
- 40,25
13
- 12
14
- zoom
15
- e
16
- pngout
17
-
18
- 2048
19
- quit
1
+ ; Create a new drawing, then export PNG (no input file).
2
+ ; Usage:
3
+ ; cad-simple-viewer-cli -s examples/create-drawing-png.scr -o ./out --mode write
4
+ qnew
5
+ line
6
+ 0,0
7
+ 80,0
8
+ 80,50
9
+ 0,50
10
+ c
11
+ circle
12
+ 40,25
13
+ 12
14
+ zoom
15
+ e
16
+ pngout
17
+
18
+ 2048
19
+ quit
@@ -1,17 +1,17 @@
1
- ; Create a new drawing with a rectangle and a circle, then export DXF.
2
- ; Usage:
3
- ; cad-simple-viewer-cli -s examples/create-shapes-dxf.scr -o ./out --mode write
4
- qnew
5
- line
6
- 0,0
7
- 120,0
8
- 120,80
9
- 0,80
10
- c
11
- circle
12
- 60,40
13
- 20
14
- zoom
15
- e
16
- cdxf
17
- quit
1
+ ; Create a new drawing with a rectangle and a circle, then export DXF.
2
+ ; Usage:
3
+ ; cad-simple-viewer-cli -s examples/create-shapes-dxf.scr -o ./out --mode write
4
+ qnew
5
+ line
6
+ 0,0
7
+ 120,0
8
+ 120,80
9
+ 0,80
10
+ c
11
+ circle
12
+ 60,40
13
+ 20
14
+ zoom
15
+ e
16
+ cdxf
17
+ quit
@@ -1,5 +1,5 @@
1
- ; Export the current drawing to DXF (cdxf triggers a browser download).
2
- ; Usage:
3
- ; cad-simple-viewer-cli -i drawing.dwg -s examples/export-dxf.scr -o ./out
4
- cdxf
5
- quit
1
+ ; Export the current drawing to DXF (cdxf triggers a browser download).
2
+ ; Usage:
3
+ ; cad-simple-viewer-cli -i drawing.dwg -s examples/export-dxf.scr -o ./out
4
+ cdxf
5
+ quit
@@ -1,9 +1,10 @@
1
- ; Export a self-contained offline HTML viewer (-chtml).
2
- ; Prompts: export invisible layers / initial view / viewer mode.
3
- ; Usage:
4
- ; cad-simple-viewer-cli -i drawing.dwg -s examples/export-html.scr -o ./out
5
- -chtml
6
- Yes
7
- Extents
8
- Measure
9
- quit
1
+ ; Export a self-contained offline HTML viewer (-chtml).
2
+ ; Prompts: export invisible layers / export layouts / initial view / viewer mode.
3
+ ; Usage:
4
+ ; cad-simple-viewer-cli -i drawing.dwg -s examples/export-html.scr -o ./out
5
+ -chtml
6
+ Yes
7
+ Yes
8
+ Extents
9
+ Measure
10
+ quit
@@ -1,9 +1,9 @@
1
- ; Zoom extents, then export the drawing extents as PNG (long side 2048px).
2
- ; Usage:
3
- ; cad-simple-viewer-cli -i drawing.dwg -s examples/export-png.scr -o ./out
4
- zoom
5
- e
6
- pngout
7
-
8
- 2048
9
- quit
1
+ ; Zoom extents, then export the drawing extents as PNG (long side 2048px).
2
+ ; Usage:
3
+ ; cad-simple-viewer-cli -i drawing.dwg -s examples/export-png.scr -o ./out
4
+ zoom
5
+ e
6
+ pngout
7
+
8
+ 2048
9
+ quit
@@ -1,15 +1,15 @@
1
- ; Turn off a layer via -LAYER, then export PNG.
2
- ; Requires --mode write (layer edits need Write open mode).
3
- ; Replace LAYER_NAME below with a real layer in your drawing.
4
- ; Usage:
5
- ; cad-simple-viewer-cli -i drawing.dwg -s examples/freeze-layer-png.scr -o ./out --mode write
6
- -layer
7
- Off
8
- LAYER_NAME
9
-
10
- zoom
11
- e
12
- pngout
13
-
14
- 2048
15
- quit
1
+ ; Turn off a layer via -LAYER, then export PNG.
2
+ ; Requires --mode write (layer edits need Write open mode).
3
+ ; Replace LAYER_NAME below with a real layer in your drawing.
4
+ ; Usage:
5
+ ; cad-simple-viewer-cli -i drawing.dwg -s examples/freeze-layer-png.scr -o ./out --mode write
6
+ -layer
7
+ Off
8
+ LAYER_NAME
9
+
10
+ zoom
11
+ e
12
+ pngout
13
+
14
+ 2048
15
+ quit