getLogs.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 logStep(message: string) {
  15. console.log(chalk.blue("➤") + ` ${message}`);
  16. }
  17. export function logDone(ctx: RenderContext) {
  18. console.log(chalk.green("✔︎") + ` ${ctx.language.infos.done}\n`);
  19. // Log next steps: Cd into the target directory.
  20. if (ctx.targetDirectory !== ctx.currentDirectory) {
  21. const cdCommand = `cd ${ctx.targetDirectoryName.includes(" ") ? `"${ctx.targetDirectoryName}"` : ctx.targetDirectoryName}`;
  22. console.log(` ${chalk.bold(chalk.green(cdCommand))}`);
  23. }
  24. // Log next steps: Install dependencies.
  25. const installCommand = ctx.getNpmCommand("install");
  26. console.log(` ${chalk.bold(chalk.green(installCommand))}`);
  27. // Log next steps: Generate Idls and clients.
  28. const generateCommand = ctx.getNpmCommand("generate");
  29. console.log(` ${chalk.bold(chalk.green(generateCommand))}`);
  30. // Final line break.
  31. console.log();
  32. }
  33. function getBanner() {
  34. const textBanner = "Create Solana Program";
  35. const gradientBanner = chalk.bold(
  36. gradient(["#89d7c8", "#dc7a8b"])(textBanner, {
  37. interpolation: "hsv",
  38. hsvSpin: "long",
  39. })
  40. );
  41. return process.stdout.isTTY && process.stdout.getColorDepth() > 8
  42. ? gradientBanner
  43. : textBanner;
  44. }