@stepzen/graphiql-proxy 0.20.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/package.json +61 -0
- package/src/server/api/debugging.js +19 -0
- package/src/server/api/details.js +15 -0
- package/src/server/api/ping.js +9 -0
- package/src/server/api/predicates.js +23 -0
- package/src/server/api/proxy.js +59 -0
- package/src/server/api/samples.js +26 -0
- package/src/server/index.js +100 -0
- package/src/server/utils/open-browser.js +144 -0
- package/src/server/utils/open-chrome.applescript +93 -0
- package/src/ui/README.md +72 -0
- package/src/ui/build/asset-manifest.json +58 -0
- package/src/ui/build/favicon.ico +0 -0
- package/src/ui/build/index.html +1 -0
- package/src/ui/build/static/css/main.f9030c32.css +2 -0
- package/src/ui/build/static/css/main.f9030c32.css.map +1 -0
- package/src/ui/build/static/js/0.a1da3266.chunk.js +2 -0
- package/src/ui/build/static/js/0.a1da3266.chunk.js.map +1 -0
- package/src/ui/build/static/js/136.7849911c.chunk.js +2 -0
- package/src/ui/build/static/js/136.7849911c.chunk.js.map +1 -0
- package/src/ui/build/static/js/170.27296619.chunk.js +2 -0
- package/src/ui/build/static/js/170.27296619.chunk.js.map +1 -0
- package/src/ui/build/static/js/190.e088a175.chunk.js +2 -0
- package/src/ui/build/static/js/190.e088a175.chunk.js.map +1 -0
- package/src/ui/build/static/js/267.962ef6a4.chunk.js +2 -0
- package/src/ui/build/static/js/267.962ef6a4.chunk.js.map +1 -0
- package/src/ui/build/static/js/306.cb66dc99.chunk.js +2 -0
- package/src/ui/build/static/js/306.cb66dc99.chunk.js.map +1 -0
- package/src/ui/build/static/js/316.7c2be1f0.chunk.js +2 -0
- package/src/ui/build/static/js/316.7c2be1f0.chunk.js.map +1 -0
- package/src/ui/build/static/js/322.5ada89eb.chunk.js +2 -0
- package/src/ui/build/static/js/322.5ada89eb.chunk.js.map +1 -0
- package/src/ui/build/static/js/344.e6b10333.chunk.js +2 -0
- package/src/ui/build/static/js/344.e6b10333.chunk.js.map +1 -0
- package/src/ui/build/static/js/39.dd9b3202.chunk.js +2 -0
- package/src/ui/build/static/js/39.dd9b3202.chunk.js.map +1 -0
- package/src/ui/build/static/js/430.de05cf2b.chunk.js +2 -0
- package/src/ui/build/static/js/430.de05cf2b.chunk.js.map +1 -0
- package/src/ui/build/static/js/503.a3ba392a.chunk.js +2 -0
- package/src/ui/build/static/js/503.a3ba392a.chunk.js.map +1 -0
- package/src/ui/build/static/js/580.b48b02d9.chunk.js +2 -0
- package/src/ui/build/static/js/580.b48b02d9.chunk.js.map +1 -0
- package/src/ui/build/static/js/587.f2cbe2fb.chunk.js +2 -0
- package/src/ui/build/static/js/587.f2cbe2fb.chunk.js.map +1 -0
- package/src/ui/build/static/js/619.cd709ae5.chunk.js +2 -0
- package/src/ui/build/static/js/619.cd709ae5.chunk.js.map +1 -0
- package/src/ui/build/static/js/658.916c9abf.chunk.js +2 -0
- package/src/ui/build/static/js/658.916c9abf.chunk.js.map +1 -0
- package/src/ui/build/static/js/756.a915a97e.chunk.js +2 -0
- package/src/ui/build/static/js/756.a915a97e.chunk.js.map +1 -0
- package/src/ui/build/static/js/76.0a014434.chunk.js +2 -0
- package/src/ui/build/static/js/76.0a014434.chunk.js.map +1 -0
- package/src/ui/build/static/js/804.118a9243.chunk.js +2 -0
- package/src/ui/build/static/js/804.118a9243.chunk.js.map +1 -0
- package/src/ui/build/static/js/849.f850f73b.chunk.js +2 -0
- package/src/ui/build/static/js/849.f850f73b.chunk.js.map +1 -0
- package/src/ui/build/static/js/88.b5b4cd91.chunk.js +2 -0
- package/src/ui/build/static/js/88.b5b4cd91.chunk.js.map +1 -0
- package/src/ui/build/static/js/983.df163755.chunk.js +2 -0
- package/src/ui/build/static/js/983.df163755.chunk.js.map +1 -0
- package/src/ui/build/static/js/main.27cac1e6.js +3 -0
- package/src/ui/build/static/js/main.27cac1e6.js.LICENSE.txt +92 -0
- package/src/ui/build/static/js/main.27cac1e6.js.map +1 -0
- package/src/ui/build/static/media/logo.2fa5e016c31f1c335b07ff477d91ee9a.svg +1 -0
- package/src/ui/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @stepzen/graphiql-proxy
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stepzen/graphiql-proxy",
|
|
3
|
+
"version": "0.20.0-beta.2",
|
|
4
|
+
"author": "Darren Waddell <darren@stepzen.com>",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://stepzen.com",
|
|
7
|
+
"files": [
|
|
8
|
+
"/src/server",
|
|
9
|
+
"/src/ui/build"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=14.0.1",
|
|
13
|
+
"npm": ">=6.14"
|
|
14
|
+
},
|
|
15
|
+
"main": "src/server",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"dev:server": "nodemon src/dev --watch src/dev --watch src/server",
|
|
18
|
+
"dev:ui": "cd src/ui && REACT_APP_IS_DEVELOPMENT=1 npm start",
|
|
19
|
+
"prepack": "cd src/ui && npm run build",
|
|
20
|
+
"prepare": "cd src/ui && npm install",
|
|
21
|
+
"start": "concurrently \"npm run dev:server\" \"npm run dev:ui\"",
|
|
22
|
+
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
|
|
23
|
+
"posttest": "prettier . --check"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"chalk": "^4.1.2",
|
|
27
|
+
"cors": "^2.8.5",
|
|
28
|
+
"cross-spawn": "^7.0.3",
|
|
29
|
+
"debug": "^4.3.4",
|
|
30
|
+
"express": "^4.17.3",
|
|
31
|
+
"express-promise-router": "^4.1.1",
|
|
32
|
+
"node-fetch": "^2.6.7",
|
|
33
|
+
"open": "^8.4.0",
|
|
34
|
+
"prettier": "^2.6.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/chai": "^4.2.12",
|
|
38
|
+
"@types/cors": "^2.8.10",
|
|
39
|
+
"@types/cross-spawn": "^6.0.2",
|
|
40
|
+
"@types/debug": "^4.1.6",
|
|
41
|
+
"@types/express": "^4.17.9",
|
|
42
|
+
"@types/glob": "^7.2.0",
|
|
43
|
+
"@types/license-checker": "^25.0.1",
|
|
44
|
+
"@types/mocha": "^5.2.7",
|
|
45
|
+
"@types/node-fetch": "^2.5.7",
|
|
46
|
+
"@types/sinon-chai": "3.2.8",
|
|
47
|
+
"chai": "^4.2.0",
|
|
48
|
+
"concurrently": "^6.0.2",
|
|
49
|
+
"dotenv": "^8.2.0",
|
|
50
|
+
"fancy-test": "^1.4.10",
|
|
51
|
+
"license-checker": "^25.0.1",
|
|
52
|
+
"mocha": "^5.2.0",
|
|
53
|
+
"nock": "^13.0.4",
|
|
54
|
+
"nodemon": "^2.0.7",
|
|
55
|
+
"nyc": "^14.1.1",
|
|
56
|
+
"sinon": "13.0.1",
|
|
57
|
+
"sinon-chai": "3.7.0",
|
|
58
|
+
"ts-node": "^10.8.2"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "91f8c64c009806c94de0495c45dc5d9e6015787d"
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
const debugging = async (req, res) => {
|
|
4
|
+
const {debugging} = req.stepzen
|
|
5
|
+
|
|
6
|
+
if (req.method === 'POST') {
|
|
7
|
+
const {enabled} = req.body
|
|
8
|
+
|
|
9
|
+
if (debugging.enabled !== enabled) {
|
|
10
|
+
debugging.onToggleDebugging()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
debugging.enabled = enabled
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
res.json(debugging)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = debugging
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
const details = async (req, res) => {
|
|
4
|
+
const {account, domain, predicates, workspace} = req.stepzen
|
|
5
|
+
|
|
6
|
+
const endpoint = `https://${account}.${domain}/${workspace.endpoint}/__graphql`
|
|
7
|
+
|
|
8
|
+
res.json({
|
|
9
|
+
endpoint,
|
|
10
|
+
predicates,
|
|
11
|
+
workspace,
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = details
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
const predicates = async (req, res) => {
|
|
4
|
+
const {predicates} = req.stepzen
|
|
5
|
+
|
|
6
|
+
if (req.method === 'POST') {
|
|
7
|
+
const {enabled, headers} = req.body
|
|
8
|
+
|
|
9
|
+
predicates.headers = headers
|
|
10
|
+
|
|
11
|
+
if (predicates.enabled !== enabled) {
|
|
12
|
+
predicates.onTogglePredicates()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
predicates.enabled = enabled
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
res.json({
|
|
19
|
+
predicates,
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = predicates
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')
|
|
4
|
+
const fetch = require('node-fetch')
|
|
5
|
+
|
|
6
|
+
const {version} = require('../../../package.json')
|
|
7
|
+
|
|
8
|
+
const proxy = async (req, res) => {
|
|
9
|
+
const {account, adminkey, debugging, domain, predicates, workspace} =
|
|
10
|
+
req.stepzen
|
|
11
|
+
|
|
12
|
+
let endpoint = workspace.endpoint
|
|
13
|
+
|
|
14
|
+
let headers = {}
|
|
15
|
+
|
|
16
|
+
if (predicates.available && predicates.enabled) {
|
|
17
|
+
try {
|
|
18
|
+
const others = JSON.parse(JSON.stringify(predicates.headers))
|
|
19
|
+
headers = {
|
|
20
|
+
...others,
|
|
21
|
+
}
|
|
22
|
+
} catch {}
|
|
23
|
+
} else {
|
|
24
|
+
headers = {
|
|
25
|
+
Authorization: `Apikey ${adminkey}`,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (debugging.enabled) {
|
|
30
|
+
headers = {
|
|
31
|
+
'StepZen-Debug-Level': 1,
|
|
32
|
+
...headers,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const url = `https://${account}.${domain.replace(
|
|
37
|
+
'.io',
|
|
38
|
+
'.net',
|
|
39
|
+
)}/${endpoint}/__graphql`
|
|
40
|
+
|
|
41
|
+
debug('stepzen:dashboard')(`proxy headers: ${JSON.stringify(headers)}`)
|
|
42
|
+
debug('stepzen:dashboard')(`proxy url: ${url}`)
|
|
43
|
+
|
|
44
|
+
const response = await fetch(url, {
|
|
45
|
+
body: JSON.stringify(req.body),
|
|
46
|
+
headers: {
|
|
47
|
+
...headers,
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
'stepzen-cli-version': version,
|
|
50
|
+
'user-agent': `stepzen-cli/${version}`,
|
|
51
|
+
},
|
|
52
|
+
method: 'POST',
|
|
53
|
+
})
|
|
54
|
+
const json = await response.json()
|
|
55
|
+
|
|
56
|
+
res.json(json)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = proxy
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const prettier = require('prettier')
|
|
5
|
+
|
|
6
|
+
const samples = async (req, res) => {
|
|
7
|
+
const {workspace} = req.stepzen
|
|
8
|
+
|
|
9
|
+
const folder = workspace.schema
|
|
10
|
+
const file = `${workspace.schema}/sample-queries.graphql`
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(folder) || !fs.existsSync(file)) {
|
|
13
|
+
return res.json({
|
|
14
|
+
samples: false,
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const samples = fs.readFileSync(file, 'utf8')
|
|
19
|
+
const formatted = prettier.format(samples, {parser: 'graphql'})
|
|
20
|
+
|
|
21
|
+
return res.json({
|
|
22
|
+
samples: formatted,
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = samples
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
const cors = require('cors')
|
|
4
|
+
const debug = require('debug')
|
|
5
|
+
const express = require('express')
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const router = require('express-promise-router')()
|
|
8
|
+
|
|
9
|
+
const openBrowser = require('./utils/open-browser')
|
|
10
|
+
|
|
11
|
+
const _debugging = require('./api/debugging')
|
|
12
|
+
const details = require('./api/details')
|
|
13
|
+
const ping = require('./api/ping')
|
|
14
|
+
const _predicates = require('./api/predicates')
|
|
15
|
+
const proxy = require('./api/proxy')
|
|
16
|
+
const samples = require('./api/samples')
|
|
17
|
+
|
|
18
|
+
module.exports = async ({
|
|
19
|
+
account,
|
|
20
|
+
adminkey,
|
|
21
|
+
apikey,
|
|
22
|
+
cli = {version: ''},
|
|
23
|
+
domain = 'stepzen.io',
|
|
24
|
+
port = 5000,
|
|
25
|
+
predicates = {
|
|
26
|
+
available: false,
|
|
27
|
+
enabled: false,
|
|
28
|
+
onTogglePredicates: async () => {},
|
|
29
|
+
},
|
|
30
|
+
debugging = {
|
|
31
|
+
enabled: false,
|
|
32
|
+
onToggleDebugging: async () => {},
|
|
33
|
+
},
|
|
34
|
+
workspace,
|
|
35
|
+
}) => {
|
|
36
|
+
const app = express()
|
|
37
|
+
|
|
38
|
+
app.use(express.json())
|
|
39
|
+
app.use(cors())
|
|
40
|
+
|
|
41
|
+
app.use(express.static(`${__dirname}/../ui/build`))
|
|
42
|
+
app.use((req, res, next) => {
|
|
43
|
+
req.stepzen = {
|
|
44
|
+
account,
|
|
45
|
+
adminkey,
|
|
46
|
+
apikey,
|
|
47
|
+
cli,
|
|
48
|
+
debugging,
|
|
49
|
+
domain,
|
|
50
|
+
predicates,
|
|
51
|
+
workspace,
|
|
52
|
+
}
|
|
53
|
+
next()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
router.all('/api/predicates', _predicates)
|
|
57
|
+
router.all('/api/debugging', _debugging)
|
|
58
|
+
router.get('/api/details', details)
|
|
59
|
+
router.get('/api/ping', ping)
|
|
60
|
+
router.get('/api/samples', samples)
|
|
61
|
+
router.post('*', proxy)
|
|
62
|
+
|
|
63
|
+
const dashboard = fs.readFileSync(
|
|
64
|
+
`${__dirname}/../ui/build/index.html`,
|
|
65
|
+
'utf8',
|
|
66
|
+
)
|
|
67
|
+
router.get('*', (req, res) => res.send(dashboard))
|
|
68
|
+
|
|
69
|
+
// generic failsafe error handler
|
|
70
|
+
// (to avoid printing 'unhandled promise rejection' errors to the console)
|
|
71
|
+
router.use((err, req, res, next) => {
|
|
72
|
+
debug('stepzen:dashboard')('router error', err)
|
|
73
|
+
|
|
74
|
+
err.statusCode = err.statusCode || 500
|
|
75
|
+
err.status = err.status || 'error'
|
|
76
|
+
|
|
77
|
+
res.status(err.statusCode).json({
|
|
78
|
+
status: err.status,
|
|
79
|
+
message: err.message,
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
app.use(router)
|
|
84
|
+
|
|
85
|
+
const open = () =>
|
|
86
|
+
openBrowser(`http://localhost:${port}/${workspace.endpoint}`)
|
|
87
|
+
|
|
88
|
+
const start = async () =>
|
|
89
|
+
new Promise(resolve => {
|
|
90
|
+
let server = app.listen(port, () => {
|
|
91
|
+
resolve(server)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
app,
|
|
97
|
+
open,
|
|
98
|
+
start,
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
2
|
+
// Original code from https://github.com/facebook/create-react-app/blob/0f6fc2bc71d78f0dcae67f3f08ce98a42fc0a57c/packages/react-dev-utils/openChrome.applescript
|
|
3
|
+
|
|
4
|
+
const chalk = require('chalk')
|
|
5
|
+
const {execSync} = require('child_process')
|
|
6
|
+
const open = require('open')
|
|
7
|
+
const spawn = require('cross-spawn')
|
|
8
|
+
|
|
9
|
+
// https://github.com/sindresorhus/open#app
|
|
10
|
+
const OSX_CHROME = 'google chrome'
|
|
11
|
+
|
|
12
|
+
const Actions = Object.freeze({
|
|
13
|
+
NONE: 0,
|
|
14
|
+
BROWSER: 1,
|
|
15
|
+
SCRIPT: 2,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
function getBrowserEnv() {
|
|
19
|
+
// Attempt to honor this environment variable.
|
|
20
|
+
// It is specific to the operating system.
|
|
21
|
+
// See https://github.com/sindresorhus/open#app for documentation.
|
|
22
|
+
const value = process.env.BROWSER
|
|
23
|
+
const args = process.env.BROWSER_ARGS
|
|
24
|
+
? process.env.BROWSER_ARGS.split(' ')
|
|
25
|
+
: []
|
|
26
|
+
let action
|
|
27
|
+
if (!value) {
|
|
28
|
+
// Default.
|
|
29
|
+
action = Actions.BROWSER
|
|
30
|
+
} else if (value.toLowerCase().endsWith('.js')) {
|
|
31
|
+
action = Actions.SCRIPT
|
|
32
|
+
} else if (value.toLowerCase() === 'none') {
|
|
33
|
+
action = Actions.NONE
|
|
34
|
+
} else {
|
|
35
|
+
action = Actions.BROWSER
|
|
36
|
+
}
|
|
37
|
+
return {action, value, args}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function executeNodeScript(scriptPath, url) {
|
|
41
|
+
const extraArgs = process.argv.slice(2)
|
|
42
|
+
const child = spawn(process.execPath, [scriptPath, ...extraArgs, url], {
|
|
43
|
+
stdio: 'inherit',
|
|
44
|
+
})
|
|
45
|
+
child.on('close', code => {
|
|
46
|
+
if (code !== 0) {
|
|
47
|
+
console.log()
|
|
48
|
+
console.log(
|
|
49
|
+
chalk.red(
|
|
50
|
+
'The script specified as BROWSER environment variable failed.',
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
console.log(chalk.cyan(scriptPath) + ' exited with code ' + code + '.')
|
|
54
|
+
console.log()
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function startBrowserProcess(browser, url, args) {
|
|
61
|
+
// If we're on OS X, the user hasn't specifically
|
|
62
|
+
// requested a different browser, we can try opening
|
|
63
|
+
// Chrome with AppleScript. This lets us reuse an
|
|
64
|
+
// existing tab when possible instead of creating a new one.
|
|
65
|
+
const shouldTryOpenChromiumWithAppleScript =
|
|
66
|
+
process.platform === 'darwin' &&
|
|
67
|
+
(typeof browser !== 'string' || browser === OSX_CHROME)
|
|
68
|
+
|
|
69
|
+
if (shouldTryOpenChromiumWithAppleScript) {
|
|
70
|
+
// Will use the first open browser found from list
|
|
71
|
+
const supportedChromiumBrowsers = [
|
|
72
|
+
'Google Chrome Canary',
|
|
73
|
+
'Google Chrome',
|
|
74
|
+
'Microsoft Edge',
|
|
75
|
+
'Brave Browser',
|
|
76
|
+
'Vivaldi',
|
|
77
|
+
'Chromium',
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
for (const chromiumBrowser of supportedChromiumBrowsers) {
|
|
81
|
+
try {
|
|
82
|
+
// Try our best to reuse existing tab
|
|
83
|
+
// on OSX Chromium-based browser with AppleScript
|
|
84
|
+
execSync('ps cax | grep "' + chromiumBrowser + '"')
|
|
85
|
+
execSync(
|
|
86
|
+
`osascript ${__dirname}/open-chrome.applescript "` +
|
|
87
|
+
encodeURI(url) +
|
|
88
|
+
'" "' +
|
|
89
|
+
chromiumBrowser +
|
|
90
|
+
'"',
|
|
91
|
+
{
|
|
92
|
+
cwd: __dirname,
|
|
93
|
+
stdio: 'ignore',
|
|
94
|
+
},
|
|
95
|
+
)
|
|
96
|
+
return true
|
|
97
|
+
} catch (error) {
|
|
98
|
+
// Ignore errors.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Another special case: on OS X, check if BROWSER has been set to "open".
|
|
104
|
+
// In this case, instead of passing `open` to `opn` (which won't work),
|
|
105
|
+
// just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
|
|
106
|
+
// https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
|
|
107
|
+
if (process.platform === 'darwin' && browser === 'open') {
|
|
108
|
+
browser = undefined
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// If there are arguments, they must be passed as array with the browser
|
|
112
|
+
if (typeof browser === 'string' && args.length > 0) {
|
|
113
|
+
browser = [browser].concat(args)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Fallback to open
|
|
117
|
+
// (It will always open new tab)
|
|
118
|
+
try {
|
|
119
|
+
const options = {app: browser, wait: false, url: true}
|
|
120
|
+
open(url, options).catch(() => null) // Prevent `unhandledRejection` error.
|
|
121
|
+
return true
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return false
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Reads the BROWSER environment variable and decides what to do with it. Returns
|
|
128
|
+
// true if it opened a browser or ran a node.js script, otherwise false.
|
|
129
|
+
function openBrowser(url) {
|
|
130
|
+
const {action, value, args} = getBrowserEnv()
|
|
131
|
+
switch (action) {
|
|
132
|
+
case Actions.NONE:
|
|
133
|
+
// Special case: BROWSER="none" will prevent opening completely.
|
|
134
|
+
return false
|
|
135
|
+
case Actions.SCRIPT:
|
|
136
|
+
return executeNodeScript(value, url)
|
|
137
|
+
case Actions.BROWSER:
|
|
138
|
+
return startBrowserProcess(value, url, args)
|
|
139
|
+
default:
|
|
140
|
+
throw new Error('Not implemented.')
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = openBrowser
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
(*
|
|
2
|
+
Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
|
|
4
|
+
Original code from https://github.com/facebook/create-react-app/blob/0f6fc2bc71d78f0dcae67f3f08ce98a42fc0a57c/packages/react-dev-utils/openChrome.applescript
|
|
5
|
+
*)
|
|
6
|
+
|
|
7
|
+
property targetTab: null
|
|
8
|
+
property targetTabIndex: -1
|
|
9
|
+
property targetWindow: null
|
|
10
|
+
property theProgram: "Google Chrome"
|
|
11
|
+
|
|
12
|
+
on run argv
|
|
13
|
+
set theURL to item 1 of argv
|
|
14
|
+
|
|
15
|
+
-- Allow requested program to be optional,
|
|
16
|
+
-- default to Google Chrome
|
|
17
|
+
if (count of argv) > 1 then
|
|
18
|
+
set theProgram to item 2 of argv
|
|
19
|
+
end if
|
|
20
|
+
|
|
21
|
+
using terms from application "Google Chrome"
|
|
22
|
+
tell application theProgram
|
|
23
|
+
|
|
24
|
+
if (count every window) = 0 then
|
|
25
|
+
make new window
|
|
26
|
+
end if
|
|
27
|
+
|
|
28
|
+
-- 1: Looking for tab running debugger
|
|
29
|
+
-- then, Reload debugging tab if found
|
|
30
|
+
-- then return
|
|
31
|
+
set found to my lookupTabWithUrl(theURL)
|
|
32
|
+
if found then
|
|
33
|
+
set targetWindow's active tab index to targetTabIndex
|
|
34
|
+
tell targetTab to reload
|
|
35
|
+
tell targetWindow to activate
|
|
36
|
+
set index of targetWindow to 1
|
|
37
|
+
return
|
|
38
|
+
end if
|
|
39
|
+
|
|
40
|
+
-- 2: Looking for Empty tab
|
|
41
|
+
-- In case debugging tab was not found
|
|
42
|
+
-- We try to find an empty tab instead
|
|
43
|
+
set found to my lookupTabWithUrl("chrome://newtab/")
|
|
44
|
+
if found then
|
|
45
|
+
set targetWindow's active tab index to targetTabIndex
|
|
46
|
+
set URL of targetTab to theURL
|
|
47
|
+
tell targetWindow to activate
|
|
48
|
+
return
|
|
49
|
+
end if
|
|
50
|
+
|
|
51
|
+
-- 3: Create new tab
|
|
52
|
+
-- both debugging and empty tab were not found
|
|
53
|
+
-- make a new tab with url
|
|
54
|
+
tell window 1
|
|
55
|
+
activate
|
|
56
|
+
make new tab with properties {URL:theURL}
|
|
57
|
+
end tell
|
|
58
|
+
end tell
|
|
59
|
+
end using terms from
|
|
60
|
+
end run
|
|
61
|
+
|
|
62
|
+
-- Function:
|
|
63
|
+
-- Lookup tab with given url
|
|
64
|
+
-- if found, store tab, index, and window in properties
|
|
65
|
+
-- (properties were declared on top of file)
|
|
66
|
+
on lookupTabWithUrl(lookupUrl)
|
|
67
|
+
using terms from application "Google Chrome"
|
|
68
|
+
tell application theProgram
|
|
69
|
+
-- Find a tab with the given url
|
|
70
|
+
set found to false
|
|
71
|
+
set theTabIndex to -1
|
|
72
|
+
repeat with theWindow in every window
|
|
73
|
+
set theTabIndex to 0
|
|
74
|
+
repeat with theTab in every tab of theWindow
|
|
75
|
+
set theTabIndex to theTabIndex + 1
|
|
76
|
+
if (theTab's URL as string) contains lookupUrl then
|
|
77
|
+
-- assign tab, tab index, and window to properties
|
|
78
|
+
set targetTab to theTab
|
|
79
|
+
set targetTabIndex to theTabIndex
|
|
80
|
+
set targetWindow to theWindow
|
|
81
|
+
set found to true
|
|
82
|
+
exit repeat
|
|
83
|
+
end if
|
|
84
|
+
end repeat
|
|
85
|
+
|
|
86
|
+
if found then
|
|
87
|
+
exit repeat
|
|
88
|
+
end if
|
|
89
|
+
end repeat
|
|
90
|
+
end tell
|
|
91
|
+
end using terms from
|
|
92
|
+
return found
|
|
93
|
+
end lookupTabWithUrl
|
package/src/ui/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Getting Started with Create React App
|
|
2
|
+
|
|
3
|
+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
|
4
|
+
|
|
5
|
+
## Available Scripts
|
|
6
|
+
|
|
7
|
+
In the project directory, you can run:
|
|
8
|
+
|
|
9
|
+
### `npm start`
|
|
10
|
+
|
|
11
|
+
Runs the app in the development mode.\
|
|
12
|
+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
|
13
|
+
|
|
14
|
+
The page will reload if you make edits.\
|
|
15
|
+
You will also see any lint errors in the console.
|
|
16
|
+
|
|
17
|
+
Note: `npm start` runs two sub-commands simultaneously, `npm run dev:ui` and `npm run dev:server`. If you wish to run these processes separately, you can also run these command separately.
|
|
18
|
+
|
|
19
|
+
### `npm test`
|
|
20
|
+
|
|
21
|
+
Launches the test runner in the interactive watch mode.\
|
|
22
|
+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
|
23
|
+
|
|
24
|
+
### `npm run build`
|
|
25
|
+
|
|
26
|
+
Builds the app for production to the `build` folder.\
|
|
27
|
+
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
28
|
+
|
|
29
|
+
The build is minified and the filenames include the hashes.\
|
|
30
|
+
Your app is ready to be deployed!
|
|
31
|
+
|
|
32
|
+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
|
33
|
+
|
|
34
|
+
### `npm run eject`
|
|
35
|
+
|
|
36
|
+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
|
37
|
+
|
|
38
|
+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
|
39
|
+
|
|
40
|
+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
|
41
|
+
|
|
42
|
+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
|
43
|
+
|
|
44
|
+
## Learn More
|
|
45
|
+
|
|
46
|
+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
|
47
|
+
|
|
48
|
+
To learn React, check out the [React documentation](https://reactjs.org/).
|
|
49
|
+
|
|
50
|
+
### Code Splitting
|
|
51
|
+
|
|
52
|
+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
|
53
|
+
|
|
54
|
+
### Analyzing the Bundle Size
|
|
55
|
+
|
|
56
|
+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
|
57
|
+
|
|
58
|
+
### Making a Progressive Web App
|
|
59
|
+
|
|
60
|
+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
|
61
|
+
|
|
62
|
+
### Advanced Configuration
|
|
63
|
+
|
|
64
|
+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
|
65
|
+
|
|
66
|
+
### Deployment
|
|
67
|
+
|
|
68
|
+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
|
69
|
+
|
|
70
|
+
### `npm run build` fails to minify
|
|
71
|
+
|
|
72
|
+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|