Thanks sylumer,
Finally got round to trying this, browerify doesn’t seem to like prettier and the transpile fails so thought I would try the shell script. This is what I have so far:
const fm = FileManager.createLocal();
const tmpFile = "tmp.md";
const tmpFilePath = fm.basePath + tmpFile
formatDraft();
function formatDraft() {
writeFile();
formatFile();
const formatted = readFile();
if (formatted) {
draft.content = formatted;
draft.update();
}
}
function writeFile() {
const result = fm.writeString(tmpFile, draft.content);
if (!result) {
console.log(`Write failed: ${fm.lastError}`);
context.fail();
}
return result;
}
function readFile() {
const result = fm.readString(tmpFile);;
if (!result) {
console.log(`Read failed: ${fm.lastError}`);
context.fail();
}
return result;
}
function formatFile() {
const script = `#!/usr/bin/env bash
prettier --write $1
`;
const runner = ShellScript.create(script);
if (runner.execute([tmpFilePath])) {
console.log(`Shell script succeeded: ${runner.standardOutput}`);
} else {
console.log(`Shell script failed: ${runner.standardError}`);
context.fail();
}
}
The script is failing with:
Shell script failed: /Users/jp/Library/Application Scripts/com.agiletortoise.Drafts-OSX/Temp/shellscript-619220700.585142.sh: line 2: prettier: command not found
- On the first run I granted access to run scripts.
- Prettier is installed globally.
- I can run prettier from
/Users/jp/Library/Application Scripts/com.agiletortoise.Drafts-OSX/Temp/
Any help appreciated.