-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: nativescript-envinfo package (#5600)
* feat: nativescript-envinfo package * fix: handle edge cases better
- Loading branch information
Showing
5 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env node | ||
|
||
import { run } from "envinfo"; | ||
import { readFileSync } from "fs"; | ||
import { resolve } from "path"; | ||
|
||
interface IPackageJSON { | ||
dependencies?: any; | ||
devDependencies?: any; | ||
} | ||
|
||
function readPackageJSON(): IPackageJSON { | ||
try { | ||
return JSON.parse( | ||
readFileSync(resolve(process.cwd(), "package.json")).toString() | ||
); | ||
} catch (err) { | ||
return {}; | ||
} | ||
} | ||
|
||
async function main() { | ||
const res = JSON.parse( | ||
await run( | ||
{ | ||
System: ["OS", "CPU", "Shell"], | ||
Binaries: ["Node", "npm"], | ||
Managers: ["CocoaPods"], | ||
IDEs: ["Xcode"], | ||
SDKs: ["iOS SDK", "Android SDK"], | ||
Languages: ["Java", "Ruby", "Python", "Python3"], | ||
npmGlobalPackages: ["nativescript"], | ||
}, | ||
{ json: true, showNotFound: true } | ||
) | ||
); | ||
|
||
const packageJSON = readPackageJSON(); | ||
const dependencies = packageJSON?.dependencies ?? {}; | ||
const devDependencies = packageJSON?.devDependencies ?? {}; | ||
|
||
const get = (key: string, defaultValue: any = "Not Found") => { | ||
try { | ||
return key.split(".").reduce((res, key) => res[key], res) ?? defaultValue; | ||
} catch (err) { | ||
return defaultValue; | ||
} | ||
}; | ||
|
||
const asList = (key: string) => { | ||
const list = get(key); | ||
|
||
if (Array.isArray(list)) { | ||
return "\n" + list.map((image: string) => ` - ${image}`).join("\n"); | ||
} | ||
|
||
return list ?? "Not Found"; | ||
}; | ||
|
||
console.log( | ||
[ | ||
`<!-- COPY START -->`, | ||
"```yaml", | ||
`OS: ${get("System.OS")}`, | ||
`CPU: ${get("System.CPU")}`, | ||
`Shell: ${get("System.Shell.path")}`, | ||
`node: ${get("Binaries.Node.version")}`, | ||
`npm: ${get("Binaries.npm.version")}`, | ||
`nativescript: ${get("npmGlobalPackages.nativescript")}`, | ||
// `git: ${sysInfo.gitVer}`, | ||
``, | ||
`# android`, | ||
`java: ${get("Languages.Java.version")}`, | ||
`ndk: ${get("SDKs.Android SDK.Android NDK")}`, | ||
`apis: ${ | ||
get("SDKs.Android SDK.API Levels")?.join?.(", ") ?? "Not Found" | ||
}`, | ||
`build_tools: ${ | ||
get("SDKs.Android SDK.Build Tools")?.join?.(", ") ?? "Not Found" | ||
}`, | ||
`system_images: ` + asList("SDKs.Android SDK.System Images"), | ||
``, | ||
`# ios`, | ||
`xcode: ${get("IDEs.Xcode.version")}`, | ||
`cocoapods: ${get("Managers.CocoaPods.version")}`, | ||
`python: ${get("Languages.Python.version")}`, | ||
`python3: ${get("Languages.Python3.version")}`, | ||
`ruby: ${get("Languages.Ruby.version")}`, | ||
`platforms: ` + asList("SDKs.iOS SDK.Platforms"), | ||
"```", | ||
``, | ||
`### Dependencies`, | ||
``, | ||
"```json", | ||
'"dependencies": ' + JSON.stringify(dependencies, null, 2) + ",", | ||
'"devDependencies": ' + JSON.stringify(devDependencies, null, 2), | ||
"```", | ||
`<!-- COPY END -->`, | ||
].join("\n") | ||
); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "nativescript-envinfo", | ||
"version": "1.0.9", | ||
"main": "dist/index.js", | ||
"bin": "dist/index.js", | ||
"files": [], | ||
"license": "MIT", | ||
"scripts": { | ||
"prepack": "tsc" | ||
}, | ||
"dependencies": { | ||
"@types/envinfo": "^7.8.1", | ||
"envinfo": "^7.8.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/envinfo@^7.8.1": | ||
version "7.8.1" | ||
resolved "https://registry.yarnpkg.com/@types/envinfo/-/envinfo-7.8.1.tgz#1915df82c16d637e92146645c70db9360eb099c6" | ||
integrity sha512-pTyshpmGxqB9lRwG75v2YR0oqKYpCrklOYlZWQ88z/JB0fimT8EVmYekuIwpU3IxPZDHSXCqXKzkCrtAcKY25g== | ||
|
||
envinfo@^7.8.1: | ||
version "7.8.1" | ||
resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.8.1.tgz#06377e3e5f4d379fea7ac592d5ad8927e0c4d475" | ||
integrity sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw== |