genezio
Version:
Command line utility to interact with Genezio infrastructure.
55 lines (54 loc) • 2.65 kB
JavaScript
import { log } from "../utils/logging.js";
import { GenezioCommand } from "../utils/reporter.js";
import colors from "colors";
import boxen from "boxen";
import { getGlobalPackageManager } from "../packageManagers/packageManager.js";
import { Language, TriggerType } from "../projectConfiguration/yaml/models.js";
import { UserError } from "../errors.js";
export function reportSuccessForSdk(language, sdkResponse, command, projectConfiguration) {
switch (language) {
case Language.ts:
case Language.js:
return reportSuccessForSdkJs(sdkResponse, command, projectConfiguration);
case Language.go:
case Language.kt:
case Language.dart:
case Language.swift:
case Language.python:
case Language.pythonAsgi:
return reportSuccessForSdkOtherLanguages();
default:
throw new UserError("Language not supported");
}
}
export function reportSuccessForSdkOtherLanguages() {
log.info("Your SDK has been generated successfully");
}
export function reportSuccessForSdkJs(sdkResponse, command, projectConfiguration) {
const className = sdkResponse.sdkGeneratorInput.classesInfo.find((c) => c.classConfiguration.type === TriggerType.jsonrpc)?.classConfiguration.name;
// No JSON RPC class means that no SDK was generated. We can skip
// all the info regarding SDK.
if (!className) {
return;
}
if (command === GenezioCommand.deploy) {
log.info(boxen(`${colors.green("To install the SDK in your client, run this command in your client's root:")}\n${colors.magenta(`${getGlobalPackageManager().command} add @genezio-sdk/${projectConfiguration.name}@1.0.0-${projectConfiguration.stage}`)}\n\n${colors.green("Then import your classes like this:")}\n${colors.magenta(`import { ${className} } from "@genezio-sdk/${projectConfiguration.name}"`)}`, {
padding: 1,
margin: 1,
borderStyle: "round",
borderColor: "magentaBright",
}));
}
else if (command === GenezioCommand.local) {
log.info(boxen(`${colors.green("Import your classes like this:")}\n${colors.magenta(`import { ${className} } from "@genezio-sdk/${projectConfiguration.name}"`)}`, {
padding: 1,
margin: 1,
borderStyle: "round",
borderColor: "magentaBright",
}));
}
else {
log.info("Your SDK has been generated successfully");
log.info(`You can now publish it to npm using ${colors.cyan(`'npm publish'`)} in the sdk directory or use it locally in your project using ${colors.cyan(`'npm link'`)}`);
}
}