UNPKG

@twilio/plugin-microvisor

Version:

Interact with your Twilio Microvisor devices

58 lines (57 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseCommand = void 0; const tslib_1 = require("tslib"); exports.BaseCommand = require('@twilio/cli-core').baseCommands.BaseCommand; const core_1 = require("@oclif/core"); const node_fs_1 = tslib_1.__importDefault(require("node:fs")); const node_path_1 = tslib_1.__importDefault(require("node:path")); const bundle_1 = require("../../../lib/apps/bundle"); class MicrovisorAppsBundle extends exports.BaseCommand { constructor() { super(...arguments); this.SIZE_OF_USER_FLASH = 0x100000; // TODO: Move to MemoryMap } async run() { await super.run(); // Only one layer is supported for now const rom = node_fs_1.default.readFileSync(this.args['rom-file']); const encryptionKeyName = (this.flags['development-keying']) ? 'twilio-encrypt-dev.pub.key' : 'twilio-encrypt-prod.pub.key'; const keysDir = node_path_1.default.join(node_path_1.default.dirname(node_fs_1.default.realpathSync(__filename)), '../../../../../resources/keys'); const encryptionKey = node_fs_1.default.readFileSync(node_path_1.default.join(keysDir, encryptionKeyName)); let layer = new bundle_1.AppLayer(rom, 0, this.SIZE_OF_USER_FLASH, bundle_1.MemoryRegion.INTERNAL_FLASH, encryptionKey, false); let debugKeyPath = this.flags['debug-auth-pubkey']; const debugKey = (debugKeyPath) ? node_fs_1.default.readFileSync(debugKeyPath) : undefined; let bundle = new bundle_1.AppBundle([layer], debugKey, 0, this.flags['connection-grace-time'], this.flags['minimum-check-in-time']); bundle.getZip().writeZip(this.args.out); } } MicrovisorAppsBundle.description = 'Manage app bundles'; MicrovisorAppsBundle.args = [ { name: 'rom-file', required: true, description: 'Input ROM file.' }, { name: 'out', required: true, description: 'Output file for bundle zip.' } ]; MicrovisorAppsBundle.flags = Object.assign({ 'debug-auth-pubkey': core_1.Flags.string({ char: 'k', required: false, description: 'Public key to be used for authentication while debugging' }), 'connection-grace-time': core_1.Flags.integer({ description: 'Connection grace time (in seconds) for the Device running this bundle as an App.', default: 0 }), 'minimum-check-in-time': core_1.Flags.integer({ description: 'Time (in seconds) after which the Device running this bundle autonomously reconnects to check for updates.', default: 0 }), 'development-keying': core_1.Flags.boolean({ description: 'Use development keying for application encryption.', default: false, hidden: true }) }, exports.BaseCommand.flags); module.exports = MicrovisorAppsBundle;