Skip to content
Snippets Groups Projects
Commit 82ce5db4 authored by Huu Le (Lee)'s avatar Huu Le (Lee) Committed by GitHub
Browse files

fix: add handle error from template installation (#522)

parent 56f8942e
No related branches found
No related tags found
No related merge requests found
/* 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();
}
}
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");
};
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.`));
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment