mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
rename features to addons
This commit is contained in:
@@ -11,7 +11,7 @@ export const DEFAULT_CONFIG: ProjectConfig = {
|
||||
database: "sqlite",
|
||||
orm: "drizzle",
|
||||
auth: true,
|
||||
features: [],
|
||||
addons: [],
|
||||
git: true,
|
||||
packageManager: "npm",
|
||||
noInstall: false,
|
||||
|
||||
@@ -2,21 +2,18 @@ import path from "node:path";
|
||||
import { log } from "@clack/prompts";
|
||||
import fs from "fs-extra";
|
||||
import pc from "picocolors";
|
||||
import type { ProjectFeature } from "../types";
|
||||
import type { ProjectAddons } from "../types";
|
||||
|
||||
export async function setupFeatures(
|
||||
projectDir: string,
|
||||
features: ProjectFeature[],
|
||||
) {
|
||||
if (features.includes("docker")) {
|
||||
export async function setupAddons(projectDir: string, addons: ProjectAddons[]) {
|
||||
if (addons.includes("docker")) {
|
||||
await setupDocker(projectDir);
|
||||
}
|
||||
|
||||
if (features.includes("github-actions")) {
|
||||
if (addons.includes("github-actions")) {
|
||||
await setupGithubActions(projectDir);
|
||||
}
|
||||
|
||||
if (features.includes("SEO")) {
|
||||
if (addons.includes("SEO")) {
|
||||
log.info(
|
||||
pc.yellow(
|
||||
"SEO feature is still a work-in-progress and will be available in a future update.",
|
||||
@@ -5,10 +5,10 @@ import fs from "fs-extra";
|
||||
import pc from "picocolors";
|
||||
import { PKG_ROOT } from "../constants";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import { setupAddons } from "./addons-setup";
|
||||
import { configureAuth } from "./auth-setup";
|
||||
import { createReadme } from "./create-readme";
|
||||
import { setupDatabase } from "./db-setup";
|
||||
import { setupFeatures } from "./feature-setup";
|
||||
import { displayPostInstallInstructions } from "./post-installation";
|
||||
|
||||
export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
@@ -92,8 +92,8 @@ export async function createProject(options: ProjectConfig): Promise<string> {
|
||||
await $({ cwd: projectDir })`git init`;
|
||||
}
|
||||
|
||||
if (options.features.length > 0) {
|
||||
await setupFeatures(projectDir, options.features);
|
||||
if (options.addons.length > 0) {
|
||||
await setupAddons(projectDir, options.addons);
|
||||
}
|
||||
|
||||
const packageJsonPath = path.join(projectDir, "package.json");
|
||||
|
||||
@@ -19,7 +19,7 @@ function generateReadmeContent(options: ProjectConfig): string {
|
||||
packageManager,
|
||||
database,
|
||||
auth,
|
||||
features = [],
|
||||
addons = [],
|
||||
orm = "drizzle",
|
||||
} = options;
|
||||
|
||||
@@ -32,7 +32,7 @@ This project was created with [Better-T-Stack](https://github.com/better-t-stack
|
||||
|
||||
## Features
|
||||
|
||||
${generateFeaturesList(database, auth, features, orm)}
|
||||
${generateFeaturesList(database, auth, addons, orm)}
|
||||
|
||||
## Getting Started
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ export async function setupDatabase(
|
||||
|
||||
if (databaseType === "none") {
|
||||
await fs.remove(path.join(serverDir, "src/db"));
|
||||
log.info(pc.yellow("Database configuration removed"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ export async function installDependencies({
|
||||
packageManager,
|
||||
}: InstallDependenciesOptions) {
|
||||
const s = spinner();
|
||||
log.info(pc.blue(`Installing dependencies using ${packageManager}...`));
|
||||
|
||||
try {
|
||||
s.start(`Running ${packageManager} install...`);
|
||||
@@ -34,7 +33,7 @@ export async function installDependencies({
|
||||
break;
|
||||
}
|
||||
|
||||
s.stop(pc.green("Dependencies installed successfully"));
|
||||
s.stop("Dependencies installed successfully");
|
||||
} catch (error) {
|
||||
s.stop(pc.red("Failed to install dependencies"));
|
||||
if (error instanceof Error) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DEFAULT_CONFIG } from "./constants";
|
||||
import { createProject } from "./helpers/create-project";
|
||||
import { installDependencies } from "./helpers/install-dependencies";
|
||||
import { gatherConfig } from "./prompts/config-prompts";
|
||||
import type { ProjectConfig, ProjectFeature } from "./types";
|
||||
import type { ProjectAddons, ProjectConfig } from "./types";
|
||||
import { displayConfig } from "./utils/display-config";
|
||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
||||
import { getVersion } from "./utils/get-version";
|
||||
@@ -33,7 +33,7 @@ async function main() {
|
||||
.option("--docker", "Include Docker setup")
|
||||
.option("--github-actions", "Include GitHub Actions")
|
||||
.option("--seo", "Include SEO setup")
|
||||
.option("--no-features", "Skip all additional features")
|
||||
.option("--no-addons", "Skip all additional addons")
|
||||
.option("--git", "Include git setup")
|
||||
.option("--no-git", "Skip git initialization")
|
||||
.option("--npm", "Use npm package manager")
|
||||
@@ -75,15 +75,15 @@ async function main() {
|
||||
...((options.docker ||
|
||||
options.githubActions ||
|
||||
options.seo ||
|
||||
options.features === false) && {
|
||||
features:
|
||||
options.features === false
|
||||
options.addons === false) && {
|
||||
addons:
|
||||
options.addons === false
|
||||
? []
|
||||
: ([
|
||||
...(options.docker ? ["docker"] : []),
|
||||
...(options.githubActions ? ["github-actions"] : []),
|
||||
...(options.seo ? ["SEO"] : []),
|
||||
] as ProjectFeature[]),
|
||||
] as ProjectAddons[]),
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -117,9 +117,9 @@ async function main() {
|
||||
: DEFAULT_CONFIG.noInstall,
|
||||
packageManager:
|
||||
flagConfig.packageManager ?? DEFAULT_CONFIG.packageManager,
|
||||
features: flagConfig.features?.length
|
||||
? flagConfig.features
|
||||
: DEFAULT_CONFIG.features,
|
||||
addons: flagConfig.addons?.length
|
||||
? flagConfig.addons
|
||||
: DEFAULT_CONFIG.addons,
|
||||
turso:
|
||||
"turso" in options
|
||||
? options.turso
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { cancel, isCancel, multiselect } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import type { ProjectFeature } from "../types";
|
||||
import type { ProjectAddons } from "../types";
|
||||
|
||||
export async function getFeaturesChoice(
|
||||
features?: ProjectFeature[],
|
||||
): Promise<ProjectFeature[]> {
|
||||
if (features !== undefined) return features;
|
||||
export async function getAddonsChoice(
|
||||
Addons?: ProjectAddons[],
|
||||
): Promise<ProjectAddons[]> {
|
||||
if (Addons !== undefined) return Addons;
|
||||
|
||||
const response = await multiselect<ProjectFeature>({
|
||||
message: "Which features would you like to add?",
|
||||
const response = await multiselect<ProjectAddons>({
|
||||
message: "Which Addons would you like to add?",
|
||||
options: [
|
||||
{
|
||||
value: "docker",
|
||||
@@ -2,14 +2,14 @@ import { cancel, group } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
import type {
|
||||
PackageManager,
|
||||
ProjectAddons,
|
||||
ProjectConfig,
|
||||
ProjectDatabase,
|
||||
ProjectFeature,
|
||||
ProjectOrm,
|
||||
} from "../types";
|
||||
import { getAddonsChoice } from "./addons";
|
||||
import { getAuthChoice } from "./auth";
|
||||
import { getDatabaseChoice } from "./database";
|
||||
import { getFeaturesChoice } from "./features";
|
||||
import { getGitChoice } from "./git";
|
||||
import { getNoInstallChoice } from "./install";
|
||||
import { getORMChoice } from "./orm";
|
||||
@@ -22,7 +22,7 @@ interface PromptGroupResults {
|
||||
database: ProjectDatabase;
|
||||
orm: ProjectOrm;
|
||||
auth: boolean;
|
||||
features: ProjectFeature[];
|
||||
addons: ProjectAddons[];
|
||||
git: boolean;
|
||||
packageManager: PackageManager;
|
||||
noInstall: boolean;
|
||||
@@ -46,7 +46,7 @@ export async function gatherConfig(
|
||||
results.database === "sqlite"
|
||||
? getTursoSetupChoice(flags.turso)
|
||||
: Promise.resolve(false),
|
||||
features: () => getFeaturesChoice(flags.features),
|
||||
addons: () => getAddonsChoice(flags.addons),
|
||||
git: () => getGitChoice(flags.git),
|
||||
packageManager: () => getPackageManagerChoice(flags.packageManager),
|
||||
noInstall: () => getNoInstallChoice(flags.noInstall),
|
||||
@@ -64,7 +64,7 @@ export async function gatherConfig(
|
||||
database: result.database,
|
||||
orm: result.orm,
|
||||
auth: result.auth,
|
||||
features: result.features,
|
||||
addons: result.addons,
|
||||
git: result.git,
|
||||
packageManager: result.packageManager,
|
||||
noInstall: result.noInstall,
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function getNoInstallChoice(
|
||||
if (noInstall !== undefined) return noInstall;
|
||||
|
||||
const response = await confirm({
|
||||
message: "Install dependencies after creating project?",
|
||||
message: "Install dependencies?",
|
||||
initialValue: !DEFAULT_CONFIG.noInstall,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
export type ProjectDatabase = "sqlite" | "postgres" | "none";
|
||||
export type ProjectOrm = "drizzle" | "prisma" | "none";
|
||||
export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
||||
export type ProjectFeature = "docker" | "github-actions" | "SEO";
|
||||
export type ProjectAddons = "docker" | "github-actions" | "SEO";
|
||||
|
||||
export interface ProjectConfig {
|
||||
projectName: string;
|
||||
database: ProjectDatabase;
|
||||
orm: ProjectOrm;
|
||||
auth: boolean;
|
||||
features: ProjectFeature[];
|
||||
addons: ProjectAddons[];
|
||||
git: boolean;
|
||||
packageManager: PackageManager;
|
||||
noInstall?: boolean;
|
||||
|
||||
@@ -16,8 +16,8 @@ export function displayConfig(config: Partial<ProjectConfig>) {
|
||||
if (config.auth !== undefined) {
|
||||
configDisplay.push(`${pc.blue("Authentication:")} ${config.auth}`);
|
||||
}
|
||||
if (config.features?.length) {
|
||||
configDisplay.push(`${pc.blue("Features:")} ${config.features.join(", ")}`);
|
||||
if (config.addons?.length) {
|
||||
configDisplay.push(`${pc.blue("Addons:")} ${config.addons.join(", ")}`);
|
||||
}
|
||||
if (config.git !== undefined) {
|
||||
configDisplay.push(`${pc.blue("Git Init:")} ${config.git}`);
|
||||
|
||||
@@ -41,12 +41,12 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
|
||||
flags.push(`--${config.packageManager}`);
|
||||
}
|
||||
|
||||
if (config.features.length > 0) {
|
||||
for (const feature of config.features) {
|
||||
flags.push(`--${feature}`);
|
||||
if (config.addons.length > 0) {
|
||||
for (const addon of config.addons) {
|
||||
flags.push(`--${addon}`);
|
||||
}
|
||||
} else {
|
||||
flags.push("--no-features");
|
||||
flags.push("--no-addons");
|
||||
}
|
||||
|
||||
const baseCommand = "npx create-better-t-stack";
|
||||
|
||||
Reference in New Issue
Block a user