@clary-so/measure 0.4.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/.postcssrc +5 -0
- package/CHANGELOG.md +81 -0
- package/LICENSE +21 -0
- package/dist/__tests__/measure.test.d.ts +1 -0
- package/dist/__tests__/measure.test.js +152 -0
- package/dist/__tests__/measure.test.js.map +1 -0
- package/dist/__tests__/server/ServerApp.test.d.ts +1 -0
- package/dist/__tests__/server/ServerApp.test.js +49 -0
- package/dist/__tests__/server/ServerApp.test.js.map +1 -0
- package/dist/__tests__/utils/removeCLIColors.d.ts +1 -0
- package/dist/__tests__/utils/removeCLIColors.js +10 -0
- package/dist/__tests__/utils/removeCLIColors.js.map +1 -0
- package/dist/__tests__/webapp/socket.test.d.ts +1 -0
- package/dist/__tests__/webapp/socket.test.js +73 -0
- package/dist/__tests__/webapp/socket.test.js.map +1 -0
- package/dist/common/useLogSocketEvents.d.ts +3 -0
- package/dist/common/useLogSocketEvents.js +18 -0
- package/dist/common/useLogSocketEvents.js.map +1 -0
- package/dist/index.87c99d25.js +88 -0
- package/dist/index.87c99d25.js.map +1 -0
- package/dist/index.html +1 -0
- package/dist/server/ServerApp.d.ts +10 -0
- package/dist/server/ServerApp.js +131 -0
- package/dist/server/ServerApp.js.map +1 -0
- package/dist/server/ServerSocketConnectionApp.d.ts +6 -0
- package/dist/server/ServerSocketConnectionApp.js +105 -0
- package/dist/server/ServerSocketConnectionApp.js.map +1 -0
- package/dist/server/bin.d.ts +2 -0
- package/dist/server/bin.js +63 -0
- package/dist/server/bin.js.map +1 -0
- package/dist/server/components/HostAndPortInfo.d.ts +4 -0
- package/dist/server/components/HostAndPortInfo.js +14 -0
- package/dist/server/components/HostAndPortInfo.js.map +1 -0
- package/dist/server/constants.d.ts +2 -0
- package/dist/server/constants.js +12 -0
- package/dist/server/constants.js.map +1 -0
- package/dist/server/socket/socketInterface.d.ts +37 -0
- package/dist/server/socket/socketInterface.js +17 -0
- package/dist/server/socket/socketInterface.js.map +1 -0
- package/dist/server/socket/socketState.d.ts +5 -0
- package/dist/server/socket/socketState.js +47 -0
- package/dist/server/socket/socketState.js.map +1 -0
- package/dist/server/useBundleIdControls.d.ts +2 -0
- package/dist/server/useBundleIdControls.js +33 -0
- package/dist/server/useBundleIdControls.js.map +1 -0
- package/dist/webapp/MeasureWebApp.d.ts +2 -0
- package/dist/webapp/MeasureWebApp.js +29 -0
- package/dist/webapp/MeasureWebApp.js.map +1 -0
- package/dist/webapp/components/AppBar.d.ts +4 -0
- package/dist/webapp/components/AppBar.js +19 -0
- package/dist/webapp/components/AppBar.js.map +1 -0
- package/dist/webapp/components/BundleIdSelector.d.ts +6 -0
- package/dist/webapp/components/BundleIdSelector.js +20 -0
- package/dist/webapp/components/BundleIdSelector.js.map +1 -0
- package/dist/webapp/components/SocketState.d.ts +2 -0
- package/dist/webapp/components/SocketState.js +95 -0
- package/dist/webapp/components/SocketState.js.map +1 -0
- package/dist/webapp/components/StartButton.d.ts +6 -0
- package/dist/webapp/components/StartButton.js +12 -0
- package/dist/webapp/components/StartButton.js.map +1 -0
- package/dist/webapp/components/TextField.d.ts +5 -0
- package/dist/webapp/components/TextField.js +81 -0
- package/dist/webapp/components/TextField.js.map +1 -0
- package/dist/webapp/socket.d.ts +3 -0
- package/dist/webapp/socket.js +8 -0
- package/dist/webapp/socket.js.map +1 -0
- package/dist/webapp/useMeasures.d.ts +10 -0
- package/dist/webapp/useMeasures.js +38 -0
- package/dist/webapp/useMeasures.js.map +1 -0
- package/package.json +48 -0
- package/src/__tests__/__snapshots__/measure.test.tsx.snap +4389 -0
- package/src/__tests__/measure.test.tsx +141 -0
- package/src/__tests__/server/ServerApp.test.ts +49 -0
- package/src/__tests__/utils/removeCLIColors.ts +5 -0
- package/src/__tests__/webapp/socket.test.ts +37 -0
- package/src/common/types/index.d.ts +3 -0
- package/src/common/useLogSocketEvents.ts +17 -0
- package/src/server/ServerApp.tsx +103 -0
- package/src/server/ServerSocketConnectionApp.tsx +82 -0
- package/src/server/bin.tsx +23 -0
- package/src/server/components/HostAndPortInfo.tsx +11 -0
- package/src/server/constants.ts +8 -0
- package/src/server/socket/socketInterface.ts +53 -0
- package/src/server/socket/socketState.ts +66 -0
- package/src/server/useBundleIdControls.ts +38 -0
- package/src/webapp/MeasureWebApp.tsx +43 -0
- package/src/webapp/components/AppBar.tsx +19 -0
- package/src/webapp/components/BundleIdSelector.tsx +26 -0
- package/src/webapp/components/SocketState.tsx +79 -0
- package/src/webapp/components/StartButton.tsx +22 -0
- package/src/webapp/components/TextField.tsx +54 -0
- package/src/webapp/globals.d.ts +9 -0
- package/src/webapp/index.html +30 -0
- package/src/webapp/index.js +9 -0
- package/src/webapp/socket.ts +12 -0
- package/src/webapp/useMeasures.ts +36 -0
- package/tailwind.config.js +7 -0
- package/tsconfig.json +8 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import MaterialAppBar from "@mui/material/AppBar";
|
|
3
|
+
|
|
4
|
+
export const AppBar = ({ children }: { children: React.ReactNode }) => {
|
|
5
|
+
return (
|
|
6
|
+
<MaterialAppBar position="relative" className="bg-dark-charcoal">
|
|
7
|
+
<div
|
|
8
|
+
style={{
|
|
9
|
+
flexDirection: "row",
|
|
10
|
+
display: "flex",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
padding: 10,
|
|
13
|
+
}}
|
|
14
|
+
>
|
|
15
|
+
{children}
|
|
16
|
+
</div>
|
|
17
|
+
</MaterialAppBar>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { TextField } from "./TextField";
|
|
3
|
+
import { Button } from "@clary-so/web-reporter-ui";
|
|
4
|
+
|
|
5
|
+
export const BundleIdSelector = ({
|
|
6
|
+
bundleId,
|
|
7
|
+
onChange,
|
|
8
|
+
autodetect,
|
|
9
|
+
}: {
|
|
10
|
+
bundleId: string | null;
|
|
11
|
+
onChange: (bundleId: string) => void;
|
|
12
|
+
autodetect: () => void;
|
|
13
|
+
}) => {
|
|
14
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
15
|
+
onChange(event.target.value);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<Button onClick={autodetect}>Auto-Detect</Button>
|
|
21
|
+
<div style={{ paddingRight: 5, paddingLeft: 5 }}>
|
|
22
|
+
<TextField onChange={handleChange} value={bundleId || ""} />
|
|
23
|
+
</div>
|
|
24
|
+
</>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import Dialog from "@mui/material/Dialog";
|
|
3
|
+
import DialogTitle from "@mui/material/DialogTitle";
|
|
4
|
+
import DialogContent from "@mui/material/DialogContent";
|
|
5
|
+
import DialogContentText from "@mui/material/DialogContentText";
|
|
6
|
+
import DialogActions from "@mui/material/DialogActions";
|
|
7
|
+
import Button from "@mui/material/Button";
|
|
8
|
+
import { Logger } from "@clary-so/logger";
|
|
9
|
+
import { socket } from "../socket";
|
|
10
|
+
import { useLogSocketEvents } from "../../common/useLogSocketEvents";
|
|
11
|
+
import { SocketEvents } from "../../server/socket/socketInterface";
|
|
12
|
+
|
|
13
|
+
const useSocketState = (onError: (error: string) => void) => {
|
|
14
|
+
useLogSocketEvents(socket);
|
|
15
|
+
const [isConnected, setIsConnected] = useState(socket.connected);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
function onConnect() {
|
|
19
|
+
setIsConnected(true);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function onDisconnect(reason: string) {
|
|
23
|
+
setIsConnected(false);
|
|
24
|
+
|
|
25
|
+
Logger.info(`socket disconnected with reason: ${reason}`);
|
|
26
|
+
|
|
27
|
+
if (reason === "transport close" || reason === "transport error") {
|
|
28
|
+
onError("flashlight CLI command exited. Restart from the CLI.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
socket.on(SocketEvents.CONNECT, onConnect);
|
|
33
|
+
socket.on(SocketEvents.DISCONNECT, onDisconnect);
|
|
34
|
+
socket.on(SocketEvents.SEND_ERROR, onError);
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
socket.off(SocketEvents.CONNECT, onConnect);
|
|
38
|
+
socket.off(SocketEvents.DISCONNECT, onDisconnect);
|
|
39
|
+
socket.off(SocketEvents.SEND_ERROR, onError);
|
|
40
|
+
};
|
|
41
|
+
}, [onError]);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
return () => {
|
|
45
|
+
socket.close();
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
return { isConnected };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const SocketState = () => {
|
|
53
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
54
|
+
const closeModal = () => setError(null);
|
|
55
|
+
useSocketState(setError);
|
|
56
|
+
|
|
57
|
+
const isModalOpened = error !== null;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<Dialog
|
|
62
|
+
open={isModalOpened}
|
|
63
|
+
onClose={closeModal}
|
|
64
|
+
aria-labelledby="alert-dialog-title"
|
|
65
|
+
aria-describedby="alert-dialog-description"
|
|
66
|
+
>
|
|
67
|
+
<DialogTitle id="alert-dialog-title">🚨 Woups, something happened</DialogTitle>
|
|
68
|
+
<DialogContent>
|
|
69
|
+
<DialogContentText id="alert-dialog-description">{error}</DialogContentText>
|
|
70
|
+
</DialogContent>
|
|
71
|
+
<DialogActions>
|
|
72
|
+
<Button onClick={closeModal} autoFocus>
|
|
73
|
+
Close
|
|
74
|
+
</Button>
|
|
75
|
+
</DialogActions>
|
|
76
|
+
</Dialog>
|
|
77
|
+
</>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PlayArrow, Stop } from "@mui/icons-material";
|
|
2
|
+
import { Button } from "@clary-so/web-reporter-ui";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
export const StartButton = ({
|
|
6
|
+
isMeasuring,
|
|
7
|
+
start,
|
|
8
|
+
stop,
|
|
9
|
+
}: {
|
|
10
|
+
isMeasuring: boolean;
|
|
11
|
+
start: () => void;
|
|
12
|
+
stop: () => void;
|
|
13
|
+
}) =>
|
|
14
|
+
isMeasuring ? (
|
|
15
|
+
<Button onClick={stop} icon={<Stop />}>
|
|
16
|
+
Stop Measuring
|
|
17
|
+
</Button>
|
|
18
|
+
) : (
|
|
19
|
+
<Button onClick={start} icon={<PlayArrow />}>
|
|
20
|
+
Start Measuring
|
|
21
|
+
</Button>
|
|
22
|
+
);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { styled, alpha } from "@mui/material/styles";
|
|
3
|
+
import InputBase from "@mui/material/InputBase";
|
|
4
|
+
import { AndroidRounded } from "@mui/icons-material";
|
|
5
|
+
|
|
6
|
+
const Search = styled("div")(({ theme }) => ({
|
|
7
|
+
position: "relative",
|
|
8
|
+
borderRadius: theme.shape.borderRadius,
|
|
9
|
+
backgroundColor: alpha(theme.palette.common.white, 0.15),
|
|
10
|
+
"&:hover": {
|
|
11
|
+
backgroundColor: alpha(theme.palette.common.white, 0.25),
|
|
12
|
+
},
|
|
13
|
+
marginLeft: 0,
|
|
14
|
+
width: 300,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const SearchIconWrapper = styled("div")(() => ({
|
|
18
|
+
paddingLeft: 10,
|
|
19
|
+
paddingRight: 10,
|
|
20
|
+
height: "100%",
|
|
21
|
+
position: "absolute",
|
|
22
|
+
pointerEvents: "none",
|
|
23
|
+
display: "flex",
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
justifyContent: "center",
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const StyledInputBase = styled(InputBase)(({ theme }) => ({
|
|
29
|
+
color: "inherit",
|
|
30
|
+
"& .MuiInputBase-input": {
|
|
31
|
+
padding: 10,
|
|
32
|
+
// vertical padding + font size from searchIcon
|
|
33
|
+
paddingLeft: 45,
|
|
34
|
+
transition: theme.transitions.create("width"),
|
|
35
|
+
width: 300 - 45 - 10,
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export const TextField = ({
|
|
40
|
+
onChange,
|
|
41
|
+
value,
|
|
42
|
+
}: {
|
|
43
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
44
|
+
value: string;
|
|
45
|
+
}) => {
|
|
46
|
+
return (
|
|
47
|
+
<Search>
|
|
48
|
+
<SearchIconWrapper>
|
|
49
|
+
<AndroidRounded />
|
|
50
|
+
</SearchIconWrapper>
|
|
51
|
+
<StyledInputBase placeholder="Fill in your app id" onChange={onChange} value={value} />
|
|
52
|
+
</Search>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>Flashlight</title>
|
|
6
|
+
<link rel="icon" href="https://app.flashlight.dev/favicon.ico" />
|
|
7
|
+
<link rel="stylesheet" href="https://use.typekit.net/onj4oqg.css" />
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<style>
|
|
11
|
+
@import "../../../../core/web-reporter-ui/index.css";
|
|
12
|
+
|
|
13
|
+
html,
|
|
14
|
+
body,
|
|
15
|
+
#app {
|
|
16
|
+
height: 100%;
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
body {
|
|
21
|
+
@apply bg-light-charcoal;
|
|
22
|
+
}
|
|
23
|
+
</style>
|
|
24
|
+
<div id="app"></div>
|
|
25
|
+
<script type="module" src="index.js"></script>
|
|
26
|
+
<script>
|
|
27
|
+
window.__FLASHLIGHT_DATA__ = { socketServerUrl: "http://localhost:4000" };
|
|
28
|
+
</script>
|
|
29
|
+
</body>
|
|
30
|
+
</html>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
import { MeasureWebApp } from "./MeasureWebApp";
|
|
4
|
+
|
|
5
|
+
// TODO: fix eslint errors
|
|
6
|
+
// eslint-disable-next-line no-undef
|
|
7
|
+
const app = document.getElementById("app");
|
|
8
|
+
// eslint-disable-next-line react/no-deprecated
|
|
9
|
+
ReactDOM.render(<MeasureWebApp />, app);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { io, Socket } from "socket.io-client";
|
|
2
|
+
import {
|
|
3
|
+
ServerToClientEvents,
|
|
4
|
+
ClientToServerEvents,
|
|
5
|
+
SocketEvents,
|
|
6
|
+
} from "../server/socket/socketInterface";
|
|
7
|
+
|
|
8
|
+
export const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(
|
|
9
|
+
window.__FLASHLIGHT_DATA__.socketServerUrl
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
socket.on(SocketEvents.DISCONNECT, () => socket.close());
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { SocketData, SocketEvents } from "../server/socket/socketInterface";
|
|
3
|
+
import { socket } from "./socket";
|
|
4
|
+
|
|
5
|
+
export const useMeasures = () => {
|
|
6
|
+
const [state, setState] = useState<SocketData>();
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
socket.on(SocketEvents.UPDATE_STATE, setState);
|
|
10
|
+
|
|
11
|
+
return () => {
|
|
12
|
+
socket.off(SocketEvents.UPDATE_STATE, setState);
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
bundleId: state?.bundleId ?? null,
|
|
18
|
+
autodetect: () => {
|
|
19
|
+
socket.emit(SocketEvents.AUTODETECT_BUNDLE_ID);
|
|
20
|
+
},
|
|
21
|
+
setBundleId: (bundleId: string) => {
|
|
22
|
+
socket.emit(SocketEvents.SET_BUNDLE_ID, bundleId);
|
|
23
|
+
},
|
|
24
|
+
results: state?.results ?? [],
|
|
25
|
+
isMeasuring: state?.isMeasuring ?? false,
|
|
26
|
+
start: () => {
|
|
27
|
+
socket.emit(SocketEvents.START);
|
|
28
|
+
},
|
|
29
|
+
stop: () => {
|
|
30
|
+
socket.emit(SocketEvents.STOP);
|
|
31
|
+
},
|
|
32
|
+
reset: () => {
|
|
33
|
+
socket.emit(SocketEvents.RESET);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|