@reliverse/rse-sdk
Version:
@reliverse/rse-sdk allows you to create new plugins for @reliverse/rse CLI, interact with reliverse.org, and even extend your own CLI functionality (you may also try @reliverse/dler-sdk for this case).
83 lines (82 loc) • 3.06 kB
JavaScript
import { re } from "@reliverse/relico";
import fs from "@reliverse/relifso";
import { relinka } from "@reliverse/relinka";
import { cancel } from "@reliverse/rempts";
import { setupAddons } from "../setup/addons-setup.js";
import { setupApi } from "../setup/api-setup.js";
import { setupAuth } from "../setup/auth-setup.js";
import { setupBackendDependencies } from "../setup/backend-setup.js";
import { setupDatabase } from "../setup/db-setup.js";
import { setupExamples } from "../setup/examples-setup.js";
import { setupRuntime } from "../setup/runtime-setup.js";
import { createReadme } from "./create-readme.js";
import { setupEnvironmentVariables } from "./env-setup.js";
import { installDependencies } from "./install-dependencies.js";
import { displayPostInstallInstructions } from "./post-installation.js";
import { initializeGit, updatePackageConfigurations } from "./project-config.js";
import {
copyBaseTemplate,
handleExtras,
setupAddonsTemplate,
setupAuthTemplate,
setupBackendFramework,
setupDbOrmTemplates,
setupExamplesTemplate,
setupFrontendTemplates
} from "./template-manager.js";
export async function createProject(options) {
const projectDir = options.projectDir;
const isConvex = options.backend === "convex";
try {
await fs.ensureDir(projectDir);
await copyBaseTemplate(projectDir, options);
await setupFrontendTemplates(projectDir, options);
await setupBackendFramework(projectDir, options);
if (!isConvex) {
await setupDbOrmTemplates(projectDir, options);
await setupAuthTemplate(projectDir, options);
}
if (options.examples.length > 0 && options.examples[0] !== "none") {
await setupExamplesTemplate(projectDir, options);
}
await setupAddonsTemplate(projectDir, options);
await setupApi(options);
if (!isConvex) {
await setupBackendDependencies(options);
await setupDatabase(options);
await setupRuntime(options);
if (options.examples.length > 0 && options.examples[0] !== "none") {
await setupExamples(options);
}
}
if (options.addons.length > 0 && options.addons[0] !== "none") {
await setupAddons(options);
}
if (!isConvex && options.auth) {
await setupAuth(options);
}
await handleExtras(projectDir, options);
await setupEnvironmentVariables(options);
await updatePackageConfigurations(projectDir, options);
await createReadme(projectDir, options);
await initializeGit(projectDir, options.git);
relinka("success", "Project template successfully scaffolded!");
if (options.install) {
await installDependencies({
projectDir,
packageManager: options.packageManager
});
}
displayPostInstallInstructions({
...options,
depsInstalled: options.install
});
return projectDir;
} catch (error) {
if (error instanceof Error) {
cancel(re.red(`Error during project creation: ${error.message}`));
} else {
cancel(re.red(`An unexpected error occurred: ${String(error)}`));
}
}
}