Require prettier argument and library in the wrapper
This commit is contained in:
parent
1ff17bd15d
commit
86618a64c6
3 changed files with 61 additions and 29 deletions
|
@ -1,4 +1,36 @@
|
|||
const { Buffer } = require('buffer');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
let prettierContainerPath = process.argv[2];
|
||||
if (prettierContainerPath == null || prettierContainerPath.length == 0) {
|
||||
console.error(`Prettier path argument was not specified or empty.\nUsage: ${process.argv[0]} ${process.argv[1]} prettier/path`);
|
||||
process.exit(1);
|
||||
}
|
||||
fs.stat(prettierContainerPath, (err, stats) => {
|
||||
if (err) {
|
||||
console.error(`Path '${prettierContainerPath}' does not exist.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
console.log(`Path '${prettierContainerPath}' exists but is not a directory.`);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
let prettierPath = path.join(prettierContainerPath, 'node_modules/prettier');
|
||||
|
||||
(async () => {
|
||||
let prettier;
|
||||
try {
|
||||
prettier = await loadPrettier(prettierPath);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log("Prettier loadded successfully.");
|
||||
// TODO kb do the rest here
|
||||
})()
|
||||
|
||||
let buffer = Buffer.alloc(0);
|
||||
process.stdin.resume();
|
||||
|
@ -28,14 +60,15 @@ function handleData() {
|
|||
try {
|
||||
const message = JSON.parse(bytes);
|
||||
handleMessage(message);
|
||||
} catch (_) {
|
||||
sendResponse(makeError("Request JSON parse error"));
|
||||
} catch (e) {
|
||||
sendResponse(makeError(`Request JSON parse error: ${e}`));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// format
|
||||
// clear_cache
|
||||
//
|
||||
// shutdown
|
||||
// error
|
||||
|
||||
|
@ -55,3 +88,19 @@ function sendResponse(response) {
|
|||
process.stdout.write(length);
|
||||
process.stdout.write(message);
|
||||
}
|
||||
|
||||
function loadPrettier(prettierPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.access(prettierPath, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
reject(`Path '${prettierPath}' does not exist.Error: ${err}`);
|
||||
} else {
|
||||
try {
|
||||
resolve(require(prettierPath));
|
||||
} catch (err) {
|
||||
reject(`Error requiring prettier module from path '${prettierPath}'.Error: ${err}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue