Skip to content
Open
25 changes: 25 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module",
"ecmaVersion": 2021
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-misused-promises": "warn",
"@typescript-eslint/await-thenable": "error",
"no-empty": ["warn", { "allowEmptyCatch": true }],
"no-constant-condition": ["warn", { "checkLoops": false }],
"prefer-const": "warn"
},
"ignorePatterns": ["bin/", "node_modules/", "src/squads_mpl.json", "src/lib/inq/**/*.js"]
}
94 changes: 49 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"description": "",
"main": "bin/index.js",
"scripts": {
"build": "tsc",
"typecheck": "tsc --noEmit",
"lint": "eslint 'src/**/*.ts'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": {
"name": "Sean Ganser",
"email": "sean.ganser@gmail.com",
"url": "https://github.com/ogmedia"
"email": "sean@sqds.io"
},
"keywords": [
"solana",
Expand All @@ -23,46 +25,45 @@
},
"license": "AGPL-3.0-or-later",
"dependencies": {
"@coral-xyz/anchor": "^0.26.0",
"@ledgerhq/errors": "^6.15.0",
"@ledgerhq/hw-app-solana": "^7.0.14",
"@ledgerhq/hw-transport-node-hid-noevents": "^6.28.0",
"@marinade.finance/cli-common": "^2.0.18",
"@marinade.finance/ledger-utils": "^2.0.18",
"@marinade.finance/ts-common": "^2.0.18",
"@marinade.finance/web3js-common": "^2.0.18",
"@metaplex-foundation/js": "^0.18.3",
"@metaplex-foundation/mpl-token-metadata": "^2.13.0",
"@metaplex/js": "^4.12.0",
"@octokit/auth-basic": "^1.4.8",
"@octokit/rest": "^19.0.3",
"@solana/spl-token": "^0.3.6",
"@solana/spl-token-registry": "^0.2.4574",
"@solana/web3.js": "^1.66.2",
"@sqds/sdk": "^2.0.2",
"@types/bn.js": "^5.1.1",
"@types/clear": "^0.1.2",
"@types/clui": "^0.3.1",
"@types/figlet": "^1.5.5",
"@types/lodash": "^4.14.191",
"axios": "1.14.0",
"bn.js": "^5.2.1",
"bs58": "^5.0.0",
"@coral-xyz/anchor": "0.26.0",
"@ledgerhq/errors": "6.15.0",
"@ledgerhq/hw-app-solana": "7.0.14",
"@ledgerhq/hw-transport-node-hid-noevents": "6.28.0",
"@marinade.finance/cli-common": "2.0.18",
"@marinade.finance/ledger-utils": "2.0.18",
"@marinade.finance/ts-common": "2.0.18",
"@marinade.finance/web3js-common": "2.0.18",
"@metaplex-foundation/js": "0.20.1",
"@metaplex-foundation/mpl-token-metadata": "2.13.0",
"@octokit/auth-basic": "1.4.8",
"@octokit/rest": "20.0.2",
"@solana/spl-token": "0.3.6",
"@solana/spl-token-registry": "0.2.4574",
"@solana/web3.js": "1.98.1",
"@sqds/sdk": "2.0.2",
"@types/bn.js": "5.1.1",
"@types/clear": "0.1.2",
"@types/clui": "0.3.1",
"@types/figlet": "1.5.5",
"@types/lodash": "4.14.191",
"axios": "1.15.2",
"bn.js": "5.2.3",
"bs58": "5.0.0",
"chalk": "4.1.2",
"clear": "^0.1.0",
"clui": "^0.3.6",
"configstore": "^6.0.0",
"console.table": "^0.10.0",
"figlet": "^1.5.2",
"inquirer": "8.0.0",
"clui": "0.3.6",
"configstore": "6.0.0",
"console.table": "0.10.0",
"figlet": "1.5.2",
"inquirer": "8.2.7",
"inquirer-press-to-continue": "1.1.4",
"lodash": "^4.17.21",
"minimist": "^1.2.6",
"simple-git": "^3.10.0",
"touch": "^3.1.0",
"tslib": "^2.5.0",
"typescript": "^4.9.5",
"yargs": "^17.6.2"
"lodash": "4.18.0",
"minimist": "1.2.6",
"simple-git": "3.36.0",
"touch": "3.1.0",
"tslib": "2.5.0",
"typescript": "4.9.5",
"yargs": "17.6.2"
},
"bin": {
"squads-cli": "./bin/index.js"
Expand All @@ -72,14 +73,17 @@
"node": ">=16.0.0"
},
"devDependencies": {
"@types/inquirer": "^9.0.3",
"@types/node": "^18.14.6",
"@types/yargs": "^17.0.22",
"ts-node": "^10.9.1"
"@types/inquirer": "9.0.3",
"@types/node": "18.14.6",
"@types/yargs": "17.0.22",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"eslint": "8.57.0",
"ts-node": "10.9.1"
},
"resolutions": {
"@solana/web3.js": "^1.66.2",
"@solana/spl-token": "^0.3.6",
"@solana/web3.js": "1.66.2",
"@solana/spl-token": "0.3.6",
"inquirer-press-to-continue": "1.1.4"
}
}
36 changes: 31 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import clear from 'clear';
import chalk from 'chalk';
import { readFileSync } from 'fs';
import { join } from 'path';

import Menu from "./lib/menu.js";
import CliWallet from './lib/wallet.js';
Expand All @@ -11,7 +13,11 @@ import yargs from 'yargs';
import {hideBin} from 'yargs/helpers'
import {parseLedgerWallet} from "@marinade.finance/ledger-utils";

const VERSION = "2.1.3";
// Read package.json at runtime so --version stays in sync with the published
// package. __dirname points at the compiled bin/ directory, so ../package.json
// resolves whether installed globally (node_modules/@sqds/cli) or run from src.
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf8")) as { version: string };
const VERSION = pkg.version;

const argv = yargs(hideBin(process.argv)).options({
cluster: { type: 'string'},
Expand All @@ -30,8 +36,13 @@ const load = async (
clear();
console.log(chalk.yellow('Starting Squads CLI...') + " Follow the prompts to get started")
const {walletPath} = await SetupWallet();
const ledgerWallet = await parseLedgerWallet(walletPath)
const cliWallet = new CliWallet(walletPath, ledgerWallet, computeUnitPrice);
// parseLedgerWallet matches only the literal "usb://ledger" prefix; normalize
// case so "USB://Ledger" etc. is also detected as a ledger URL.
const normalizedWalletPath = walletPath.toLowerCase().startsWith("usb://ledger")
? "usb://ledger" + walletPath.slice("usb://ledger".length)
: walletPath;
const ledgerWallet = await parseLedgerWallet(normalizedWalletPath);
const cliWallet = new CliWallet(normalizedWalletPath, ledgerWallet, computeUnitPrice);
let cliConnection;
if(!initCluster){
const {cluster} = await SetupCluster();
Expand All @@ -40,9 +51,9 @@ const load = async (
cliConnection = new CliConnection(initCluster);
}

// start the menu
// start the menu state machine
const cli = new Menu(cliWallet, cliConnection, programId, programManagerId, txMetaProgramId);
cli.top();
await cli.run();
};

const help = async () => {
Expand Down Expand Up @@ -72,6 +83,21 @@ if (typeof argv.computeUnitPrice == "number") {
computeUnitPrice = argv.computeUnitPrice;
}

// Graceful exit on Ctrl+C — inquirer 8 throws ExitPromptError on SIGINT which
// otherwise surfaces as an ugly unhandled rejection.
process.on("SIGINT", () => {
console.log(chalk.blue("\nGoodbye!"));
process.exit(0);
});
process.on("unhandledRejection", (reason) => {
const msg = reason instanceof Error ? reason.message : String(reason);
if (/ExitPromptError|force closed the prompt/i.test(msg)) {
process.exit(0);
}
console.error(chalk.red("\nUnexpected error:"), reason);
process.exit(1);
});

if (argv.help){
help();
}else if (argv.version || argv.v){
Expand Down
Loading
Loading