Skip to content

Commit

Permalink
Improve reading of hypermode settings file (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Oct 24, 2024
1 parent b090e06 commit 5089ef7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ In previous releases, the name "Hypermode" was used for all three._
- Highlight endpoints when running in dev [#490](https://github.com/hypermodeinc/modus/pull/490)
- Fix data race in logging adapter [#491](https://github.com/hypermodeinc/modus/pull/491)
- Add Anthropic model interface to the Go SDK [#493](https://github.com/hypermodeinc/modus/pull/493)
- Move hyp settings for local model invocation to env variables [#495](https://github.com/hypermodeinc/modus/pull/495)
- Move hyp settings for local model invocation to env variables [#495](https://github.com/hypermodeinc/modus/pull/495) [#504](https://github.com/hypermodeinc/modus/pull/504)
- Change GraphQL SDK examples to use a generic public GraphQL API [#501](https://github.com/hypermodeinc/modus/pull/501)

## 2024-10-02 - Version 0.12.7
Expand Down
10 changes: 5 additions & 5 deletions cli/src/commands/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as installer from "../../util/installer.js";
import { getHeader } from "../../custom/header.js";
import { getAppInfo } from "../../util/appinfo.js";
import { isOnline, withSpinner } from "../../util/index.js";
import { readSettingsJson } from "../../util/hypermode.js";
import { readHypermodeSettings } from "../../util/hypermode.js";
import BuildCommand from "../build/index.js";

export default class DevCommand extends Command {
Expand Down Expand Up @@ -144,14 +144,14 @@ export default class DevCommand extends Command {
await BuildCommand.run([appPath, "--no-logo"]);

// read from settings.json if it exists, load env vars into env
const settings = await readSettingsJson();
const hypSettings = await readHypermodeSettings();

const env = {
...process.env,
MODUS_ENV: "dev",
HYP_EMAIL: settings.email,
HYP_JWT: settings.jwt,
HYP_ORG_ID: settings.orgId,
HYP_EMAIL: hypSettings.email,
HYP_JWT: hypSettings.jwt,
HYP_ORG_ID: hypSettings.orgId,
};

const runtime = spawn(runtimePath, ["-appPath", path.join(appPath, "build")], {
Expand Down
35 changes: 16 additions & 19 deletions cli/src/util/hypermode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,36 @@
* SPDX-License-Identifier: Apache-2.0
*/

import os from "node:os";
import * as path from "node:path";
import * as fs from "node:fs";
import * as utils from "./fs.js";
import * as fs from "./fs.js";
import chalk from "chalk";

function getHypEnvDir(): string {
return path.join(process.env.HOME || "", ".hypermode");
}

function getSettingsFilePath(): string {
return path.join(getHypEnvDir(), "settings.json");
}

type HypSettings = {
email?: string;
jwt?: string;
orgId?: string;
};

export async function readSettingsJson(): Promise<HypSettings> {
export async function readHypermodeSettings(): Promise<HypSettings> {
const path = getSettingsFilePath();
const content = await utils.readFile(path, "utf-8");

const settings: HypSettings = {};
if (!(await fs.exists(path))) {
return {};
}

try {
const jsonContent = JSON.parse(content);
settings.email = jsonContent.HYP_EMAIL;
settings.jwt = jsonContent.HYP_JWT;
settings.orgId = jsonContent.HYP_ORG_ID;
const settings = JSON.parse(await fs.readFile(path, "utf-8"));
return {
email: settings.HYP_EMAIL,
jwt: settings.HYP_JWT,
orgId: settings.HYP_ORG_ID,
};
} catch (e) {
console.warn(chalk.yellow("Error reading " + path), e);
return {};
}
}

return settings;
function getSettingsFilePath(): string {
return path.join(os.homedir(), ".hypermode", "settings.json");
}

0 comments on commit 5089ef7

Please sign in to comment.