UNPKG

1.55 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const os = require("os");
4const cmds = require("./composer-cmds");
5function isSet(variable) {
6 return typeof variable !== 'undefined';
7}
8function systemDeps(basePath, options) {
9 const composerOk = isSet(options.composerIsFine) ? options.composerIsFine : cmds.cmdReturnsOk(cmds.composerCmd);
10 const composerPharOk = isSet(options.composerPharIsFine) ?
11 options.composerPharIsFine : cmds.cmdReturnsOk(cmds.pharCmd);
12 let finalVersionsObj = {};
13 if (options.systemVersions && (Object.keys(options.systemVersions).length > 0)) {
14 // give first preference to a stub
15 finalVersionsObj = options.systemVersions;
16 }
17 else if (composerOk) {
18 const lines = cmds.execWithResult(cmds.composerShowCmd, basePath).split(os.EOL);
19 lines.forEach((line) => {
20 const [part1, part2] = line.split(/\s+/);
21 if (part2) {
22 finalVersionsObj[part1] = part2;
23 }
24 });
25 }
26 else if (composerPharOk) {
27 const output = cmds.execWithResult(cmds.pharCmd, basePath);
28 const versionsObj = JSON.parse(output).platform;
29 versionsObj.forEach(({ name, version }) => {
30 finalVersionsObj[name] = version;
31 });
32 }
33 else {
34 // TODO: tell the user we are not reporting accurately system versions, so some version info may not be exact
35 }
36 return finalVersionsObj;
37}
38exports.systemDeps = systemDeps;
39//# sourceMappingURL=system-deps.js.map
\No newline at end of file