@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
60 lines (58 loc) • 1.95 kB
JavaScript
import { SOFTR_CONFIG_FILE, loadSoftrConfig } from "./softr-config.schema.js";
import { createRequire } from "node:module";
import path from "node:path";
//#region src/vite.ts
function softr() {
return [softrConfig(), softrLogoIcon()];
}
function softrConfig() {
let root;
return {
name: "softr:config",
config(userConfig) {
root = path.resolve(userConfig.root ?? process.cwd());
return { define: {
__SOFTR_CONFIG__: JSON.stringify(loadSoftrConfig(root)),
__SOFTR_BUILD_ID__: JSON.stringify(Date.now().toString(36))
} };
},
configureServer(server) {
const file = path.join(root, SOFTR_CONFIG_FILE);
server.watcher.add(file);
server.watcher.on("change", (changed) => {
if (changed === file) server.restart();
});
}
};
}
const LOGO_ICON = "virtual:softr/logo-icon";
const RESOLVED_LOGO_ICON = `\0${LOGO_ICON}`;
const DEFAULT_LOGO_ICON = "layers";
function softrLogoIcon() {
let root;
return {
name: "softr:logo-icon",
configResolved(config) {
root = config.root;
},
resolveId(id) {
return id === LOGO_ICON ? RESOLVED_LOGO_ICON : void 0;
},
load(id) {
if (id !== RESOLVED_LOGO_ICON) return void 0;
const lucide = createRequire(path.join(root, "package.json"))("lucide-react");
const exported = [loadSoftrConfig(root).logo.icon, DEFAULT_LOGO_ICON].map(exportName).find((name) => Object.hasOwn(lucide, name));
if (exported === void 0) throw new Error(`lucide-react in ${root} has no "${DEFAULT_LOGO_ICON}" icon to draw the logo with`);
return `export { ${exported} as default } from "lucide-react";`;
}
};
}
/**
* The name lucide-react exports this icon under: "paw-print" is PawPrintIcon. Every icon and alias has
* one. Lucide's one other export that ends in Icon is Icon itself, and no icon name maps to it.
*/
function exportName(icon) {
return `${icon.replace(/(?:^|-)([a-z0-9])/g, (_, letter) => letter.toUpperCase())}Icon`;
}
//#endregion
export { softr };