probe.mjs 1.2 KB

12345678910111213141516171819202122232425262728
  1. import { readFile, readdir } from "node:fs/promises";
  2. import { delimiter, dirname, join } from "node:path";
  3. import { fileURLToPath } from "node:url";
  4. import { promisify } from "node:util";
  5. import { execFile } from "node:child_process";
  6. const directory = dirname(fileURLToPath(import.meta.url));
  7. const config = JSON.parse(await readFile(join(directory, "config.json"), "utf8"));
  8. const cache = join(config.storageRoot, "cli/plugins/cache/zcode-plugins-official/documents");
  9. const versions = await readdir(cache);
  10. if (versions.length !== 1) throw new Error("Expected one distributed documents version");
  11. const helper = join(cache, versions[0], "scripts/zcode_libreoffice.py");
  12. let result;
  13. try {
  14. result = {
  15. ...(await promisify(execFile)(config.python, [helper, "check"], { timeout: 30000 })),
  16. exitCode: 0,
  17. };
  18. } catch (error) {
  19. result = { stdout: error.stdout, stderr: error.stderr, exitCode: error.code };
  20. }
  21. console.log(
  22. JSON.stringify({
  23. available: process.env.ZCODE_PREINSTALLED_TOOLS_AVAILABLE ?? null,
  24. pathFirst: process.env.PATH.split(delimiter)[0],
  25. binDir: join(config.storageRoot, "preinstalled-tools", "development", "bin"),
  26. ...result,
  27. }),
  28. );