Lazy-load etcher-sdk to speed up startup

Change-type: patch
This commit is contained in:
Pagan Gazzard 2019-01-11 18:29:58 +00:00
parent f780d47198
commit 3cc632fbbb

View File

@ -1,12 +1,12 @@
import chalk from 'chalk';
import * as sdk from 'etcher-sdk';
import * as _sdk from 'etcher-sdk';
import { CustomDynamicList } from './custom-dynamic-list';
export class DriveList extends CustomDynamicList<
sdk.sourceDestination.BlockDevice
_sdk.sourceDestination.BlockDevice
> {
constructor(private scanner: sdk.scanner.Scanner) {
constructor(private scanner: _sdk.scanner.Scanner) {
super(
'Select a drive',
`${chalk.red('x')} No available drives were detected, plug one in!`,
@ -17,6 +17,7 @@ export class DriveList extends CustomDynamicList<
}
protected *getThings() {
const sdk: typeof _sdk = require('etcher-sdk')
for (const drive of this.scanner.drives) {
if (drive instanceof sdk.sourceDestination.BlockDevice) {
yield drive;
@ -24,7 +25,7 @@ export class DriveList extends CustomDynamicList<
}
}
protected format(drive: sdk.sourceDestination.BlockDevice) {
protected format(drive: _sdk.sourceDestination.BlockDevice) {
const size = drive.size / 1e9;
return `${drive.device} (${size.toFixed(1)} GB) - ${drive.description}`;
}