Some checks failed
Build & Deploy / 🔍 Prepare Environment (push) Successful in 8s
Build & Deploy / 🏗️ Build (push) Failing after 12s
Build & Deploy / 🧪 QA (push) Successful in 1m13s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🔔 Notifications (push) Successful in 2s
116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
import {
|
||
createMintelDirectusClient,
|
||
ensureDirectusAuthenticated,
|
||
} from "@mintel/next-utils";
|
||
import { createCollection, createField, updateSettings } from "@directus/sdk";
|
||
|
||
const client = createMintelDirectusClient();
|
||
|
||
async function setupBranding() {
|
||
const prjName = process.env.PROJECT_NAME || "Mintel Project";
|
||
const prjColor = process.env.PROJECT_COLOR || "#82ed20";
|
||
|
||
console.log(`🎨 Setup Directus Branding for ${prjName}...`);
|
||
await ensureDirectusAuthenticated(client);
|
||
|
||
const cssInjection = `
|
||
<style>
|
||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
|
||
body, .v-app { font-family: 'Inter', sans-serif !important; }
|
||
.public-view .v-card {
|
||
backdrop-filter: blur(20px);
|
||
border-radius: 32px !important;
|
||
box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.4) !important;
|
||
}
|
||
.v-navigation-drawer { background: #000c24 !important; }
|
||
</style>
|
||
<div style="font-family: 'Inter', sans-serif; text-align: center; margin-top: 24px;">
|
||
<p style="color: rgba(255,255,255,0.7); font-size: 14px; margin-bottom: 4px; font-weight: 500;">MINTEL INFRASTRUCTURE ENGINE</p>
|
||
<h1 style="color: #ffffff; font-size: 18px; font-weight: 700; margin: 0;">${prjName.toUpperCase()} <span style="color: ${prjColor};">RELIABILITY.</span></h1>
|
||
</div>
|
||
`;
|
||
|
||
try {
|
||
await client.request(
|
||
updateSettings({
|
||
project_name: prjName,
|
||
project_color: prjColor,
|
||
public_note: cssInjection,
|
||
theme_light_overrides: {
|
||
primary: prjColor,
|
||
borderRadius: "16px",
|
||
navigationBackground: "#000c24",
|
||
navigationForeground: "#ffffff",
|
||
},
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||
} as any),
|
||
);
|
||
console.log("✨ Branding applied!");
|
||
|
||
try {
|
||
await createCollectionAndFields();
|
||
console.log("🏗️ Schema alignment complete!");
|
||
} catch (error) {
|
||
console.error("❌ Error aligning schema:", error);
|
||
}
|
||
} catch (error) {
|
||
console.error("❌ Error setting up branding:", error);
|
||
}
|
||
}
|
||
|
||
async function createCollectionAndFields() {
|
||
const collectionName = "contact_submissions";
|
||
|
||
try {
|
||
await client.request(
|
||
createCollection({
|
||
collection: collectionName,
|
||
schema: {},
|
||
meta: {
|
||
icon: "contact_mail",
|
||
display_template: "{{name}} <{{email}}>",
|
||
},
|
||
}),
|
||
);
|
||
|
||
// Add ID field
|
||
await client.request(
|
||
createField(collectionName, {
|
||
field: "id",
|
||
type: "integer",
|
||
meta: { hidden: true },
|
||
schema: { is_primary_key: true, has_auto_increment: true },
|
||
}),
|
||
);
|
||
console.log(`✅ Collection ${collectionName} created.`);
|
||
} catch {
|
||
console.log(
|
||
`ℹ️ Collection ${collectionName} already exists or error occured.`,
|
||
);
|
||
}
|
||
|
||
const safeAddField = async (
|
||
field: string,
|
||
type: string,
|
||
meta: Record<string, unknown> = {},
|
||
) => {
|
||
try {
|
||
await client.request(createField(collectionName, { field, type, meta }));
|
||
console.log(`✅ Field ${field} added.`);
|
||
} catch {
|
||
// Ignore if exists
|
||
}
|
||
};
|
||
|
||
await safeAddField("name", "string", { interface: "input" });
|
||
await safeAddField("email", "string", { interface: "input" });
|
||
await safeAddField("company", "string", { interface: "input" });
|
||
await safeAddField("message", "text", { interface: "textarea" });
|
||
await safeAddField("date_created", "timestamp", {
|
||
interface: "datetime",
|
||
special: ["date-created"],
|
||
});
|
||
}
|
||
|
||
setupBranding();
|