Skip to content

Commit

Permalink
try and rename starship context
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Jun 24, 2024
1 parent f9fac40 commit 9721c2f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
14 changes: 7 additions & 7 deletions clients/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ npm install @starship-ci/client
First, you need to import and initialize the `StarshipClient` with your Helm configuration:

```js
import { StarshipClient } from '@starship-ci/client';
import {StarshipClient} from '@starship-ci/client';

const client = new StarshipClient({
helmName: 'osmojs',
helmFile: 'path/to/config.yaml',
helmRepo: 'starship',
helmRepoUrl: 'https://cosmology-tech.github.io/starship/',
helmChart: 'devnet',
helmVersion: 'v0.2.3'
name: 'osmojs',
config: 'path/to/config.yaml',
repo: 'starship',
repoUrl: 'https://cosmology-tech.github.io/starship/',
chart: 'devnet',
version: 'v0.2.3'
});
```

Expand Down
12 changes: 6 additions & 6 deletions clients/js/packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const loadConfig = (argv: any): Config => {
let starship: StarshipConfig = {} as StarshipConfig;

if (argv.config) {
context.helmFile = argv.config;
context.config = argv.config;
}

console.log("context", context);
Expand All @@ -61,9 +61,9 @@ export const loadConfig = (argv: any): Config => {
}
});

if (context.helmFile) {
context.helmFile = resolvePath(context.helmFile);
starship = loadYaml(context.helmFile) as StarshipConfig
if (context.config) {
context.config = resolvePath(context.config);
starship = loadYaml(context.config) as StarshipConfig
}

console.log("starship: ", starship);
Expand Down Expand Up @@ -91,9 +91,9 @@ Configuration File:
Command-line options will override settings from this file if both are provided.
Command-line Options:
--helmName <name> Specify the Helm release name, default: starship.
--name <name> Specify the Helm release name, default: starship.
Will overide config file settings for name.
--helmVersion <ver> Specify the version of the Helm chart, default: v0.2.3.
--version <ver> Specify the version of the Helm chart, default: v0.2.6.
Will overide config file settings for version.
Examples:
Expand Down
14 changes: 7 additions & 7 deletions clients/js/packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ The `StarshipClient` simplifies managing Kubernetes resources, specifically tail
First, you need to import and initialize the `StarshipClient` with your Helm configuration:

```js
import { StarshipClient } from '@starship-ci/client';
import {StarshipClient} from '@starship-ci/client';

const client = new StarshipClient({
helmName: 'osmojs',
helmFile: 'path/to/config.yaml',
helmRepo: 'starship',
helmRepoUrl: 'https://cosmology-tech.github.io/starship/',
helmChart: 'devnet',
helmVersion: 'v0.2.3'
name: 'osmojs',
config: 'path/to/config.yaml',
repo: 'starship',
repoUrl: 'https://cosmology-tech.github.io/starship/',
chart: 'devnet',
version: 'v0.2.3'
});
```

Expand Down
8 changes: 4 additions & 4 deletions clients/js/packages/client/__tests__/client.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ describe('StarshipClient', () => {
client.dependencies.forEach(dep => dep.installed = true);

client.setConfig(config.config);
const helmFile = client.ctx.helmFile;
client.ctx.helmFile = join(outputDir, 'my-config.yaml');
client.ctx.helmFile = relative(process.cwd(), client.ctx.helmChart)
const helmFile = client.ctx.config;
client.ctx.config = join(outputDir, 'my-config.yaml');
client.ctx.config = relative(process.cwd(), client.ctx.chart)
// @ts-ignore
client.saveYaml = () => {};
client.saveConfig();
client.ctx.helmFile = helmFile;
client.ctx.config = helmFile;

const portYaml = join(outputDir, 'default-pod-ports.yaml');
const relativePortYaml = relative(process.cwd(), portYaml);
Expand Down
64 changes: 32 additions & 32 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import { dependencies as defaultDependencies, Dependency } from "./deps";
import { readAndParsePackageJson } from './package';

export interface StarshipContext {
helmName?: string;
helmFile?: string;
helmRepo?: string;
helmRepoUrl?: string;
helmChart?: string;
helmVersion?: string;
helmNamespace?: string;
name?: string;
config?: string;
repo?: string;
repoUrl?: string;
chart?: string;
version?: string;
namespace?: string;
verbose?: boolean;
curdir?: string;
};

export const defaultStarshipContext: Partial<StarshipContext> = {
helmName: '',
helmRepo: 'starship',
helmRepoUrl: 'https://cosmology-tech.github.io/starship/',
helmChart: 'starship/devnet',
helmNamespace: '',
helmVersion: '',
name: '',
repo: 'starship',
repoUrl: 'https://cosmology-tech.github.io/starship/',
chart: 'starship/devnet',
namespace: '',
version: '',
};

export interface PodPorts {
Expand Down Expand Up @@ -206,13 +206,13 @@ export class StarshipClient implements StarshipClientI {
}

public loadConfig(): void {
this.ensureFileExists(this.ctx.helmFile);
this.config = this.loadYaml(this.ctx.helmFile) as StarshipConfig;
this.ensureFileExists(this.ctx.config);
this.config = this.loadYaml(this.ctx.config) as StarshipConfig;
this.overrideNameAndVersion();
}

public saveConfig(): void {
this.saveYaml(this.ctx.helmFile, this.config);
this.saveYaml(this.ctx.config, this.config);
}

public savePodPorts(filename: string): void {
Expand Down Expand Up @@ -243,11 +243,11 @@ export class StarshipClient implements StarshipClientI {
}

// Override config name and version if provided in context
if (this.ctx.helmName) {
this.config.name = this.ctx.helmName;
if (this.ctx.name) {
this.config.name = this.ctx.name;
}
if (this.ctx.helmVersion) {
this.config.version = this.ctx.helmVersion;
if (this.ctx.version) {
this.config.version = this.ctx.version;
}

// Use default name and version if not provided
Expand All @@ -265,15 +265,15 @@ export class StarshipClient implements StarshipClientI {

public getArgs(): string[] {
const args = [];
if (this.ctx.helmNamespace) {
args.push('--namespace', this.ctx.helmNamespace);
if (this.ctx.namespace) {
args.push('--namespace', this.ctx.namespace);
}
return args;
}

public getDeployArgs(): string[] {
const args = this.getArgs();
if (this.ctx.helmNamespace) {
if (this.ctx.namespace) {
args.push('--create-namespace');
}
return args;
Expand All @@ -285,7 +285,7 @@ export class StarshipClient implements StarshipClientI {
'yarn',
'run',
'jest',
`--testPathPattern=../${this.ctx.helmRepo}`,
`--testPathPattern=../${this.ctx.repo}`,
'--verbose',
'--bail'
]);
Expand All @@ -308,15 +308,15 @@ export class StarshipClient implements StarshipClientI {
'helm',
'repo',
'add',
this.ctx.helmRepo,
this.ctx.helmRepoUrl
this.ctx.repo,
this.ctx.repoUrl
]);
this.exec(['helm', 'repo', 'update']);
this.exec([
'helm',
'search',
'repo',
this.ctx.helmChart,
this.ctx.chart,
'--version',
this.config.version
]);
Expand All @@ -330,24 +330,24 @@ export class StarshipClient implements StarshipClientI {
}

public deploy(options: string[] = []): void {
this.ensureFileExists(this.ctx.helmFile);
this.ensureFileExists(this.ctx.config);
this.log("Installing the helm chart. This is going to take a while.....");

const cmd: string[] = [
'helm',
'install',
'-f',
this.ctx.helmFile,
this.ctx.config,
this.config.name,
this.ctx.helmChart,
this.ctx.chart,
'--version',
this.config.version,
...this.getDeployArgs(),
...options,
];

// Determine the data directory of the config file
const datadir = resolve(dirname(this.ctx.helmFile!));
const datadir = resolve(dirname(this.ctx.config!));

// Iterate through each chain to add script arguments
this.config.chains.forEach((chain, chainIndex) => {
Expand All @@ -367,7 +367,7 @@ export class StarshipClient implements StarshipClientI {
}

public debug(): void {
this.ensureFileExists(this.ctx.helmFile);
this.ensureFileExists(this.ctx.config);
this.deploy(['--dry-run', '--debug']);
}

Expand Down
4 changes: 2 additions & 2 deletions clients/js/packages/client/test-utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const createClient = () => {
};

const client = new StarshipClient({
helmName: 'osmojs',
helmFile: relative(process.cwd(), config.configPath),
name: 'osmojs',
config: relative(process.cwd(), config.configPath),
});

const handler = {
Expand Down

0 comments on commit 9721c2f

Please sign in to comment.