@mlightcad/cad-simple-viewer-cli 1.5.11
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 +21 -0
- package/README.md +139 -0
- package/dist/cli.js +55 -0
- package/dist/cli.js.map +1 -0
- package/dist/examplesServer.js +413 -0
- package/dist/examplesServer.js.map +1 -0
- package/dist/runHeadless.js +281 -0
- package/dist/runHeadless.js.map +1 -0
- package/dist-runner/assets/cad-html-plugin-Bu0XYtd-.js +477 -0
- package/dist-runner/assets/cad-pdf-plugin-BK4sGA5p.js +312 -0
- package/dist-runner/assets/cad-svg-plugin-pfRr575l.js +17 -0
- package/dist-runner/assets/index-rDY9i-tf.js +5319 -0
- package/dist-runner/index.html +25 -0
- package/dist-runner/viewer-runtime.iife.js +4653 -0
- package/dist-runner/workers/libredwg-parser-worker.js +7525 -0
- package/dist-runner/workers/mtext-renderer-worker.js +36369 -0
- package/examples/batch-export-html.mjs +105 -0
- package/examples/batch-export-png.mjs +103 -0
- package/examples/create-drawing-dxf.scr +15 -0
- package/examples/create-drawing-png.scr +19 -0
- package/examples/create-shapes-dxf.scr +17 -0
- package/examples/export-dxf.scr +5 -0
- package/examples/export-html.scr +9 -0
- package/examples/export-png.scr +9 -0
- package/examples/freeze-layer-png.scr +15 -0
- package/examples/index.json +87 -0
- package/package.json +73 -0
|
@@ -0,0 +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 (same pipeline as cad-html-exporter-cli).
|
|
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()
|
|
@@ -0,0 +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()
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
|
@@ -0,0 +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
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"fixtureDrawing": "https://cdn.jsdelivr.net/gh/mlightcad/cad-data@main/data/canteen.dwg",
|
|
3
|
+
"defaultOutputDir": "tmp/examples-gallery",
|
|
4
|
+
"examples": [
|
|
5
|
+
{
|
|
6
|
+
"id": "create-drawing-dxf",
|
|
7
|
+
"title": "Create drawing -> DXF",
|
|
8
|
+
"description": "qnew, draw a closed rectangle with LINE, export DXF. No input file.",
|
|
9
|
+
"script": "create-drawing-dxf.scr",
|
|
10
|
+
"mode": "write",
|
|
11
|
+
"inputKind": "none",
|
|
12
|
+
"runnable": true
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "create-shapes-dxf",
|
|
16
|
+
"title": "Create shapes -> DXF",
|
|
17
|
+
"description": "qnew, draw a rectangle and a circle, export DXF.",
|
|
18
|
+
"script": "create-shapes-dxf.scr",
|
|
19
|
+
"mode": "write",
|
|
20
|
+
"inputKind": "none",
|
|
21
|
+
"runnable": true
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "create-drawing-png",
|
|
25
|
+
"title": "Create drawing -> PNG",
|
|
26
|
+
"description": "qnew, draw geometry, zoom extents, export PNG.",
|
|
27
|
+
"script": "create-drawing-png.scr",
|
|
28
|
+
"mode": "write",
|
|
29
|
+
"inputKind": "none",
|
|
30
|
+
"runnable": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "export-png",
|
|
34
|
+
"title": "Export PNG",
|
|
35
|
+
"description": "Zoom extents and export the drawing as PNG (long side 2048).",
|
|
36
|
+
"script": "export-png.scr",
|
|
37
|
+
"mode": "read",
|
|
38
|
+
"inputKind": "file",
|
|
39
|
+
"runnable": true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "export-html",
|
|
43
|
+
"title": "Export HTML",
|
|
44
|
+
"description": "Export a self-contained offline HTML viewer (-chtml).",
|
|
45
|
+
"script": "export-html.scr",
|
|
46
|
+
"mode": "read",
|
|
47
|
+
"inputKind": "file",
|
|
48
|
+
"runnable": true
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "export-dxf",
|
|
52
|
+
"title": "Export DXF",
|
|
53
|
+
"description": "Convert the open drawing to DXF (cdxf).",
|
|
54
|
+
"script": "export-dxf.scr",
|
|
55
|
+
"mode": "read",
|
|
56
|
+
"inputKind": "file",
|
|
57
|
+
"runnable": true
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "freeze-layer-png",
|
|
61
|
+
"title": "Layer off -> PNG",
|
|
62
|
+
"description": "Turn off a layer with -LAYER, then export PNG. Edit LAYER_NAME in the script first.",
|
|
63
|
+
"script": "freeze-layer-png.scr",
|
|
64
|
+
"mode": "write",
|
|
65
|
+
"inputKind": "file",
|
|
66
|
+
"runnable": true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": "batch-export-png",
|
|
70
|
+
"title": "Batch export PNG",
|
|
71
|
+
"description": "Scan a folder of DWG/DXF files and export each to PNG.",
|
|
72
|
+
"script": "batch-export-png.mjs",
|
|
73
|
+
"kind": "batch",
|
|
74
|
+
"inputKind": "directory",
|
|
75
|
+
"runnable": true
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "batch-export-html",
|
|
79
|
+
"title": "Batch export HTML",
|
|
80
|
+
"description": "Scan a folder and export each drawing to HTML.",
|
|
81
|
+
"script": "batch-export-html.mjs",
|
|
82
|
+
"kind": "batch",
|
|
83
|
+
"inputKind": "directory",
|
|
84
|
+
"runnable": true
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mlightcad/cad-simple-viewer-cli",
|
|
3
|
+
"version": "1.5.11",
|
|
4
|
+
"description": "AcCoreConsole-style headless CLI: run .scr command scripts against DXF/DWG drawings",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"cad-simple-viewer-cli": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"dist-runner",
|
|
13
|
+
"examples",
|
|
14
|
+
"README.md",
|
|
15
|
+
"package.json"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./dist/runHeadless.js"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/mlightcad/cad-viewer.git",
|
|
26
|
+
"directory": "packages/cad-simple-viewer-cli"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/mlightcad/cad-viewer/tree/main/packages/cad-simple-viewer-cli",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/mlightcad/cad-viewer/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"autocad",
|
|
34
|
+
"cad",
|
|
35
|
+
"cad-viewer",
|
|
36
|
+
"cli",
|
|
37
|
+
"dwg",
|
|
38
|
+
"dxf",
|
|
39
|
+
"headless",
|
|
40
|
+
"mlight",
|
|
41
|
+
"mlightcad",
|
|
42
|
+
"script"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@mlightcad/data-model": "^1.12.5",
|
|
46
|
+
"@mlightcad/libredwg-converter": "^3.12.5",
|
|
47
|
+
"@mlightcad/mtext-renderer": "^0.12.4",
|
|
48
|
+
"commander": "^12.1.0",
|
|
49
|
+
"playwright": "^1.49.1",
|
|
50
|
+
"@mlightcad/cad-html-plugin": "1.5.11",
|
|
51
|
+
"@mlightcad/cad-simple-viewer": "1.5.11",
|
|
52
|
+
"@mlightcad/cad-pdf-plugin": "1.5.11",
|
|
53
|
+
"@mlightcad/cad-svg-plugin": "1.5.11"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^20.14.9",
|
|
57
|
+
"rimraf": "^6.0.1",
|
|
58
|
+
"typescript": "^5.5.2",
|
|
59
|
+
"vite": "^6.4.3"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=20"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc && vite build --config vite.runner.config.ts && node scripts/copy-runner-assets.mjs",
|
|
66
|
+
"install-browser": "playwright install chromium",
|
|
67
|
+
"clean": "rimraf dist dist-runner tsconfig.tsbuildinfo",
|
|
68
|
+
"run:cli": "node ./dist/cli.js",
|
|
69
|
+
"examples": "tsc && node ./dist/examplesServer.js",
|
|
70
|
+
"lint": "eslint src/",
|
|
71
|
+
"lint:fix": "eslint --fix --quiet src/"
|
|
72
|
+
}
|
|
73
|
+
}
|