UNPKG

rooibos-roku

Version:

simple, flexible, fun brightscript test framework for roku scenegraph apps - roku brighterscript plugin

111 lines 4.79 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const roku_debug_1 = require("roku-debug"); const brighterscript_1 = require("brighterscript"); const yargs = require("yargs"); const roku_deploy_1 = require("roku-deploy"); const fs = require("fs"); let options = yargs .usage('$0', 'Rooibos: a simple, flexible, fun Brightscript test framework for Roku Scenegraph apps') .help('help', 'View help information about this tool.') .option('project', { type: 'string', description: 'Path to a bsconfig.json project file.' }) .option('host', { type: 'string', description: 'Host of the Roku device to connect to. Overrides value in bsconfig file.' }) .option('password', { type: 'string', description: 'Password of the Roku device to connect to. Overrides value in bsconfig file.' }) .option('log-level', { type: 'string', defaultDescription: '"log"', description: 'The log level. Value can be "error", "warn", "log", "info", "debug".' }) .check((argv) => { if (!argv.host) { return new Error('You must provide a host. (--host)'); } if (!argv.password) { return new Error('You must provide a password. (--password)'); } if (!argv.project) { console.log('No project file specified. Using "./bsconfig.json"'); } let bsconfigPath = argv.project || './bsconfig.json'; if (!fs.existsSync(bsconfigPath)) { return new Error(`Unable to load ${bsconfigPath}`); } return true; }) .argv; async function main() { var _a, _b, _c, _d; let currentErrorCode = 0; let bsconfigPath = (_a = options.project) !== null && _a !== void 0 ? _a : 'bsconfig.json'; console.log(`Using bsconfig: ${bsconfigPath}`); const rawConfig = brighterscript_1.util.loadConfigFile(bsconfigPath); const bsConfig = brighterscript_1.util.normalizeConfig(rawConfig); const host = (_b = options.host) !== null && _b !== void 0 ? _b : bsConfig.host; const password = (_c = options.password) !== null && _c !== void 0 ? _c : bsConfig.password; const logLevel = (_d = brighterscript_1.LogLevel[options['log-level']]) !== null && _d !== void 0 ? _d : bsConfig.logLevel; const builder = new brighterscript_1.ProgramBuilder(); builder.logger.logLevel = logLevel; await builder.run(Object.assign(Object.assign({}, options), { retainStagingDir: true, createPackage: true })); const rokuDeploy = new roku_deploy_1.RokuDeploy(); const deviceInfo = await rokuDeploy.getDeviceInfo({ host: host }); const rendezvousTracker = new roku_debug_1.RendezvousTracker({ softwareVersion: deviceInfo['software-version'] }, { host: host, remotePort: 8085 }); const telnet = new roku_debug_1.TelnetAdapter({ host: options.host }, rendezvousTracker); telnet.logger.logLevel = logLevel; await telnet.activate(); await telnet.connect(); const failRegex = /\[Rooibos Result\]: (FAIL|PASS)/g; const endRegex = /\[Rooibos Shutdown\]/g; async function doExit(emitAppExit = false) { if (emitAppExit) { telnet.beginAppExit(); } await rokuDeploy.pressHomeButton(host); // roku-deploy v4: keyPress({ host: options.host, key: 'home' }); process.exit(currentErrorCode); } telnet.on('console-output', (output) => { console.log(output); //check for Fails or Crashes let failMatches = failRegex.exec(output); if (failMatches && failMatches.length > 0) { if (failMatches[1] === 'FAIL') { currentErrorCode = 1; } } let endMatches = endRegex.exec(output); if (endMatches && endMatches.length > 0) { doExit(true).catch(e => { console.error(e); process.exit(1); }); } }); telnet.on('runtime-error', (error) => { console.error(`Runtime Error: ${error.errorCode} - ${error.message}`); currentErrorCode = 1; doExit(true).catch(e => { console.error(e); process.exit(1); }); }); telnet.on('app-exit', () => { doExit(false).catch(e => { console.error(e); process.exit(1); }); }); // Actually start the unit tests //deploy a .zip package of your project to a roku device async function deployBuiltFiles() { const outFile = bsConfig.outFile; console.log(`Deploying ${outFile} to ${host}`); await rokuDeploy.publish({ password: password, host: host, outFile: outFile, outDir: process.cwd() }); } await deployBuiltFiles(); } main().catch(e => { console.error(e); process.exit(1); }); //# sourceMappingURL=cli.js.map