chore: add inquirer, add blank theme

This commit is contained in:
2026-06-01 14:21:03 +02:00
parent eea32cf96a
commit 31507041a5
33 changed files with 3151 additions and 56 deletions
+67 -25
View File
@@ -1,29 +1,71 @@
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import fs from "fs";
import path from "path";
import { execSync } from "child_process";
import { fileURLToPath } from "url";
import { input, select } from "@inquirer/prompts";
const projectTypes = [
{
name: "blank",
value: "blank",
description: "start with a blank project",
},
{
name: "example",
value: "example",
description: "start with an example project, to see how theming works",
},
];
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const projectName = process.argv[2];
if (!projectName) {
console.error('❌ Please provide a project name');
process.exit(1);
async function main() {
let projectName = process.argv[2];
if (!projectName) {
projectName = await input({
message: "Please enter a project name:",
pattern: /^[a-zA-Z0-9-]+$/,
validate: (value) => {
if (!value)
return "Project name is required";
if (!/^[a-zA-Z0-9-]+$/.test(value))
return "Project name can only contain letters, numbers, and dashes";
if (fs.existsSync(value))
return "Directory already exists";
return true;
},
});
if (!projectName) {
console.error("❌ Project name is required");
process.exit(1);
}
}
const templateType = await select({
message: "Please select a template type:",
choices: projectTypes,
});
const targetDir = path.resolve(process.cwd(), projectName);
const templateDir = path.resolve(__dirname, `../templates/${templateType}`);
if (!fs.existsSync(templateDir)) {
console.error("❌ Template directory not found");
process.exit(1);
}
if (fs.existsSync(targetDir)) {
console.error("❌ Directory already exists");
process.exit(1);
}
fs.cpSync(templateDir, targetDir, { recursive: true });
const pkgPath = path.join(targetDir, "package.json");
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
pkg.name = projectName;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
const themePath = path.join(targetDir, "theme.json");
const theme = JSON.parse(fs.readFileSync(themePath, "utf-8"));
theme.name = projectName;
fs.writeFileSync(themePath, JSON.stringify(theme, null, 2));
console.log("📦 Installing dependencies...");
execSync("npm install", { cwd: targetDir, stdio: "inherit" });
console.log(`\n✅ Theme created!\n`);
}
const targetDir = path.resolve(process.cwd(), projectName);
const templateDir = path.resolve(__dirname, '../templates/base');
if (fs.existsSync(targetDir)) {
console.error('❌ Directory already exists');
main().catch((err) => {
console.error(err);
process.exit(1);
}
fs.cpSync(templateDir, targetDir, { recursive: true });
const pkgPath = path.join(targetDir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
pkg.name = projectName;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
const themePath = path.join(targetDir, 'theme.json');
const theme = JSON.parse(fs.readFileSync(themePath, 'utf-8'));
theme.name = projectName;
fs.writeFileSync(themePath, JSON.stringify(theme, null, 2));
console.log('📦 Installing dependencies...');
execSync('npm install', { cwd: targetDir, stdio: 'inherit' });
console.log(`\n✅ Theme created!\n`);
});