3030 */
3131"use strict" ;
3232
33+ var home = require ( '../../lib/home' ) ;
3334var path = require ( 'path' ) ;
3435var Promise = require ( 'promise' ) ;
3536var sprintf = require ( 'sprintf-js' ) . sprintf ;
37+ var strings = require ( '../../lib/strings' ) ;
3638
3739var list = function ( args ) {
3840 return new Promise ( function ( resolve , reject ) {
@@ -43,14 +45,37 @@ var list = function(args) {
4345 console . log ( JSON . stringify ( gameList , undefined , " " ) ) ;
4446 } else {
4547 if ( gameList . length > 0 ) {
46- var longestIdLength = gameList . reduce ( function ( previous , current ) {
47- return Math . max ( previous , current . originalGameId . length ) ;
48+ var longest = {
49+ id : 0 ,
50+ version : 7 ,
51+ apiVersion : 3 ,
52+ } ;
53+ gameList . forEach ( function ( runtimeInfo ) {
54+ longest . id = Math . max ( longest . id , runtimeInfo . originalGameId . length ) ;
55+ longest . version = Math . max ( longest . version , runtimeInfo . info . version . length ) ;
56+ longest . apiVersion = Math . max ( longest . apiVersion , runtimeInfo . info . happyFunTimes . apiVersion . length ) ;
4857 } , 0 ) ;
58+ var format = strings . replaceParams ( "%-%(id)ss %3s %%(version)ss %%(apiVersion)ss %s" , longest ) ;
59+ console . log ( sprintf ( format ,
60+ "id" ,
61+ "dev" ,
62+ "version" ,
63+ "api" ,
64+ "path" ) ) ;
65+ console . log ( "------------------------------------------------------------------------------" ) ;
4966 console . log ( gameList . map ( function ( game ) {
50- return sprintf ( "id: %-" + ( longestIdLength ) + "s dev: %s path: %s" ,
67+ var basePath = game . basePath ;
68+ if ( process . platform . substring ( 0 , 3 ) . toLowerCase ( ) != "win" ) {
69+ if ( strings . startsWith ( basePath , home . homeDir ) ) {
70+ basePath = basePath . replace ( home . homeDir , "~" ) ;
71+ }
72+ }
73+ return sprintf ( format ,
5174 game . originalGameId ,
5275 game . originalGameId != game . info . happyFunTimes . gameId ? "*" : " " ,
53- game . basePath ) ;
76+ game . info . version ,
77+ game . info . happyFunTimes . apiVersion ,
78+ basePath ) ;
5479 } ) . join ( "\n" ) ) ;
5580 } else {
5681 console . log ( "no games installed" ) ;
0 commit comments