Skip to content

Commit b2940c3

Browse files
author
Pavel Petroshenko
authored
Merge pull request #45 from electricimp/develop
v2.4.0
2 parents 10f9ef5 + 5a97f9d commit b2940c3

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Diff for: README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- [Including JavaScript Libraries](#including-javascript-libraries)
3939
- [Binding the Context Object Correctly](#binding-the-context-object-correctly)
4040
- [Cache for Remote Includes](#cache-for-remote-includes)
41+
- [Proxy for Remote Includes](#proxy-for-remote-includes)
4142
- [Testing](#testing)
4243
- [License](#license)
4344

@@ -46,7 +47,7 @@
4647

4748
_Builder_ combines a preprocessor with an expression language and advanced imports.
4849

49-
#### Current version: 2.3.1
50+
#### Current version: 2.4.0
5051

5152
# Syntax
5253

@@ -682,6 +683,15 @@ To reset the cache use both the `--cache` and the `--clear-cache` options.
682683

683684
If a resource should never be cached, it needs to be added to the *exclude-list.builder* file. You can use wildcard characters to mask file names.
684685

686+
## Proxy for Remote Includes
687+
688+
To specify proxy that should be used to include files from remote resources (GitHub or remote HTTP/HTTPs servers), set environment variable(s) `HTTP_PROXY`/`http_proxy` and/or `HTTPS_PROXY`/`https_proxy` for HTTP and HTTPS protocols respectively.
689+
690+
For example, to use a proxy is running at IP `192.168.10.2` on port 3128 for HTTP requests you should set the environment variable:
691+
`HTTP_PROXY='http://192.168.10.2:3128'`. This will make all the Builder's HTTP requests to go through the proxy.
692+
693+
**Note**: files from GitHub (`github:` protocol) are always included via HTTPS protocol, so the HTTPS_PROXY (if any) should be used to specify proxy in this case.
694+
685695
### Wildcard pattern matching
686696

687697
Pattern matching syntax is a similar to that of *.gitignore*. A string is a wildcard pattern if it contains '```?```' or '```*```' characters. Empty strings or strings that starts with '```#```' are ignored.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Builder",
3-
"version": "2.3.1",
3+
"version": "2.4.0",
44
"description": "Builder Language Implementation",
55
"main": "src/index.js",
66
"bin": {
@@ -22,7 +22,7 @@
2222
"homepage": "https://github.com/electricimp/Builder#readme",
2323
"dependencies": {
2424
"clone": "^1.0.2",
25-
"github": "^0.2.4",
25+
"@octokit/rest": "^15.2.6",
2626
"glob": "^7.1.2",
2727
"jsep": "^0.3.1",
2828
"request": "^2.71.0",

Diff for: src/Readers/GithubReader.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
'use strict';
2626

27+
const HttpsProxyAgent = require('https-proxy-agent');
2728
const path = require('path');
28-
const GitHubApi = require('github');
29+
const GitHubApi = require('@octokit/rest');
2930
const childProcess = require('child_process');
3031
const packageJson = require('../../package.json');
3132
const AbstractReader = require('./AbstractReader');
@@ -122,7 +123,7 @@ class GithubReader extends AbstractReader {
122123
const parsed = GithubReader.parseUrl(source);
123124
return {
124125
__FILE__: path.basename(parsed.path),
125-
__PATH__: `github:${parsed.user}/${parsed.repo}/${path.dirname(parsed.path)}`
126+
__PATH__: `github:${parsed.owner}/${parsed.repo}/${path.dirname(parsed.path)}`
126127
};
127128
}
128129

@@ -131,17 +132,21 @@ class GithubReader extends AbstractReader {
131132
* @param {string} source
132133
*/
133134
static fetch(source, username, password) {
134-
135+
var agent = null;
136+
if (process.env.HTTPS_PROXY) {
137+
agent = HttpsProxyAgent(process.env.HTTPS_PROXY);
138+
} else if (process.env.https_proxy) {
139+
agent = HttpsProxyAgent(process.env.https_proxy);
140+
}
135141
const github = new GitHubApi({
136-
version: '3.0.0',
137142
debug: false,
138-
protocol: 'https',
139-
host: 'api.github.com',
143+
baseUrl: 'https://api.github.com',
140144
timeout: 5000,
141145
headers: {
142146
'user-agent': packageJson.name + '/' + packageJson.version,
143147
'accept': 'application/vnd.github.VERSION.raw'
144-
}
148+
},
149+
agent: agent
145150
});
146151

147152
// authorization
@@ -176,7 +181,7 @@ class GithubReader extends AbstractReader {
176181
process.exit(STATUS_FETCH_FAILED);
177182

178183
} else {
179-
process.stdout.write(res);
184+
process.stdout.write(res['data']);
180185
}
181186
});
182187
}
@@ -194,7 +199,7 @@ class GithubReader extends AbstractReader {
194199

195200
if (m) {
196201
const res = {
197-
'user': m[1],
202+
'owner': m[1],
198203
'repo': m[2],
199204
'path': m[3]
200205
};

0 commit comments

Comments
 (0)