-
-
-
- {template.links.website && (
+ {template?.links?.github && (
+
+
+
+ )}
+ {template?.links?.website && (
)}
- {template.links.docs && (
+ {template?.links?.docs && (
@@ -419,7 +421,7 @@ export const AddTemplate = ({ projectId, baseUrl }: Props) => {
This will create an application from the{" "}
- {template.name} template and add it to your
+ {template?.name} template and add it to your
project.
diff --git a/packages/server/src/templates/processors.ts b/packages/server/src/templates/processors.ts
index 86d3cdf740..7ef774f8a0 100644
--- a/packages/server/src/templates/processors.ts
+++ b/packages/server/src/templates/processors.ts
@@ -70,7 +70,7 @@ function processValue(
schema: Schema,
): string {
// First replace utility functions
- let processedValue = value.replace(/\${([^}]+)}/g, (match, varName) => {
+ let processedValue = value?.replace(/\${([^}]+)}/g, (match, varName) => {
// Handle utility functions
if (varName === "domain") {
return generateRandomDomain(schema);
@@ -177,7 +177,14 @@ export function processDomains(
variables: Record
,
schema: Schema,
): Template["domains"] {
- if (!template?.config?.domains) return [];
+ if (
+ !template?.config?.domains ||
+ template.config.domains.length === 0 ||
+ template.config.domains.every((domain) => !domain.serviceName)
+ ) {
+ return [];
+ }
+
return template?.config?.domains?.map((domain: DomainConfig) => ({
...domain,
host: domain.host
@@ -194,7 +201,9 @@ export function processEnvVars(
variables: Record,
schema: Schema,
): Template["envs"] {
- if (!template?.config?.env) return [];
+ if (!template?.config?.env || Object.keys(template.config.env).length === 0) {
+ return [];
+ }
// Handle array of env vars
if (Array.isArray(template.config.env)) {
@@ -233,7 +242,13 @@ export function processMounts(
variables: Record,
schema: Schema,
): Template["mounts"] {
- if (!template?.config?.mounts) return [];
+ if (
+ !template?.config?.mounts ||
+ template.config.mounts.length === 0 ||
+ template.config.mounts.every((mount) => !mount.filePath && !mount.content)
+ ) {
+ return [];
+ }
return template?.config?.mounts?.map((mount: MountConfig) => ({
filePath: processValue(mount.filePath, variables, schema),
From 9a839de022fac468287934c35e2ded3bbda7defb Mon Sep 17 00:00:00 2001
From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com>
Date: Thu, 3 Apr 2025 00:22:29 -0600
Subject: [PATCH 2/2] feat(templates): add username and email generation using
faker
---
packages/server/src/templates/processors.ts | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/packages/server/src/templates/processors.ts b/packages/server/src/templates/processors.ts
index 7ef774f8a0..31e7861ada 100644
--- a/packages/server/src/templates/processors.ts
+++ b/packages/server/src/templates/processors.ts
@@ -1,3 +1,4 @@
+import { faker } from "@faker-js/faker";
import type { Schema } from "./index";
import {
generateBase64,
@@ -117,6 +118,14 @@ function processValue(
return generateJwt(length);
}
+ if (varName === "username") {
+ return faker.internet.userName().toLowerCase();
+ }
+
+ if (varName === "email") {
+ return faker.internet.email().toLowerCase();
+ }
+
// If not a utility function, try to get from variables
return variables[varName] || match;
});