@@ -7,14 +7,34 @@ const { join, sep } = require('path');
7
7
const { platform } = require ( 'os' ) ;
8
8
const appPath = join ( __dirname , '..' ) ;
9
9
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;
13
16
14
17
/** 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
+ } ;
18
38
} ;
19
39
20
40
/** list of proto files and patches to apply */
@@ -30,7 +50,7 @@ const filePatches = {
30
50
*/
31
51
const download = async ( ) => {
32
52
console . log ( '\nDownloading proto files...' ) ;
33
- for ( [ name , urlPath ] of Object . entries ( protoSources ) ) {
53
+ for ( [ name , urlPath ] of Object . entries ( await protoSources ( ) ) ) {
34
54
const url = `https://raw.githubusercontent.com/${ urlPath } ` ;
35
55
const filePath = join ( appPath , '..' , 'proto' , `${ name } .proto` ) ;
36
56
console . log ( `${ url } ` ) ;
0 commit comments