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