Skip to content

Commit 3d93358

Browse files
authored
Merge pull request #159 from lightninglabs/update-proto-build
Update protos build script
2 parents e1e7855 + 130bd40 commit 3d93358

File tree

12 files changed

+1395
-23
lines changed

12 files changed

+1395
-23
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# that, generated. This will make sure the JS (and TS types for that matter)
33
# will not show up in the repository's language statistics.
44

5-
app/src/types/generated* linguist-generated
5+
app/src/types/generated/** linguist-generated

.github/workflows/main.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ jobs:
3636
with:
3737
node-version: ${{ matrix.node_version }}
3838

39-
- name: setup protoc
40-
uses: arduino/setup-protoc@master
41-
with:
42-
repo-token: ${{ secrets.GITHUB_TOKEN }}
43-
4439
- name: get yarn cache dir
4540
id: yarn-cache-dir
4641
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -115,11 +110,6 @@ jobs:
115110
with:
116111
go-version: '~${{ matrix.go_version }}'
117112

118-
- name: setup protoc
119-
uses: arduino/setup-protoc@master
120-
with:
121-
repo-token: ${{ secrets.GITHUB_TOKEN }}
122-
123113
- name: build backend binary
124114
run: make build
125115

app/scripts/build-protos.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const util = require('util');
3+
const https = require('https');
34
const exec = util.promisify(require('child_process').exec);
45
const { promises: fs } = require('fs');
56
const { join, sep } = require('path');
67
const { platform } = require('os');
78
const appPath = join(__dirname, '..');
89

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';
13+
14+
/** 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+
};
19+
920
/** list of proto files and patches to apply */
1021
const filePatches = {
1122
lnd: 'lnrpc: {}',
@@ -14,11 +25,33 @@ const filePatches = {
1425
'google/api/http': 'google: { api: {} }',
1526
};
1627

28+
/**
29+
* Downloads the *.proto files into the `../proto` dir
30+
*/
31+
const download = async () => {
32+
console.log('\nDownloading proto files...');
33+
for ([name, urlPath] of Object.entries(protoSources)) {
34+
const url = `https://raw.githubusercontent.com/${urlPath}`;
35+
const filePath = join(appPath, '..', 'proto', `${name}.proto`);
36+
console.log(`${url}`);
37+
console.log(` -> ${filePath}`);
38+
const content = await new Promise((resolve, reject) => {
39+
https.get(url, res => {
40+
let data = '';
41+
res.on('data', chunk => (data += chunk));
42+
res.on('error', err => reject(err));
43+
res.on('end', () => resolve(data));
44+
});
45+
});
46+
await fs.writeFile(filePath, content);
47+
}
48+
};
49+
1750
/**
1851
* Executes the `protoc` compiler to convert *.proto files into TS & JS code
1952
*/
2053
const generate = async () => {
21-
console.log('Compiling protobuf definitions');
54+
console.log('\nCompiling protobuf definitions...');
2255
await fs.mkdir('./src/types/generated', { recursive: true });
2356

2457
const protocGen = join(
@@ -37,11 +70,10 @@ const generate = async () => {
3770
].join(' ');
3871

3972
console.log(protocCmd);
40-
const { stdout, stderr } = await exec(protocCmd, { cwd: appPath });
73+
const { stderr } = await exec(protocCmd, { cwd: appPath });
4174
if (stderr) {
4275
throw new Error(`exec stderr:\n${stderr}`);
4376
}
44-
console.log(stdout);
4577
};
4678

4779
/**
@@ -50,7 +82,7 @@ const generate = async () => {
5082
* Example: prepends `var proto = { lnrpc: {} };` to lnd_pb.js
5183
*/
5284
const patch = async () => {
53-
console.log('Patching generated JS files');
85+
console.log('\nPatching generated JS files');
5486

5587
for (const filename of Object.keys(filePatches)) {
5688
const patch = [
@@ -78,6 +110,7 @@ const patch = async () => {
78110
*/
79111
const main = async () => {
80112
try {
113+
await download();
81114
await generate();
82115
await patch();
83116
} catch (error) {

app/src/types/generated/lnd_pb.d.ts

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)