generate-plugin-imports.js 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const fs = require("fs");
  2. const getPackageJSON = () => {
  3. try {
  4. return require("./src/extensions/package.json").dependencies;
  5. } catch (error) {
  6. return {};
  7. }
  8. };
  9. const main = async () => {
  10. const installedPackages = getPackageJSON();
  11. if (!installedPackages || Object.keys(installedPackages).length === 0) {
  12. console.log("No React UI extensions found");
  13. fs.writeFileSync("./src/extensions/link.ts", "export default {};\n");
  14. return;
  15. }
  16. const ttsWebuiPackages = Object.keys(installedPackages).filter((x) =>
  17. x.startsWith("@tts-webui")
  18. );
  19. console.log("Found React UI extensions:", ttsWebuiPackages.join(", "));
  20. const imports = ttsWebuiPackages
  21. .map(
  22. (x) =>
  23. `export { default as ${x.replace("@tts-webui/", "")} } from "${x}";`
  24. )
  25. .join("\n");
  26. fs.writeFileSync("./src/extensions/link.ts", imports);
  27. console.log("Generated React UI extensions imports");
  28. return;
  29. };
  30. main();