Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"eslint": "^9.39.2",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-unicorn": "^62.0.0",
"front-matter": "^4.0.2",
"globby": "^16.1.0",
"json5": "^2.2.3",
"ky": "^1.14.2",
Expand Down
18 changes: 13 additions & 5 deletions src/core/project/template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { join } from "node:path";
import { join, dirname } from "node:path";
import { globby } from "globby";
import ejs from "ejs";
import frontmatter from 'front-matter';
import { getTemplatesDir, getTemplatesIndexPath } from "../config.js";
import { readJsonFile, writeFile, copyFile } from "../utils/fs.js";
import { TemplatesConfigSchema } from "./schema.js";
Expand All @@ -12,6 +13,10 @@ export interface TemplateData {
projectId: string;
}

interface TemplateFrontmatter {
outputFileName?: string;
}

export async function listTemplates(): Promise<Template[]> {
const parsed = await readJsonFile(getTemplatesIndexPath());
const result = TemplatesConfigSchema.parse(parsed);
Expand All @@ -21,6 +26,7 @@ export async function listTemplates(): Promise<Template[]> {
/**
* Render a template directory to a destination path.
* - Files ending in .ejs are rendered with EJS and written without the .ejs extension
* - EJS files can have frontmatter with custom attributes
* - All other files are copied directly
*/
export async function renderTemplate(
Expand All @@ -42,11 +48,13 @@ export async function renderTemplate(

try {
if (file.endsWith(".ejs")) {
// Render EJS template and write without .ejs extension
const destFile = file.replace(/\.ejs$/, "");
const destFilePath = join(destPath, destFile);
// Render EJS template and write to outputFileName or filename without .ejs extension
const rendered = await ejs.renderFile(srcPath, data);
await writeFile(destFilePath, rendered);
const { attributes, body } = frontmatter<TemplateFrontmatter>(rendered);
const destFile = attributes.outputFileName ? join(dirname(file), attributes.outputFileName) : file.replace(/\.ejs$/, "");
const destFilePath = join(destPath, destFile);

await writeFile(destFilePath, body);
} else {
// Copy file directly
const destFilePath = join(destPath, file);
Expand Down
1 change: 1 addition & 0 deletions templates/backend-and-client/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.21.1
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
outputFileName: .env.local
---
# Base44 Project Environment Variables
# This file contains environment-specific configuration for your Base44 project.
# Do not commit this file to version control if it contains sensitive data.
Expand Down
9 changes: 9 additions & 0 deletions templates/backend-only/base44/env.local.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
outputFileName: .env.local
---
# Base44 Project Environment Variables
# This file contains environment-specific configuration for your Base44 project.
# Do not commit this file to version control if it contains sensitive data.

# Your Base44 Application ID
BASE44_CLIENT_ID=<%= projectId %>