@elytro/cli 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +132 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4221,9 +4221,139 @@ function registerConfigCommand(program2, ctx) {
|
|
|
4221
4221
|
});
|
|
4222
4222
|
}
|
|
4223
4223
|
|
|
4224
|
+
// src/commands/update.ts
|
|
4225
|
+
import { execSync } from "child_process";
|
|
4226
|
+
|
|
4227
|
+
// src/version.ts
|
|
4228
|
+
import { createRequire } from "module";
|
|
4229
|
+
function resolveVersion() {
|
|
4230
|
+
if (true) {
|
|
4231
|
+
return "0.5.0";
|
|
4232
|
+
}
|
|
4233
|
+
try {
|
|
4234
|
+
const require2 = createRequire(import.meta.url);
|
|
4235
|
+
const pkg = require2("../package.json");
|
|
4236
|
+
return pkg.version;
|
|
4237
|
+
} catch {
|
|
4238
|
+
return "0.0.0";
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
var VERSION = resolveVersion();
|
|
4242
|
+
|
|
4243
|
+
// src/commands/update.ts
|
|
4244
|
+
import ora6 from "ora";
|
|
4245
|
+
import chalk2 from "chalk";
|
|
4246
|
+
import { realpathSync } from "fs";
|
|
4247
|
+
import { fileURLToPath } from "url";
|
|
4248
|
+
var PACKAGE_NAME = "@elytro/cli";
|
|
4249
|
+
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
|
|
4250
|
+
async function fetchLatestVersion() {
|
|
4251
|
+
const res = await fetch(NPM_REGISTRY_URL);
|
|
4252
|
+
if (!res.ok) {
|
|
4253
|
+
throw new Error(`npm registry returned ${res.status}`);
|
|
4254
|
+
}
|
|
4255
|
+
const data = await res.json();
|
|
4256
|
+
return data.version;
|
|
4257
|
+
}
|
|
4258
|
+
function compareSemver(a, b) {
|
|
4259
|
+
const pa = a.split(".").map(Number);
|
|
4260
|
+
const pb = b.split(".").map(Number);
|
|
4261
|
+
for (let i = 0; i < 3; i++) {
|
|
4262
|
+
if ((pa[i] ?? 0) < (pb[i] ?? 0)) return -1;
|
|
4263
|
+
if ((pa[i] ?? 0) > (pb[i] ?? 0)) return 1;
|
|
4264
|
+
}
|
|
4265
|
+
return 0;
|
|
4266
|
+
}
|
|
4267
|
+
function detectPackageManager() {
|
|
4268
|
+
try {
|
|
4269
|
+
const scriptPath = realpathSync(fileURLToPath(import.meta.url));
|
|
4270
|
+
if (scriptPath.includes("/.bun/")) return "bun";
|
|
4271
|
+
if (scriptPath.includes("/pnpm/") || scriptPath.includes("/pnpm-global/"))
|
|
4272
|
+
return "pnpm";
|
|
4273
|
+
if (scriptPath.includes("/yarn/global/")) return "yarn";
|
|
4274
|
+
} catch {
|
|
4275
|
+
}
|
|
4276
|
+
const ua = process.env.npm_config_user_agent ?? "";
|
|
4277
|
+
if (ua.startsWith("bun")) return "bun";
|
|
4278
|
+
if (ua.startsWith("pnpm")) return "pnpm";
|
|
4279
|
+
if (ua.startsWith("yarn")) return "yarn";
|
|
4280
|
+
return "npm";
|
|
4281
|
+
}
|
|
4282
|
+
function buildInstallCommand(pm, version) {
|
|
4283
|
+
const pkg = `${PACKAGE_NAME}@${version}`;
|
|
4284
|
+
switch (pm) {
|
|
4285
|
+
case "yarn":
|
|
4286
|
+
return `yarn global add ${pkg}`;
|
|
4287
|
+
case "pnpm":
|
|
4288
|
+
return `pnpm add -g ${pkg}`;
|
|
4289
|
+
case "bun":
|
|
4290
|
+
return `bun add -g ${pkg}`;
|
|
4291
|
+
default:
|
|
4292
|
+
return `npm install -g ${pkg}`;
|
|
4293
|
+
}
|
|
4294
|
+
}
|
|
4295
|
+
function registerUpdateCommand(program2) {
|
|
4296
|
+
const updateCmd = program2.command("update").alias("upgrade").description("Check for updates and upgrade to the latest version");
|
|
4297
|
+
updateCmd.command("check").description("Check if a newer version is available (no install)").action(async () => {
|
|
4298
|
+
try {
|
|
4299
|
+
const latest = await fetchLatestVersion();
|
|
4300
|
+
const cmp = compareSemver(VERSION, latest);
|
|
4301
|
+
outputResult({
|
|
4302
|
+
currentVersion: VERSION,
|
|
4303
|
+
latestVersion: latest,
|
|
4304
|
+
updateAvailable: cmp < 0,
|
|
4305
|
+
...cmp < 0 ? {
|
|
4306
|
+
upgradeCommand: buildInstallCommand(
|
|
4307
|
+
detectPackageManager(),
|
|
4308
|
+
latest
|
|
4309
|
+
)
|
|
4310
|
+
} : {}
|
|
4311
|
+
});
|
|
4312
|
+
} catch (err) {
|
|
4313
|
+
outputError(
|
|
4314
|
+
-32e3,
|
|
4315
|
+
`Failed to check for updates: ${err.message}`
|
|
4316
|
+
);
|
|
4317
|
+
}
|
|
4318
|
+
});
|
|
4319
|
+
updateCmd.action(async () => {
|
|
4320
|
+
const spinner = ora6("Checking for updates\u2026").start();
|
|
4321
|
+
try {
|
|
4322
|
+
const latest = await fetchLatestVersion();
|
|
4323
|
+
const cmp = compareSemver(VERSION, latest);
|
|
4324
|
+
if (cmp >= 0) {
|
|
4325
|
+
spinner.succeed(chalk2.green(`Already up to date (v${VERSION})`));
|
|
4326
|
+
outputResult({
|
|
4327
|
+
currentVersion: VERSION,
|
|
4328
|
+
latestVersion: latest,
|
|
4329
|
+
updateAvailable: false
|
|
4330
|
+
});
|
|
4331
|
+
return;
|
|
4332
|
+
}
|
|
4333
|
+
spinner.text = `Updating ${chalk2.gray(`v${VERSION}`)} \u2192 ${chalk2.green(`v${latest}`)}\u2026`;
|
|
4334
|
+
const pm = detectPackageManager();
|
|
4335
|
+
const cmd = buildInstallCommand(pm, latest);
|
|
4336
|
+
execSync(cmd, { stdio: "pipe" });
|
|
4337
|
+
spinner.succeed(chalk2.green(`Updated to v${latest}`));
|
|
4338
|
+
outputResult({
|
|
4339
|
+
previousVersion: VERSION,
|
|
4340
|
+
currentVersion: latest,
|
|
4341
|
+
updateAvailable: false,
|
|
4342
|
+
packageManager: pm
|
|
4343
|
+
});
|
|
4344
|
+
} catch (err) {
|
|
4345
|
+
spinner.fail("Update failed");
|
|
4346
|
+
outputError(-32e3, `Update failed: ${err.message}`);
|
|
4347
|
+
}
|
|
4348
|
+
});
|
|
4349
|
+
}
|
|
4350
|
+
|
|
4224
4351
|
// src/index.ts
|
|
4225
4352
|
var program = new Command();
|
|
4226
|
-
program.name("elytro").description("Elytro \u2014 ERC-4337 Smart Account Wallet CLI").version(
|
|
4353
|
+
program.name("elytro").description("Elytro \u2014 ERC-4337 Smart Account Wallet CLI").version(VERSION).addHelpText(
|
|
4354
|
+
"after",
|
|
4355
|
+
"\nLearn how to use Elytro skills: https://github.com/Elytro-eth/skills\n"
|
|
4356
|
+
);
|
|
4227
4357
|
async function main() {
|
|
4228
4358
|
let ctx = null;
|
|
4229
4359
|
try {
|
|
@@ -4234,6 +4364,7 @@ async function main() {
|
|
|
4234
4364
|
registerQueryCommand(program, ctx);
|
|
4235
4365
|
registerSecurityCommand(program, ctx);
|
|
4236
4366
|
registerConfigCommand(program, ctx);
|
|
4367
|
+
registerUpdateCommand(program);
|
|
4237
4368
|
await program.parseAsync(process.argv);
|
|
4238
4369
|
} catch (err) {
|
|
4239
4370
|
outputError(-32e3, sanitizeErrorMessage(err.message));
|