dsh-artcraft-plugin-lightcraft 0.2.13 → 0.2.14
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/package.json +1 -1
- package/src/kit/tools.js +26 -0
package/package.json
CHANGED
package/src/kit/tools.js
CHANGED
|
@@ -105,6 +105,31 @@ function extractParams(stdout ) {
|
|
|
105
105
|
return match?.[1]?.trim()
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Create the folder an output file lives in.
|
|
110
|
+
*
|
|
111
|
+
* A crafting app refuses to write into a directory that does not exist and
|
|
112
|
+
* reports it as a bare OS error; creating the parent here turns "save to
|
|
113
|
+
* ~/Documents/2026 Q3/report.docx" into one call instead of two, and the same
|
|
114
|
+
* behaviour on macOS, Windows and Linux.
|
|
115
|
+
* @param args - the tool arguments, which may name `save`, `export`, `out` or `output`.
|
|
116
|
+
*/
|
|
117
|
+
function ensureOutputDir(args ) {
|
|
118
|
+
for (const key of ['save', 'export', 'out', 'output']) {
|
|
119
|
+
const value = args[key]
|
|
120
|
+
if (typeof value !== 'string' || value.length === 0) continue
|
|
121
|
+
const folder = dirname(value)
|
|
122
|
+
// A bare filename has no folder part; `dirname('x.xlsx')` is '.', and a
|
|
123
|
+
// Windows-looking absolute path on POSIX is not ours to create.
|
|
124
|
+
if (folder === '.' || folder === '' || folder === '/') continue
|
|
125
|
+
try {
|
|
126
|
+
mkdirSync(folder, { recursive: true })
|
|
127
|
+
} catch {
|
|
128
|
+
// Leave it to the craft to report; a read-only volume should fail there.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
108
133
|
/** Scratch directory for files the kernel generates per craft (script modes). */
|
|
109
134
|
function craftWorkDir(profile ) {
|
|
110
135
|
return join(tmpdir(), 'dsh-artcraft', profile.id)
|
|
@@ -663,6 +688,7 @@ export function createToolSet(runtime ) {
|
|
|
663
688
|
]
|
|
664
689
|
return await runOrStart(binary, [...globalFlagsFor(profile, args), profile.run.verb, ...extra], args.background, documentOf(args), labelOf(args))
|
|
665
690
|
}
|
|
691
|
+
ensureOutputDir(args)
|
|
666
692
|
// PdfCraft's `run` accepts exactly one tool per invocation; sending a
|
|
667
693
|
// list would produce "expected key=value" from the CLI, so the extra
|
|
668
694
|
// commands are reported instead of silently mis-executed.
|