Skip to content

Commit

Permalink
fix: 'any' type in restart call
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuslbenachio committed Jul 4, 2022
1 parent 5f91aee commit e4d010f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/tcore-api/src/Helpers/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function internalLog(channel: string, ...args: any[]) {
/**
* Logs the "start box" with the localhost and internal ips.
*/
export async function logSystemStart(port?: number | string) {
export async function logSystemStart(port?: number | string | null) {
const systemName = getSystemName();
const systemVers = pkg?.version;

Expand Down
9 changes: 8 additions & 1 deletion packages/tcore-cli/src/Commands/Restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import fs from "fs";
import * as API from "@tago-io/tcore-api";
import chalk from "chalk";
import { IEnvironmentVariables } from "@tago-io/tcore-sdk/types";
import { getSystemName } from "@tago-io/tcore-shared";
import { pm2Connect, pm2Disconnect, pm2Restart, pm2GetApp } from "../Helpers/PM2";
import { log } from "../Helpers/Log";
Expand All @@ -20,12 +21,18 @@ export async function restart() {
const pm2LogPath = path.join(settingsPath, "tcore.log");
await fs.promises.unlink(pm2LogPath).catch(() => null);

// generate a type to access TCORE_PORT without `any`
type Pm2TCoreEnvironment = typeof app.pm2_env & IEnvironmentVariables;

// store the env in a variable to make it easier to access
const env = app.pm2_env as Pm2TCoreEnvironment;

await pm2Restart();

const newApp = await pm2GetApp();
if (newApp) {
log(`${getSystemName()} Server was ${chalk.green("successfully restarted")} with PID`, newApp.pid);
API.logSystemStart((app?.pm2_env as any)?.TCORE_PORT);
API.logSystemStart(env?.TCORE_PORT);
} else {
log(`${getSystemName()} Server ${chalk.redBright("could not be started")}.`);
log(`You can check the logs by running ${chalk.cyan("tcore logs")}`);
Expand Down
12 changes: 12 additions & 0 deletions packages/tcore-sdk/src/Types/Common/Common.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ export const zTagsAutoGen = z
.nullish()
.transform((e) => e ?? []); // use transform instead of `default` because `default` doesn't apply to `null`.

/**
* Environment variables for the application.
*/
export const zEnvironmentVariables = z.object({
TCORE_PORT: z.string().nullish(),
TCORE_DAEMON: z.string().nullish(),
TCORE_PLUGIN_FOLDER: z.string().nullish(),
TCORE_SETTINGS_FOLDER: z.string().nullish(),
TCORE_DATABASE_PLUGIN: z.string().nullish(),
});

export type IEnvironmentVariables = z.infer<typeof zEnvironmentVariables>;
export type TGenericID = string;
export type TGenericToken = string;
export type TDate = Date | number | null;
Expand Down

0 comments on commit e4d010f

Please sign in to comment.