@@ -17,14 +17,7 @@ commander
1717 . parse ( process . argv ) ;
1818
1919const {
20- workingDir,
21- outFile,
22- configFile,
23- appId,
24- versionTagPrefix,
25- pretty,
26- repository,
27- versionOnly
20+ workingDir, outFile, configFile, appId, versionTagPrefix, pretty, repository, versionOnly
2821} = commander ;
2922
3023if ( ! workingDir || ! fs . existsSync ( workingDir ) || ! fs . lstatSync ( workingDir ) . isDirectory ( ) ) {
@@ -40,40 +33,40 @@ const getDefaultApp = () => {
4033 id : appId ,
4134 name : pack . name ,
4235 version : pack . version ,
43- versionTagPrefix
36+ versionTagPrefix,
4437 } ;
4538 }
4639 return {
4740 id : appId ,
4841 name : path . basename ( workingDir ) ,
49- versionTagPrefix
42+ versionTagPrefix,
5043 } ;
5144} ;
5245
5346const configFilePath = path . join ( workingDir , configFile ) ;
54- const config = fs . existsSync ( configFilePath )
55- ? JSON . parse ( fs . readFileSync ( configFilePath , 'utf8' ) )
56- : [ getDefaultApp ( ) ] ;
47+ const config = fs . existsSync ( configFilePath ) ? JSON . parse ( fs . readFileSync ( configFilePath , 'utf8' ) ) : [ getDefaultApp ( ) ] ;
5748
5849const outFilePath = outFile ? path . join ( workingDir , outFile ) : null ;
5950
60- const appConfig = config . find ( c => c . id === appId ) ;
51+ const appConfig = config . find ( ( c ) => c . id === appId ) ;
6152if ( ! appConfig ) {
6253 console . error ( `Expected an item with id '${ appId } ' in '${ configFilePath } '` ) ;
6354 process . exit ( 1 ) ;
6455}
6556
66- const execGetOutput = async ( command , cwd ) => new Promise ( resolve => {
67- exec ( command , { cwd } , ( error , stdout ) => {
68- resolve ( error ? null : ( stdout || '' ) . trim ( ) ) ;
57+ const execGetOutput = async ( command , cwd ) =>
58+ new Promise ( ( resolve ) => {
59+ exec ( command , { cwd } , ( error , stdout ) => {
60+ resolve ( error ? null : ( stdout || '' ) . trim ( ) ) ;
61+ } ) ;
6962 } ) ;
70- } ) ;
7163
72- const execGetExitCode = async ( command , cwd ) => new Promise ( resolve => {
73- exec ( command , { cwd } , ( error ) => {
74- resolve ( error ? error . code : 0 ) ;
64+ const execGetExitCode = async ( command , cwd ) =>
65+ new Promise ( ( resolve ) => {
66+ exec ( command , { cwd } , ( error ) => {
67+ resolve ( error ? error . code : 0 ) ;
68+ } ) ;
7569 } ) ;
76- } ) ;
7770
7871async function getGitInfo ( dirPath , describeMatchPrefix ) {
7972 const remoteUrl = repository ? await execGetOutput ( 'git config --get remote.origin.url' , dirPath ) : undefined ;
@@ -93,38 +86,40 @@ async function getGitInfo(dirPath, describeMatchPrefix) {
9386 branch,
9487 sha1,
9588 date : dateUnix ? new Date ( 1000 * dateUnix ) : undefined ,
96- clean : ( diffExitCode === 0 )
97- }
89+ clean : diffExitCode === 0 ,
90+ } ,
9891 } ;
9992}
10093
101- Promise . all ( config . map ( async item => (
102- {
94+ Promise . all (
95+ config . map ( async ( item ) => ( {
10396 id : item . id ,
10497 name : item . name ,
105- ...await getGitInfo ( path . join ( workingDir , item . path || '.' ) , item . versionTagPrefix ) ,
106- }
107- ) ) ) . then ( ( versions ) => {
108- const app = versions . find ( c => c . id === appId ) ;
109- const components = versions . filter ( c => c . id !== appId ) ;
98+ ...( await getGitInfo ( path . join ( workingDir , item . path || '.' ) , item . versionTagPrefix ) ) ,
99+ } ) )
100+ ) . then ( ( versions ) => {
101+ const app = versions . find ( ( c ) => c . id === appId ) ;
102+ const components = versions . filter ( ( c ) => c . id !== appId ) ;
110103
111104 let version = {
112105 name : app . name ,
113- version : app . version || appConfig . version
106+ version : app . version || appConfig . version ,
114107 } ;
115108
116109 if ( ! versionOnly ) {
117110 version = Object . assign ( version , {
118111 git : app . git ,
119- components : components . length ? components : undefined
112+ components : components . length ? components : undefined ,
120113 } ) ;
121114 }
122115
123116 const json = JSON . stringify ( version , undefined , pretty ? 2 : 0 ) ;
124117
125118 if ( outFilePath ) {
126119 fs . writeFile ( outFilePath , json , ( err ) => {
127- if ( err ) { console . error ( err ) ; }
120+ if ( err ) {
121+ console . error ( err ) ;
122+ }
128123 } ) ;
129124 } else {
130125 console . log ( json ) ;
0 commit comments