From e2de1671d1200258efbb34d3f98a2d39f72dec57 Mon Sep 17 00:00:00 2001 From: Vladimir Kalnitsky Date: Tue, 25 Aug 2020 23:00:12 +0300 Subject: [PATCH] Add `launch`. --- bower.json | 17 +++++++ package.json | 32 +++++++++++++ packages.dhall | 8 ++++ spago.dhall | 6 +++ src/Playwright.js | 14 ++++++ src/Playwright.purs | 113 ++++++++++++++++++++++++++++++++++++++++++++ test/Main.purs | 9 ++++ 7 files changed, 199 insertions(+) create mode 100644 bower.json create mode 100644 package.json create mode 100644 packages.dhall create mode 100644 spago.dhall create mode 100644 src/Playwright.js create mode 100644 src/Playwright.purs create mode 100644 test/Main.purs diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..8e2d49a --- /dev/null +++ b/bower.json @@ -0,0 +1,17 @@ +{ + "name": "purescript-playwright", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "output" + ], + "dependencies": { + "purescript-prelude": "^4.1.1", + "purescript-console": "^4.4.0", + "purescript-effect": "^2.0.1" + }, + "devDependencies": { + "purescript-psci-support": "^4.0.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..a45a63c --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "purescript-playwright", + "version": "0.0.1", + "description": "PureScript bindings for Playwright", + "main": "index.js", + "directories": { + "test": "test" + }, + "dependencies": { + "bower": "^1.8.8", + "playwright": "^1.3.0", + "pulp": "^15.0.0" + }, + "devDependencies": {}, + "scripts": { + "test": "pulp test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/klntsky/purescript-playwright.git" + }, + "keywords": [ + "purescript", + "playwright" + ], + "author": "Vladimir Kalnitsky ", + "license": "BSD-3-Clause", + "bugs": { + "url": "https://github.com/klntsky/purescript-playwright/issues" + }, + "homepage": "https://github.com/klntsky/purescript-playwright#readme" +} diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..e455430 --- /dev/null +++ b/packages.dhall @@ -0,0 +1,8 @@ +let upstream = + https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200822/packages.dhall sha256:b4f151f1af4c5cb6bf5437489f4231fbdd92792deaf32971e6bcb0047b3dd1f8 + +let overrides = {=} + +let additions = {=} + +in upstream ⫽ overrides ⫽ additions diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..604d8b0 --- /dev/null +++ b/spago.dhall @@ -0,0 +1,6 @@ +{ name = "playwright" +, dependencies = + [ "console", "effect", "prelude", "psci-support", "aff-promise", "options" ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] +} diff --git a/src/Playwright.js b/src/Playwright.js new file mode 100644 index 0000000..bdefbd6 --- /dev/null +++ b/src/Playwright.js @@ -0,0 +1,14 @@ +/* global require exports */ + +var P = require('playwright'); + +exports.chromium = P.chromium; +exports.firefox = P.firefox; +exports.webkit = P.webkit; +exports._launch = function (browser) { + return function (opts) { + return function () { + return browser.launch(opts); + }; + }; +}; diff --git a/src/Playwright.purs b/src/Playwright.purs new file mode 100644 index 0000000..726f83b --- /dev/null +++ b/src/Playwright.purs @@ -0,0 +1,113 @@ +module Playwright + ( BrowserType + , Browser + + , firefox + , chromium + , webkit + + , launch + , LaunchOptions + , headless + , executablePath + , args + , ignoreDefaultArgs + , ProxyOptions + , server + , bypass + , username + , password + , proxy + , downloadsPath + , chromiumSandbox + , firefoxUserPrefs + , handleSIGINT + , handleSIGTERM + , handleSIGHUP + , timeout + , env + , devtools + , slowMo + ) +where + +import Prelude +import Effect (Effect) +import Control.Promise (Promise, toAffE) +import Data.Options (Option, Options, opt) +import Effect.Aff (Aff) +import Foreign (Foreign) +import Foreign.Object (Object) + +foreign import data BrowserType :: Type +foreign import data Browser :: Type + +foreign import firefox :: BrowserType +foreign import chromium :: BrowserType +foreign import webkit :: BrowserType + +foreign import _launch :: BrowserType -> Options LaunchOptions -> Effect (Promise Browser) + +launch :: BrowserType -> Options LaunchOptions -> Aff Browser +launch bt = toAffE <<< _launch bt + +foreign import data LaunchOptions :: Type + +headless :: Option LaunchOptions Boolean +headless = opt "headless" + +executablePath :: Option LaunchOptions String +executablePath = opt "executablePath" + +args :: Option LaunchOptions String +args = opt "args" + +ignoreDefaultArgs :: Option LaunchOptions (Array String) +ignoreDefaultArgs = opt "ignoreDefaultArgs" + +foreign import data ProxyOptions :: Type + +server :: Option ProxyOptions String +server = opt "server" + +bypass :: Option ProxyOptions String +bypass = opt "bypass" + +username :: Option ProxyOptions String +username = opt "username" + +password :: Option ProxyOptions String +password = opt "password" + +proxy :: Option LaunchOptions (Options ProxyOptions) +proxy = opt "proxy" + +downloadsPath :: Option LaunchOptions String +downloadsPath = opt "downloadsPath" + +chromiumSandbox :: Option LaunchOptions Boolean +chromiumSandbox = opt "chromiumSandbox" + +firefoxUserPrefs :: Option LaunchOptions Foreign +firefoxUserPrefs = opt "firefoxUserPrefs" + +handleSIGINT :: Option LaunchOptions Boolean +handleSIGINT = opt "handleSIGINT" + +handleSIGTERM :: Option LaunchOptions Boolean +handleSIGTERM = opt "handleSIGTERM" + +handleSIGHUP :: Option LaunchOptions Boolean +handleSIGHUP = opt "handleSIGHUP" + +timeout :: Option LaunchOptions Number +timeout = opt "timeout" + +env :: Option LaunchOptions (Object String) +env = opt "env" + +devtools :: Option LaunchOptions Boolean +devtools = opt "devtools" + +slowMo :: Option LaunchOptions Number +slowMo = opt "slowMo" diff --git a/test/Main.purs b/test/Main.purs new file mode 100644 index 0000000..bbe367f --- /dev/null +++ b/test/Main.purs @@ -0,0 +1,9 @@ +module Test.Main where + +import Prelude +import Effect (Effect) +import Effect.Console (log) + +main :: Effect Unit +main = do + log "You should add some tests."