diff --git a/create-app.ts b/create-app.ts index 835c02f16e89ab41a6c4e52ff70e0150bad169ed..316d213661e724efa74645bdaf1297acbb47a64f 100644 --- a/create-app.ts +++ b/create-app.ts @@ -1,6 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies */ import path from "path"; -import { green, yellow } from "picocolors"; +import { green, red } from "picocolors"; import { tryGitInit } from "./helpers/git"; import { isFolderEmpty } from "./helpers/is-folder-empty"; import { getOnline } from "./helpers/is-online"; @@ -87,28 +87,48 @@ export async function createApp({ tools, }; + let installationErrors = []; + if (frontend) { // install backend const backendRoot = path.join(root, "backend"); await makeDir(backendRoot); - await installTemplate({ ...args, root: backendRoot, backend: true }); + try { + await installTemplate({ + ...args, + root: backendRoot, + backend: true, + }); + } catch (error) { + installationErrors.push(error); + console.log(red(`${error}`)); + } // install frontend const frontendRoot = path.join(root, "frontend"); await makeDir(frontendRoot); - await installTemplate({ - ...args, - root: frontendRoot, - framework: "nextjs", - customApiPath: `http://localhost:${externalPort ?? 8000}/api/chat`, - backend: false, - }); + try { + await installTemplate({ + ...args, + root: frontendRoot, + framework: "nextjs", + customApiPath: `http://localhost:${externalPort ?? 8000}/api/chat`, + backend: false, + }); + } catch (error) { + installationErrors.push(error); + } + // copy readme for fullstack await fs.promises.copyFile( path.join(templatesDir, "README-fullstack.md"), path.join(root, "README.md"), ); } else { - await installTemplate({ ...args, backend: true, forBackend: framework }); + try { + await installTemplate({ ...args, backend: true, forBackend: framework }); + } catch (error) { + installationErrors.push(error); + } } process.chdir(root); @@ -119,7 +139,7 @@ export async function createApp({ if (toolsRequireConfig(tools)) { console.log( - yellow( + red( `You have selected tools that require configuration. Please configure them in the ${terminalLink( "tools_config.json", `file://${root}/tools_config.json`, @@ -127,14 +147,24 @@ export async function createApp({ ), ); } - console.log(""); - console.log(`${green("Success!")} Created ${appName} at ${appPath}`); - console.log( - `Now have a look at the ${terminalLink( - "README.md", - `file://${root}/README.md`, - )} and learn how to get started.`, - ); console.log(); + if (installationErrors.length > 0) { + for (const error of installationErrors) { + console.log(red(`${error}`)); + } + console.log( + "\nExiting installation. Please check the generated code or try create app again!", + ); + process.exit(1); + } else { + console.log(`${green("Success!")} Created ${appName} at ${appPath}`); + console.log( + `Now have a look at the ${terminalLink( + "README.md", + `file://${root}/README.md`, + )} and learn how to get started.`, + ); + console.log(); + } } diff --git a/helpers/python.ts b/helpers/python.ts index 6fbc48b571fa925658483b2aa30494f79bc1bfa2..8de1e528dd160bb95a0fa71e917f95741bc7977f 100644 --- a/helpers/python.ts +++ b/helpers/python.ts @@ -1,6 +1,6 @@ import fs from "fs/promises"; import path from "path"; -import { cyan, red, yellow } from "picocolors"; +import { cyan } from "picocolors"; import { parse, stringify } from "smol-toml"; import terminalLink from "terminal-link"; import { copy } from "./copy"; @@ -103,22 +103,16 @@ export const installPythonDependencies = ( ); const installSuccessful = tryPoetryInstall(noRoot); if (!installSuccessful) { - console.error( - red("Install failed. Please install dependencies manually."), + throw new Error( + "Poetry installation failed. Please install dependencies manually.", ); - process.exit(1); } } else { - console.warn( - yellow( - `Poetry is not available in the current environment. The Python dependencies will not be installed automatically. + throw new Error(`Poetry is not available in the current environment. The Python dependencies will not be installed automatically. Please check ${terminalLink( - "Poetry Installation", - `https://python-poetry.org/docs/#installation`, - )} to install poetry first, then install the dependencies manually.`, - ), - ); - process.exit(1); + "Poetry Installation", + `https://python-poetry.org/docs/#installation`, + )} to install poetry first, then install the dependencies manually.`); } }; @@ -222,4 +216,5 @@ export const installPythonTemplate = async ({ if (postInstallAction !== "none") { installPythonDependencies(); } + console.log("\nFastAPI project initialized successfully!\n"); }; diff --git a/helpers/typescript.ts b/helpers/typescript.ts index cfadc67b1f96dd3e16c97fb5f938612067517168..d9d78161391f2f3c1cc1fed5c5572d5f0823391b 100644 --- a/helpers/typescript.ts +++ b/helpers/typescript.ts @@ -1,7 +1,7 @@ import fs from "fs/promises"; import os from "os"; import path from "path"; -import { bold, cyan } from "picocolors"; +import { bold, cyan, green } from "picocolors"; import { version } from "../../core/package.json"; import { copy } from "../helpers/copy"; import { callPackageManager } from "../helpers/install"; @@ -231,4 +231,6 @@ export const installTSTemplate = async ({ if (postInstallAction !== "none") { await installTSDependencies(packageJson, packageManager, isOnline); } + + console.log(green(`${framework} project is initialized successfully.`)); };