@mlightcad/cad-simple-viewer-cli 1.8.0-preview.3 → 1.8.0-preview.4
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 -21
- package/README.md +182 -182
- package/dist-runner/assets/cad-html-plugin-ndOcDphI.js +1565 -0
- package/dist-runner/assets/cad-pdf-plugin-COsuQTug.js +1043 -0
- package/dist-runner/assets/cad-simple-viewer-AcApSimpleUiChrome-D_0b6okm-DBsZjt_l.js +1 -0
- package/dist-runner/assets/{cad-svg-plugin-D-Z-nIZi.js → cad-svg-plugin-BWbiwrld.js} +2 -2
- package/dist-runner/assets/index-DIn0aEGh.js +9530 -0
- package/dist-runner/index.html +12 -12
- package/dist-runner/viewer-runtime.iife.js +258 -258
- package/dist-runner/workers/libredwg-parser-worker.js +20 -20
- package/dist-runner/workers/libredwg-web.wasm +0 -0
- package/dist-runner/workers/mtext-renderer-worker.js +4 -5
- package/examples/batch-export-html-multi-preview.mjs +306 -306
- package/examples/batch-export-html.mjs +105 -105
- package/examples/batch-export-pdf.mjs +114 -114
- package/examples/batch-export-png.mjs +103 -103
- package/examples/create-drawing-dxf.scr +15 -15
- package/examples/create-drawing-png.scr +19 -19
- package/examples/create-shapes-dxf.scr +17 -17
- package/examples/export-dxf.scr +5 -5
- package/examples/export-html-multi-preview.scr +23 -21
- package/examples/export-html-multi.scr +18 -16
- package/examples/export-html.scr +15 -13
- package/examples/export-pdf-monochrome.scr +14 -13
- package/examples/export-pdf.scr +16 -14
- package/examples/export-png.scr +9 -9
- package/examples/freeze-layer-png.scr +15 -15
- package/examples/index.json +141 -141
- package/examples/open-quit.scr +2 -2
- package/package.json +10 -10
- package/dist-runner/assets/cad-html-plugin-B7q3l8cW.js +0 -1565
- package/dist-runner/assets/cad-pdf-plugin-CN3SFYWU.js +0 -209
- package/dist-runner/assets/index-C50ZUySK.js +0 -7820
|
@@ -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,114 +1,114 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Recursively scan a directory for .dwg / .dxf files and export each to PDF
|
|
4
|
-
* via cad-simple-viewer-cli + export-pdf.scr (or export-pdf-monochrome.scr).
|
|
5
|
-
*
|
|
6
|
-
* Usage (from packages/cad-simple-viewer-cli after build):
|
|
7
|
-
* node examples/batch-export-pdf.mjs <inputDir> [outputDir] [--color-mode color|monochrome]
|
|
8
|
-
*
|
|
9
|
-
* --color-mode monochrome writes white paper with black linework and text.
|
|
10
|
-
*/
|
|
11
|
-
import { spawn } from 'node:child_process'
|
|
12
|
-
import { existsSync } from 'node:fs'
|
|
13
|
-
import { mkdir, readdir } from 'node:fs/promises'
|
|
14
|
-
import path from 'node:path'
|
|
15
|
-
import { fileURLToPath } from 'node:url'
|
|
16
|
-
|
|
17
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
18
|
-
const packageRoot = path.resolve(__dirname, '..')
|
|
19
|
-
const cliJs = path.join(packageRoot, 'dist', 'cli.js')
|
|
20
|
-
const args = process.argv.slice(2)
|
|
21
|
-
const colorModeIndex = args.indexOf('--color-mode')
|
|
22
|
-
const colorMode = colorModeIndex >= 0 ? args[colorModeIndex + 1] : 'color'
|
|
23
|
-
if (colorModeIndex >= 0) args.splice(colorModeIndex, 2)
|
|
24
|
-
const scriptPath = path.join(
|
|
25
|
-
__dirname,
|
|
26
|
-
colorMode === 'monochrome' ? 'export-pdf-monochrome.scr' : 'export-pdf.scr'
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
const DRAWING_EXT = new Set(['.dwg', '.dxf'])
|
|
30
|
-
|
|
31
|
-
async function collectDrawings(dir, out = []) {
|
|
32
|
-
const entries = await readdir(dir, { withFileTypes: true })
|
|
33
|
-
for (const entry of entries) {
|
|
34
|
-
const full = path.join(dir, entry.name)
|
|
35
|
-
if (entry.isDirectory()) {
|
|
36
|
-
await collectDrawings(full, out)
|
|
37
|
-
} else if (DRAWING_EXT.has(path.extname(entry.name).toLowerCase())) {
|
|
38
|
-
out.push(full)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return out
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function runCli(input, outputDir) {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
const child = spawn(
|
|
47
|
-
process.execPath,
|
|
48
|
-
[cliJs, '-i', input, '-s', scriptPath, '-o', outputDir, '--mode', 'read'],
|
|
49
|
-
{ stdio: 'inherit' }
|
|
50
|
-
)
|
|
51
|
-
child.on('error', reject)
|
|
52
|
-
child.on('exit', code => {
|
|
53
|
-
if (code === 0) resolve()
|
|
54
|
-
else
|
|
55
|
-
reject(
|
|
56
|
-
new Error(
|
|
57
|
-
`cad-simple-viewer-cli exited with code ${code} for ${input}`
|
|
58
|
-
)
|
|
59
|
-
)
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function main() {
|
|
65
|
-
const inputDir = path.resolve(args[0] ?? '')
|
|
66
|
-
const outputDir = path.resolve(args[1] ?? path.join(inputDir, 'pdf-out'))
|
|
67
|
-
|
|
68
|
-
if (colorMode !== 'color' && colorMode !== 'monochrome') {
|
|
69
|
-
console.error(`Invalid --color-mode: ${colorMode} (color | monochrome)`)
|
|
70
|
-
process.exitCode = 1
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
if (!args[0] || !existsSync(inputDir)) {
|
|
74
|
-
console.error(
|
|
75
|
-
'Usage: node examples/batch-export-pdf.mjs <inputDir> [outputDir] [--color-mode color|monochrome]'
|
|
76
|
-
)
|
|
77
|
-
process.exitCode = 1
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
if (!existsSync(cliJs)) {
|
|
81
|
-
console.error(
|
|
82
|
-
'CLI not built. Run: pnpm --filter @mlightcad/cad-simple-viewer-cli build'
|
|
83
|
-
)
|
|
84
|
-
process.exitCode = 1
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
await mkdir(outputDir, { recursive: true })
|
|
89
|
-
const drawings = await collectDrawings(inputDir)
|
|
90
|
-
if (!drawings.length) {
|
|
91
|
-
console.error(`No .dwg/.dxf files found under ${inputDir}`)
|
|
92
|
-
process.exitCode = 1
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
console.log(
|
|
97
|
-
`Found ${drawings.length} drawing(s). Color mode: ${colorMode}. Output: ${outputDir}`
|
|
98
|
-
)
|
|
99
|
-
let failed = 0
|
|
100
|
-
for (const drawing of drawings) {
|
|
101
|
-
console.log(`\n=== ${drawing} ===`)
|
|
102
|
-
try {
|
|
103
|
-
await runCli(drawing, outputDir)
|
|
104
|
-
} catch (error) {
|
|
105
|
-
failed++
|
|
106
|
-
console.error(error instanceof Error ? error.message : String(error))
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
console.log(`\nDone. success=${drawings.length - failed} failed=${failed}`)
|
|
111
|
-
if (failed) process.exitCode = 1
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
await main()
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Recursively scan a directory for .dwg / .dxf files and export each to PDF
|
|
4
|
+
* via cad-simple-viewer-cli + export-pdf.scr (or export-pdf-monochrome.scr).
|
|
5
|
+
*
|
|
6
|
+
* Usage (from packages/cad-simple-viewer-cli after build):
|
|
7
|
+
* node examples/batch-export-pdf.mjs <inputDir> [outputDir] [--color-mode color|monochrome]
|
|
8
|
+
*
|
|
9
|
+
* --color-mode monochrome writes white paper with black linework and text.
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'node:child_process'
|
|
12
|
+
import { existsSync } from 'node:fs'
|
|
13
|
+
import { mkdir, readdir } from 'node:fs/promises'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
|
|
17
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
const packageRoot = path.resolve(__dirname, '..')
|
|
19
|
+
const cliJs = path.join(packageRoot, 'dist', 'cli.js')
|
|
20
|
+
const args = process.argv.slice(2)
|
|
21
|
+
const colorModeIndex = args.indexOf('--color-mode')
|
|
22
|
+
const colorMode = colorModeIndex >= 0 ? args[colorModeIndex + 1] : 'color'
|
|
23
|
+
if (colorModeIndex >= 0) args.splice(colorModeIndex, 2)
|
|
24
|
+
const scriptPath = path.join(
|
|
25
|
+
__dirname,
|
|
26
|
+
colorMode === 'monochrome' ? 'export-pdf-monochrome.scr' : 'export-pdf.scr'
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const DRAWING_EXT = new Set(['.dwg', '.dxf'])
|
|
30
|
+
|
|
31
|
+
async function collectDrawings(dir, out = []) {
|
|
32
|
+
const entries = await readdir(dir, { withFileTypes: true })
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const full = path.join(dir, entry.name)
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
await collectDrawings(full, out)
|
|
37
|
+
} else if (DRAWING_EXT.has(path.extname(entry.name).toLowerCase())) {
|
|
38
|
+
out.push(full)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function runCli(input, outputDir) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const child = spawn(
|
|
47
|
+
process.execPath,
|
|
48
|
+
[cliJs, '-i', input, '-s', scriptPath, '-o', outputDir, '--mode', 'read'],
|
|
49
|
+
{ stdio: 'inherit' }
|
|
50
|
+
)
|
|
51
|
+
child.on('error', reject)
|
|
52
|
+
child.on('exit', code => {
|
|
53
|
+
if (code === 0) resolve()
|
|
54
|
+
else
|
|
55
|
+
reject(
|
|
56
|
+
new Error(
|
|
57
|
+
`cad-simple-viewer-cli exited with code ${code} for ${input}`
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function main() {
|
|
65
|
+
const inputDir = path.resolve(args[0] ?? '')
|
|
66
|
+
const outputDir = path.resolve(args[1] ?? path.join(inputDir, 'pdf-out'))
|
|
67
|
+
|
|
68
|
+
if (colorMode !== 'color' && colorMode !== 'monochrome') {
|
|
69
|
+
console.error(`Invalid --color-mode: ${colorMode} (color | monochrome)`)
|
|
70
|
+
process.exitCode = 1
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
if (!args[0] || !existsSync(inputDir)) {
|
|
74
|
+
console.error(
|
|
75
|
+
'Usage: node examples/batch-export-pdf.mjs <inputDir> [outputDir] [--color-mode color|monochrome]'
|
|
76
|
+
)
|
|
77
|
+
process.exitCode = 1
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
if (!existsSync(cliJs)) {
|
|
81
|
+
console.error(
|
|
82
|
+
'CLI not built. Run: pnpm --filter @mlightcad/cad-simple-viewer-cli build'
|
|
83
|
+
)
|
|
84
|
+
process.exitCode = 1
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await mkdir(outputDir, { recursive: true })
|
|
89
|
+
const drawings = await collectDrawings(inputDir)
|
|
90
|
+
if (!drawings.length) {
|
|
91
|
+
console.error(`No .dwg/.dxf files found under ${inputDir}`)
|
|
92
|
+
process.exitCode = 1
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log(
|
|
97
|
+
`Found ${drawings.length} drawing(s). Color mode: ${colorMode}. Output: ${outputDir}`
|
|
98
|
+
)
|
|
99
|
+
let failed = 0
|
|
100
|
+
for (const drawing of drawings) {
|
|
101
|
+
console.log(`\n=== ${drawing} ===`)
|
|
102
|
+
try {
|
|
103
|
+
await runCli(drawing, outputDir)
|
|
104
|
+
} catch (error) {
|
|
105
|
+
failed++
|
|
106
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log(`\nDone. success=${drawings.length - failed} failed=${failed}`)
|
|
111
|
+
if (failed) process.exitCode = 1
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
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
|