UNPKG

@acurast/cli

Version:

A cli to interact with the Acurast Cloud.

92 lines 3.95 kB
#! /usr/bin/env node import fs from 'fs'; import { Command } from 'commander'; import figlet from 'figlet'; const { textSync } = figlet; import { addCommandInit } from './commands/init.js'; import { addCommandDeploy } from './commands/deploy.js'; import { addCommandDeployVps } from './commands/deploy-vps.js'; import { addCommandLogin } from './commands/login.js'; import { addCommandLogout } from './commands/logout.js'; import { addCommandWhoami } from './commands/whoami.js'; import { addCommandOpen } from './commands/open.js'; import { addCommandLive } from './commands/live.js'; import { acurastColor } from './util.js'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { addCommandDeployments } from './commands/deployments.js'; import { addCommandCancel } from './commands/cancel.js'; import { addCommandNew } from './commands/new.js'; import { addCommandEstimateFee } from './commands/estimate-fee.js'; import { addCommandDevtools } from './commands/devtools.js'; import { ACURAST_CLI_VERSION_CHECK_URL } from './constants.js'; import { filelogger } from './util/fileLogger.js'; import { fetchDeviceVersions } from '@acurast/sdk/chain'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // Read package.json const packagePath = join(__dirname, '..', 'package.json'); const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')); filelogger.debug(`--------------------------------`); filelogger.debug(`CLI is running version ${packageJson.version}`); filelogger.debug(`COMMAND: acurast ${process.argv.slice(2).join(' ')}`); const program = new Command(); program .name('acurast') .version(packageJson.version, '-v, --version') .description(packageJson.description) // Required so `deploy vps` can define flags that also exist on `deploy` // (e.g. --dry-run) without the parent consuming them. .enablePositionalOptions(); addCommandDeployVps(addCommandDeploy(program)); addCommandInit(program); addCommandDeployments(program); addCommandCancel(program); addCommandLive(program); addCommandLogin(program); addCommandLogout(program); addCommandWhoami(program); addCommandOpen(program); // addCommandRun(program) // addCommandTest(program) // addCommandWatch(program) addCommandNew(program); addCommandEstimateFee(program); addCommandDevtools(program); if (!process.argv.slice(2).length) { console.log(acurastColor(textSync('Acurast CLI'))); program.outputHelp(); // TODO: Add info about each command // program.commands.forEach((command) => { // console.log(); // console.log(`##### ${command.name()} #####`); // console.log(); // command.outputHelp(); // }); process.exit(0); // If no command is provided, exit the process } // Check if there's a newer version available const cliVersionCheck = fetch(ACURAST_CLI_VERSION_CHECK_URL) .then((response) => response.json()) .then((remotePackage) => { const localVersion = packageJson.version; const remoteVersion = remotePackage.version; if (remoteVersion > localVersion) { filelogger.debug(`New version available. Local: ${localVersion}, Remote: ${remoteVersion}`); console.log(acurastColor(`\nA new version (v${remoteVersion}) is available! You are currently on version v${localVersion}\n` + 'Update by running: npm install -g @acurast/cli\n')); } }) .catch(() => { // Silently fail if unable to check version }); // Refresh processor build-number → human-version map so `minProcessorVersions` // in acurast.json can be resolved against the latest releases (SDK ships a // stale bundled list). const deviceVersionsRefresh = fetchDeviceVersions().catch((err) => { filelogger.debug(`Failed to refresh device versions: ${err}`); }); Promise.allSettled([cliVersionCheck, deviceVersionsRefresh]).finally(() => { program.parse(process.argv); }); //# sourceMappingURL=index.js.map