UNPKG

@devicecloud.dev/dcd

Version:

Better cloud maestro testing

67 lines (66 loc) 2.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const constants_1 = require("../constants"); const methods_1 = require("../methods"); const styling_1 = require("../utils/styling"); class Upload extends core_1.Command { static args = { appFile: core_1.Args.string({ description: 'The binary file to upload (e.g. test.apk for android or test.app/.zip for ios)', name: 'App file', required: true, }), }; static description = 'Upload an app binary to devicecloud.dev'; static enableJsonFlag = true; static examples = [ '<%= config.bin %> <%= command.id %> path/to/app.apk', '<%= config.bin %> <%= command.id %> path/to/app.zip --api-key YOUR_API_KEY', ]; static flags = { apiKey: constants_1.flags.apiKey, apiUrl: constants_1.flags.apiUrl, debug: constants_1.flags.debug, 'ignore-sha-check': constants_1.flags['ignore-sha-check'], }; async run() { try { const { args, flags } = await this.parse(Upload); const { appFile } = args; const { apiKey: apiKeyFlag, apiUrl, debug, 'ignore-sha-check': ignoreShaCheck, json, } = flags; const apiKey = apiKeyFlag || process.env.DEVICE_CLOUD_API_KEY; if (!apiKey) { throw new Error('You must provide an API key via --api-key flag or DEVICE_CLOUD_API_KEY environment variable'); } if (!['apk', '.app', '.zip'].some((ext) => appFile.endsWith(ext))) { throw new Error('App file must be a .apk for android or .app/.zip file for iOS'); } if (appFile.endsWith('.zip')) { await (0, methods_1.verifyAppZip)(appFile); } this.log((0, styling_1.sectionHeader)('Uploading app binary')); this.log(` ${styling_1.colors.dim('→ File:')} ${styling_1.colors.highlight(appFile)}`); this.log(''); const appBinaryId = await (0, methods_1.uploadBinary)({ apiKey, apiUrl, debug, filePath: appFile, ignoreShaCheck, log: !json, }); if (json) { return { appBinaryId }; } this.log(`\n${styling_1.colors.success('✓')} ${styling_1.colors.bold('Upload complete')}`); this.log(` ${styling_1.colors.dim('Binary ID:')} ${(0, styling_1.formatId)(appBinaryId)}\n`); this.log(styling_1.colors.dim('You can use this Binary ID in subsequent test runs with:')); this.log(styling_1.colors.info(`dcd cloud --app-binary-id ${appBinaryId} path/to/flow.yaml\n`)); } catch (error) { this.error(error, { exit: 1 }); } } } exports.default = Upload;