-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BrowserFetcher bindings #42
Merged
zploskey
merged 12 commits into
zploskey:master
from
jihchi:40_bindings_for_browserfetcher
Mar 26, 2018
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d69fa84
Add BrowserFetcher bindings
2a776b3
Add unit test for Puppeteer.createBrowserFetcher
cf3daab
Add unit test for BrowserFetcher.canDownload
e250bb9
Add unit test for BrowserFetcher.download
cfd315b
Fix `Win64 should be "win64"
83faada
Add unit test for BrowserFetcher.localRevisions
c8cc7c1
Add unit test for BrowserFetcher.platform
d562102
Add unit test for BrowserFetcher.remove
107457a
Add unit test for BrowserFetcher.revisionInfo
cb4d29c
platform type don't need bs.as
50f927d
Remove unnecessary createBrowserFetcher test
784ba5c
Change naming to `makeBrowserFetcherOptions`
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
var Js_mapperRt = require("bs-platform/lib/js/js_mapperRt.js"); | ||
var Js_undefined = require("bs-platform/lib/js/js_undefined.js"); | ||
|
||
function download(revision, progressCallback, t) { | ||
return t.download(revision, Js_undefined.fromOption(progressCallback)); | ||
} | ||
|
||
var jsMapperConstantArray = /* array */[ | ||
/* tuple */[ | ||
-577272933, | ||
"win32" | ||
], | ||
/* tuple */[ | ||
-577272262, | ||
"Win64" | ||
], | ||
/* tuple */[ | ||
3850863, | ||
"mac" | ||
], | ||
/* tuple */[ | ||
137321428, | ||
"linux" | ||
] | ||
]; | ||
|
||
function platformToJs(param) { | ||
return Js_mapperRt.binarySearch(4, param, jsMapperConstantArray); | ||
} | ||
|
||
function platformFromJs(param) { | ||
return Js_mapperRt.revSearch(4, jsMapperConstantArray, param); | ||
} | ||
|
||
exports.download = download; | ||
exports.platformToJs = platformToJs; | ||
exports.platformFromJs = platformFromJs; | ||
/* No side effect */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
type t; | ||
|
||
type revisionInfo = { | ||
. | ||
"revision": string, | ||
"folderPath": string, | ||
"executablePath": string, | ||
"url": string, | ||
"local": Js.boolean, | ||
}; | ||
|
||
external empty : unit => t = "%identity"; | ||
|
||
[@bs.send] | ||
external canDownload : (t, string) => Js.Promise.t(Js.boolean) = ""; | ||
|
||
[@bs.send] | ||
external download : | ||
(t, string, Js.Undefined.t((float, float) => unit)) => | ||
Js.Promise.t(revisionInfo) = | ||
""; | ||
|
||
let download = | ||
(~revision, ~progressCallback=?, t) | ||
: Js.Promise.t(revisionInfo) => | ||
download(t, revision, progressCallback |> Js.Undefined.fromOption); | ||
|
||
[@bs.send] external localRevisions : t => Js.Promise.t(array(string)) = ""; | ||
|
||
[@bs.deriving jsConverter] | ||
type platform = [ | ||
| [@bs.as "mac"] `Mac | ||
| [@bs.as "linux"] `Linux | ||
| [@bs.as "win32"] `Win32 | ||
| [@bs.as "Win64"] `Win64 | ||
]; | ||
|
||
/* Returns one of mac, linux, win32 or win64. */ | ||
[@bs.send] external platform : t => platform = ""; | ||
|
||
[@bs.send] external remove : (t, string) => Js.Promise.t(unit) = ""; | ||
|
||
[@bs.send] | ||
external revisionInfo : (t, string) => Js.Promise.t(revisionInfo) = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,3 +116,32 @@ external launch : (~options: launchOptions=?, unit) => Js.Promise.t(Browser.t) = | |
[@bs.val] | ||
[@bs.module "puppeteer"] | ||
external defaultArgs : unit => array(string) = ""; | ||
|
||
type browserFetcherOptions = { | ||
. | ||
"host": Js.undefined(string), | ||
"path": Js.undefined(string), | ||
"platform": Js.undefined(string), | ||
}; | ||
|
||
[@bs.obj] | ||
external makeBrowserFetcherOption : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consistent this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in commit 784ba5c |
||
(~host: string=?, ~path: string=?, ~platform: string=?, unit) => | ||
browserFetcherOptions = | ||
""; | ||
|
||
let makeBrowserFetcherOption = | ||
(~host=?, ~path=?, ~platform=?, ()) | ||
: browserFetcherOptions => | ||
makeBrowserFetcherOption( | ||
~host?, | ||
~path?, | ||
~platform=? | ||
platform |> Js.Option.map((. v) => v |> BrowserFetcher.platformToJs), | ||
(), | ||
); | ||
|
||
[@bs.val] [@bs.module "puppeteer"] | ||
external createBrowserFetcher : | ||
(~options: browserFetcherOptions=?, unit) => BrowserFetcher.t = | ||
""; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
win64 should be all lower case. If you just make the polymorphic variants all lower case and the same as the string doesn't it convert them to the right string? No need to use bs.as.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought variant constructor need to be capitalized. tried lower case but without success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polymorphic variants don't need to be capitalized. For example: https://github.com/bs-puppeteer/bs-puppeteer/blob/master/src/ConsoleMessage.re
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! That works, Thanks!