Skip to content

feat: nativescript-envinfo package #5600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/nativescript-envinfo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
103 changes: 103 additions & 0 deletions packages/nativescript-envinfo/index.ts
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();
15 changes: 15 additions & 0 deletions packages/nativescript-envinfo/package.json
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"
}
}
6 changes: 6 additions & 0 deletions packages/nativescript-envinfo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
}
}
13 changes: 13 additions & 0 deletions packages/nativescript-envinfo/yarn.lock
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==