diff --git a/packages/nativescript-envinfo/.gitignore b/packages/nativescript-envinfo/.gitignore new file mode 100644 index 0000000000..763301fc00 --- /dev/null +++ b/packages/nativescript-envinfo/.gitignore @@ -0,0 +1,2 @@ +dist/ +node_modules/ \ No newline at end of file diff --git a/packages/nativescript-envinfo/index.ts b/packages/nativescript-envinfo/index.ts new file mode 100644 index 0000000000..91bcbfb4fb --- /dev/null +++ b/packages/nativescript-envinfo/index.ts @@ -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( + [ + ``, + "```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), + "```", + ``, + ].join("\n") + ); +} + +main(); diff --git a/packages/nativescript-envinfo/package.json b/packages/nativescript-envinfo/package.json new file mode 100644 index 0000000000..bf78b6bceb --- /dev/null +++ b/packages/nativescript-envinfo/package.json @@ -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" + } +} diff --git a/packages/nativescript-envinfo/tsconfig.json b/packages/nativescript-envinfo/tsconfig.json new file mode 100644 index 0000000000..fe914d0eb2 --- /dev/null +++ b/packages/nativescript-envinfo/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist" + } +} diff --git a/packages/nativescript-envinfo/yarn.lock b/packages/nativescript-envinfo/yarn.lock new file mode 100644 index 0000000000..2bb724c50e --- /dev/null +++ b/packages/nativescript-envinfo/yarn.lock @@ -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==