import { SfdxProject } from "@salesforce/core" ; import { SfdxCommand } from "@salesforce/command" ; import { PackageGraph } from '../../../lib/packageGraph' ; import { Package } from '../../../lib/PackageDefs' ; import process = require ( 'child_process' ) ; export default class Version extends SfdxCommand { public static description = 'List version updates available to packages in the org.' ; protected static flagsConfig = { } ; protected static requiresUsername = true ; protected static supportsDevhubUsername = true ; protected static supportsUsername = true ; protected static requiresProject = true ; protected subscriberPackage : Package [ ] = [ ] ; public async run ( ) { const conn = this . org . getConnection ( ) ; conn . version = '45.0' ; const project = await SfdxProject . resolve ( ) ; const projectJson = await project . resolveProjectConfig ( ) ; const packageAliases = new Array ( projectJson . packageAliases ) ; for ( var application of packageAliases ) { for ( var key in Object ( application ) ) { let packageVersion = application [ key ] ; if ( packageVersion . startsWith ( '04t' ) ) { } } } this . getForcePackageInstalledList ( ) . then ( async ( installedPackages ) => { const graph = new PackageGraph ( conn , installedPackages ) ; await graph . init ( ) ; graph . buildGraph ( ) ; console . log ( graph . toDotFormat ( ) ) ; } ) . catch ( ( error ) => { console . log ( error ) ; } ) ; } private async getForcePackageInstalledList ( ) { const username = this . flags . targetusername ; let cmd = 'NODE_OPTIONS=--inspect=0 sfdx force:package:installed:list -u ' + username + ' --json ' ; await this . sh ( cmd ) . then ( ( stdout ) => { var output = JSON . parse ( stdout ) ; if ( output . result ) { for ( var _subscriberPackage of output . result ) { const _package = { Id : _subscriberPackage . SubscriberPackageId , Path : null , Name : _subscriberPackage . SubscriberPackageName , Namespace : _subscriberPackage . SubscriberPackageNamespace , VersionId : _subscriberPackage . SubscriberPackageVersionId , VersionName : _subscriberPackage . SubscriberPackageVersionName , VersionNumber : _subscriberPackage . SubscriberPackageVersionNumber } ; this . subscriberPackage . push ( _package ) ; } } } ) . catch ( ( stderr ) => { console . log ( stderr ) ; } ) ; return this . subscriberPackage ; } private async sh ( cmd ) { return new Promise ( ( resolve , reject ) => { process . exec ( cmd , ( err , stdout , stderr ) => { if ( err ) { console . log ( err ) ; reject ( { err } ) ; } else { resolve ( stdout ) ; } } ) ; } ) ; } }