getLogs.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import chalk from "chalk";
  2. import gradient from "gradient-string";
  3. import type { RenderContext } from "./getRenderContext";
  4. export function logBanner() {
  5. console.log(`\n${getBanner()}\n`);
  6. }
  7. export function logErrorAndExit(message: string) {
  8. logError(message);
  9. process.exit(1);
  10. }
  11. export function logError(message: string) {
  12. console.log(chalk.red("✖") + ` ${message}`);
  13. }
  14. export function logStart(ctx: RenderContext) {
  15. console.log(
  16. `\n${ctx.language.infos.scaffolding} ${ctx.targetDirectoryName}...`
  17. );
  18. }
  19. export function logEnd(ctx: RenderContext) {
  20. console.log(`\n${ctx.language.infos.done}\n`);
  21. // Log next steps: Cd into the target directory.
  22. if (ctx.targetDirectory !== ctx.currentDirectory) {
  23. const cdCommand = `cd ${ctx.targetDirectoryName.includes(" ") ? `"${ctx.targetDirectoryName}"` : ctx.targetDirectoryName}`;
  24. console.log(` ${chalk.bold(chalk.green(cdCommand))}`);
  25. }
  26. // Log next steps: Install dependencies.
  27. const installCommand = ctx.getNpmCommand("install");
  28. console.log(` ${chalk.bold(chalk.green(installCommand))}`);
  29. // Log next steps: Generate Idls and clients.
  30. const generateCommand = ctx.getNpmCommand("generate");
  31. console.log(` ${chalk.bold(chalk.green(generateCommand))}`);
  32. // Final line break.
  33. console.log();
  34. }
  35. function getBanner() {
  36. const textBanner = "Create Solana Program";
  37. const gradientBanner = chalk.bold(
  38. gradient(["#89d7c8", "#dc7a8b"])(textBanner, {
  39. interpolation: "hsv",
  40. hsvSpin: "long",
  41. })
  42. );
  43. return process.stdout.isTTY && process.stdout.getColorDepth() > 8
  44. ? gradientBanner
  45. : textBanner;
  46. }