Skip to content

Commit a34fe8f

Browse files
committed
Refactor export command to make easier to distinguish CLI output and the actual output path
1 parent 4db6b2f commit a34fe8f

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/commands/export.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ export const doExport = async (uri: Uri, document: TextDocument) => {
120120
const input = await createWorkFile(document)
121121

122122
try {
123-
let output = { path: uri.fsPath, isTmp: false }
124-
125123
const ouputExt = path.extname(uri.path)
126124
const outputToLocalFS = uri.scheme === 'file'
127125

@@ -131,16 +129,16 @@ export const doExport = async (uri: Uri, document: TextDocument) => {
131129
throw new Error(`Could not write to ${uri.scheme} file system.`)
132130
}
133131

134-
if (!outputToLocalFS) {
135-
// Marp CLI cannot write the output directly to the path that has a
136-
// virtual scheme. So export to a temporary file and after copy it to
137-
// the actual path by using VS Code API if the output path has not a
138-
// scheme of the local file system.
139-
output = {
140-
path: path.join(tmpdir(), `marp-vscode-tmp-${nanoid()}${ouputExt}`),
141-
isTmp: true,
142-
}
143-
}
132+
// Marp CLI cannot write the output directly to the path that has a
133+
// virtual scheme. So export to a temporary file and after copy it to the
134+
// actual path by using VS Code API if the output path has not a scheme of
135+
// the local file system.
136+
const cliOutput = outputToLocalFS
137+
? { path: uri.fsPath, isTmp: false }
138+
: {
139+
path: path.join(tmpdir(), `marp-vscode-tmp-${nanoid()}${ouputExt}`),
140+
isTmp: true,
141+
}
144142

145143
const pptxEditableSmart =
146144
ouputExt === '.pptx' &&
@@ -161,7 +159,7 @@ export const doExport = async (uri: Uri, document: TextDocument) => {
161159

162160
try {
163161
await marpCli(
164-
['-c', conf.path, input.path, '-o', output.path],
162+
['-c', conf.path, input.path, '-o', cliOutput.path],
165163
{ baseUrl },
166164
{
167165
onCLIError: ({ error, codes }) => {
@@ -225,8 +223,8 @@ export const doExport = async (uri: Uri, document: TextDocument) => {
225223

226224
// If the output has been created in the temporary directory, we should
227225
// copy it to the actual path and remove the tmpfile.
228-
if (output.isTmp) {
229-
const outputUri = Uri.file(output.path)
226+
if (cliOutput.isTmp) {
227+
const outputUri = Uri.file(cliOutput.path)
230228

231229
try {
232230
await workspace.fs.copy(outputUri, uri, { overwrite: true })

0 commit comments

Comments
 (0)