diff --git a/CHANGELOG.md b/CHANGELOG.md index a6671a3e..79dcb4c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ ### 🐞 Fixes +- [#628](https://github.com/estruyf/vscode-front-matter/issues/628): Fix path argument and JSON data on custom scripts + ## [9.0.0] - 2023-08-21 - [Release notes](https://beta.frontmatter.codes/updates/v9.0.0) ### 🌎 Multilingual support diff --git a/src/helpers/CustomScript.ts b/src/helpers/CustomScript.ts index d3a4855b..9d3909d7 100644 --- a/src/helpers/CustomScript.ts +++ b/src/helpers/CustomScript.ts @@ -222,7 +222,12 @@ export class CustomScript { let articleData = ''; if (os.type() === 'Windows_NT') { const jsonData = JSON.stringify(article?.data); - articleData = `'${jsonData.replace(/"/g, `\"`)}'`; + + if (script.command && script.command.toLowerCase() === "powershell") { + articleData = `'${jsonData.replace(/"/g, `\\"`)}'`; + } else { + articleData = `"${jsonData.replace(/"/g, `\\"`)}"`; + } } else { articleData = JSON.stringify(article?.data).replace(/'/g, '%27'); articleData = `'${articleData}'`; @@ -360,7 +365,11 @@ export class CustomScript { return; } - const fullScript = `${command} ${scriptPath} ${args}`; + if (osType === 'Windows_NT' && command.toLowerCase() === "powershell") { + command = `${command} -File`; + } + + const fullScript = `${command} "${scriptPath}" ${args}`; Logger.info(`Executing: ${fullScript}`); exec(fullScript, { cwd: wsPath }, (error, stdout) => {