|
1 | 1 | import ansi from "#core/ansi"; |
| 2 | +import Table from "#core/text/table"; |
2 | 3 | import Command from "#lib/command"; |
3 | 4 |
|
4 | 5 | export default class extends Command { |
@@ -42,14 +43,14 @@ Last release (next): ${ ansi.hl( status.releases.lastRelease || "-" ) } |
42 | 43 | Is dirty: ${ status.isDirty |
43 | 44 | ? ansi.error( " DIRTY " ) |
44 | 45 | : ansi.ok( " COMMITED " ) } |
45 | | -Branch sync. status: ${ Object.keys( status.branchStatus ) |
46 | | - .map( branch => branch + ": " + this.#getBranchStatusText( status.branchStatus[ branch ] ) ) |
47 | | - .join( "\n" + " ".repeat( 25 ) ) } |
48 | 46 | Unreleased commits: ${ pkg.isReleaseEnabled |
49 | 47 | ? ( status.currentReleaseDistance |
50 | 48 | ? ansi.error( " " + status.currentReleaseDistance + " " ) |
51 | 49 | : ansi.ok( " RELEASED " ) ) |
52 | 50 | : "-" } |
| 51 | +
|
| 52 | +Branch status: |
| 53 | +${ await this.#createBranchStatus( pkg, status.branchStatus ) } |
53 | 54 | `.trim() ); |
54 | 55 |
|
55 | 56 | if ( upstream ) { |
@@ -80,27 +81,104 @@ Clone wiki: ${ ansi.hl( upstream.wikiSshCloneUrl ) } |
80 | 81 | } |
81 | 82 |
|
82 | 83 | // private |
83 | | - #getBranchStatusText ( status ) { |
84 | | - if ( status.upstream ) { |
85 | | - if ( status.synchronized ) { |
86 | | - return "OK"; |
87 | | - } |
88 | | - else { |
89 | | - const text = []; |
90 | | - |
91 | | - if ( status.ahead ) { |
92 | | - text.push( "push " + ansi.error( ` ${ status.ahead } ` ) ); |
93 | | - } |
| 84 | + async #createBranchStatus ( pkg, branchStatus ) { |
| 85 | + const table = new Table( { |
| 86 | + "ansi": true, |
| 87 | + "columns": { |
| 88 | + "branch": { |
| 89 | + "title": ansi.hl( "BRANCH" ), |
| 90 | + "headerAlign": "center", |
| 91 | + "headerValign": "end", |
| 92 | + "width": 30, |
| 93 | + }, |
| 94 | + "pushStatus": { |
| 95 | + "title": ansi.hl( "PUSH STATUS" ), |
| 96 | + "headerAlign": "center", |
| 97 | + "headerValign": "end", |
| 98 | + "width": 20, |
| 99 | + "align": "end", |
| 100 | + "format": status => { |
| 101 | + if ( status.upstream ) { |
| 102 | + if ( status.synchronized ) { |
| 103 | + return " - "; |
| 104 | + } |
| 105 | + else { |
| 106 | + const text = []; |
| 107 | + |
| 108 | + if ( status.ahead ) { |
| 109 | + text.push( "push: " + ansi.error( ` ${ status.ahead } ` ) ); |
| 110 | + } |
| 111 | + |
| 112 | + if ( status.behind ) { |
| 113 | + text.push( "pull: " + ansi.error( ` ${ status.behind } ` ) ); |
| 114 | + } |
| 115 | + |
| 116 | + return text.join( ", " ); |
| 117 | + } |
| 118 | + } |
| 119 | + else { |
| 120 | + return ansi.dim( "NOT TRACKED" ); |
| 121 | + } |
| 122 | + }, |
| 123 | + }, |
| 124 | + "currentRelease": { |
| 125 | + "title": ansi.hl( "CURRENT\nRELEASE" ), |
| 126 | + "headerAlign": "center", |
| 127 | + "headerValign": "end", |
| 128 | + "width": 15, |
| 129 | + "align": "end", |
| 130 | + "format": status => { |
| 131 | + if ( pkg.isReleaseEnabled ) { |
| 132 | + if ( status.currentRelease ) { |
| 133 | + return `${ status.currentRelease.versionString }${ status.releases.lastRelease.eq( status.currentRelease ) |
| 134 | + ? " ✅️" |
| 135 | + : " " }`; |
| 136 | + } |
| 137 | + else { |
| 138 | + return " - " + " "; |
| 139 | + } |
| 140 | + } |
| 141 | + else { |
| 142 | + return ansi.dim( " DISABLED " ); |
| 143 | + } |
| 144 | + }, |
| 145 | + }, |
| 146 | + "unreleasedCommits": { |
| 147 | + "title": ansi.hl( "UNRELEASED\nCOMMITS" ), |
| 148 | + "headerAlign": "center", |
| 149 | + "headerValign": "end", |
| 150 | + "width": 15, |
| 151 | + "align": "end", |
| 152 | + "format": status => { |
| 153 | + if ( pkg.isReleaseEnabled ) { |
| 154 | + if ( status.currentReleaseDistance ) { |
| 155 | + return ansi.error( ` ${ status.currentReleaseDistance } ` ); |
| 156 | + } |
| 157 | + else { |
| 158 | + return " - "; |
| 159 | + } |
| 160 | + } |
| 161 | + else { |
| 162 | + return ansi.dim( " DISABLED " ); |
| 163 | + } |
| 164 | + }, |
| 165 | + }, |
| 166 | + }, |
| 167 | + } ); |
94 | 168 |
|
95 | | - if ( status.behind ) { |
96 | | - text.push( "pull " + ansi.error( ` ${ status.behind } ` ) ); |
97 | | - } |
| 169 | + for ( const branch of Object.keys( branchStatus ).sort() ) { |
| 170 | + const res = await pkg.git.getCurrentRelease( { "commitRef": branch } ); |
98 | 171 |
|
99 | | - return text.join( ", " ); |
100 | | - } |
101 | | - } |
102 | | - else { |
103 | | - return "NOT TRACKED"; |
| 172 | + table.write( { |
| 173 | + branch, |
| 174 | + "pushStatus": branchStatus[ branch ], |
| 175 | + "currentRelease": res.data, |
| 176 | + "unreleasedCommits": res.data, |
| 177 | + } ); |
104 | 178 | } |
| 179 | + |
| 180 | + table.end(); |
| 181 | + |
| 182 | + return table.content + "✅️ - latest release"; |
105 | 183 | } |
106 | 184 | } |
0 commit comments