mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
wip
This commit is contained in:
parent
b9060a04fe
commit
a91a306f86
@ -8,14 +8,14 @@ The balena CLI is an open source project and your contribution is welcome!
|
||||
* Clone the `balena-cli` repository (or a [forked
|
||||
repo](https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/fork-a-repo),
|
||||
if you are not in the balena team), `cd` to it and run `npm install`.
|
||||
* Build the CLI with `npm run build` or `npm test`, and execute it with `./bin/balena`
|
||||
* Build the CLI with `npm run build` or `npm test`, and execute it with `./bin/balena.js`
|
||||
(on a Windows command prompt, you may need to run `node .\bin\balena`).
|
||||
|
||||
In order to ease development:
|
||||
|
||||
* `npm run build:fast` skips some of the build steps for interactive testing, or
|
||||
* `npm run test:source` skips testing the standalone zip packages (which is rather slow)
|
||||
* `./bin/balena-dev` uses `ts-node/register` to transpile on the fly.
|
||||
* `./bin/balena-dev.js` uses `ts-node/register` to transpile on the fly.
|
||||
|
||||
Before opening a PR, test your changes with `npm test`. Keep compatibility in mind, as the CLI is
|
||||
meant to run on Linux, macOS and Windows. balena CI will run test code on all three platforms, but
|
||||
@ -230,7 +230,7 @@ be automatically invalidated if `npm link` is used or if manual modifications ar
|
||||
`node_modules` folder. In this situation:
|
||||
|
||||
* Manually delete the module cache file (typically `~/.balena/cli-module-cache.json`), or
|
||||
* Use the `bin/balena-dev` entry point (instead of `bin/balena`) as it does not activate
|
||||
* Use the `bin/balena-dev.js` entry point (instead of `bin/balena.js`) as it does not activate
|
||||
`fast-boot2`.
|
||||
|
||||
## TypeScript and oclif
|
||||
|
@ -40,7 +40,7 @@ By default, the CLI is installed to the following folders:
|
||||
OS | Folders
|
||||
--- | ---
|
||||
Windows: | `C:\Program Files\balena-cli\`
|
||||
macOS: | `/usr/local/lib/balena-cli/` <br> `/usr/local/bin/balena`
|
||||
macOS: | `/usr/local/lib/balena-cli/` <br> `/usr/local/bin/balena.js`
|
||||
|
||||
## Standalone Zip Package
|
||||
|
||||
@ -65,7 +65,7 @@ macOS: | `/usr/local/lib/balena-cli/` <br> `/usr/local/bin/balena`
|
||||
> these "compact" Linux distributions, because of the alternative C libraries they ship with.
|
||||
> For these, consider the [NPM Installation](#npm-installation) option.
|
||||
> * Note that moving the `balena` executable out of the extracted `balena-cli` folder on its own
|
||||
> (e.g. moving it to `/usr/local/bin/balena`) will **not** work, as it depends on the other
|
||||
> (e.g. moving it to `/usr/local/bin/balena.js`) will **not** work, as it depends on the other
|
||||
> folders and files also present in the `balena-cli` folder.
|
||||
|
||||
To update the CLI to a new version, download a new release zip file and replace the previous
|
||||
|
@ -83,6 +83,7 @@ function importOclifCommands(jsFilename: string): OclifCommand[] {
|
||||
// an error when parsed. This should be improved so that `usage` does not have
|
||||
// to be overridden if not necessary.
|
||||
|
||||
// TODO: FIX ME ESM
|
||||
const command: OclifCommand =
|
||||
jsFilename === 'help'
|
||||
? (new FakeHelpCommand() as unknown as OclifCommand)
|
||||
|
@ -97,7 +97,7 @@ export function loadPackageJson() {
|
||||
* @returns The program's full path, e.g. 'C:\WINDOWS\System32\OpenSSH\ssh.EXE'
|
||||
*/
|
||||
export async function which(program: string): Promise<string> {
|
||||
const whichMod = await import('which');
|
||||
const { default: whichMod } = await import('which');
|
||||
let programPath: string;
|
||||
try {
|
||||
programPath = await whichMod(program);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
// ****************************************************************************
|
||||
// THIS IS FOR DEV PURPOSES ONLY AND WILL NOT BE PART OF THE PUBLISHED PACKAGE
|
||||
// Before opening a PR you should build and test your changes using bin/balena
|
||||
// Before opening a PR you should build and test your changes using bin/balena.js
|
||||
// ****************************************************************************
|
||||
|
||||
// We boost the threadpool size as ext2fs can deadlock with some
|
||||
@ -57,7 +57,10 @@ require('ts-node').register({
|
||||
project: path.join(rootDir, 'tsconfig.json'),
|
||||
transpileOnly: true,
|
||||
});
|
||||
require('../lib/app').run(undefined, { dir: __dirname, development: true });
|
||||
require('../lib/app').run(undefined, {
|
||||
dir: import.meta.url,
|
||||
development: true,
|
||||
});
|
||||
|
||||
// Modify package.json oclif paths from build/ -> lib/, or vice versa
|
||||
function modifyOclifPaths(revert) {
|
@ -9,13 +9,13 @@ process.env.OCLIF_TS_NODE = 0;
|
||||
|
||||
async function run() {
|
||||
// Use fast-boot to cache require lookups, speeding up startup
|
||||
await require('../build/fast-boot').start();
|
||||
await (await import('../build/fast-boot.js')).start();
|
||||
|
||||
// Set the desired es version for downstream modules that support it
|
||||
require('@balena/es-version').set('es2018');
|
||||
(await import('@balena/es-version')).set('es2018');
|
||||
|
||||
// Run the CLI
|
||||
await require('../build/app').run(undefined, { dir: __dirname });
|
||||
await (await import('../build/app.js')).run(undefined, { dir: import.meta.url });
|
||||
}
|
||||
|
||||
run();
|
||||
await run();
|
46
lib/app.ts
46
lib/app.ts
@ -15,23 +15,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as packageJSON from '../package.json';
|
||||
import packageJSON from '../package.json' assert {type: 'json'};
|
||||
import {
|
||||
AppOptions,
|
||||
checkDeletedCommand,
|
||||
preparseArgs,
|
||||
unsupportedFlag,
|
||||
} from './preparser';
|
||||
import { CliSettings } from './utils/bootstrap';
|
||||
import { onceAsync } from './utils/lazy';
|
||||
import { run as mainRun, settings } from '@oclif/core';
|
||||
} from './preparser.js';
|
||||
import { CliSettings } from './utils/bootstrap.js';
|
||||
import { onceAsync } from './utils/lazy.js';
|
||||
import { run as mainRun, flush, settings } from '@oclif/core';
|
||||
|
||||
/**
|
||||
* Sentry.io setup
|
||||
* @see https://docs.sentry.io/error-reporting/quickstart/?platform=node
|
||||
*/
|
||||
export const setupSentry = onceAsync(async () => {
|
||||
const config = await import('./config');
|
||||
const config = await import('./config.js');
|
||||
const Sentry = await import('@sentry/node');
|
||||
Sentry.init({
|
||||
autoSessionTracking: false,
|
||||
@ -51,14 +51,14 @@ export const setupSentry = onceAsync(async () => {
|
||||
async function checkNodeVersion() {
|
||||
const validNodeVersions = packageJSON.engines.node;
|
||||
if (!(await import('semver')).satisfies(process.version, validNodeVersions)) {
|
||||
const { getNodeEngineVersionWarn } = await import('./utils/messages');
|
||||
const { getNodeEngineVersionWarn } = await import('./utils/messages.js');
|
||||
console.warn(getNodeEngineVersionWarn(process.version, validNodeVersions));
|
||||
}
|
||||
}
|
||||
|
||||
/** Setup balena-sdk options that are shared with imported packages */
|
||||
function setupBalenaSdkSharedOptions(settings: CliSettings) {
|
||||
const BalenaSdk = require('balena-sdk') as typeof import('balena-sdk');
|
||||
async function setupBalenaSdkSharedOptions(settings: CliSettings) {
|
||||
const BalenaSdk = await import('balena-sdk');
|
||||
BalenaSdk.setSharedOptions({
|
||||
apiUrl: settings.get<string>('apiUrl'),
|
||||
dataDirectory: settings.get<string>('dataDirectory'),
|
||||
@ -71,8 +71,8 @@ function setupBalenaSdkSharedOptions(settings: CliSettings) {
|
||||
* leak detected. 11 error listeners added. Use emitter.setMaxListeners() to
|
||||
* increase limit
|
||||
*/
|
||||
export function setMaxListeners(maxListeners: number) {
|
||||
require('events').EventEmitter.defaultMaxListeners = maxListeners;
|
||||
export async function setMaxListeners(maxListeners: number) {
|
||||
(await import('events')).EventEmitter.defaultMaxListeners = maxListeners;
|
||||
}
|
||||
|
||||
/** Selected CLI initialization steps */
|
||||
@ -89,13 +89,13 @@ async function init() {
|
||||
const settings = new CliSettings();
|
||||
|
||||
// Proxy setup should be done early on, before loading balena-sdk
|
||||
await (await import('./utils/proxy')).setupGlobalHttpProxy(settings);
|
||||
await (await import('./utils/proxy.js')).setupGlobalHttpProxy(settings);
|
||||
|
||||
setupBalenaSdkSharedOptions(settings);
|
||||
await setupBalenaSdkSharedOptions(settings);
|
||||
|
||||
// check for CLI updates once a day
|
||||
if (!process.env.BALENARC_OFFLINE_MODE) {
|
||||
(await import('./utils/update')).notify();
|
||||
(await import('./utils/update.js')).notify();
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ async function oclifRun(command: string[], options: AppOptions) {
|
||||
if (unsupportedFlag || process.env.BALENARC_UNSUPPORTED) {
|
||||
deprecationPromise = Promise.resolve();
|
||||
} else {
|
||||
const { DeprecationChecker } = await import('./deprecation');
|
||||
const { DeprecationChecker } = await import('./deprecation.js');
|
||||
const deprecationChecker = new DeprecationChecker(packageJSON.version);
|
||||
// warnAndAbortIfDeprecated uses previously cached data only
|
||||
await deprecationChecker.warnAndAbortIfDeprecated();
|
||||
@ -137,7 +137,7 @@ async function oclifRun(command: string[], options: AppOptions) {
|
||||
}
|
||||
}
|
||||
if (shouldFlush) {
|
||||
await import('@oclif/core/flush');
|
||||
await flush();
|
||||
}
|
||||
// TODO: figure out why we need to call fast-boot stop() here, in
|
||||
// addition to calling it in the main `run()` function in this file.
|
||||
@ -148,20 +148,20 @@ async function oclifRun(command: string[], options: AppOptions) {
|
||||
// the try/catch block above, execution does not get past the
|
||||
// Promise.all() call below, but I don't understand why.
|
||||
if (isEEXIT) {
|
||||
(await import('./fast-boot')).stop();
|
||||
(await import('./fast-boot.js')).stop();
|
||||
}
|
||||
})(!options.noFlush);
|
||||
|
||||
const { trackPromise } = await import('./hooks/prerun/track');
|
||||
const { trackPromise } = await import('./hooks/prerun/track.js');
|
||||
|
||||
await Promise.all([trackPromise, deprecationPromise, runPromise]);
|
||||
}
|
||||
|
||||
/** CLI entrypoint. Called by the `bin/balena` and `bin/balena-dev` scripts. */
|
||||
/** CLI entrypoint. Called by the `bin/balena.js` and `bin/balena-dev.js` scripts. */
|
||||
export async function run(cliArgs = process.argv, options: AppOptions) {
|
||||
try {
|
||||
const { setOfflineModeEnvVars, normalizeEnvVars, pkgExec } = await import(
|
||||
'./utils/bootstrap'
|
||||
'./utils/bootstrap.js'
|
||||
);
|
||||
setOfflineModeEnvVars();
|
||||
normalizeEnvVars();
|
||||
@ -175,15 +175,15 @@ export async function run(cliArgs = process.argv, options: AppOptions) {
|
||||
await init();
|
||||
|
||||
// Look for commands that have been removed and if so, exit with a notice
|
||||
checkDeletedCommand(cliArgs.slice(2));
|
||||
await checkDeletedCommand(cliArgs.slice(2));
|
||||
|
||||
const args = await preparseArgs(cliArgs);
|
||||
await oclifRun(args, options);
|
||||
} catch (err) {
|
||||
await (await import('./errors')).handleError(err);
|
||||
await (await import('./errors.js')).handleError(err);
|
||||
} finally {
|
||||
try {
|
||||
(await import('./fast-boot')).stop();
|
||||
(await import('./fast-boot.js')).stop();
|
||||
} catch (e) {
|
||||
if (process.env.DEBUG) {
|
||||
console.error(`[debug] Stopping fast-boot: ${e}`);
|
||||
|
@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { getBalenaSdk } from '../utils/lazy';
|
||||
import { LoginServer } from './server';
|
||||
import { getBalenaSdk } from '../utils/lazy.js';
|
||||
import { LoginServer } from './server.js';
|
||||
|
||||
/**
|
||||
* @module auth
|
||||
@ -42,7 +42,7 @@ import { LoginServer } from './server';
|
||||
* console.log("My session token is: #{sessionToken}")
|
||||
*/
|
||||
export async function login({ host = '127.0.0.1', port = 0 }) {
|
||||
const utils = await import('./utils');
|
||||
const utils = await import('./utils.js');
|
||||
|
||||
const loginServer = new LoginServer();
|
||||
const {
|
||||
@ -55,10 +55,10 @@ export async function login({ host = '127.0.0.1', port = 0 }) {
|
||||
const loginUrl = await utils.getDashboardLoginURL(callbackUrl);
|
||||
|
||||
console.info(`Opening web browser for URL:\n${loginUrl}`);
|
||||
const open = await import('open');
|
||||
const { default: open } = await import('open');
|
||||
await open(loginUrl, { wait: false });
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const token = await loginServer.awaitForToken();
|
||||
await balena.auth.loginWithToken(token);
|
||||
loginServer.shutdown();
|
||||
|
@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as bodyParser from 'body-parser';
|
||||
import bodyParser from 'body-parser';
|
||||
import { EventEmitter } from 'events';
|
||||
import * as express from 'express';
|
||||
import express from 'express';
|
||||
import type { Socket } from 'net';
|
||||
import * as path from 'path';
|
||||
import path from 'path';
|
||||
|
||||
import * as utils from './utils';
|
||||
import { ExpectedError } from '../errors';
|
||||
import * as utils from './utils.js';
|
||||
import { ExpectedError } from '../errors.js';
|
||||
|
||||
export class LoginServer extends EventEmitter {
|
||||
protected expressApp: express.Express;
|
||||
@ -56,7 +56,7 @@ export class LoginServer extends EventEmitter {
|
||||
);
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', path.join(__dirname, 'pages'));
|
||||
app.set('views', path.join(import.meta.url, 'pages'));
|
||||
|
||||
this.server = await new Promise<import('net').Server>((resolve, reject) => {
|
||||
const callback = (err: Error) => {
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { getBalenaSdk } from '../utils/lazy';
|
||||
import { getBalenaSdk } from '../utils/lazy.js';
|
||||
|
||||
/**
|
||||
* Get dashboard CLI login URL
|
||||
@ -32,7 +32,7 @@ export async function getDashboardLoginURL(
|
||||
|
||||
const [{ URL }, dashboardUrl] = await Promise.all([
|
||||
import('url'),
|
||||
getBalenaSdk().settings.get('dashboardUrl'),
|
||||
(await getBalenaSdk()).settings.get('dashboardUrl'),
|
||||
]);
|
||||
return new URL(`/login/cli/${callbackUrl}`, dashboardUrl).href;
|
||||
}
|
||||
@ -54,7 +54,7 @@ export async function loginIfTokenValid(token?: string): Promise<boolean> {
|
||||
if (!token) {
|
||||
return false;
|
||||
}
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
let currentToken;
|
||||
try {
|
||||
|
@ -19,9 +19,9 @@ import { Command } from '@oclif/core';
|
||||
import {
|
||||
InsufficientPrivilegesError,
|
||||
NotAvailableInOfflineModeError,
|
||||
} from './errors';
|
||||
import { stripIndent } from './utils/lazy';
|
||||
import * as output from './framework/output';
|
||||
} from './errors.js';
|
||||
import { stripIndent } from './utils/lazy.js';
|
||||
import * as output from './framework/output.js';
|
||||
|
||||
export default abstract class BalenaCommand extends Command {
|
||||
/**
|
||||
@ -71,7 +71,7 @@ export default abstract class BalenaCommand extends Command {
|
||||
* - other code needs to execute before check
|
||||
*/
|
||||
protected static async checkElevatedPrivileges() {
|
||||
const isElevated = await (await import('is-elevated'))();
|
||||
const isElevated = await (await import('is-elevated')).default();
|
||||
if (!isElevated) {
|
||||
throw new InsufficientPrivilegesError(
|
||||
'You need root/admin privileges to run this command',
|
||||
@ -94,7 +94,7 @@ export default abstract class BalenaCommand extends Command {
|
||||
* @throws {NotLoggedInError}
|
||||
*/
|
||||
public static async checkLoggedIn() {
|
||||
await (await import('./utils/patterns')).checkLoggedIn();
|
||||
await (await import('./utils/patterns.js')).checkLoggedIn();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,14 +139,14 @@ export default abstract class BalenaCommand extends Command {
|
||||
* values from stdin based in configuration, minimising command implementation.
|
||||
*/
|
||||
protected async getStdin() {
|
||||
this.stdin = await (await import('get-stdin'))();
|
||||
this.stdin = await (await import('get-stdin')).default();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a logger instance.
|
||||
*/
|
||||
protected static async getLogger() {
|
||||
return (await import('./utils/logger')).getLogger();
|
||||
return (await import('./utils/logger.js')).default.getLogger();
|
||||
}
|
||||
|
||||
protected async init() {
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class GenerateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -53,7 +53,7 @@ export default class GenerateCmd extends Command {
|
||||
|
||||
let key;
|
||||
try {
|
||||
key = await getBalenaSdk().models.apiKey.create(params.name);
|
||||
key = await (await getBalenaSdk()).models.apiKey.create(params.name);
|
||||
} catch (e) {
|
||||
if (e.name === 'BalenaNotLoggedIn') {
|
||||
throw new ExpectedError(stripIndent`
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class RevokeCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -59,7 +59,8 @@ export default class RevokeCmd extends Command {
|
||||
}
|
||||
await Promise.all(
|
||||
apiKeyIds.map(
|
||||
async (id) => await getBalenaSdk().models.apiKey.revoke(Number(id)),
|
||||
async (id) =>
|
||||
await (await getBalenaSdk()).models.apiKey.revoke(Number(id)),
|
||||
),
|
||||
);
|
||||
console.log('Successfully revoked the given API keys');
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ApiKeysCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -46,15 +46,16 @@ export default class ApiKeysCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(ApiKeysCmd);
|
||||
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
const balena = await getBalenaSdk();
|
||||
const actorId = options.fleet
|
||||
? (
|
||||
await getApplication(getBalenaSdk(), options.fleet, {
|
||||
await getApplication(balena, options.fleet, {
|
||||
$select: 'actor',
|
||||
})
|
||||
).actor
|
||||
: await getBalenaSdk().auth.getActorId();
|
||||
const keys = await getBalenaSdk().pine.get({
|
||||
: await balena.auth.getActorId();
|
||||
const keys = await balena.pine.get({
|
||||
resource: 'api_key',
|
||||
options: {
|
||||
$select: ['id', 'created_at', 'name', 'description', 'expiry_date'],
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class AppCreateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -77,7 +77,7 @@ export default class AppCreateCmd extends Command {
|
||||
const { args: params, flags: options } = await this.parse(AppCreateCmd);
|
||||
|
||||
await (
|
||||
await import('../../utils/application-create')
|
||||
await import('../../utils/application-create.js')
|
||||
).applicationCreateBase('app', options, params);
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class BlockCreateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -77,7 +77,7 @@ export default class BlockCreateCmd extends Command {
|
||||
const { args: params, flags: options } = await this.parse(BlockCreateCmd);
|
||||
|
||||
await (
|
||||
await import('../../utils/application-create')
|
||||
await import('../../utils/application-create.js')
|
||||
).applicationCreateBase('block', options, params);
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,23 @@
|
||||
*/
|
||||
|
||||
import { Args, Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { getBalenaSdk } from '../../utils/lazy';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as compose from '../../utils/compose';
|
||||
import Command from '../../command.js';
|
||||
import { getBalenaSdk } from '../../utils/lazy.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as compose from '../../utils/compose.js';
|
||||
import type { ApplicationType, BalenaSDK } from 'balena-sdk';
|
||||
import {
|
||||
buildArgDeprecation,
|
||||
dockerignoreHelp,
|
||||
registrySecretsHelp,
|
||||
} from '../../utils/messages';
|
||||
import type { ComposeCliFlags, ComposeOpts } from '../../utils/compose-types';
|
||||
import { buildProject, composeCliFlags } from '../../utils/compose_ts';
|
||||
import type { BuildOpts, DockerCliFlags } from '../../utils/docker';
|
||||
import { dockerCliFlags } from '../../utils/docker';
|
||||
} from '../../utils/messages.js';
|
||||
import type {
|
||||
ComposeCliFlags,
|
||||
ComposeOpts,
|
||||
} from '../../utils/compose-types.js';
|
||||
import { buildProject, composeCliFlags } from '../../utils/compose_ts.js';
|
||||
import type { BuildOpts, DockerCliFlags } from '../../utils/docker.js';
|
||||
import { dockerCliFlags } from '../../utils/docker.js';
|
||||
|
||||
// TODO: For this special one we can't use Interfaces.InferredFlags/InferredArgs
|
||||
// because of the 'registry-secrets' type which is defined in the actual code
|
||||
@ -105,7 +108,7 @@ ${dockerignoreHelp}
|
||||
|
||||
(await import('events')).defaultMaxListeners = 1000;
|
||||
|
||||
const sdk = getBalenaSdk();
|
||||
const sdk = await getBalenaSdk();
|
||||
|
||||
const logger = await Command.getLogger();
|
||||
logger.logDebug('Parsing input...');
|
||||
@ -148,14 +151,16 @@ ${dockerignoreHelp}
|
||||
(opts.fleet == null && (opts.arch == null || opts.deviceType == null)) ||
|
||||
(opts.fleet != null && (opts.arch != null || opts.deviceType != null))
|
||||
) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(
|
||||
'You must specify either a fleet (-f), or the device type (-d) and architecture (-A)',
|
||||
);
|
||||
}
|
||||
|
||||
// Validate project directory
|
||||
const { validateProjectDirectory } = await import('../../utils/compose_ts');
|
||||
const { validateProjectDirectory } = await import(
|
||||
'../../utils/compose_ts.js'
|
||||
);
|
||||
const { dockerfilePath, registrySecrets } = await validateProjectDirectory(
|
||||
sdk,
|
||||
{
|
||||
@ -172,7 +177,7 @@ ${dockerignoreHelp}
|
||||
|
||||
protected async getAppAndResolveArch(opts: FlagsDef) {
|
||||
if (opts.fleet) {
|
||||
const { getAppWithArch } = await import('../../utils/helpers');
|
||||
const { getAppWithArch } = await import('../../utils/helpers.js');
|
||||
const app = await getAppWithArch(opts.fleet);
|
||||
opts.arch = app.arch;
|
||||
opts.deviceType = app.is_for__device_type[0].slug;
|
||||
@ -180,8 +185,11 @@ ${dockerignoreHelp}
|
||||
}
|
||||
}
|
||||
|
||||
protected async prepareBuild(options: FlagsDef) {
|
||||
const { getDocker, generateBuildOpts } = await import('../../utils/docker');
|
||||
// TODO: FIX ME ESM
|
||||
protected async prepareBuild(options: FlagsDef): Promise<any> {
|
||||
const { getDocker, generateBuildOpts } = await import(
|
||||
'../../utils/docker.js'
|
||||
);
|
||||
const [docker, buildOpts, composeOpts] = await Promise.all([
|
||||
getDocker(options),
|
||||
generateBuildOpts(options),
|
||||
@ -209,7 +217,7 @@ ${dockerignoreHelp}
|
||||
*/
|
||||
protected async buildProject(
|
||||
docker: import('dockerode'),
|
||||
logger: import('../../utils/logger'),
|
||||
logger: import('../../utils/logger.js').default,
|
||||
composeOpts: ComposeOpts,
|
||||
opts: {
|
||||
app?: {
|
||||
@ -221,7 +229,7 @@ ${dockerignoreHelp}
|
||||
buildOpts: BuildOpts;
|
||||
},
|
||||
) {
|
||||
const { loadProject } = await import('../../utils/compose_ts');
|
||||
const { loadProject } = await import('../../utils/compose_ts.js');
|
||||
|
||||
const project = await loadProject(
|
||||
logger,
|
||||
|
@ -17,14 +17,14 @@
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import type { Interfaces } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getCliForm, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getCliForm, stripIndent } from '../../utils/lazy.js';
|
||||
import {
|
||||
applicationIdInfo,
|
||||
devModeInfo,
|
||||
secureBootInfo,
|
||||
} from '../../utils/messages';
|
||||
} from '../../utils/messages.js';
|
||||
import type { BalenaSDK, PineDeferred } from 'balena-sdk';
|
||||
|
||||
export default class ConfigGenerateCmd extends Command {
|
||||
@ -126,7 +126,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
public static authenticated = true;
|
||||
|
||||
public async getApplication(balena: BalenaSDK, fleet: string) {
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
return await getApplication(balena, fleet, {
|
||||
$select: 'slug',
|
||||
$expand: {
|
||||
@ -137,7 +137,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(ConfigGenerateCmd);
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
await this.validateOptions(options);
|
||||
|
||||
@ -152,7 +152,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
$expand: { is_of__device_type: { $select: 'slug' } },
|
||||
});
|
||||
if (!rawDevice.belongs_to__application) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(stripIndent`
|
||||
Device ${options.device} does not appear to belong to an accessible fleet.
|
||||
Try with a different device, or use '--fleet' instead of '--device'.`);
|
||||
@ -171,14 +171,14 @@ export default class ConfigGenerateCmd extends Command {
|
||||
|
||||
// Check compatibility if application and deviceType provided
|
||||
if (options.fleet && options.deviceType) {
|
||||
const helpers = await import('../../utils/helpers');
|
||||
const helpers = await import('../../utils/helpers.js');
|
||||
if (
|
||||
!(await helpers.areDeviceTypesCompatible(
|
||||
resourceDeviceType,
|
||||
deviceType,
|
||||
))
|
||||
) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(
|
||||
`Device type ${options.deviceType} is incompatible with fleet ${options.fleet}`,
|
||||
);
|
||||
@ -189,7 +189,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
await balena.models.config.getDeviceTypeManifestBySlug(deviceType);
|
||||
|
||||
const { validateSecureBootOptionAndWarn } = await import(
|
||||
'../../utils/config'
|
||||
'../../utils/config.js'
|
||||
);
|
||||
await validateSecureBootOptionAndWarn(
|
||||
options.secureBoot,
|
||||
@ -211,7 +211,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
|
||||
// Generate config
|
||||
const { generateDeviceConfig, generateApplicationConfig } = await import(
|
||||
'../../utils/config'
|
||||
'../../utils/config.js'
|
||||
);
|
||||
|
||||
let config;
|
||||
@ -250,7 +250,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
protected async validateOptions(
|
||||
options: Interfaces.InferredFlags<typeof ConfigGenerateCmd.flags>,
|
||||
) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
|
||||
if (options.device == null && options.fleet == null) {
|
||||
throw new ExpectedError(this.missingDeviceOrAppMessage);
|
||||
@ -259,7 +259,7 @@ export default class ConfigGenerateCmd extends Command {
|
||||
if (!options.fleet && options.deviceType) {
|
||||
throw new ExpectedError(this.deviceTypeNotAllowedMessage);
|
||||
}
|
||||
const { validateDevOptionAndWarn } = await import('../../utils/config');
|
||||
const { validateDevOptionAndWarn } = await import('../../utils/config.js');
|
||||
await validateDevOptionAndWarn(options.dev, options.version);
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ConfigInjectCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -56,7 +56,7 @@ export default class ConfigInjectCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(ConfigInjectCmd);
|
||||
|
||||
const { safeUmount } = await import('../../utils/umount');
|
||||
const { safeUmount } = await import('../../utils/umount.js');
|
||||
|
||||
const drive =
|
||||
options.drive || (await getVisuals().drive('Select the device/OS drive'));
|
||||
|
@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ConfigReadCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -50,7 +50,7 @@ export default class ConfigReadCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(ConfigReadCmd);
|
||||
|
||||
const { safeUmount } = await import('../../utils/umount');
|
||||
const { safeUmount } = await import('../../utils/umount.js');
|
||||
|
||||
const drive =
|
||||
options.drive || (await getVisuals().drive('Select the device drive'));
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ConfigReconfigureCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -59,7 +59,7 @@ export default class ConfigReconfigureCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(ConfigReconfigureCmd);
|
||||
|
||||
const { safeUmount } = await import('../../utils/umount');
|
||||
const { safeUmount } = await import('../../utils/umount.js');
|
||||
|
||||
const drive =
|
||||
options.drive || (await getVisuals().drive('Select the device drive'));
|
||||
@ -70,7 +70,7 @@ export default class ConfigReconfigureCmd extends Command {
|
||||
await safeUmount(drive);
|
||||
|
||||
if (!uuid) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(
|
||||
`Error: UUID not found in 'config.json' file for '${drive}'`,
|
||||
);
|
||||
@ -84,7 +84,7 @@ export default class ConfigReconfigureCmd extends Command {
|
||||
configureCommand.push('--advanced');
|
||||
}
|
||||
|
||||
const { runCommand } = await import('../../utils/helpers');
|
||||
const { runCommand } = await import('../../utils/helpers.js');
|
||||
await runCommand(configureCommand);
|
||||
|
||||
console.info('Done');
|
||||
|
@ -16,10 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy';
|
||||
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { createRequire } from 'node:module';
|
||||
const require = createRequire(import.meta.url);
|
||||
export default class ConfigWriteCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
Write a key-value pair to the config.json file of an OS image or attached media.
|
||||
@ -61,7 +62,7 @@ export default class ConfigWriteCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(ConfigWriteCmd);
|
||||
|
||||
const { denyMount, safeUmount } = await import('../../utils/umount');
|
||||
const { denyMount, safeUmount } = await import('../../utils/umount.js');
|
||||
|
||||
const drive =
|
||||
options.drive || (await getVisuals().drive('Select the device drive'));
|
||||
|
@ -14,35 +14,34 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Args, Flags } from '@oclif/core';
|
||||
import type { ImageDescriptor } from '@balena/compose/dist/parse';
|
||||
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import { getBalenaSdk, getChalk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import { getBalenaSdk, getChalk, stripIndent } from '../../utils/lazy.js';
|
||||
import {
|
||||
dockerignoreHelp,
|
||||
registrySecretsHelp,
|
||||
buildArgDeprecation,
|
||||
} from '../../utils/messages';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import * as compose from '../../utils/compose';
|
||||
} from '../../utils/messages.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import * as compose from '../../utils/compose.js';
|
||||
import type {
|
||||
BuiltImage,
|
||||
ComposeCliFlags,
|
||||
ComposeOpts,
|
||||
Release as ComposeReleaseInfo,
|
||||
} from '../../utils/compose-types';
|
||||
import type { BuildOpts, DockerCliFlags } from '../../utils/docker';
|
||||
} from '../../utils/compose-types.js';
|
||||
import type { BuildOpts, DockerCliFlags } from '../../utils/docker.js';
|
||||
import {
|
||||
applyReleaseTagKeysAndValues,
|
||||
buildProject,
|
||||
composeCliFlags,
|
||||
isBuildConfig,
|
||||
parseReleaseTagKeysAndValues,
|
||||
} from '../../utils/compose_ts';
|
||||
import { dockerCliFlags } from '../../utils/docker';
|
||||
} from '../../utils/compose_ts.js';
|
||||
import { dockerCliFlags } from '../../utils/docker.js';
|
||||
import type { ApplicationType, DeviceType, Release } from 'balena-sdk';
|
||||
|
||||
interface ApplicationWithArch {
|
||||
@ -173,9 +172,9 @@ ${dockerignoreHelp}
|
||||
);
|
||||
}
|
||||
|
||||
const sdk = getBalenaSdk();
|
||||
const sdk = await getBalenaSdk();
|
||||
const { getRegistrySecrets, validateProjectDirectory } = await import(
|
||||
'../../utils/compose_ts'
|
||||
'../../utils/compose_ts.js'
|
||||
);
|
||||
|
||||
const { releaseTagKeys, releaseTagValues } = parseReleaseTagKeysAndValues(
|
||||
@ -199,10 +198,10 @@ ${dockerignoreHelp}
|
||||
(options as FlagsDef)['registry-secrets'] = registrySecrets;
|
||||
}
|
||||
|
||||
const helpers = await import('../../utils/helpers');
|
||||
const helpers = await import('../../utils/helpers.js');
|
||||
const app = await helpers.getAppWithArch(fleet);
|
||||
|
||||
const dockerUtils = await import('../../utils/docker');
|
||||
const dockerUtils = await import('../../utils/docker.js');
|
||||
const [docker, buildOpts, composeOpts] = await Promise.all([
|
||||
dockerUtils.getDocker(options),
|
||||
dockerUtils.generateBuildOpts(options as FlagsDef),
|
||||
@ -232,7 +231,7 @@ ${dockerignoreHelp}
|
||||
|
||||
async deployProject(
|
||||
docker: import('dockerode'),
|
||||
logger: import('../../utils/logger'),
|
||||
logger: import('../../utils/logger.js').default,
|
||||
composeOpts: ComposeOpts,
|
||||
opts: {
|
||||
app: ApplicationWithArch; // the application instance to deploy to
|
||||
@ -248,9 +247,9 @@ ${dockerignoreHelp}
|
||||
) {
|
||||
const _ = await import('lodash');
|
||||
const doodles = await import('resin-doodles');
|
||||
const sdk = getBalenaSdk();
|
||||
const sdk = await getBalenaSdk();
|
||||
const { deployProject: $deployProject, loadProject } = await import(
|
||||
'../../utils/compose_ts'
|
||||
'../../utils/compose_ts.js'
|
||||
);
|
||||
|
||||
const appType = opts.app.application_type[0];
|
||||
@ -321,7 +320,7 @@ ${dockerignoreHelp}
|
||||
builtImagesByService = _.keyBy(builtImages, 'serviceName');
|
||||
}
|
||||
const images: BuiltImage[] = project.descriptors.map(
|
||||
(d) =>
|
||||
(d: any) =>
|
||||
builtImagesByService[d.serviceName] ?? {
|
||||
serviceName: d.serviceName,
|
||||
name: (isBuildConfig(d.image) ? d.image.tag : d.image) || '',
|
||||
@ -332,7 +331,7 @@ ${dockerignoreHelp}
|
||||
|
||||
let release: Release | ComposeReleaseInfo['release'];
|
||||
if (appType.slug === 'legacy-v1' || appType.slug === 'legacy-v2') {
|
||||
const { deployLegacy } = require('../../utils/deploy-legacy');
|
||||
const { deployLegacy } = await import('../../utils/deploy-legacy.js');
|
||||
|
||||
const msg = getChalk().yellow(
|
||||
'Target fleet requires legacy deploy method.',
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DeviceDeactivateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -54,8 +54,8 @@ export default class DeviceDeactivateCmd extends Command {
|
||||
const { args: params, flags: options } =
|
||||
await this.parse(DeviceDeactivateCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const balena = await getBalenaSdk();
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
|
||||
const uuid = params.uuid;
|
||||
const deactivationWarning = `
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
|
||||
export default class DeviceIdentifyCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -47,7 +47,7 @@ export default class DeviceIdentifyCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DeviceIdentifyCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
try {
|
||||
await balena.models.device.identify(params.uuid);
|
||||
|
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { expandForAppName } from '../../utils/helpers';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { jsonInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { expandForAppName } from '../../utils/helpers.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { jsonInfo } from '../../utils/messages.js';
|
||||
|
||||
import type { Application, Release } from 'balena-sdk';
|
||||
|
||||
@ -79,7 +79,7 @@ export default class DeviceCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(DeviceCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const device = (await balena.models.device.get(
|
||||
params.uuid,
|
||||
@ -124,7 +124,7 @@ export default class DeviceCmd extends Command {
|
||||
if (options.view) {
|
||||
const open = await import('open');
|
||||
const dashboardUrl = balena.models.device.getDashboardUrl(device.uuid);
|
||||
await open(dashboardUrl, { wait: false });
|
||||
await open.default(dashboardUrl, { wait: false });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import { runCommand } from '../../utils/helpers';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
import { runCommand } from '../../utils/helpers.js';
|
||||
|
||||
interface FlagsDef {
|
||||
fleet?: string;
|
||||
@ -113,15 +113,15 @@ export default class DeviceInitCmd extends Command {
|
||||
|
||||
// Imports
|
||||
const { promisify } = await import('util');
|
||||
const rimraf = promisify(await import('rimraf'));
|
||||
const rimraf = promisify((await import('rimraf')).default);
|
||||
const tmp = await import('tmp');
|
||||
const tmpNameAsync = promisify(tmp.tmpName);
|
||||
tmp.setGracefulCleanup();
|
||||
const { downloadOSImage } = await import('../../utils/cloud');
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { downloadOSImage } = await import('../../utils/cloud.js');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
const logger = await Command.getLogger();
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Get application and
|
||||
const application = options.fleet
|
||||
@ -133,7 +133,7 @@ export default class DeviceInitCmd extends Command {
|
||||
},
|
||||
},
|
||||
})
|
||||
: await (await import('../../utils/patterns')).selectApplication();
|
||||
: await (await import('../../utils/patterns.js')).selectApplication();
|
||||
|
||||
// Register new device
|
||||
const deviceUuid = balena.models.device.generateUniqueKey();
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DeviceLocalModeCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -66,7 +66,7 @@ export default class DeviceLocalModeCmd extends Command {
|
||||
const { args: params, flags: options } =
|
||||
await this.parse(DeviceLocalModeCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
if (options.enable) {
|
||||
await balena.models.device.enableLocalMode(params.uuid);
|
||||
|
@ -22,11 +22,11 @@ import type {
|
||||
PineOptions,
|
||||
PineTypedResult,
|
||||
} from 'balena-sdk';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class DeviceMoveCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -93,7 +93,7 @@ export default class DeviceMoveCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(DeviceMoveCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Split uuids string into array of uuids
|
||||
const deviceUuids = params.uuid.split(',');
|
||||
@ -101,7 +101,7 @@ export default class DeviceMoveCmd extends Command {
|
||||
const devices = await this.getDevices(balena, deviceUuids);
|
||||
|
||||
// Disambiguate application
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
// Get destination application
|
||||
const application = options.fleet
|
||||
@ -151,7 +151,7 @@ export default class DeviceMoveCmd extends Command {
|
||||
})
|
||||
.map((deviceType) => deviceType.id);
|
||||
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
try {
|
||||
const application = await patterns.selectApplication(
|
||||
{
|
||||
|
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js';
|
||||
import type { Device } from 'balena-sdk';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
|
||||
export default class DeviceOsUpdateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -62,7 +62,7 @@ export default class DeviceOsUpdateCmd extends Command {
|
||||
const { args: params, flags: options } =
|
||||
await this.parse(DeviceOsUpdateCmd);
|
||||
|
||||
const sdk = getBalenaSdk();
|
||||
const sdk = await getBalenaSdk();
|
||||
|
||||
// Get device info
|
||||
const { uuid, is_of__device_type, os_version, os_variant } =
|
||||
@ -119,7 +119,7 @@ export default class DeviceOsUpdateCmd extends Command {
|
||||
});
|
||||
}
|
||||
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
// Confirm and start update
|
||||
await patterns.confirm(
|
||||
options.yes || false,
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { getExpandedProp } from '../../utils/pine';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { getExpandedProp } from '../../utils/pine.js';
|
||||
|
||||
export default class DevicePinCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -55,7 +55,7 @@ export default class DevicePinCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DevicePinCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const device = await balena.models.device.get(params.uuid, {
|
||||
$expand: {
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DevicePublicUrlCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -68,7 +68,7 @@ export default class DevicePublicUrlCmd extends Command {
|
||||
const { args: params, flags: options } =
|
||||
await this.parse(DevicePublicUrlCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
if (options.enable) {
|
||||
// Enable public URL
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DevicePurgeCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -53,7 +53,7 @@ export default class DevicePurgeCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DevicePurgeCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const ux = getCliUx();
|
||||
|
||||
const deviceUuids = params.uuid.split(',');
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DeviceRebootCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -47,7 +47,7 @@ export default class DeviceRebootCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(DeviceRebootCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// The SDK current throws "BalenaDeviceNotFound: Device not found: xxxxx"
|
||||
// when the device is not online, which may be confusing.
|
||||
|
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class DeviceRegisterCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -64,9 +64,9 @@ export default class DeviceRegisterCmd extends Command {
|
||||
const { args: params, flags: options } =
|
||||
await this.parse(DeviceRegisterCmd);
|
||||
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const application = await getApplication(balena, params.fleet, {
|
||||
$select: ['id', 'slug'],
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js';
|
||||
|
||||
export default class DeviceRenameCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -54,7 +54,7 @@ export default class DeviceRenameCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DeviceRenameCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const newName =
|
||||
params.newName ||
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js';
|
||||
import type {
|
||||
BalenaSDK,
|
||||
DeviceWithServiceDetails,
|
||||
@ -69,7 +69,7 @@ export default class DeviceRestartCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(DeviceRestartCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const ux = getCliUx();
|
||||
|
||||
const deviceUuids = params.uuid.split(',');
|
||||
@ -94,8 +94,8 @@ export default class DeviceRestartCmd extends Command {
|
||||
deviceUuid: string,
|
||||
serviceNames: string[],
|
||||
) {
|
||||
const { ExpectedError, instanceOf } = await import('../../errors');
|
||||
const { getExpandedProp } = await import('../../utils/pine');
|
||||
const { ExpectedError, instanceOf } = await import('../../errors.js');
|
||||
const { getExpandedProp } = await import('../../utils/pine.js');
|
||||
|
||||
// Get device
|
||||
let device: DeviceWithServiceDetails<CurrentServiceWithCommit>;
|
||||
@ -161,7 +161,7 @@ export default class DeviceRestartCmd extends Command {
|
||||
// Note: device.restartApplication throws `BalenaDeviceNotFound: Device not found` if device not online.
|
||||
// Need to use device.get first to distinguish between non-existant and offline devices.
|
||||
// Remove this workaround when SDK issue resolved: https://github.com/balena-io/balena-sdk/issues/649
|
||||
const { instanceOf, ExpectedError } = await import('../../errors');
|
||||
const { instanceOf, ExpectedError } = await import('../../errors.js');
|
||||
try {
|
||||
const device = await balena.models.device.get(deviceUuid);
|
||||
if (!device.is_online) {
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DeviceRmCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -55,8 +55,8 @@ export default class DeviceRmCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(DeviceRmCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const balena = await getBalenaSdk();
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
|
||||
// Confirm
|
||||
const uuids = params.uuid.split(',');
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
|
||||
export default class DeviceShutdownCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -49,7 +49,7 @@ export default class DeviceShutdownCmd extends Command {
|
||||
const { args: params, flags: options } =
|
||||
await this.parse(DeviceShutdownCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
try {
|
||||
await balena.models.device.shutdown(params.uuid, options);
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js';
|
||||
import type { BalenaSDK } from 'balena-sdk';
|
||||
|
||||
export default class DeviceStartServiceCmd extends Command {
|
||||
@ -57,7 +57,7 @@ export default class DeviceStartServiceCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DeviceStartServiceCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const ux = getCliUx();
|
||||
|
||||
const deviceUuids = params.uuid.split(',');
|
||||
@ -78,8 +78,8 @@ export default class DeviceStartServiceCmd extends Command {
|
||||
deviceUuid: string,
|
||||
serviceNames: string[],
|
||||
) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { getExpandedProp } = await import('../../utils/pine');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
const { getExpandedProp } = await import('../../utils/pine.js');
|
||||
|
||||
// Get device
|
||||
const device = await balena.models.device.getWithServiceDetails(
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js';
|
||||
import type { BalenaSDK } from 'balena-sdk';
|
||||
|
||||
export default class DeviceStopServiceCmd extends Command {
|
||||
@ -57,7 +57,7 @@ export default class DeviceStopServiceCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DeviceStopServiceCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const ux = getCliUx();
|
||||
|
||||
const deviceUuids = params.uuid.split(',');
|
||||
@ -78,8 +78,8 @@ export default class DeviceStopServiceCmd extends Command {
|
||||
deviceUuid: string,
|
||||
serviceNames: string[],
|
||||
) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { getExpandedProp } = await import('../../utils/pine');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
const { getExpandedProp } = await import('../../utils/pine.js');
|
||||
|
||||
// Get device
|
||||
const device = await balena.models.device.getWithServiceDetails(
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class DeviceTrackFleetCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -46,7 +46,7 @@ export default class DeviceTrackFleetCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(DeviceTrackFleetCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
await balena.models.device.trackApplicationRelease(params.uuid);
|
||||
}
|
||||
|
@ -15,11 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { expandForAppName } from '../../utils/helpers';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo, jsonInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { expandForAppName } from '../../utils/helpers.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo, jsonInfo } from '../../utils/messages.js';
|
||||
|
||||
import type { Device, PineOptions } from 'balena-sdk';
|
||||
|
||||
@ -68,7 +68,7 @@ export default class DevicesCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(DevicesCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const devicesOptions = {
|
||||
...devicesSelectFields,
|
||||
...expandForAppName,
|
||||
@ -78,7 +78,7 @@ export default class DevicesCmd extends Command {
|
||||
const devices = (
|
||||
await (async () => {
|
||||
if (options.fleet != null) {
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
const application = await getApplication(balena, options.fleet, {
|
||||
$select: 'slug',
|
||||
$expand: {
|
||||
@ -115,7 +115,7 @@ export default class DevicesCmd extends Command {
|
||||
];
|
||||
|
||||
if (options.json) {
|
||||
const { pickAndRename } = await import('../../utils/helpers');
|
||||
const { pickAndRename } = await import('../../utils/helpers.js');
|
||||
const mapped = devices.map((device) => pickAndRename(device, fields));
|
||||
console.log(JSON.stringify(mapped, null, 4));
|
||||
} else {
|
||||
|
@ -16,12 +16,12 @@
|
||||
*/
|
||||
import { Flags } from '@oclif/core';
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
import * as _ from 'lodash';
|
||||
import Command from '../../command';
|
||||
import _ from 'lodash';
|
||||
import Command from '../../command.js';
|
||||
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { CommandHelp } from '../../utils/oclif-utils';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { CommandHelp } from '../../utils/oclif-utils.js';
|
||||
|
||||
export default class DevicesSupportedCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -65,9 +65,9 @@ export default class DevicesSupportedCmd extends Command {
|
||||
},
|
||||
},
|
||||
} satisfies BalenaSdk.PineOptions<BalenaSdk.DeviceType>;
|
||||
const dts = (await getBalenaSdk().models.deviceType.getAllSupported(
|
||||
pineOptions,
|
||||
)) as Array<
|
||||
const dts = (await (
|
||||
await getBalenaSdk()
|
||||
).models.deviceType.getAllSupported(pineOptions)) as Array<
|
||||
BalenaSdk.PineTypedResult<BalenaSdk.DeviceType, typeof pineOptions>
|
||||
>;
|
||||
interface DT {
|
||||
|
16
lib/commands/env/add.ts
vendored
16
lib/commands/env/add.ts
vendored
@ -17,11 +17,11 @@
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
interface FlagsDef {
|
||||
fleet?: string;
|
||||
@ -128,7 +128,7 @@ export default class EnvAddCmd extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const reservedPrefixes = await getReservedPrefixes(balena);
|
||||
const isConfigVar = reservedPrefixes.some((prefix) =>
|
||||
params.name.startsWith(prefix),
|
||||
@ -185,7 +185,7 @@ async function resolveFleetSlugs(
|
||||
fleetOption: string,
|
||||
) {
|
||||
const fleetSlugs: string[] = [];
|
||||
const { getFleetSlug } = await import('../../utils/sdk');
|
||||
const { getFleetSlug } = await import('../../utils/sdk.js');
|
||||
for (const appNameOrSlug of fleetOption.split(',')) {
|
||||
try {
|
||||
fleetSlugs.push(await getFleetSlug(balena, appNameOrSlug));
|
||||
@ -222,7 +222,7 @@ async function setServiceVars(
|
||||
}
|
||||
}
|
||||
} else if (options.device) {
|
||||
const { getDeviceAndAppFromUUID } = await import('../../utils/cloud');
|
||||
const { getDeviceAndAppFromUUID } = await import('../../utils/cloud.js');
|
||||
for (const uuid of options.device.split(',')) {
|
||||
let device;
|
||||
let app;
|
||||
|
14
lib/commands/env/rename.ts
vendored
14
lib/commands/env/rename.ts
vendored
@ -15,12 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import Command from '../../command.js';
|
||||
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ec from '../../utils/env-common';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { parseAsInteger } from '../../utils/validation';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ec from '../../utils/env-common.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { parseAsInteger } from '../../utils/validation.js';
|
||||
|
||||
export default class EnvRenameCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -67,7 +67,9 @@ export default class EnvRenameCmd extends Command {
|
||||
|
||||
await Command.checkLoggedIn();
|
||||
|
||||
await getBalenaSdk().pine.patch({
|
||||
await (
|
||||
await getBalenaSdk()
|
||||
).pine.patch({
|
||||
resource: ec.getVarResourceName(opt.config, opt.device, opt.service),
|
||||
id: params.id,
|
||||
body: {
|
||||
|
12
lib/commands/env/rm.ts
vendored
12
lib/commands/env/rm.ts
vendored
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import Command from '../../command.js';
|
||||
|
||||
import * as ec from '../../utils/env-common';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { parseAsInteger } from '../../utils/validation';
|
||||
import * as ec from '../../utils/env-common.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { parseAsInteger } from '../../utils/validation.js';
|
||||
|
||||
export default class EnvRmCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -71,13 +71,13 @@ export default class EnvRmCmd extends Command {
|
||||
|
||||
await Command.checkLoggedIn();
|
||||
|
||||
const { confirm } = await import('../../utils/patterns');
|
||||
const { confirm } = await import('../../utils/patterns.js');
|
||||
await confirm(
|
||||
opt.yes || false,
|
||||
'Are you sure you want to delete the environment variable?',
|
||||
);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
await balena.pine.delete({
|
||||
resource: ec.getVarResourceName(opt.config, opt.device, opt.service),
|
||||
id: params.id,
|
||||
|
@ -17,12 +17,12 @@
|
||||
import { Flags } from '@oclif/core';
|
||||
import type { Interfaces } from '@oclif/core';
|
||||
import type * as SDK from 'balena-sdk';
|
||||
import * as _ from 'lodash';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import _ from 'lodash';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
type FlagsDef = Interfaces.InferredFlags<typeof EnvsCmd.flags>;
|
||||
|
||||
@ -121,18 +121,18 @@ export default class EnvsCmd extends Command {
|
||||
throw new ExpectedError('Missing --fleet or --device option');
|
||||
}
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
let fleetSlug: string | undefined = options.fleet
|
||||
? await (
|
||||
await import('../../utils/sdk')
|
||||
await import('../../utils/sdk.js')
|
||||
).getFleetSlug(balena, options.fleet)
|
||||
: undefined;
|
||||
let fullUUID: string | undefined; // as oppposed to the short, 7-char UUID
|
||||
|
||||
if (options.device) {
|
||||
const { getDeviceAndMaybeAppFromUUID } = await import(
|
||||
'../../utils/cloud'
|
||||
'../../utils/cloud.js'
|
||||
);
|
||||
const [device, app] = await getDeviceAndMaybeAppFromUUID(
|
||||
balena,
|
||||
@ -186,7 +186,7 @@ export default class EnvsCmd extends Command {
|
||||
}
|
||||
|
||||
if (options.json) {
|
||||
const { pickAndRename } = await import('../../utils/helpers');
|
||||
const { pickAndRename } = await import('../../utils/helpers.js');
|
||||
const mapped = varArray.map((o) => pickAndRename(o, fields));
|
||||
this.log(JSON.stringify(mapped, null, 4));
|
||||
} else {
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class FleetCreateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -77,7 +77,7 @@ export default class FleetCreateCmd extends Command {
|
||||
const { args: params, flags: options } = await this.parse(FleetCreateCmd);
|
||||
|
||||
await (
|
||||
await import('../../utils/application-create')
|
||||
await import('../../utils/application-create.js')
|
||||
).applicationCreateBase('fleet', options, params);
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class FleetCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -58,9 +58,9 @@ export default class FleetCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(FleetCmd);
|
||||
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const application = await getApplication(balena, params.fleet, {
|
||||
$expand: {
|
||||
@ -70,7 +70,7 @@ export default class FleetCmd extends Command {
|
||||
});
|
||||
|
||||
if (options.view) {
|
||||
const open = await import('open');
|
||||
const { default: open } = await import('open');
|
||||
const dashboardUrl = balena.models.application.getDashboardUrl(
|
||||
application.id,
|
||||
);
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { getExpandedProp } from '../../utils/pine';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { getExpandedProp } from '../../utils/pine.js';
|
||||
|
||||
export default class FleetPinCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -55,7 +55,7 @@ export default class FleetPinCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(FleetPinCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const fleet = await balena.models.application.get(params.slug, {
|
||||
$expand: {
|
||||
|
@ -15,11 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class FleetPurgeCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -51,9 +51,9 @@ export default class FleetPurgeCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(FleetPurgeCmd);
|
||||
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// balena.models.application.purge only accepts a numeric id
|
||||
// so we must first fetch the app to get it's id,
|
||||
|
@ -17,11 +17,11 @@
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class FleetRenameCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -59,13 +59,15 @@ export default class FleetRenameCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(FleetRenameCmd);
|
||||
|
||||
const { validateApplicationName } = await import('../../utils/validation');
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { validateApplicationName } = await import(
|
||||
'../../utils/validation.js'
|
||||
);
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Disambiguate target application (if params.params is a number, it could either be an ID or a numerical name)
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
const application = await getApplication(balena, params.fleet, {
|
||||
$select: ['id', 'app_name', 'slug'],
|
||||
$expand: {
|
||||
|
@ -15,11 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class FleetRestartCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -50,9 +50,9 @@ export default class FleetRestartCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(FleetRestartCmd);
|
||||
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Disambiguate application
|
||||
const application = await getApplication(balena, params.fleet, {
|
||||
|
@ -15,11 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import * as ca from '../../utils/common-args';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import * as ca from '../../utils/common-args.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class FleetRmCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -54,9 +54,9 @@ export default class FleetRmCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(FleetRmCmd);
|
||||
|
||||
const { confirm } = await import('../../utils/patterns');
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const balena = getBalenaSdk();
|
||||
const { confirm } = await import('../../utils/patterns.js');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Confirm
|
||||
await confirm(
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class FleetTrackLatestCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -49,7 +49,7 @@ export default class FleetTrackLatestCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(FleetTrackLatestCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
await balena.models.application.trackLatestRelease(params.slug);
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
interface ExtendedApplication extends ApplicationWithDeviceTypeSlug {
|
||||
device_count: number;
|
||||
@ -52,7 +52,7 @@ export default class FleetsCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(FleetsCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const pineOptions = {
|
||||
$select: ['id', 'app_name', 'slug'],
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import { CommandHelp } from '../../utils/oclif-utils';
|
||||
import Command from '../../command.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
import { CommandHelp } from '../../utils/oclif-utils.js';
|
||||
|
||||
// 'Internal' commands are called during the execution of other commands.
|
||||
// `osinit` is called during `os initialize`
|
||||
@ -63,7 +63,7 @@ export default class OsinitCmd extends Command {
|
||||
const config = JSON.parse(params.config);
|
||||
|
||||
const { getManifest, osProgressHandler } = await import(
|
||||
'../../utils/helpers'
|
||||
'../../utils/helpers.js'
|
||||
);
|
||||
const manifest = await getManifest(params.image, params.type);
|
||||
|
||||
|
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Args, Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import { parseAsLocalHostnameOrIp } from '../../utils/validation';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
import { parseAsLocalHostnameOrIp } from '../../utils/validation.js';
|
||||
|
||||
export default class JoinCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -78,8 +78,8 @@ export default class JoinCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(JoinCmd);
|
||||
|
||||
const promote = await import('../../utils/promote');
|
||||
const sdk = getBalenaSdk();
|
||||
const promote = await import('../../utils/promote.js');
|
||||
const sdk = await getBalenaSdk();
|
||||
const logger = await Command.getLogger();
|
||||
return promote.join(
|
||||
logger,
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class KeyAddCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -84,6 +84,6 @@ export default class KeyAddCmd extends Command {
|
||||
throw new ExpectedError('No public key file or path provided.');
|
||||
}
|
||||
|
||||
await getBalenaSdk().models.key.create(params.name, key);
|
||||
await (await getBalenaSdk()).models.key.create(params.name, key);
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { parseAsInteger } from '../../utils/validation';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { parseAsInteger } from '../../utils/validation.js';
|
||||
|
||||
export default class KeyCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -49,7 +49,7 @@ export default class KeyCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(KeyCmd);
|
||||
|
||||
const key = await getBalenaSdk().models.key.get(params.id);
|
||||
const key = await (await getBalenaSdk()).models.key.get(params.id);
|
||||
|
||||
// Use 'name' instead of 'title' to match dashboard.
|
||||
const displayKey = {
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { parseAsInteger } from '../../utils/validation';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { parseAsInteger } from '../../utils/validation.js';
|
||||
|
||||
export default class KeyRmCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -52,13 +52,13 @@ export default class KeyRmCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(KeyRmCmd);
|
||||
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
|
||||
await patterns.confirm(
|
||||
options.yes ?? false,
|
||||
`Are you sure you want to delete key ${params.id}?`,
|
||||
);
|
||||
|
||||
await getBalenaSdk().models.key.remove(params.id);
|
||||
await (await getBalenaSdk()).models.key.remove(params.id);
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class KeysCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -38,7 +38,7 @@ export default class KeysCmd extends Command {
|
||||
public async run() {
|
||||
await this.parse(KeysCmd);
|
||||
|
||||
const keys = await getBalenaSdk().models.key.getAll();
|
||||
const keys = await (await getBalenaSdk()).models.key.getAll();
|
||||
|
||||
// Use 'name' instead of 'title' to match dashboard.
|
||||
const displayKeys: Array<{ id: number; name: string }> = keys.map((k) => {
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import { parseAsLocalHostnameOrIp } from '../../utils/validation';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
import { parseAsLocalHostnameOrIp } from '../../utils/validation.js';
|
||||
|
||||
export default class LeaveCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -62,7 +62,7 @@ export default class LeaveCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(LeaveCmd);
|
||||
|
||||
const promote = await import('../../utils/promote');
|
||||
const promote = await import('../../utils/promote.js');
|
||||
const logger = await Command.getLogger();
|
||||
return promote.leave(logger, params.deviceIpOrHostname);
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import { promisify } from 'util';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class LocalConfigureCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -53,8 +53,8 @@ export default class LocalConfigureCmd extends Command {
|
||||
const { args: params } = await this.parse(LocalConfigureCmd);
|
||||
|
||||
const reconfix = await import('reconfix');
|
||||
const { denyMount, safeUmount } = await import('../../utils/umount');
|
||||
const Logger = await import('../../utils/logger');
|
||||
const { denyMount, safeUmount } = await import('../../utils/umount.js');
|
||||
const { default: Logger } = await import('../../utils/logger.js');
|
||||
|
||||
const logger = Logger.getLogger();
|
||||
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import type { BlockDevice } from 'etcher-sdk/build/source-destination';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getChalk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getChalk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class LocalFlashCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -79,7 +79,7 @@ export default class LocalFlashCmd extends Command {
|
||||
|
||||
const drive = await this.getDrive(options);
|
||||
|
||||
const { confirm } = await import('../../utils/patterns');
|
||||
const { confirm } = await import('../../utils/patterns.js');
|
||||
await confirm(
|
||||
options.yes,
|
||||
'This will erase the selected drive. Are you sure?',
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import type { WhoamiResult } from 'balena-sdk';
|
||||
|
||||
interface FlagsDef {
|
||||
@ -122,8 +122,8 @@ export default class LoginCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options, args: params } = await this.parse(LoginCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const messages = await import('../../utils/messages');
|
||||
const balena = await getBalenaSdk();
|
||||
const messages = await import('../../utils/messages.js');
|
||||
const balenaUrl = await balena.settings.get('balenaUrl');
|
||||
|
||||
// Consolidate user/email options
|
||||
@ -186,7 +186,7 @@ ${messages.reachingOut}`);
|
||||
type: 'input',
|
||||
});
|
||||
}
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
await balena.auth.loginWithToken(token!);
|
||||
try {
|
||||
if (!(await balena.auth.whoami())) {
|
||||
@ -202,20 +202,20 @@ ${messages.reachingOut}`);
|
||||
}
|
||||
// Credentials
|
||||
else if (loginOptions.credentials) {
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
return patterns.authenticate(loginOptions);
|
||||
}
|
||||
// Web
|
||||
else if (loginOptions.web) {
|
||||
const auth = await import('../../auth');
|
||||
const auth = await import('../../auth/index.js');
|
||||
await auth.login({ port: loginOptions.port });
|
||||
return;
|
||||
} else {
|
||||
const patterns = await import('../../utils/patterns');
|
||||
const patterns = await import('../../utils/patterns.js');
|
||||
// User had not selected login preference, prompt interactively
|
||||
const loginType = await patterns.askLoginType();
|
||||
if (loginType === 'register') {
|
||||
const open = await import('open');
|
||||
const { default: open } = await import('open');
|
||||
const signupUrl = `https://dashboard.${balenaUrl}/signup`;
|
||||
await open(signupUrl, { wait: false });
|
||||
throw new ExpectedError(`Please sign up at ${signupUrl}`);
|
||||
|
@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class LogoutCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -30,6 +30,6 @@ export default class LogoutCmd extends Command {
|
||||
|
||||
public async run() {
|
||||
await this.parse(LogoutCmd);
|
||||
await getBalenaSdk().auth.logout();
|
||||
await (await getBalenaSdk()).auth.logout();
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { LogMessage } from 'balena-sdk';
|
||||
|
||||
const MAX_RETRY = 1000;
|
||||
@ -95,15 +95,15 @@ export default class LogsCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(LogsCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const { serviceIdToName } = await import('../../utils/cloud');
|
||||
const balena = await getBalenaSdk();
|
||||
const { serviceIdToName } = await import('../../utils/cloud.js');
|
||||
const { connectAndDisplayDeviceLogs, displayLogObject } = await import(
|
||||
'../../utils/device/logs'
|
||||
'../../utils/device/logs.js'
|
||||
);
|
||||
const { validateIPAddress, validateDotLocalUrl } = await import(
|
||||
'../../utils/validation'
|
||||
'../../utils/validation.js'
|
||||
);
|
||||
const Logger = await import('../../utils/logger');
|
||||
const { default: Logger } = await import('../../utils/logger.js');
|
||||
|
||||
const logger = Logger.getLogger();
|
||||
|
||||
@ -132,13 +132,13 @@ export default class LogsCmd extends Command {
|
||||
validateDotLocalUrl(params.device)
|
||||
) {
|
||||
// Logs from local device
|
||||
const { DeviceAPI } = await import('../../utils/device/api');
|
||||
const { DeviceAPI } = await import('../../utils/device/api.js');
|
||||
const deviceApi = new DeviceAPI(logger, params.device);
|
||||
logger.logDebug('Checking we can access device');
|
||||
try {
|
||||
await deviceApi.ping();
|
||||
} catch (e) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(
|
||||
`Cannot access device at address ${params.device}. Device may not be in local mode.`,
|
||||
);
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class NoteCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -73,7 +73,7 @@ export default class NoteCmd extends Command {
|
||||
throw new ExpectedError('Missing device UUID (--device)');
|
||||
}
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
return balena.models.device.setNote(options.device, params.note);
|
||||
}
|
||||
|
@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class OrgsCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -38,10 +38,10 @@ export default class OrgsCmd extends Command {
|
||||
public async run() {
|
||||
await this.parse(OrgsCmd);
|
||||
|
||||
const { getOwnOrganizations } = await import('../../utils/sdk');
|
||||
const { getOwnOrganizations } = await import('../../utils/sdk.js');
|
||||
|
||||
// Get organizations
|
||||
const organizations = await getOwnOrganizations(getBalenaSdk(), {
|
||||
const organizations = await getOwnOrganizations(await getBalenaSdk(), {
|
||||
$select: ['name', 'handle'],
|
||||
});
|
||||
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getCliForm, stripIndent } from '../../utils/lazy';
|
||||
import * as _ from 'lodash';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getCliForm, stripIndent } from '../../utils/lazy.js';
|
||||
import _ from 'lodash';
|
||||
import type { DeviceTypeJson } from 'balena-sdk';
|
||||
|
||||
export default class OsBuildConfigCmd extends Command {
|
||||
@ -82,7 +82,7 @@ export default class OsBuildConfigCmd extends Command {
|
||||
async buildConfig(image: string, deviceTypeSlug: string, advanced: boolean) {
|
||||
advanced = advanced || false;
|
||||
|
||||
const { getManifest } = await import('../../utils/helpers');
|
||||
const { getManifest } = await import('../../utils/helpers.js');
|
||||
|
||||
const deviceTypeManifest = await getManifest(image, deviceTypeSlug);
|
||||
return this.buildConfigForDeviceType(deviceTypeManifest, advanced);
|
||||
@ -103,7 +103,7 @@ export default class OsBuildConfigCmd extends Command {
|
||||
});
|
||||
|
||||
if (advancedGroup != null) {
|
||||
const { getGroupDefaults } = await import('../../utils/helpers');
|
||||
const { getGroupDefaults } = await import('../../utils/helpers.js');
|
||||
override = getGroupDefaults(advancedGroup);
|
||||
}
|
||||
}
|
||||
|
@ -19,16 +19,16 @@ import { Flags, Args } from '@oclif/core';
|
||||
import type { Interfaces } from '@oclif/core';
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
import { promisify } from 'util';
|
||||
import * as _ from 'lodash';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy';
|
||||
import _ from 'lodash';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js';
|
||||
import {
|
||||
applicationIdInfo,
|
||||
devModeInfo,
|
||||
secureBootInfo,
|
||||
} from '../../utils/messages';
|
||||
} from '../../utils/messages.js';
|
||||
|
||||
const CONNECTIONS_FOLDER = '/system-connections';
|
||||
|
||||
@ -175,16 +175,16 @@ export default class OsConfigureCmd extends Command {
|
||||
const devInit = await import('balena-device-init');
|
||||
const { promises: fs } = await import('fs');
|
||||
const { generateDeviceConfig, generateApplicationConfig } = await import(
|
||||
'../../utils/config'
|
||||
'../../utils/config.js'
|
||||
);
|
||||
const helpers = await import('../../utils/helpers');
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const helpers = await import('../../utils/helpers.js');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
let app: ApplicationWithDeviceTypeSlug | undefined;
|
||||
let device;
|
||||
let deviceTypeSlug: string;
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
if (options.device) {
|
||||
device = (await balena.models.device.get(options.device, {
|
||||
$expand: {
|
||||
@ -210,7 +210,7 @@ export default class OsConfigureCmd extends Command {
|
||||
deviceTypeSlug,
|
||||
);
|
||||
|
||||
let configJson: import('../../utils/config').ImgConfig | undefined;
|
||||
let configJson: import('../../utils/config.js').ImgConfig | undefined;
|
||||
if (options.config) {
|
||||
const rawConfig = await fs.readFile(options.config, 'utf8');
|
||||
configJson = JSON.parse(rawConfig);
|
||||
@ -220,11 +220,11 @@ export default class OsConfigureCmd extends Command {
|
||||
options.version ||
|
||||
(await getOsVersionFromImage(params.image, deviceTypeManifest, devInit));
|
||||
|
||||
const { validateDevOptionAndWarn } = await import('../../utils/config');
|
||||
const { validateDevOptionAndWarn } = await import('../../utils/config.js');
|
||||
await validateDevOptionAndWarn(options.dev, osVersion);
|
||||
|
||||
const { validateSecureBootOptionAndWarn } = await import(
|
||||
'../../utils/config'
|
||||
'../../utils/config.js'
|
||||
);
|
||||
await validateSecureBootOptionAndWarn(
|
||||
options.secureBoot,
|
||||
@ -362,7 +362,7 @@ async function checkDeviceTypeCompatibility(
|
||||
},
|
||||
) {
|
||||
if (options['device-type']) {
|
||||
const helpers = await import('../../utils/helpers');
|
||||
const helpers = await import('../../utils/helpers.js');
|
||||
if (
|
||||
!(await helpers.areDeviceTypesCompatible(
|
||||
app.is_for__device_type[0].slug,
|
||||
@ -393,7 +393,7 @@ async function checkDeviceTypeCompatibility(
|
||||
async function askQuestionsForDeviceType(
|
||||
deviceType: BalenaSdk.DeviceTypeJson.DeviceType,
|
||||
options: FlagsDef,
|
||||
configJson?: import('../../utils/config').ImgConfig,
|
||||
configJson?: import('../../utils/config.js').ImgConfig,
|
||||
): Promise<Answers> {
|
||||
const answerSources: any[] = [
|
||||
{
|
||||
@ -416,7 +416,7 @@ async function askQuestionsForDeviceType(
|
||||
isGroup: true,
|
||||
});
|
||||
if (!_.isEmpty(advancedGroup)) {
|
||||
const helpers = await import('../../utils/helpers');
|
||||
const helpers = await import('../../utils/helpers.js');
|
||||
answerSources.push(helpers.getGroupDefaults(advancedGroup));
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class OsDownloadCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -95,7 +95,7 @@ export default class OsDownloadCmd extends Command {
|
||||
await OsDownloadCmd.checkLoggedIn();
|
||||
} catch (e) {
|
||||
const { ExpectedError, NotLoggedInError } = await import(
|
||||
'../../errors'
|
||||
'../../errors.js'
|
||||
);
|
||||
if (e instanceof NotLoggedInError) {
|
||||
throw new ExpectedError(stripIndent`
|
||||
@ -107,7 +107,7 @@ export default class OsDownloadCmd extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
const { downloadOSImage } = await import('../../utils/cloud');
|
||||
const { downloadOSImage } = await import('../../utils/cloud.js');
|
||||
|
||||
try {
|
||||
await downloadOSImage(params.type, options.output, options.version);
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getCliForm, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getCliForm, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
const INIT_WARNING_MESSAGE = `
|
||||
|
||||
@ -62,7 +62,7 @@ export default class OsInitializeCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(OsInitializeCmd);
|
||||
|
||||
const { getManifest, sudo } = await import('../../utils/helpers');
|
||||
const { getManifest, sudo } = await import('../../utils/helpers.js');
|
||||
|
||||
console.info(`Initializing device ${INIT_WARNING_MESSAGE}`);
|
||||
|
||||
@ -75,13 +75,13 @@ export default class OsInitializeCmd extends Command {
|
||||
});
|
||||
|
||||
if (answers.drive != null) {
|
||||
const { confirm } = await import('../../utils/patterns');
|
||||
const { confirm } = await import('../../utils/patterns.js');
|
||||
await confirm(
|
||||
options.yes,
|
||||
`This will erase ${answers.drive}. Are you sure?`,
|
||||
`Going to erase ${answers.drive}.`,
|
||||
);
|
||||
const { safeUmount } = await import('../../utils/umount');
|
||||
const { safeUmount } = await import('../../utils/umount.js');
|
||||
await safeUmount(answers.drive);
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ export default class OsInitializeCmd extends Command {
|
||||
]);
|
||||
|
||||
if (answers.drive != null) {
|
||||
const { safeUmount } = await import('../../utils/umount');
|
||||
const { safeUmount } = await import('../../utils/umount.js');
|
||||
await safeUmount(answers.drive);
|
||||
console.info(`You can safely remove ${answers.drive} now`);
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class OsVersionsCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -54,7 +54,7 @@ export default class OsVersionsCmd extends Command {
|
||||
const { args: params, flags: options } = await this.parse(OsVersionsCmd);
|
||||
|
||||
const { formatOsVersion, getOsVersions } = await import(
|
||||
'../../utils/cloud'
|
||||
'../../utils/cloud.js'
|
||||
);
|
||||
const vs = await getOsVersions(params.type, !!options.esr);
|
||||
|
||||
|
@ -15,21 +15,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import {
|
||||
getBalenaSdk,
|
||||
getCliForm,
|
||||
getVisuals,
|
||||
stripIndent,
|
||||
} from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import { dockerConnectionCliFlags } from '../../utils/docker';
|
||||
import { parseAsInteger } from '../../utils/validation';
|
||||
} from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
import { dockerConnectionCliFlags } from '../../utils/docker.js';
|
||||
import { parseAsInteger } from '../../utils/validation.js';
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import * as _ from 'lodash';
|
||||
import _ from 'lodash';
|
||||
import type {
|
||||
Application,
|
||||
BalenaSDK,
|
||||
@ -39,6 +39,7 @@ import type {
|
||||
Release,
|
||||
} from 'balena-sdk';
|
||||
import type { Preloader } from 'balena-preload';
|
||||
import type EventEmitter from 'events';
|
||||
|
||||
export default class PreloadCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -144,11 +145,11 @@ Can be repeated to add multiple certificates.\
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(PreloadCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const balenaPreload = await import('balena-preload');
|
||||
const visuals = getVisuals();
|
||||
const nodeCleanup = await import('node-cleanup');
|
||||
const { instanceOf } = await import('../../errors');
|
||||
const { instanceOf } = await import('../../errors.js');
|
||||
|
||||
// Check image file exists
|
||||
try {
|
||||
@ -172,7 +173,7 @@ Can be repeated to add multiple certificates.\
|
||||
// Load app here, and use app slug from hereon
|
||||
const fleetSlug: string | undefined = options.fleet
|
||||
? await (
|
||||
await import('../../utils/sdk')
|
||||
await import('../../utils/sdk.js')
|
||||
).getFleetSlug(balena, options.fleet)
|
||||
: undefined;
|
||||
|
||||
@ -229,7 +230,7 @@ Can be repeated to add multiple certificates.\
|
||||
}
|
||||
|
||||
// Get a configured dockerode instance
|
||||
const dockerUtils = await import('../../utils/docker');
|
||||
const dockerUtils = await import('../../utils/docker.js');
|
||||
const docker = await dockerUtils.getDocker(options);
|
||||
const preloader = new balenaPreload.Preloader(
|
||||
undefined,
|
||||
@ -243,11 +244,11 @@ Can be repeated to add multiple certificates.\
|
||||
pinDevice ?? false,
|
||||
certificates,
|
||||
additionalSpace,
|
||||
);
|
||||
) as Preloader & EventEmitter;
|
||||
|
||||
let gotSignal = false;
|
||||
|
||||
nodeCleanup(function (_exitCode, signal) {
|
||||
nodeCleanup.default(function (_exitCode, signal) {
|
||||
if (signal) {
|
||||
gotSignal = true;
|
||||
nodeCleanup.uninstall(); // don't call cleanup handler again
|
||||
@ -326,7 +327,7 @@ Can be repeated to add multiple certificates.\
|
||||
}
|
||||
|
||||
async getApplicationsWithSuccessfulBuilds(deviceTypeSlug: string) {
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
try {
|
||||
await balena.models.deviceType.get(deviceTypeSlug);
|
||||
@ -434,7 +435,7 @@ Can be repeated to add multiple certificates.\
|
||||
commit: string,
|
||||
pinDevice: boolean | undefined,
|
||||
) {
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
if (
|
||||
this.isCurrentCommit(commit) ||
|
||||
@ -481,7 +482,7 @@ Would you like to disable automatic updates for this fleet now?\
|
||||
}
|
||||
|
||||
async getAppWithReleases(balenaSdk: BalenaSDK, slug: string) {
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
return await getApplication(balenaSdk, slug, {
|
||||
$expand: this.applicationExpandOptions,
|
||||
|
@ -17,18 +17,18 @@
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import type { Interfaces } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { dockerignoreHelp, registrySecretsHelp } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { dockerignoreHelp, registrySecretsHelp } from '../../utils/messages.js';
|
||||
import type { BalenaSDK } from 'balena-sdk';
|
||||
import { ExpectedError, instanceOf } from '../../errors';
|
||||
import { ExpectedError, instanceOf } from '../../errors.js';
|
||||
import { RegistrySecrets } from '@balena/compose/dist/multibuild';
|
||||
import { lowercaseIfSlug } from '../../utils/normalization';
|
||||
import { lowercaseIfSlug } from '../../utils/normalization.js';
|
||||
import {
|
||||
applyReleaseTagKeysAndValues,
|
||||
parseReleaseTagKeysAndValues,
|
||||
} from '../../utils/compose_ts';
|
||||
} from '../../utils/compose_ts.js';
|
||||
|
||||
enum BuildTarget {
|
||||
Cloud,
|
||||
@ -232,8 +232,10 @@ export default class PushCmd extends Command {
|
||||
const logger = await Command.getLogger();
|
||||
logger.logDebug(`Using build source directory: ${options.source} `);
|
||||
|
||||
const sdk = getBalenaSdk();
|
||||
const { validateProjectDirectory } = await import('../../utils/compose_ts');
|
||||
const sdk = await getBalenaSdk();
|
||||
const { validateProjectDirectory } = await import(
|
||||
'../../utils/compose_ts.js'
|
||||
);
|
||||
const { dockerfilePath, registrySecrets } = await validateProjectDirectory(
|
||||
sdk,
|
||||
{
|
||||
@ -276,8 +278,8 @@ export default class PushCmd extends Command {
|
||||
dockerfilePath: string,
|
||||
registrySecrets: RegistrySecrets,
|
||||
) {
|
||||
const remote = await import('../../utils/remote-build');
|
||||
const { getApplication } = await import('../../utils/sdk');
|
||||
const remote = await import('../../utils/remote-build.js');
|
||||
const { getApplication } = await import('../../utils/sdk.js');
|
||||
|
||||
// Check for invalid options
|
||||
const localOnlyOptions: Array<keyof FlagsDef> = [
|
||||
@ -356,7 +358,7 @@ export default class PushCmd extends Command {
|
||||
'is only valid when pushing to a fleet',
|
||||
);
|
||||
|
||||
const deviceDeploy = await import('../../utils/device/deploy');
|
||||
const deviceDeploy = await import('../../utils/device/deploy.js');
|
||||
|
||||
try {
|
||||
await deviceDeploy.deployToDevice({
|
||||
@ -376,7 +378,7 @@ export default class PushCmd extends Command {
|
||||
convertEol: !options['noconvert-eol'],
|
||||
});
|
||||
} catch (e) {
|
||||
const { BuildError } = await import('../../utils/device/errors');
|
||||
const { BuildError } = await import('../../utils/device/errors.js');
|
||||
if (instanceOf(e, BuildError)) {
|
||||
throw new ExpectedError(e.toString());
|
||||
} else {
|
||||
@ -387,7 +389,7 @@ export default class PushCmd extends Command {
|
||||
|
||||
protected async getBuildTarget(appOrDevice: string): Promise<BuildTarget> {
|
||||
const { validateLocalHostnameOrIp } = await import(
|
||||
'../../utils/validation'
|
||||
'../../utils/validation.js'
|
||||
);
|
||||
|
||||
return validateLocalHostnameOrIp(appOrDevice)
|
||||
|
@ -15,10 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { commitOrIdArg } from '.';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { commitOrIdArg } from './index.js';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ReleaseFinalizeCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -58,7 +58,7 @@ export default class ReleaseFinalizeCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(ReleaseFinalizeCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const release = await balena.models.release.get(params.commitOrId, {
|
||||
$select: ['id', 'is_final'],
|
||||
|
@ -14,15 +14,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Flags, Args, type Interfaces } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
import jsyaml = require('js-yaml');
|
||||
import { tryAsInteger } from '../../utils/validation';
|
||||
import { jsonInfo } from '../../utils/messages';
|
||||
import jsyaml from 'js-yaml';
|
||||
import { tryAsInteger } from '../../utils/validation.js';
|
||||
import { jsonInfo } from '../../utils/messages.js';
|
||||
|
||||
export const commitOrIdArg = Args.custom({
|
||||
parse: async (commitOrId: string) => tryAsInteger(commitOrId),
|
||||
@ -66,7 +65,7 @@ export default class ReleaseCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(ReleaseCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
if (options.composition) {
|
||||
await this.showComposition(params.commitOrId, balena);
|
||||
} else {
|
||||
|
@ -15,10 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { commitOrIdArg } from '.';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { commitOrIdArg } from './index.js';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ReleaseInvalidateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -53,7 +53,7 @@ export default class ReleaseInvalidateCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(ReleaseInvalidateCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const release = await balena.models.release.get(params.commitOrId, {
|
||||
$select: ['id', 'is_invalidated'],
|
||||
|
@ -15,10 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { commitOrIdArg } from '.';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { commitOrIdArg } from './index.js';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ReleaseValidateCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -52,7 +52,7 @@ export default class ReleaseValidateCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params } = await this.parse(ReleaseValidateCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const release = await balena.models.release.get(params.commitOrId, {
|
||||
$select: ['id', 'is_invalidated'],
|
||||
|
@ -16,12 +16,12 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { applicationNameNote } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationNameNote } from '../../utils/messages.js';
|
||||
import type * as BalenaSdk from 'balena-sdk';
|
||||
import { jsonInfo } from '../../utils/messages';
|
||||
import { jsonInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class ReleasesCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -66,8 +66,8 @@ export default class ReleasesCmd extends Command {
|
||||
'is_final',
|
||||
];
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const { getFleetSlug } = await import('../../utils/sdk');
|
||||
const balena = await getBalenaSdk();
|
||||
const { getFleetSlug } = await import('../../utils/sdk.js');
|
||||
|
||||
const releases = await balena.models.release.getAllByApplication(
|
||||
await getFleetSlug(balena, params.fleet),
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getCliUx, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getCliUx, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class ScanCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -65,10 +65,10 @@ export default class ScanCmd extends Command {
|
||||
public async run() {
|
||||
const _ = await import('lodash');
|
||||
const { discoverLocalBalenaOsDevices } = await import(
|
||||
'../../utils/discover'
|
||||
'../../utils/discover.js'
|
||||
);
|
||||
const prettyjson = await import('prettyjson');
|
||||
const dockerUtils = await import('../../utils/docker');
|
||||
const dockerUtils = await import('../../utils/docker.js');
|
||||
|
||||
const dockerPort = 2375;
|
||||
const dockerTimeout = 2000;
|
||||
|
@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class SettingsCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -36,7 +36,7 @@ export default class SettingsCmd extends Command {
|
||||
public async run() {
|
||||
await this.parse(SettingsCmd);
|
||||
|
||||
const settings = await getBalenaSdk().settings.getAll();
|
||||
const settings = await (await getBalenaSdk()).settings.getAll();
|
||||
|
||||
const prettyjson = await import('prettyjson');
|
||||
console.log(prettyjson.render(settings));
|
||||
|
@ -16,13 +16,13 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import {
|
||||
parseAsInteger,
|
||||
validateLocalHostnameOrIp,
|
||||
} from '../../utils/validation';
|
||||
} from '../../utils/validation.js';
|
||||
|
||||
export default class SshCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -111,7 +111,9 @@ export default class SshCmd extends Command {
|
||||
|
||||
// Local connection
|
||||
if (validateLocalHostnameOrIp(params.fleetOrDevice)) {
|
||||
const { performLocalDeviceSSH } = await import('../../utils/device/ssh');
|
||||
const { performLocalDeviceSSH } = await import(
|
||||
'../../utils/device/ssh.js'
|
||||
);
|
||||
return await performLocalDeviceSSH({
|
||||
hostname: params.fleetOrDevice,
|
||||
port: options.port || 'local',
|
||||
@ -122,9 +124,11 @@ export default class SshCmd extends Command {
|
||||
}
|
||||
|
||||
// Remote connection
|
||||
const { getProxyConfig } = await import('../../utils/helpers');
|
||||
const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns');
|
||||
const sdk = getBalenaSdk();
|
||||
const { getProxyConfig } = await import('../../utils/helpers.js');
|
||||
const { getOnlineTargetDeviceUuid } = await import(
|
||||
'../../utils/patterns.js'
|
||||
);
|
||||
const sdk = await getBalenaSdk();
|
||||
|
||||
const proxyConfig = getProxyConfig();
|
||||
const useProxy = !!proxyConfig && !options.noproxy;
|
||||
@ -137,7 +141,7 @@ export default class SshCmd extends Command {
|
||||
params.fleetOrDevice,
|
||||
);
|
||||
|
||||
const { which } = await import('../../utils/which');
|
||||
const { which } = await import('../../utils/which.js');
|
||||
|
||||
const [whichProxytunnel, { username }, proxyUrl] = await Promise.all([
|
||||
useProxy ? which('proxytunnel', false) : undefined,
|
||||
@ -189,7 +193,7 @@ export default class SshCmd extends Command {
|
||||
let containerId: string | undefined;
|
||||
if (params.service != null) {
|
||||
const { getContainerIdForService } = await import(
|
||||
'../../utils/device/ssh'
|
||||
'../../utils/device/ssh.js'
|
||||
);
|
||||
containerId = await getContainerIdForService({
|
||||
deviceUuid,
|
||||
@ -207,7 +211,7 @@ export default class SshCmd extends Command {
|
||||
} else {
|
||||
accessCommand = `host ${deviceUuid}`;
|
||||
}
|
||||
const { runRemoteCommand } = await import('../../utils/ssh');
|
||||
const { runRemoteCommand } = await import('../../utils/ssh.js');
|
||||
await runRemoteCommand({
|
||||
cmd: accessCommand,
|
||||
hostname: `ssh.${proxyUrl}`,
|
||||
|
@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class SupportCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -77,7 +77,7 @@ export default class SupportCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(SupportCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
const ux = getCliUx();
|
||||
|
||||
const enabling = params.action === 'enable';
|
||||
@ -116,7 +116,7 @@ export default class SupportCmd extends Command {
|
||||
ux.action.stop();
|
||||
}
|
||||
|
||||
const { getFleetSlug } = await import('../../utils/sdk');
|
||||
const { getFleetSlug } = await import('../../utils/sdk.js');
|
||||
|
||||
// Process applications
|
||||
for (const appName of appNames) {
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class TagRmCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -68,16 +68,16 @@ export default class TagRmCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(TagRmCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Check user has specified one of application/device/release
|
||||
if (!options.fleet && !options.device && !options.release) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(TagRmCmd.missingResourceMessage);
|
||||
}
|
||||
|
||||
if (options.fleet) {
|
||||
const { getFleetSlug } = await import('../../utils/sdk');
|
||||
const { getFleetSlug } = await import('../../utils/sdk.js');
|
||||
return balena.models.application.tags.remove(
|
||||
await getFleetSlug(balena, options.fleet),
|
||||
params.tagKey,
|
||||
@ -88,7 +88,7 @@ export default class TagRmCmd extends Command {
|
||||
}
|
||||
if (options.release) {
|
||||
const { disambiguateReleaseParam } = await import(
|
||||
'../../utils/normalization'
|
||||
'../../utils/normalization.js'
|
||||
);
|
||||
const releaseParam = await disambiguateReleaseParam(
|
||||
balena,
|
||||
|
@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class TagSetCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -81,18 +81,18 @@ export default class TagSetCmd extends Command {
|
||||
public async run() {
|
||||
const { args: params, flags: options } = await this.parse(TagSetCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Check user has specified one of application/device/release
|
||||
if (!options.fleet && !options.device && !options.release) {
|
||||
const { ExpectedError } = await import('../../errors');
|
||||
const { ExpectedError } = await import('../../errors.js');
|
||||
throw new ExpectedError(TagSetCmd.missingResourceMessage);
|
||||
}
|
||||
|
||||
params.value ??= '';
|
||||
|
||||
if (options.fleet) {
|
||||
const { getFleetSlug } = await import('../../utils/sdk');
|
||||
const { getFleetSlug } = await import('../../utils/sdk.js');
|
||||
return balena.models.application.tags.set(
|
||||
await getFleetSlug(balena, options.fleet),
|
||||
params.tagKey,
|
||||
@ -108,7 +108,7 @@ export default class TagSetCmd extends Command {
|
||||
}
|
||||
if (options.release) {
|
||||
const { disambiguateReleaseParam } = await import(
|
||||
'../../utils/normalization'
|
||||
'../../utils/normalization.js'
|
||||
);
|
||||
const releaseParam = await disambiguateReleaseParam(
|
||||
balena,
|
||||
|
@ -15,11 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import { ExpectedError } from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { applicationIdInfo } from '../../utils/messages';
|
||||
import Command from '../../command.js';
|
||||
import { ExpectedError } from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
import { applicationIdInfo } from '../../utils/messages.js';
|
||||
|
||||
export default class TagsCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -61,7 +61,7 @@ export default class TagsCmd extends Command {
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(TagsCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
// Check user has specified one of application/device/release
|
||||
if (!options.fleet && !options.device && !options.release) {
|
||||
@ -71,7 +71,7 @@ export default class TagsCmd extends Command {
|
||||
let tags;
|
||||
|
||||
if (options.fleet) {
|
||||
const { getFleetSlug } = await import('../../utils/sdk');
|
||||
const { getFleetSlug } = await import('../../utils/sdk.js');
|
||||
tags = await balena.models.application.tags.getAllByApplication(
|
||||
await getFleetSlug(balena, options.fleet),
|
||||
);
|
||||
@ -81,7 +81,7 @@ export default class TagsCmd extends Command {
|
||||
}
|
||||
if (options.release) {
|
||||
const { disambiguateReleaseParam } = await import(
|
||||
'../../utils/normalization'
|
||||
'../../utils/normalization.js'
|
||||
);
|
||||
const releaseParam = await disambiguateReleaseParam(
|
||||
balena,
|
||||
|
@ -16,15 +16,15 @@
|
||||
*/
|
||||
|
||||
import { Flags, Args } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import Command from '../../command.js';
|
||||
import {
|
||||
NoPortsDefinedError,
|
||||
InvalidPortMappingError,
|
||||
ExpectedError,
|
||||
} from '../../errors';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
||||
import { lowercaseIfSlug } from '../../utils/normalization';
|
||||
} from '../../errors.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { getBalenaSdk, stripIndent } from '../../utils/lazy.js';
|
||||
import { lowercaseIfSlug } from '../../utils/normalization.js';
|
||||
|
||||
import type { Server, Socket } from 'net';
|
||||
|
||||
@ -97,7 +97,7 @@ export default class TunnelCmd extends Command {
|
||||
const { args: params, flags: options } = await this.parse(TunnelCmd);
|
||||
|
||||
const logger = await Command.getLogger();
|
||||
const sdk = getBalenaSdk();
|
||||
const sdk = await getBalenaSdk();
|
||||
|
||||
const logConnection = (
|
||||
fromHost: string,
|
||||
@ -122,7 +122,9 @@ export default class TunnelCmd extends Command {
|
||||
}
|
||||
|
||||
// Ascertain device uuid
|
||||
const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns');
|
||||
const { getOnlineTargetDeviceUuid } = await import(
|
||||
'../../utils/patterns.js'
|
||||
);
|
||||
const uuid = await getOnlineTargetDeviceUuid(sdk, params.deviceOrFleet);
|
||||
logger.logInfo(`Opening a tunnel to ${uuid}...`);
|
||||
|
||||
@ -134,7 +136,7 @@ export default class TunnelCmd extends Command {
|
||||
.map(async ({ localPort, localAddress, remotePort }) => {
|
||||
try {
|
||||
const { tunnelConnectionToDevice } = await import(
|
||||
'../../utils/tunnel'
|
||||
'../../utils/tunnel.js'
|
||||
);
|
||||
const handler = await tunnelConnectionToDevice(uuid, remotePort, sdk);
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { stripIndent, getChalk, getVisuals } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import * as cf from '../../utils/common-flags.js';
|
||||
import { stripIndent, getChalk, getVisuals } from '../../utils/lazy.js';
|
||||
|
||||
export default class UtilAvailableDrivesCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
|
@ -16,8 +16,8 @@
|
||||
*/
|
||||
|
||||
import { Flags } from '@oclif/core';
|
||||
import Command from '../../command';
|
||||
import { stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export interface JsonVersions {
|
||||
'balena-cli': string;
|
||||
@ -71,8 +71,9 @@ export default class VersionCmd extends Command {
|
||||
|
||||
public async run() {
|
||||
const { flags: options } = await this.parse(VersionCmd);
|
||||
const { default: packageJson } = await import('../../../package.json');
|
||||
const versions: JsonVersions = {
|
||||
'balena-cli': (await import('../../../package.json')).version,
|
||||
'balena-cli': packageJson.version,
|
||||
'Node.js':
|
||||
process.version && process.version.startsWith('v')
|
||||
? process.version.slice(1)
|
||||
|
@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Command from '../../command';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import Command from '../../command.js';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js';
|
||||
|
||||
export default class WhoamiCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
@ -34,7 +34,7 @@ export default class WhoamiCmd extends Command {
|
||||
public async run() {
|
||||
await this.parse(WhoamiCmd);
|
||||
|
||||
const balena = getBalenaSdk();
|
||||
const balena = await getBalenaSdk();
|
||||
|
||||
const [whoamiResult, url] = await Promise.all([
|
||||
balena.auth.whoami(),
|
||||
|
@ -14,7 +14,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createRequire } from 'node:module';
|
||||
const require = createRequire(import.meta.url);
|
||||
import type { BalenaSettingsStorage } from 'balena-settings-storage';
|
||||
|
||||
export interface ReleaseTimestampsByVersion {
|
||||
@ -106,7 +107,7 @@ export class DeprecationChecker {
|
||||
const url = this.getNpmUrl(version);
|
||||
let response: import('got').Response<Dictionary<any>> | undefined;
|
||||
try {
|
||||
response = await got(url, {
|
||||
response = await got.default(url, {
|
||||
responseType: 'json',
|
||||
retry: 0,
|
||||
timeout: 4000,
|
||||
@ -198,17 +199,16 @@ or release date not available`);
|
||||
const nextMajorDate = new Date(nextMajorDateStr).getTime();
|
||||
const daysElapsed = Math.trunc((this.now - nextMajorDate) / this.msInDay);
|
||||
if (daysElapsed > this.expiryDays) {
|
||||
const { ExpectedError } = await import('./errors');
|
||||
const { ExpectedError } = await import('./errors.js');
|
||||
throw new ExpectedError(this.getExpiryMsg(daysElapsed));
|
||||
} else if (daysElapsed > this.deprecationDays && process.stderr.isTTY) {
|
||||
console.error(this.getDeprecationMsg(daysElapsed));
|
||||
console.error(await this.getDeprecationMsg(daysElapsed));
|
||||
}
|
||||
}
|
||||
|
||||
/** Separate function for the benefit of code testing */
|
||||
getDeprecationMsg(daysElapsed: number) {
|
||||
const { warnify } =
|
||||
require('./utils/messages') as typeof import('./utils/messages');
|
||||
async getDeprecationMsg(daysElapsed: number) {
|
||||
const { warnify } = await import('./utils/messages.js');
|
||||
return warnify(`\
|
||||
CLI version ${this.nextMajorVersion} was released ${daysElapsed} days ago: please upgrade.
|
||||
This version of the balena CLI (${this.currentVersion}) will exit with an error
|
||||
|
@ -15,12 +15,12 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import type { BalenaError } from 'balena-errors';
|
||||
import * as _ from 'lodash';
|
||||
import _ from 'lodash';
|
||||
import * as os from 'os';
|
||||
import { TypedError } from 'typed-error';
|
||||
import { getChalk, stripIndent } from './utils/lazy';
|
||||
import { getHelp } from './utils/messages';
|
||||
import { CliSettings } from './utils/bootstrap';
|
||||
import { getChalk, stripIndent } from './utils/lazy.js';
|
||||
import { getHelp } from './utils/messages.js';
|
||||
import { CliSettings } from './utils/bootstrap.js';
|
||||
|
||||
export class ExpectedError extends TypedError {
|
||||
public code?: string;
|
||||
|
@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as packageJSON from '../package.json';
|
||||
import { stripIndent } from './utils/lazy';
|
||||
import packageJSON from '../package.json' assert {type: 'json'};
|
||||
import { stripIndent } from './utils/lazy.js';
|
||||
|
||||
/**
|
||||
* Track balena CLI usage events (product improvement analytics).
|
||||
@ -44,7 +44,7 @@ export async function trackCommand(commandSignature: string) {
|
||||
scope.setExtra('command', commandSignature);
|
||||
});
|
||||
}
|
||||
const { getCachedUsername } = await import('./utils/bootstrap');
|
||||
const { getCachedUsername } = await import('./utils/bootstrap.js');
|
||||
let username: string | undefined;
|
||||
try {
|
||||
username = (await getCachedUsername())?.username;
|
||||
@ -99,7 +99,7 @@ async function sendEvent(balenaUrl: string, event: string, username?: string) {
|
||||
const url = `https://data.${balenaUrl}/amplitude/2/httpapi`;
|
||||
|
||||
try {
|
||||
await got.post(url, {
|
||||
await got.default.post(url, {
|
||||
json: trackData,
|
||||
retry: 0,
|
||||
timeout: {
|
||||
|
@ -20,13 +20,14 @@
|
||||
* we have permissions over the cache file before even attempting to load
|
||||
* fast boot.
|
||||
* DON'T IMPORT BALENA-CLI MODULES HERE, as this module is loaded directly
|
||||
* from `bin/balena`, before the CLI's entrypoint in `lib/app.ts`.
|
||||
* from `bin/balena.js`, before the CLI's entrypoint in `lib/app.ts`.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
import { createRequire } from 'node:module';
|
||||
const require = createRequire(import.meta.url);
|
||||
const stat = process.pkg ? fs.statSync : fs.promises.stat;
|
||||
|
||||
let fastBootStarted = false;
|
||||
@ -66,15 +67,15 @@ async function $start() {
|
||||
// such as `/usr[/local]/lib/balena-cli`, while being executed by
|
||||
// a regular user account.
|
||||
const cacheFile = path.join(dataDir, 'cli-module-cache.json');
|
||||
const root = path.join(__dirname, '..');
|
||||
const [, pJson, pStat, nStat] = await Promise.all([
|
||||
const root = path.join(import.meta.url, '..');
|
||||
const [, pStat, nStat] = await Promise.all([
|
||||
ensureCanWrite(dataDir, cacheFile),
|
||||
import('../package.json'),
|
||||
stat(path.join(root, 'package.json'), { bigint: true }),
|
||||
stat(path.join(root, 'npm-shrinkwrap.json'), { bigint: true }),
|
||||
]);
|
||||
// Include timestamps to account for dev-time changes to node_modules
|
||||
const cacheKiller = `${pJson.version}-${pStat.mtimeMs}-${nStat.mtimeMs}`;
|
||||
const pJson = await import('../package.json');
|
||||
const cacheKiller = `${pJson.default.version}-${pStat.mtimeMs}-${nStat.mtimeMs}`;
|
||||
require('fast-boot2').start({
|
||||
cacheFile,
|
||||
cacheKiller,
|
||||
|
@ -14,6 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import type { DataOutputOptions, DataSetOutputOptions } from './output';
|
||||
import type { DataOutputOptions, DataSetOutputOptions } from './output.js';
|
||||
|
||||
export { DataOutputOptions, DataSetOutputOptions };
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user