envinfo
Advanced tools
Comparing version 4.0.0-beta.3 to 4.0.0-beta.4
{ | ||
"name": "envinfo", | ||
"version": "4.0.0-beta.3", | ||
"version": "4.0.0-beta.4", | ||
"description": "Info about your dev environment for debugging purposes", | ||
@@ -20,11 +20,3 @@ "repository": "https://github.com/tabrindle/envinfo", | ||
}, | ||
"keywords": [ | ||
"development", | ||
"env", | ||
"environment", | ||
"info", | ||
"issues", | ||
"reporting", | ||
"diagnostics" | ||
], | ||
"keywords": ["development", "env", "environment", "info", "issues", "reporting", "diagnostics"], | ||
"dependencies": { | ||
@@ -38,3 +30,4 @@ "array-includes": "^3.0.3", | ||
"os-name": "^2.0.1", | ||
"which": "^1.2.14" | ||
"which": "^1.2.14", | ||
"yamlify-object": "^0.4.5" | ||
}, | ||
@@ -41,0 +34,0 @@ "devDependencies": { |
@@ -23,2 +23,3 @@ #!/usr/bin/env node | ||
Binaries: ['Node', 'Yarn', 'npm', 'Watchman', 'Docker', 'Homebrew'], | ||
SDKs: ['Android'], | ||
IDEs: ['Android Studio', 'Atom', 'VSCode', 'Sublime Text', 'Xcode'], | ||
@@ -63,3 +64,3 @@ Languages: ['Bash', 'Go', 'PHP', 'Python', 'Ruby'], | ||
if (options.markdown) return formatters.markdown; | ||
return formatters.table; | ||
return formatters.yaml; | ||
})(); | ||
@@ -66,0 +67,0 @@ const formatted = formatter(data, { console: false }); |
@@ -1,88 +0,143 @@ | ||
function formatPackage(packageData, format) { | ||
const name = packageData[0]; | ||
const data = packageData[1]; | ||
const wanted = data.wanted ? `${data.wanted} =>` : ''; | ||
const installed = Array.isArray(data.installed) ? data.installed.join(', ') : data.installed; | ||
const duplicates = data.duplicates ? `(${data.duplicates.join(', ')})` : ''; | ||
if (format === 'markdown') return `* ${name}: ${wanted} ${installed} ${duplicates}`; | ||
return ` ${name}: ${wanted} ${installed} ${duplicates}`; | ||
const yamlify = require('yamlify-object'); | ||
const utils = require('./utils'); | ||
function clean(data) { | ||
return Object.keys(data).reduce((acc, prop) => { | ||
if (data[prop] === 'N/A') return acc; | ||
if (utils.isObject(data[prop])) { | ||
return Object.assign(acc, { [prop]: clean(data[prop]) }); | ||
} | ||
return Object.assign(acc, { [prop]: data[prop] }); | ||
}, {}); | ||
} | ||
function formatJson(data, options) { | ||
if (!options) options = {}; | ||
function formatHeaders(data, options) { | ||
if (!options) options = { type: 'underline' }; | ||
const formats = { | ||
underline: ['\x1b[4m', '\x1b[0m'], | ||
}; | ||
return data | ||
.slice() | ||
.split('\n') | ||
.map(line => { | ||
const isHeading = line.slice('-1') === ':'; | ||
if (isHeading) { | ||
return `${formats[options.type][0]}${line}${formats[options.type][1]}`; | ||
} | ||
return line; | ||
}) | ||
.join('\n'); | ||
} | ||
// delete properties that are not applicable | ||
Object.entries(data).forEach(d => { | ||
Object.entries(d[1]).forEach(i => { | ||
if (i[1] === 'N/A') delete d[1][i[0]]; | ||
}); | ||
}); | ||
function formatPackages(data) { | ||
return Object.assign( | ||
data, | ||
Object.entries(data.packages || {}).reduce((acc, entry) => { | ||
const key = entry[0]; | ||
const value = entry[1]; | ||
const wanted = value.wanted ? `${value.wanted} =>` : ''; | ||
const installed = Array.isArray(value.installed) | ||
? value.installed.join(', ') | ||
: value.installed; | ||
const duplicates = value.duplicates ? `(${value.duplicates.join(', ')})` : ''; | ||
return Object.assign(acc, { | ||
[key]: `${wanted} ${installed} ${duplicates}`, | ||
}); | ||
}, {}) | ||
); | ||
} | ||
if (options.console) { | ||
return `\n${JSON.stringify(data, null, ' ')}\n`; | ||
function joinArray(key, value, options) { | ||
if (!options) options = { emptyMessage: 'None' }; | ||
if (Array.isArray(value)) { | ||
value = value.length > 0 ? value.join(', ') : options.emptyMessage; | ||
} | ||
return JSON.stringify(data, null, ' '); | ||
return { | ||
[key]: value, | ||
}; | ||
} | ||
function formatMarkdown(data, options) { | ||
if (!options) options = {}; | ||
var compiled = []; | ||
Object.entries(data).forEach(d => { | ||
const category = d[0]; | ||
const values = d[1]; | ||
if (Object.entries(values).length) compiled.push(`### ${category}:`); | ||
function recursiveTransform(data, fn) { | ||
return Object.entries(data).reduce((acc, entry) => { | ||
const key = entry[0]; | ||
const value = entry[1]; | ||
if (utils.isObject(value)) { | ||
return Object.assign(acc, { [key]: recursiveTransform(value, fn) }); | ||
} | ||
return Object.assign(acc, fn(key, value)); | ||
}, {}); | ||
} | ||
if (category === 'Packages') { | ||
Object.entries(values) | ||
.map(p => formatPackage(p, 'markdown')) | ||
.map(p => compiled.push(p)); | ||
} else { | ||
Object.entries(values).forEach(v => { | ||
const name = v[0]; | ||
const version = v[1]; | ||
if (version !== 'N/A') compiled.push(`* ${name}: ${version}`); | ||
}); | ||
} | ||
function serializeArrays(data) { | ||
return recursiveTransform(data, joinArray); | ||
} | ||
function yaml(data) { | ||
return yamlify(data, { | ||
indent: ' ', | ||
prefix: '\n', | ||
postfix: '\n', | ||
}); | ||
if (options.console) { | ||
return '\n' + compiled.join('\n') + '\n'; | ||
} | ||
return compiled.join('\n'); | ||
} | ||
function formatTable(data, options) { | ||
var compiled = []; | ||
if (!options) options = {}; | ||
Object.entries(data).forEach(d => { | ||
const category = d[0]; | ||
const values = d[1]; | ||
if (Object.entries(values).length) { | ||
if (options.console) { | ||
compiled.push(`\x1b[4m${category}:\x1b[0m`); | ||
} else { | ||
compiled.push(`${category}:`); | ||
function markdown(data) { | ||
return data | ||
.slice() | ||
.split('\n') | ||
.map(line => { | ||
if (line !== '') { | ||
const isHeading = line.slice('-1') === ':'; | ||
const indent = line.search(/\S|$/); | ||
if (isHeading) { | ||
return `${'#'.repeat(indent / 2 + 1)} ` + line.slice(indent); | ||
} | ||
return ' - ' + line.slice(indent); | ||
} | ||
} | ||
if (category === 'Packages') { | ||
Object.entries(values) | ||
.map(p => formatPackage(p, 'table')) | ||
.map(p => compiled.push(p)); | ||
} else { | ||
Object.entries(values).forEach(v => { | ||
const name = v[0]; | ||
const version = v[1]; | ||
if (version !== 'N/A') compiled.push(` ${name}: ${version}`); | ||
}); | ||
} | ||
}); | ||
if (options.console) { | ||
return '\n' + compiled.join('\n') + '\n'; | ||
} | ||
return compiled.join('\n'); | ||
return ''; | ||
}) | ||
.join('\n'); | ||
} | ||
function json(data, options) { | ||
if (!options) | ||
options = { | ||
indent: ' ', | ||
}; | ||
return JSON.stringify(data, null, options.indent); | ||
} | ||
function formatToYaml(data, options) { | ||
return utils.pipe([ | ||
formatPackages, | ||
serializeArrays, | ||
clean, | ||
yaml, | ||
options.console ? formatHeaders : utils.noop, | ||
])(data); | ||
} | ||
function formatToMarkdown(data, options) { | ||
return utils.pipe([ | ||
formatPackages, | ||
serializeArrays, | ||
clean, | ||
yaml, | ||
markdown, | ||
options.console ? formatHeaders : utils.noop, | ||
])(data); | ||
} | ||
function formatToJson(data, options) { | ||
if (!options) options = {}; | ||
data = utils.pipe([json])(data); | ||
data = options.console ? `\n${data}\n` : data; | ||
return data; | ||
} | ||
module.exports = { | ||
json: formatJson, | ||
markdown: formatMarkdown, | ||
table: formatTable, | ||
json: formatToJson, | ||
markdown: formatToMarkdown, | ||
yaml: formatToYaml, | ||
}; |
@@ -56,2 +56,32 @@ var childProcess = require('child_process'); | ||
function getAllAndroidSDKs() { | ||
var buildTools = []; | ||
var androidAPIs = []; | ||
try { | ||
// try to use preferred install path | ||
var command = process.env.ANDROID_HOME ? '$ANDROID_HOME/tools/bin/sdkmanager' : 'sdkmanager'; | ||
var installed = utils.run(command + ' --list').split('Available')[0]; | ||
var getBuildVersions = /build-tools;([\d|.]+)[\S\s]/g; | ||
var getAPIVersions = /platforms;android-(\d+)[\S\s]/g; | ||
var matcher; | ||
// eslint-disable-next-line | ||
while ((matcher = getBuildVersions.exec(installed))) { | ||
buildTools.push(matcher[1]); | ||
} | ||
// eslint-disable-next-line | ||
while ((matcher = getAPIVersions.exec(installed))) { | ||
androidAPIs.push(matcher[1]); | ||
} | ||
} catch (err) { | ||
buildTools = ['Unknown']; | ||
androidAPIs = ['Unknown']; | ||
} | ||
return { | ||
'Build Tools': buildTools, | ||
'API Levels': androidAPIs, | ||
}; | ||
} | ||
function getAndroidStudioVersion() { | ||
@@ -394,2 +424,3 @@ var androidStudioVersion = 'Not Found'; | ||
generatePlistBuddyCommand: generatePlistBuddyCommand, | ||
getAllAndroidSDKs: getAllAndroidSDKs, | ||
getAndroidStudioVersion: getAndroidStudioVersion, | ||
@@ -396,0 +427,0 @@ getAtomVersion: getAtomVersion, |
@@ -18,2 +18,3 @@ var helpers = require('./helpers'); | ||
homebrew: helpers.getHomeBrewVersion, | ||
android: helpers.getAllAndroidSDKs, | ||
// browsers | ||
@@ -20,0 +21,0 @@ chrome_canary: () => |
@@ -27,2 +27,5 @@ var path = require('path'); | ||
const isObject = val => typeof val === 'object' && !Array.isArray(val); | ||
const pipe = fns => x => fns.reduce((v, f) => f(v), x); | ||
function requireJson(filePath) { | ||
@@ -49,2 +52,4 @@ var packageJson; | ||
const noop = d => d; | ||
module.exports = { | ||
@@ -54,2 +59,5 @@ run: run, | ||
getPackageJsonByPath: getPackageJsonByPath, | ||
isObject: isObject, | ||
noop: noop, | ||
pipe: pipe, | ||
requireJson: requireJson, | ||
@@ -56,0 +64,0 @@ toReadableBytes: toReadableBytes, |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
87179
924
9
7
+ Addedyamlify-object@^0.4.5
+ Addedyamlify-object@0.4.5(transitive)