UNPKG

@devicecloud.dev/dcd

Version:

Better cloud maestro testing

58 lines (57 loc) 2.38 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"); 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, '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, '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(` Uploading app binary → File: ${appFile} `); const appBinaryId = await (0, methods_1.uploadBinary)(appFile, apiUrl, apiKey, ignoreShaCheck, !json); if (json) { return { appBinaryId }; } this.log(`\nUpload complete. Binary ID: ${appBinaryId}\n`); this.log(`You can use this Binary ID in subsequent test runs with:`); this.log(`dcd cloud --app-binary-id ${appBinaryId} path/to/flow.yaml\n`); } catch (error) { this.error(error, { exit: 1 }); } } } exports.default = Upload;