Skip to content

Commit

Permalink
fix: env in local config
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Feb 29, 2024
1 parent 37d8db7 commit 9b97ed5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/commands/env/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SwankyCommand } from "../../lib/swankyCommand.js";
import { InputError } from "../../lib/errors.js";
import { installCliDevDeps } from "../../lib/tasks.js";
import { SUPPORTED_DEPS } from "../../lib/consts.js";
import { DependencyName, getSwankyConfig } from "../../index.js";
import { DependencyName, SwankyConfig, getSwankyConfig } from "../../index.js";
import { ConfigBuilder } from "../../lib/config-builder.js";

export class Install extends SwankyCommand<typeof Install> {
Expand Down Expand Up @@ -50,9 +50,10 @@ export class Install extends SwankyCommand<typeof Install> {
newDeps[key] = value || "latest";
}

const globalConfig = getSwankyConfig("global");
const newEnv = { ...globalConfig.env, ...newDeps };
const localConfig = getSwankyConfig("local") as SwankyConfig;
const newEnv = { ...localConfig.env, ...newDeps };
const deps = Object.entries(newEnv);

for (const [dep, version] of deps) {
const typedDep = dep as DependencyName;
await this.spinner.runCommand(
Expand All @@ -63,10 +64,10 @@ export class Install extends SwankyCommand<typeof Install> {

if (Object.keys(newDeps).length > 0) {
await this.spinner.runCommand(async () => {
const newLocalConfig = new ConfigBuilder(getSwankyConfig("global"))
const newLocalConfig = new ConfigBuilder(getSwankyConfig("local"))
.updateEnv(newDeps)
.build();
await this.storeConfig(newLocalConfig, "global");
await this.storeConfig(newLocalConfig, "local");
}, "Updating swanky config");
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/config-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class ConfigBuilder<T extends SwankySystemConfig | SwankyConfig> {
}

updateEnv(env: Record<string, string>): ConfigBuilder<T> {
this.config.env = {...this.config.env, ...env};
if ("env" in this.config) {
this.config.env = {...this.config.env, ...env};
}
return this;
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/swankyCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export abstract class SwankyCommand<T extends typeof Command> extends Command {
defaultAccount: newConfig.defaultAccount,
accounts: newConfig.accounts,
networks: newConfig.networks,
env: newConfig.env,
};
}
if (existsSync(configPath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export interface SwankyConfig extends SwankySystemConfig{
};
contracts: Record<string, ContractData> | Record<string, never>;
zombienet?: ZombienetData;
env: Record<string, string>;
}

export interface SwankySystemConfig {
defaultAccount: string | null;
accounts: AccountData[];
networks: Record<string, {url: string}>;
env: Record<string, string>;
}

export interface ZombienetData {
Expand Down

0 comments on commit 9b97ed5

Please sign in to comment.