Skip to content

Commit 5afccea

Browse files
committed
scripts+docs: extract lnd and loop version from go.mod
To make sure we always use the *.proto files for the correct versions of the daemons we include, we parse the versions of lnd and loop directly from the go.mod file.
1 parent c7dda12 commit 5afccea

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

app/scripts/build-protos.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,34 @@ const { join, sep } = require('path');
77
const { platform } = require('os');
88
const 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 = /^\tgithub\.com\/lightningnetwork\/lnd (v[\d.]+-beta)/ms;
15+
const LOOP_VERSION_PATTERN = /^\tgithub\.com\/lightninglabs\/loop (v[\d.]+-beta)/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
*/
3151
const 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}`);

doc/compile.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ To compile the proto files into JS/TS code, follow the following steps:
8383
work properly.
8484

8585
> Note: if you are running on a Mac, you only need to perform step 1
86-
1. Update the version of `lnd` and/or `loop` at the top of the [build-protos.js](../src/scripts/build-protos.js)
87-
file.
8886
1. Run the following command to download the proto files from each repo and compile the
8987
JS/TS code using the updated protos.
9088
```shell script

0 commit comments

Comments
 (0)