This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
651d3e6
commit 84f5dd6
Showing
19 changed files
with
546 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
helmFile: ./config.yaml | ||
helmRepo: starship | ||
helmRepoUrl: https://cosmology-tech.github.io/starship/ | ||
helmChart: devnet | ||
helmVersion: v0.1.38 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Starship CLI | ||
|
||
<p align="center"> | ||
<img src="https://user-images.githubusercontent.com/10805402/242348990-c141d6cd-e1c9-413f-af68-283de029c3a4.png" width="80"><br /> | ||
StarshipJS enables developers to efficiently set up and test chains, explorers, and validators, making it easier to handle development projects spanning several blockchain networks. | ||
</p> | ||
|
||
<p align="center" width="100%"> | ||
<a href="https://github.com/cosmology-tech/starshipjs/actions/workflows/run-tests.yml"> | ||
<img height="20" src="https://github.com/cosmology-tech/starshipjs/actions/workflows/run-tests.yml/badge.svg" /> | ||
</a> | ||
<a href="https://github.com/cosmology-tech/starshipjs/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a> | ||
</p> | ||
|
||
**`starship`** is the command-line interface designed to deploy and manage [Starship](https://cosmology.zone/products/starship), catering specifically to Node.js and TypeScript developers. This CLI tool offers a seamless and intuitive interface that dramatically simplifies the development, testing, and deployment of interchain applications across both local environments and CI/CD pipelines. | ||
|
||
Designed with simplicity and speed in mind, **Starship** enables developers to quickly integrate Starship into their blockchain projects without complex orchestration. | ||
|
||
## Table of contents | ||
|
||
- [StarshipJS](#starshipjs) | ||
- [Table of contents](#table-of-contents) | ||
- [Install](#install) | ||
- [Examples](#examples) | ||
- [Commands](#commands) | ||
- [Options](#options) | ||
- [Developing](#developing) | ||
- [Credits](#credits) | ||
|
||
## install | ||
|
||
Install `@starship-ci/cli` globally to use the `starship` command: | ||
|
||
```sh | ||
npm install -g @starship-ci/cli | ||
``` | ||
|
||
## Examples | ||
|
||
Here are some common usages of the starship CLI: | ||
|
||
```sh | ||
starship deploy --helmFile ./config/helm.yaml --helmName my-release | ||
starship undeploy --config ./config/settings.json | ||
starship setupKind | ||
starship startPortForward | ||
starship stopPortForward | ||
starship upgrade | ||
starship teardown | ||
starship clean | ||
``` | ||
|
||
## Commands | ||
|
||
Here's a concise overview of the commands available in the `starship` CLI: | ||
|
||
|
||
| Command | Description | | ||
| ---------------- | ----------------------------------------------- | | ||
| `deploy` | Deploy starship using specified options or configuration file. | | ||
| `setup` | Setup initial configuration and dependencies. | | ||
| `startPortForward` | Start port forwarding for the deployed services. | | ||
| `stopPortForward` | Stop port forwarding. | | ||
| `teardown` | Remove all components related to the deployment. | | ||
| `upgrade` | Upgrade the deployed application to a new version. | | ||
| `undeploy` | Remove starship deployment using specified options or configuration file. | | ||
| `cleanKind` | Clean up Kubernetes kind cluster resources. | | ||
| `deleteHelm` | Delete a specific Helm release. | | ||
| `removeHelm` | Remove Helm chart from local configuration. | | ||
| `setupKind` | Setup a Kubernetes kind cluster for development. | | ||
| `clean` | Perform a clean operation to tidy up resources. | | ||
| `version`, `-v` | Display the version of the Starship Client. | | ||
|
||
## Options | ||
|
||
Options in the CLI allow for dynamic configuration of `starship`. You can specify individual options directly in the command line to fine-tune the behavior of the tool. Alternatively, you can use the `--config` option to specify a YAML configuration file that sets up the initial parameters. If both methods are used, any options provided directly in the command line will override the corresponding settings in the configuration file, giving you the flexibility to customize specific aspects of the deployment without altering the entire configuration. | ||
|
||
| Option | Description | | ||
|--------------------|-------------------------------------------------------| | ||
| `--config <path>` | Specify the path to the JSON configuration file containing all settings. | | ||
| `--helmFile <path>`| Specify the path to the Helm file. | | ||
| `--helmName <name>`| Specify the Helm release name. | | ||
| `--helmRepo <repo>`| Specify the Helm repository. | | ||
| `--helmRepoUrl <url>` | Specify the Helm repository URL. | | ||
| `--helmChart <chart>` | Specify the Helm chart. | | ||
| `--helmVersion <ver>` | Specify the version of the Helm chart. | | ||
| `--kindCluster <name>` | Specify the name of the Kubernetes kind cluster. | | ||
| `--verbose` | Enable verbose output for debugging purposes. | | ||
| `--curdir <dir>` | Specify the current working directory of the operation. | | ||
|
||
|
||
## Developing | ||
|
||
When first cloning the repo: | ||
``` | ||
yarn | ||
yarn build | ||
``` | ||
|
||
## Related | ||
|
||
Checkout these related projects: | ||
|
||
* [@cosmology/telescope](https://github.com/cosmology-tech/telescope) Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. | ||
* [@cosmwasm/ts-codegen](https://github.com/CosmWasm/ts-codegen) Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. | ||
* [chain-registry](https://github.com/cosmology-tech/chain-registry) Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application. | ||
* [cosmos-kit](https://github.com/cosmology-tech/cosmos-kit) Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface. | ||
* [create-cosmos-app](https://github.com/cosmology-tech/create-cosmos-app) Set up a modern Cosmos app by running one command. | ||
* [interchain-ui](https://github.com/cosmology-tech/interchain-ui) The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit. | ||
* [starship](https://github.com/cosmology-tech/starship) Unified Testing and Development for the Interchain. | ||
|
||
## Credits | ||
|
||
🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.zone/validator) | ||
|
||
|
||
## Disclaimer | ||
|
||
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND. | ||
|
||
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.tsx?$": [ | ||
"ts-jest", | ||
{ | ||
babelConfig: false, | ||
tsconfig: "tsconfig.json", | ||
}, | ||
], | ||
}, | ||
transformIgnorePatterns: [`/node_modules/*`], | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
modulePathIgnorePatterns: ["dist/*"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "@starship-ci/cli", | ||
"version": "0.1.0", | ||
"author": "Dan Lynch <[email protected]>", | ||
"description": "Starship CLI", | ||
"main": "index.js", | ||
"module": "esm/index.js", | ||
"types": "index.d.ts", | ||
"homepage": "https://github.com/cosmology-tech/starshipjs", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cosmology-tech/starshipjs" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/cosmology-tech/starshipjs/issues" | ||
}, | ||
"bin": { | ||
"starship": "./index.js" | ||
}, | ||
"scripts": { | ||
"copy": "copyfiles -f ../../LICENSE README.md package.json dist", | ||
"clean": "del dist/**", | ||
"prepare": "npm run build", | ||
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy", | ||
"dev": "ts-node src/index", | ||
"test": "jest", | ||
"test:watch": "jest --watch" | ||
}, | ||
"keywords": [ | ||
"blockchain", | ||
"blockchain-simulation", | ||
"blockchain-testing", | ||
"TDD", | ||
"multi-chain", | ||
"crypto", | ||
"cryptocurrency", | ||
"ethereum", | ||
"bitcoin", | ||
"cosmos", | ||
"smart-contracts", | ||
"decentralized", | ||
"DApps", | ||
"web3", | ||
"interchain" | ||
], | ||
"devDependencies": { | ||
"@types/js-yaml": "^4.0.9" | ||
}, | ||
"dependencies": { | ||
"@starship-ci/client": "^0.1.2", | ||
"chalk": "^4.1.0", | ||
"deepmerge": "^4.3.1", | ||
"js-yaml": "^4.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env node | ||
import { StarshipClient } from '@starship-ci/client'; // Adjust the import path as necessary | ||
import minimist from 'minimist'; | ||
|
||
import { Inquirerer, type Question } from './prompt'; | ||
import { displayUsage, displayVersion, loadConfig } from './utils'; | ||
|
||
const argv = minimist(process.argv.slice(2), { | ||
alias: { | ||
v: 'version' | ||
} | ||
}); | ||
|
||
if (argv.version) { | ||
displayVersion(); | ||
process.exit(0); | ||
} | ||
|
||
const prompter = new Inquirerer(); | ||
|
||
const questions: Question[] = [ | ||
'helmName', | ||
'helmFile', | ||
'helmRepo', | ||
'helmRepoUrl', | ||
'helmChart', | ||
'helmVersion' | ||
].map(name => ({ name })); | ||
|
||
// Main function to run the application | ||
async function main() { | ||
const command: string = argv._[0]; | ||
|
||
// Display usage and exit early if no command or help command is provided | ||
if (!command || command === 'help') { | ||
displayUsage(); | ||
prompter.close(); | ||
return; | ||
} | ||
|
||
// Load configuration and prompt for missing parameters | ||
const config = loadConfig(argv); | ||
const args = await prompter.prompt({ ...config.context }, questions); | ||
|
||
const client = new StarshipClient(args); | ||
client.setConfig(config.starship); | ||
|
||
// Mocking the exec method for demonstration purposes | ||
// @ts-ignore | ||
client.exec = (cmd: string) => console.log(cmd); | ||
|
||
// Execute command based on input | ||
switch (command) { | ||
case 'deploy': | ||
client.deploy(); | ||
break; | ||
case 'setup': | ||
client.setup(); | ||
break; | ||
case 'startPortForward': | ||
client.startPortForward(); | ||
break; | ||
case 'stopPortForward': | ||
client.stopPortForward(); | ||
break; | ||
case 'teardown': | ||
client.teardown(); | ||
break; | ||
case 'upgrade': | ||
client.upgrade(); | ||
break; | ||
case 'undeploy': | ||
client.undeploy(); | ||
break; | ||
case 'cleanKind': | ||
client.cleanKind(); | ||
break; | ||
case 'deleteHelm': | ||
client.deleteHelm(); | ||
break; | ||
case 'removeHelm': | ||
client.removeHelm(); | ||
break; | ||
case 'setupKind': | ||
client.setupKind(); | ||
break; | ||
case 'clean': | ||
client.clean(); | ||
break; | ||
default: | ||
console.log(`Unknown command: ${command}`); | ||
displayUsage(); | ||
} | ||
|
||
prompter.close(); | ||
} | ||
|
||
// Improved error handling | ||
main().catch(err => { | ||
console.error('An error occurred:', err); | ||
prompter.close(); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { existsSync,readFileSync } from "fs"; | ||
import { dirname,join } from "path"; | ||
|
||
// need to search due to the dist/ folder and src/, etc. | ||
function findPackageJson(currentDir: string) { | ||
const filePath = join(currentDir, 'package.json'); | ||
|
||
// Check if package.json exists in the current directory | ||
if (existsSync(filePath)) { | ||
return filePath; | ||
} | ||
|
||
// Get the parent directory | ||
const parentDir = dirname(currentDir); | ||
|
||
// If reached the root directory, package.json is not found | ||
if (parentDir === currentDir) { | ||
throw new Error('package.json not found in any parent directory'); | ||
} | ||
|
||
// Recursively look in the parent directory | ||
return findPackageJson(parentDir); | ||
} | ||
|
||
export function readAndParsePackageJson() { | ||
// Start searching from the current directory | ||
const pkgPath = findPackageJson(__dirname); | ||
|
||
// Read and parse the package.json | ||
const str = readFileSync(pkgPath, 'utf8'); | ||
const pkg = JSON.parse(str); | ||
return pkg; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import readline from 'readline'; | ||
|
||
export interface Question { | ||
name: string; | ||
type?: string; // This can be used for further customizations like validating input based on type | ||
} | ||
|
||
export class Inquirerer { | ||
private rl: readline.Interface; | ||
|
||
constructor() { | ||
this.rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
} | ||
|
||
// Method to prompt for missing parameters | ||
public async prompt<T extends object>(params: T, questions: Question[]): Promise<T> { | ||
const obj: any = { ...params }; | ||
|
||
for (const question of questions) { | ||
if (obj[question.name] === undefined) { | ||
obj[question.name] = await new Promise<string>((resolve) => { | ||
this.rl.question(`Enter ${question.name}: `, resolve); | ||
}); | ||
} | ||
} | ||
|
||
return obj as T; | ||
} | ||
|
||
// Method to cleanly close the readline interface | ||
public close() { | ||
this.rl.close(); | ||
} | ||
} |
Oops, something went wrong.