Create a system lib that can be used in the UI and cli.

This commit is contained in:
mmcwilliams 2019-03-22 20:29:36 -04:00
parent b02b92c1c7
commit e35c41791b
10 changed files with 342 additions and 138 deletions

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const os = require('os'); const os = require("os");
const electron = require('electron'); const si = require("systeminformation");
//private //private
const exec = require('exec'); const exec = require('exec');
/** /**
@ -11,14 +11,13 @@ const exec = require('exec');
* *
* @param {string} platform Operating system type * @param {string} platform Operating system type
**/ **/
async function dependencies(platform) {
async function dependencies (platform) {
let obj = {}; let obj = {};
try { try {
await exec('ffmpeg -h'); await exec('ffmpeg -h');
obj.ffmpeg = 'ffmpeg'; obj.ffmpeg = 'ffmpeg';
} catch (err) { }
catch (err) {
//return exit('ffmpeg is not installed', 3); //return exit('ffmpeg is not installed', 3);
return console.error('ffmpeg is not installed', err); return console.error('ffmpeg is not installed', err);
} }
@ -27,28 +26,26 @@ async function dependencies (platform) {
try { try {
await exec('eog -h'); await exec('eog -h');
obj.eog = 'eog'; obj.eog = 'eog';
} catch (err) { }
catch (err) {
//return exit('eog is not installed', 4); //return exit('eog is not installed', 4);
return console.error('eog is not installed', err); return console.error('eog is not installed', err);
} }
} }
return obj; return obj;
} }
function displayMap(obj) {
function getDisplays () { const sm = {
let displays = electron.screen.getAllDisplays(); width: obj.resolutionx,
return displays.map(obj => { height: obj.resolutiony
return { };
width : obj.workArea.width, return sm;
height : obj.workArea.height, }
x : obj.bounds.x, async function displays() {
y : obj.bounds.y const obj = await si.graphics();
} const arr = obj.displays;
}); return arr.map(displayMap);
} }
/** /**
* Profile the current system and return an object with * Profile the current system and return an object with
* data about the displays and dependencies for the digital * data about the displays and dependencies for the digital
@ -56,30 +53,28 @@ function getDisplays () {
* *
* @returns {object} Object containing system information * @returns {object} Object containing system information
*/ */
async function system () { async function system() {
const obj = {}; const obj = {};
let platform; let platform;
try { try {
obj.tmp = os.tmpdir(); obj.tmp = os.tmpdir();
} catch (err) {
obj.tmp = '/tmp'
} }
catch (err) {
obj.tmp = '/tmp';
}
platform = os.type(); platform = os.type();
if (platform === 'Darwin') { if (platform === 'Darwin') {
obj.platform = 'osx'; obj.platform = 'osx';
} else if (platform === 'Windows_NT') { }
else if (platform === 'Windows_NT') {
obj.platform = 'win'; obj.platform = 'win';
} else { }
else {
obj.platform = 'nix'; obj.platform = 'nix';
} }
obj.displays = await displays();
obj.displays = getDisplays()
obj.deps = await dependencies(obj.platform); obj.deps = await dependencies(obj.platform);
return obj; return obj;
} }
module.exports = system; module.exports = system;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/system/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yBAA0B;AAC1B,wCAAyC;AACzC,SAAS;AACT,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B;;;;;;IAMI;AAEJ,KAAK,UAAU,YAAY,CAAE,QAAiB;IAC7C,IAAI,GAAG,GAAS,EAAE,CAAC;IAEnB,IAAI;QACH,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC;QACxB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACb,4CAA4C;QAC5C,OAAO,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;KACrD;IACD,UAAU;IACV,IAAI,QAAQ,KAAK,KAAK,EAAE;QACvB,IAAI;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;YACrB,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC;SAChB;QAAC,OAAO,GAAG,EAAE;YACb,yCAAyC;YACzC,OAAO,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;SAClD;KACD;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,UAAU,CAAE,GAAS;IAC7B,MAAM,EAAE,GAAG;QACV,KAAK,EAAG,GAAG,CAAC,WAAW;QACvB,MAAM,EAAG,GAAG,CAAC,WAAW;KACxB,CAAC;IACF,OAAO,EAAE,CAAC;AACX,CAAC;AAED,KAAK,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAS,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAA;IACrC,MAAM,GAAG,GAAW,GAAG,CAAC,QAAQ,CAAC;IACjC,OAAO,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,MAAM;IACpB,MAAM,GAAG,GAAS,EAAE,CAAC;IACrB,IAAI,QAAiB,CAAC;IAEtB,IAAI;QACH,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACb,GAAG,CAAC,GAAG,GAAG,MAAM,CAAA;KAChB;IAED,QAAQ,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IAErB,IAAI,QAAQ,KAAK,QAAQ,EAAE;QAC1B,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;KACrB;SAAM,IAAI,QAAQ,KAAK,YAAY,EAAE;QACrC,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;KACrB;SAAM;QACN,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;KACrB;IAED,GAAG,CAAC,QAAQ,GAAG,MAAM,QAAQ,EAAE,CAAA;IAC/B,GAAG,CAAC,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const os = require('os'); const os = require("os");
const si = require('systeminformation'); const si = require("systeminformation");
//private //private
const exec = require('exec'); const exec = require('exec');
/** /**
@ -11,14 +11,13 @@ const exec = require('exec');
* *
* @param {string} platform Operating system type * @param {string} platform Operating system type
**/ **/
async function dependencies(platform) {
async function dependencies (platform) {
let obj = {}; let obj = {};
try { try {
await exec('ffmpeg -h'); await exec('ffmpeg -h');
obj.ffmpeg = 'ffmpeg'; obj.ffmpeg = 'ffmpeg';
} catch (err) { }
catch (err) {
//return exit('ffmpeg is not installed', 3); //return exit('ffmpeg is not installed', 3);
return console.error('ffmpeg is not installed', err); return console.error('ffmpeg is not installed', err);
} }
@ -27,32 +26,26 @@ async function dependencies (platform) {
try { try {
await exec('eog -h'); await exec('eog -h');
obj.eog = 'eog'; obj.eog = 'eog';
} catch (err) { }
catch (err) {
//return exit('eog is not installed', 4); //return exit('eog is not installed', 4);
return console.error('eog is not installed', err); return console.error('eog is not installed', err);
} }
} }
return obj; return obj;
} }
/** function displayMap(obj) {
* const sm = {
* width: obj.resolutionx,
* @returns {array} Array of objects containing displays and relative positions height: obj.resolutiony
*/ };
function getDisplays () { return sm;
let displays = electron.screen.getAllDisplays(); }
return displays.map(obj => { async function displays() {
return { const obj = await si.graphics();
width : obj.workArea.width, const arr = obj.displays;
height : obj.workArea.height, return arr.map(displayMap);
x : obj.bounds.x,
y : obj.bounds.y
}
});
} }
/** /**
* Profile the current system and return an object with * Profile the current system and return an object with
* data about the displays and dependencies for the digital * data about the displays and dependencies for the digital
@ -60,30 +53,28 @@ function getDisplays () {
* *
* @returns {object} Object containing system information * @returns {object} Object containing system information
*/ */
async function system () { async function system() {
const obj = {}; const obj = {};
let platform; let platform;
try { try {
obj.tmp = os.tmpdir(); obj.tmp = os.tmpdir();
} catch (err) {
obj.tmp = '/tmp'
} }
catch (err) {
obj.tmp = '/tmp';
}
platform = os.type(); platform = os.type();
if (platform === 'Darwin') { if (platform === 'Darwin') {
obj.platform = 'osx'; obj.platform = 'osx';
} else if (platform === 'Windows_NT') { }
else if (platform === 'Windows_NT') {
obj.platform = 'win'; obj.platform = 'win';
} else { }
else {
obj.platform = 'nix'; obj.platform = 'nix';
} }
obj.displays = await displays();
obj.displays = getDisplays()
obj.deps = await dependencies(obj.platform); obj.deps = await dependencies(obj.platform);
return obj; return obj;
} }
module.exports = system; module.exports = system;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/system/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yBAA0B;AAC1B,wCAAyC;AACzC,SAAS;AACT,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B;;;;;;IAMI;AAEJ,KAAK,UAAU,YAAY,CAAE,QAAiB;IAC7C,IAAI,GAAG,GAAS,EAAE,CAAC;IAEnB,IAAI;QACH,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC;QACxB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACb,4CAA4C;QAC5C,OAAO,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;KACrD;IACD,UAAU;IACV,IAAI,QAAQ,KAAK,KAAK,EAAE;QACvB,IAAI;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;YACrB,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC;SAChB;QAAC,OAAO,GAAG,EAAE;YACb,yCAAyC;YACzC,OAAO,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;SAClD;KACD;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,UAAU,CAAE,GAAS;IAC7B,MAAM,EAAE,GAAG;QACV,KAAK,EAAG,GAAG,CAAC,WAAW;QACvB,MAAM,EAAG,GAAG,CAAC,WAAW;KACxB,CAAC;IACF,OAAO,EAAE,CAAC;AACX,CAAC;AAED,KAAK,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAS,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAA;IACrC,MAAM,GAAG,GAAW,GAAG,CAAC,QAAQ,CAAC;IACjC,OAAO,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,MAAM;IACpB,MAAM,GAAG,GAAS,EAAE,CAAC;IACrB,IAAI,QAAiB,CAAC;IAEtB,IAAI;QACH,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACb,GAAG,CAAC,GAAG,GAAG,MAAM,CAAA;KAChB;IAED,QAAQ,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IAErB,IAAI,QAAQ,KAAK,QAAQ,EAAE;QAC1B,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;KACrB;SAAM,IAAI,QAAQ,KAAK,YAAY,EAAE;QACrC,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;KACrB;SAAM;QACN,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC;KACrB;IAED,GAAG,CAAC,QAAQ,GAAG,MAAM,QAAQ,EAAE,CAAA;IAC/B,GAAG,CAAC,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"}

80
lib/system/index.js Normal file
View File

@ -0,0 +1,80 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const os = require("os");
const si = require("systeminformation");
//private
const exec = require('exec');
/**
* Evaluates system dependencies for digital
* projector features by executing processes with
* --help flag. If they do not exist, log to console
*
* @param {string} platform Operating system type
**/
async function dependencies(platform) {
let obj = {};
try {
await exec('ffmpeg -h');
obj.ffmpeg = 'ffmpeg';
}
catch (err) {
//return exit('ffmpeg is not installed', 3);
return console.error('ffmpeg is not installed', err);
}
//if linux
if (platform === 'nix') {
try {
await exec('eog -h');
obj.eog = 'eog';
}
catch (err) {
//return exit('eog is not installed', 4);
return console.error('eog is not installed', err);
}
}
return obj;
}
function displayMap(obj) {
const sm = {
width: obj.resolutionx,
height: obj.resolutiony
};
return sm;
}
async function displays() {
const obj = await si.graphics();
const arr = obj.displays;
return arr.map(displayMap);
}
/**
* Profile the current system and return an object with
* data about the displays and dependencies for the digital
* projector feature.
*
* @returns {object} Object containing system information
*/
async function system() {
const obj = {};
let platform;
try {
obj.tmp = os.tmpdir();
}
catch (err) {
obj.tmp = '/tmp';
}
platform = os.type();
if (platform === 'Darwin') {
obj.platform = 'osx';
}
else if (platform === 'Windows_NT') {
obj.platform = 'win';
}
else {
obj.platform = 'nix';
}
obj.displays = await displays();
obj.deps = await dependencies(obj.platform);
return obj;
}
module.exports = system;
//# sourceMappingURL=index.js.map

1
lib/system/index.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/system/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yBAA0B;AAC1B,wCAAyC;AACzC,SAAS;AACT,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B;;;;;;IAMI;AAEJ,KAAK,UAAU,YAAY,CAAE,QAAiB;IAC7C,IAAI,GAAG,GAAS,EAAE,CAAC;IAEnB,IAAI;QACH,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC;QACxB,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACb,4CAA4C;QAC5C,OAAO,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;KACrD;IACD,UAAU;IACV,IAAI,QAAQ,KAAK,KAAK,EAAE;QACvB,IAAI;YACH,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;YACrB,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC;SAChB;QAAC,OAAO,GAAG,EAAE;YACb,yCAAyC;YACzC,OAAO,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,GAAG,C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s-extra'; declare module 'fs-extra';
declare module 'exec'; declare module 'exec';
declare module 'spawn'; declare module 'spawn';
declare module 'systeminformation';
interface Device { interface Device {
arduino : string; arduino : string;

37
src/system/Readme.md Normal file
View File

@ -0,0 +1,37 @@
## Functions
<dl>
<dt><a href="#dependencies">dependencies(platform)</a></dt>
<dd><p>Evaluates system dependencies for digital
projector features by executing processes with
--help flag. If they do not exist, log to console</p>
</dd>
<dt><a href="#system">system()</a><code>object</code></dt>
<dd><p>Profile the current system and return an object with
data about the displays and dependencies for the digital
projector feature.</p>
</dd>
</dl>
<a name="dependencies"></a>
## dependencies(platform)
Evaluates system dependencies for digital
projector features by executing processes with
--help flag. If they do not exist, log to console
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| platform | <code>string</code> | Operating system type |
<a name="system"></a>
## system() ⇒ <code>object</code>
Profile the current system and return an object with
data about the displays and dependencies for the digital
projector feature.
**Kind**: global function
**Returns**: <code>object</code> - Object containing system information

86
src/system/index.ts Normal file
View File

@ -0,0 +1,86 @@
'use strict';
import os = require('os');
import si = require('systeminformation');
//private
const exec = require('exec');
/**
* Evaluates system dependencies for digital
* projector features by executing processes with
* --help flag. If they do not exist, log to console
*
* @param {string} platform Operating system type
**/
async function dependencies (platform : string ) {
let obj : any = {};
try {
await exec('ffmpeg -h');
obj.ffmpeg = 'ffmpeg';
} catch (err) {
//return exit('ffmpeg is not installed', 3);
return console.error('ffmpeg is not installed', err);
}
//if linux
if (platform === 'nix') {
try {
await exec('eog -h');
obj.eog = 'eog';
} catch (err) {
//return exit('eog is not installed', 4);
return console.error('eog is not installed', err);
}
}
return obj;
}
function displayMap (obj : any) {
const sm = {
width : obj.resolutionx,
height : obj.resolutiony
};
return sm;
}
async function displays () {
const obj : any = await si.graphics()
const arr : any[] = obj.displays;
return arr.map(displayMap);
}
/**
* Profile the current system and return an object with
* data about the displays and dependencies for the digital
* projector feature.
*
* @returns {object} Object containing system information
*/
async function system () {
const obj : any = {};
let platform : string;
try {
obj.tmp = os.tmpdir();
} catch (err) {
obj.tmp = '/tmp'
}
platform = os.type();
if (platform === 'Darwin') {
obj.platform = 'osx';
} else if (platform === 'Windows_NT') {
obj.platform = 'win';
} else {
obj.platform = 'nix';
}
obj.displays = await displays()
obj.deps = await dependencies(obj.platform);
return obj;
}
module.exports = system;

11
src/system/package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "system",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}