@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.
Files changed (99) hide show
  1. package/.postcssrc +5 -0
  2. package/CHANGELOG.md +81 -0
  3. package/LICENSE +21 -0
  4. package/dist/__tests__/measure.test.d.ts +1 -0
  5. package/dist/__tests__/measure.test.js +152 -0
  6. package/dist/__tests__/measure.test.js.map +1 -0
  7. package/dist/__tests__/server/ServerApp.test.d.ts +1 -0
  8. package/dist/__tests__/server/ServerApp.test.js +49 -0
  9. package/dist/__tests__/server/ServerApp.test.js.map +1 -0
  10. package/dist/__tests__/utils/removeCLIColors.d.ts +1 -0
  11. package/dist/__tests__/utils/removeCLIColors.js +10 -0
  12. package/dist/__tests__/utils/removeCLIColors.js.map +1 -0
  13. package/dist/__tests__/webapp/socket.test.d.ts +1 -0
  14. package/dist/__tests__/webapp/socket.test.js +73 -0
  15. package/dist/__tests__/webapp/socket.test.js.map +1 -0
  16. package/dist/common/useLogSocketEvents.d.ts +3 -0
  17. package/dist/common/useLogSocketEvents.js +18 -0
  18. package/dist/common/useLogSocketEvents.js.map +1 -0
  19. package/dist/index.87c99d25.js +88 -0
  20. package/dist/index.87c99d25.js.map +1 -0
  21. package/dist/index.html +1 -0
  22. package/dist/server/ServerApp.d.ts +10 -0
  23. package/dist/server/ServerApp.js +131 -0
  24. package/dist/server/ServerApp.js.map +1 -0
  25. package/dist/server/ServerSocketConnectionApp.d.ts +6 -0
  26. package/dist/server/ServerSocketConnectionApp.js +105 -0
  27. package/dist/server/ServerSocketConnectionApp.js.map +1 -0
  28. package/dist/server/bin.d.ts +2 -0
  29. package/dist/server/bin.js +63 -0
  30. package/dist/server/bin.js.map +1 -0
  31. package/dist/server/components/HostAndPortInfo.d.ts +4 -0
  32. package/dist/server/components/HostAndPortInfo.js +14 -0
  33. package/dist/server/components/HostAndPortInfo.js.map +1 -0
  34. package/dist/server/constants.d.ts +2 -0
  35. package/dist/server/constants.js +12 -0
  36. package/dist/server/constants.js.map +1 -0
  37. package/dist/server/socket/socketInterface.d.ts +37 -0
  38. package/dist/server/socket/socketInterface.js +17 -0
  39. package/dist/server/socket/socketInterface.js.map +1 -0
  40. package/dist/server/socket/socketState.d.ts +5 -0
  41. package/dist/server/socket/socketState.js +47 -0
  42. package/dist/server/socket/socketState.js.map +1 -0
  43. package/dist/server/useBundleIdControls.d.ts +2 -0
  44. package/dist/server/useBundleIdControls.js +33 -0
  45. package/dist/server/useBundleIdControls.js.map +1 -0
  46. package/dist/webapp/MeasureWebApp.d.ts +2 -0
  47. package/dist/webapp/MeasureWebApp.js +29 -0
  48. package/dist/webapp/MeasureWebApp.js.map +1 -0
  49. package/dist/webapp/components/AppBar.d.ts +4 -0
  50. package/dist/webapp/components/AppBar.js +19 -0
  51. package/dist/webapp/components/AppBar.js.map +1 -0
  52. package/dist/webapp/components/BundleIdSelector.d.ts +6 -0
  53. package/dist/webapp/components/BundleIdSelector.js +20 -0
  54. package/dist/webapp/components/BundleIdSelector.js.map +1 -0
  55. package/dist/webapp/components/SocketState.d.ts +2 -0
  56. package/dist/webapp/components/SocketState.js +95 -0
  57. package/dist/webapp/components/SocketState.js.map +1 -0
  58. package/dist/webapp/components/StartButton.d.ts +6 -0
  59. package/dist/webapp/components/StartButton.js +12 -0
  60. package/dist/webapp/components/StartButton.js.map +1 -0
  61. package/dist/webapp/components/TextField.d.ts +5 -0
  62. package/dist/webapp/components/TextField.js +81 -0
  63. package/dist/webapp/components/TextField.js.map +1 -0
  64. package/dist/webapp/socket.d.ts +3 -0
  65. package/dist/webapp/socket.js +8 -0
  66. package/dist/webapp/socket.js.map +1 -0
  67. package/dist/webapp/useMeasures.d.ts +10 -0
  68. package/dist/webapp/useMeasures.js +38 -0
  69. package/dist/webapp/useMeasures.js.map +1 -0
  70. package/package.json +48 -0
  71. package/src/__tests__/__snapshots__/measure.test.tsx.snap +4389 -0
  72. package/src/__tests__/measure.test.tsx +141 -0
  73. package/src/__tests__/server/ServerApp.test.ts +49 -0
  74. package/src/__tests__/utils/removeCLIColors.ts +5 -0
  75. package/src/__tests__/webapp/socket.test.ts +37 -0
  76. package/src/common/types/index.d.ts +3 -0
  77. package/src/common/useLogSocketEvents.ts +17 -0
  78. package/src/server/ServerApp.tsx +103 -0
  79. package/src/server/ServerSocketConnectionApp.tsx +82 -0
  80. package/src/server/bin.tsx +23 -0
  81. package/src/server/components/HostAndPortInfo.tsx +11 -0
  82. package/src/server/constants.ts +8 -0
  83. package/src/server/socket/socketInterface.ts +53 -0
  84. package/src/server/socket/socketState.ts +66 -0
  85. package/src/server/useBundleIdControls.ts +38 -0
  86. package/src/webapp/MeasureWebApp.tsx +43 -0
  87. package/src/webapp/components/AppBar.tsx +19 -0
  88. package/src/webapp/components/BundleIdSelector.tsx +26 -0
  89. package/src/webapp/components/SocketState.tsx +79 -0
  90. package/src/webapp/components/StartButton.tsx +22 -0
  91. package/src/webapp/components/TextField.tsx +54 -0
  92. package/src/webapp/globals.d.ts +9 -0
  93. package/src/webapp/index.html +30 -0
  94. package/src/webapp/index.js +9 -0
  95. package/src/webapp/socket.ts +12 -0
  96. package/src/webapp/useMeasures.ts +36 -0
  97. package/tailwind.config.js +7 -0
  98. package/tsconfig.json +8 -0
  99. 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,9 @@
1
+ import type { FlashlightData } from "../common/types";
2
+
3
+ declare global {
4
+ interface Window {
5
+ __FLASHLIGHT_DATA__: FlashlightData;
6
+ }
7
+ }
8
+
9
+ export {};
@@ -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
+ };
@@ -0,0 +1,7 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2
+ const tailwindConfig = require("@clary-so/web-reporter-ui/tailwind.config");
3
+
4
+ module.exports = {
5
+ content: [...tailwindConfig.content, "./src/webapp/**/*.tsx"],
6
+ presets: [tailwindConfig],
7
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../../tsconfig.module.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "./dist"
6
+ },
7
+ "include": ["src"]
8
+ }