Skip to content
Merged
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
17 changes: 17 additions & 0 deletions packages/create-termui-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ import {
import { generateProject, type ProjectConfig } from "./templates.js";
import { parseArgs, isNonInteractive } from "./args.js";

const VALID_PROJECT_NAME_RE = /^[a-zA-Z0-9@][a-zA-Z0-9_.-]*$/;

function validateProjectName(name: string, source: string): void {
if (!VALID_PROJECT_NAME_RE.test(name)) {
throw new Error(
`Invalid project name "${name}" (from ${source}). Use only letters, digits, hyphens, underscores, dots, or start with @ for scoped packages.`
);
}
if (name === "." || name === "..") {
throw new Error(
`Invalid project name "${name}". "." and ".." are not allowed as project names.`
);
}
}

const TEMPLATES = [
"Empty (start from scratch)",
"Dashboard (real-time data)",
Expand Down Expand Up @@ -56,6 +71,7 @@ async function main() {
// ───────── CI MODE ─────────
if (isNonInteractive(args)) {
projectName ??= "my-termui-app";
validateProjectName(projectName, "command-line argument");

if (args.template && !TEMPLATE_KEYS.includes(args.template as any)) {
throw new Error(
Expand Down Expand Up @@ -116,6 +132,7 @@ async function main() {
if (!projectName) {
projectName = await textPrompt("Project name", "my-termui-app");
}
validateProjectName(projectName, "interactive prompt");

const templateIdx = await selectPrompt("What kind of app?", TEMPLATES);
template = TEMPLATE_KEYS[templateIdx];
Expand Down
Loading