Skip to content

Commit

Permalink
Expose cli args to client (#584)
Browse files Browse the repository at this point in the history
* expose cliArgs to client

* bump version
  • Loading branch information
saikrishna321 authored Dec 14, 2022
1 parent e296b47 commit 629cc7e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-device-farm",
"version": "3.5.0",
"version": "3.6.0",
"description": "An appium 2.0 plugin that manages and create driver session on available devices",
"main": "./lib/index.js",
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express';
import path from 'path';
import log from './logger';
import { DeviceModel, PendingSessionsModel } from './data-service/db';
import { getCLIArgs } from './data-service/pluginArgs';
import cors from 'cors';
import AsyncLock from 'async-lock';
import axios from 'axios';
Expand Down Expand Up @@ -71,6 +72,10 @@ apiRouter.get('/queue', (req, res) => {
res.json(PendingSessionsModel.chain().find().data().length);
});

apiRouter.get('/cliArgs', (req, res) => {
res.json(getCLIArgs());
});

apiRouter.get('/devices/android', (req, res) => {
res.json(
DeviceModel.find({
Expand Down
3 changes: 2 additions & 1 deletion src/data-service/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import loki from 'lokijs';
const db = new loki('db.json');
const DeviceModel = db.addCollection('devices');
const PendingSessionsModel = db.addCollection('pending-sessions');
const CLIArgs = db.addCollection('cliArgs');

export { DeviceModel, PendingSessionsModel };
export { DeviceModel, PendingSessionsModel, CLIArgs };
11 changes: 11 additions & 0 deletions src/data-service/pluginArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CLIArgs } from './db';

async function addCLIArgs(args: any) {
CLIArgs.insert(args);
}

function getCLIArgs() {
return CLIArgs.chain().find().data();
}

export { addCLIArgs, getCLIArgs };
4 changes: 3 additions & 1 deletion src/device-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export function getDeviceFiltersFromCapability(capability: any): IDeviceFilterOp
}
return {
platform,
platformVersion: capability['appium:platformVersion'] ? capability['appium:platformVersion'] : undefined,
platformVersion: capability['appium:platformVersion']
? capability['appium:platformVersion']
: undefined,
name,
deviceType,
udid: udids?.length ? udids : undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { hubUrl } from './helpers';
import Cloud from './enums/Cloud';
import ChromeDriverManager from './device-managers/ChromeDriverManager';
import { LocalStorage } from 'node-persist';
import { addCLIArgs } from './data-service/pluginArgs';

const commandsQueueGuard = new AsyncLock();
const DEVICE_MANAGER_LOCK_NAME = 'DeviceManager';
Expand Down Expand Up @@ -78,6 +79,7 @@ class DevicePlugin extends BasePlugin {
});
Container.set(DeviceFarmManager, deviceManager);
if (chromeDriverManager) Container.set(ChromeDriverManager, chromeDriverManager);
await addCLIArgs(cliArgs);
await initlializeStorage();
logger.info(
`📣📣📣 Device Farm Plugin will be served at 🔗 http://localhost:${cliArgs.port}/device-farm`
Expand Down

0 comments on commit 629cc7e

Please sign in to comment.