Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: try and rename starship context #501

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions clients/js/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.json
*.md
*.css
*.d.ts

node_modules/
dist/
main/
module/
coverage/
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
2 changes: 2 additions & 0 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"clean": "lerna run clean",
"build": "lerna run build --stream",
"symlink": "symlink-workspace --logLevel error",
"lint": "lerna run lint",
"format": "lerna run format",
"postinstall": "yarn symlink",
"publish": "yarn build; yarn lerna publish --no-private",
"publish:minor": "yarn build; yarn lerna publish minor --no-private"
Expand Down
6 changes: 6 additions & 0 deletions clients/js/packages/cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
main/
module/
coverage/
prompt.js
2 changes: 2 additions & 0 deletions clients/js/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy; npm run chmod",
"chmod": "chmod +x dist/index.js",
"dev": "ts-node src/index",
"lint": "eslint .",
"format": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch"
},
Expand Down
2 changes: 1 addition & 1 deletion clients/js/packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StarshipClient, StarshipInstaller } from '@starship-ci/client'; // Adju
import { Inquirerer, type Question } from 'inquirerer';
import minimist from 'minimist';

import { displayUsage, displayVersion, loadConfig, usageText, params } from './utils';
import { displayUsage, displayVersion, loadConfig, params,usageText } from './utils';

const argv = minimist(process.argv.slice(2), {
alias: {
Expand Down
28 changes: 13 additions & 15 deletions clients/js/packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {defaultStarshipContext, StarshipConfig, StarshipContext} from '@starship-ci/client'; // Adjust the import path as necessary
import { type Question } from 'inquirerer';
import chalk from 'chalk';
import {readFileSync} from 'fs';
import * as yaml from 'js-yaml';
import {dirname, resolve} from 'path';
import { resolve} from 'path';

import {readAndParsePackageJson} from './package';
import deepmerge from 'deepmerge';

// Function to display the version information
export function displayVersion() {
Expand All @@ -32,12 +30,12 @@ export interface Config {
}

export const params: string[] = [
'helmName',
'helmVersion',
'helmRepo',
'helmRepoUrl',
'helmChart',
'helmNamespace',
'name',
'version',
'repo',
'repoUrl',
'chart',
'namespace',
]

export const loadConfig = (argv: any): Config => {
Expand All @@ -47,7 +45,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 +59,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 +89,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
6 changes: 6 additions & 0 deletions clients/js/packages/client/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
main/
module/
coverage/
prompt.js
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
2 changes: 2 additions & 0 deletions clients/js/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"clean": "del dist/**",
"prepare": "npm run build",
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
"lint": "eslint .",
"format": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch"
},
Expand Down
66 changes: 33 additions & 33 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ import * as os from 'os';
import { dirname, resolve } from 'path';
import * as shell from 'shelljs';

import {Chain, Relayer, Script, StarshipConfig} from './config';
import {Chain, Relayer, StarshipConfig} from './config';
import { Ports } from './config';
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
6 changes: 6 additions & 0 deletions clients/js/packages/starshipjs/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
main/
module/
coverage/
prompt.js
2 changes: 1 addition & 1 deletion clients/js/packages/starshipjs/__tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainRegistryFetcher } from "@chain-registry/client";
import path from "path";

import { Config, ConfigContext } from "../src/config";
import { ChainRegistryFetcher } from "@chain-registry/client";

// it's more recommended to use ConfigContext.init to set the config file and registry.
it("1. throws without init;\n 2. init the setup and gets config;\n 3. throws when double init;\n", async () => {
Expand Down
4 changes: 2 additions & 2 deletions clients/js/packages/starshipjs/__tests__/legacy.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainRegistryFetcher } from "@chain-registry/client";
import path from "path";

import { Config, ConfigContext } from "../src/config";
import { ChainRegistryFetcher } from "@chain-registry/client";
import { ConfigContext } from "../src/config";

// people can still use legacy ConfigContext to set the config file and registry.
it("1. throws without init;\n 2. throws only init partially;\n 3. init the setup and gets config;\n 4. throws when double init;\n", async () => {
Expand Down
Loading