check-document-libreoffice.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env node
  2. import { readFile, readdir } from "node:fs/promises";
  3. import { join, resolve } from "node:path";
  4. import { fileURLToPath } from "node:url";
  5. const root =
  6. process.argv[2] || fileURLToPath(new URL("../apps/zcode-cli/packages", import.meta.url));
  7. async function files(directory, relative = "") {
  8. const found = [];
  9. for (const item of await readdir(join(directory, relative), { withFileTypes: true })) {
  10. const path = join(relative, item.name);
  11. if (item.isDirectory()) found.push(...(await files(directory, path)));
  12. else if (item.isFile()) found.push(path);
  13. else throw new Error(`Unexpected launcher profile entry: ${path}`);
  14. }
  15. return found.sort();
  16. }
  17. try {
  18. const reference = resolve(root, "documents-plugin/scripts");
  19. const profile = "libreoffice-profile";
  20. const expected = await files(join(reference, profile));
  21. for (const name of ["pdf", "presentations", "spreadsheets"]) {
  22. const target = resolve(root, `${name}-plugin/scripts`);
  23. const actual = await files(join(target, profile));
  24. if (JSON.stringify(actual) !== JSON.stringify(expected))
  25. throw new Error(`${name}: profile file set differs`);
  26. for (const file of ["zcode_libreoffice.py", ...expected.map((path) => join(profile, path))]) {
  27. const [a, b] = await Promise.all([
  28. readFile(join(reference, file)),
  29. readFile(join(target, file)),
  30. ]);
  31. if (!a.equals(b)) throw new Error(`${name}: ${file} differs`);
  32. }
  33. }
  34. process.stdout.write("Document LibreOffice launchers and profiles are identical.\n");
  35. } catch (error) {
  36. process.stderr.write(`${error.message}\n`);
  37. process.exitCode = 1;
  38. }