@@ -7,14 +7,34 @@ const { join, sep } = require('path');
77const { platform } = require ( 'os' ) ;
88const appPath = join ( __dirname , '..' ) ;
99
10- /** Specify the versions of LND and Loop protos to download */
11- const LND_VERSION = 'v0.11.1-beta' ;
12- const LOOP_VERSION = 'v0.11.2-beta' ;
10+ /**
11+ * Specify the pattern under which the project's version can be found in the
12+ * root directory's go.mod file.
13+ */
14+ const LND_VERSION_PATTERN = / ^ \t g i t h u b \. c o m \/ l i g h t n i n g n e t w o r k \/ l n d ( v [ \d . ] + - b e t a ) / ms;
15+ const LOOP_VERSION_PATTERN = / ^ \t g i t h u b \. c o m \/ l i g h t n i n g l a b s \/ l o o p ( v [ \d . ] + - b e t a ) / ms;
1316
1417/** mapping of proto files to the github url to download each from */
15- const protoSources = {
16- lnd : `lightningnetwork/lnd/${ LND_VERSION } /lnrpc/rpc.proto` ,
17- loop : `lightninglabs/loop/${ LOOP_VERSION } /looprpc/client.proto` ,
18+ const protoSources = async ( ) => {
19+ console . log ( 'Parsing go.mod for versions...' ) ;
20+ const goModPath = join ( appPath , '..' , 'go.mod' ) ;
21+ const goModSource = ( await fs . readFile ( goModPath ) ) . toString ( ) ;
22+
23+ const lndVersion = goModSource . match ( LND_VERSION_PATTERN ) ;
24+ if ( ! lndVersion || lndVersion . length !== 2 ) {
25+ throw new Error ( `go.mod did not match pattern ${ LND_VERSION_PATTERN } ` ) ;
26+ }
27+
28+ const loopVersion = goModSource . match ( LOOP_VERSION_PATTERN ) ;
29+ if ( ! loopVersion || loopVersion . length !== 2 ) {
30+ throw new Error ( `go.mod did not match pattern ${ LOOP_VERSION_PATTERN } ` ) ;
31+ }
32+
33+ console . log ( `Found lnd version ${ lndVersion [ 1 ] } and loop version ${ loopVersion [ 1 ] } .` ) ;
34+ return {
35+ lnd : `lightningnetwork/lnd/${ lndVersion [ 1 ] } /lnrpc/rpc.proto` ,
36+ loop : `lightninglabs/loop/${ loopVersion [ 1 ] } /looprpc/client.proto` ,
37+ } ;
1838} ;
1939
2040/** list of proto files and patches to apply */
@@ -30,7 +50,7 @@ const filePatches = {
3050 */
3151const download = async ( ) => {
3252 console . log ( '\nDownloading proto files...' ) ;
33- for ( [ name , urlPath ] of Object . entries ( protoSources ) ) {
53+ for ( [ name , urlPath ] of Object . entries ( await protoSources ( ) ) ) {
3454 const url = `https://raw.githubusercontent.com/${ urlPath } ` ;
3555 const filePath = join ( appPath , '..' , 'proto' , `${ name } .proto` ) ;
3656 console . log ( `${ url } ` ) ;
0 commit comments