Skip to content

Commit 7512876

Browse files
committed
build: use vite env variables
1 parent 78a6ccf commit 7512876

File tree

19 files changed

+96
-74
lines changed

19 files changed

+96
-74
lines changed

.env.example

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
REACT_APP_VERSION=$npm_package_version
2-
REACT_APP_NAME=$npm_package_name
1+
# Url of the Zou server
2+
VITE_ZOU_API=
33

4-
REACT_APP_ZOU_API=
5-
REACT_APP_WS_SERVER=
4+
# Url of the silex websocket server
5+
VITE_WS_SERVER=http://localhost:5118
66

7-
REACT_APP_TRACTOR_URL=
8-
REACT_APP_TRACTOR_BLADE=
9-
REACT_APP_TRACTOR_LOG_URL=
7+
# Url of the tractor interface
8+
VITE_TRACTOR_URL=
109

11-
REACT_APP_TICKET_URL=
10+
# Url of the Tractor blade api
11+
VITE_TRACTOR_BLADE=
1212

13-
REACT_APP_HARVEST_URL=
13+
# Url for Tractor logs retrieval
14+
VITE_TRACTOR_LOG_URL=
15+
16+
# Url of your ticket system
17+
VITE_TICKET_URL=
18+
19+
# Url of Harvest
20+
VITE_HARVEST_URL=

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ yarn-error.log*
2525
.env
2626

2727
*.tsbuildinfo
28+
dist

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
5+
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
88
<title>Silex</title>

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"@emotion/styled": "^11.3.0",
1212
"@mui/icons-material": "^5.8.3",
1313
"@mui/material": "^5.2.1",
14-
"axios": "^1.3.5",
14+
"axios": "^1.3.6",
1515
"color-hash": "^2.0.1",
1616
"deepmerge": "^4.2.2",
17-
"graphql": "^15.6.0",
17+
"graphql": "^16.6.0",
1818
"is-electron": "^2.2.0",
1919
"notistack": "^3.0.1",
2020
"react": "^18.2.0",
@@ -53,7 +53,7 @@
5353
"@commitlint/cli": "^17.6.1",
5454
"@commitlint/config-conventional": "^17.6.1",
5555
"@types/color-hash": "^1.0.1",
56-
"@types/node": "^18.15.11",
56+
"@types/node": "^18.15.12",
5757
"@types/react": "^18.0.37",
5858
"@types/react-dom": "^18.0.11",
5959
"@types/react-router-dom": "^5.1.9",

src/components/pages/DCCClientsPage/DCCClientsPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const DCCClientsPage = (): JSX.Element => {
2020
<Alert severity="error">
2121
<AlertTitle>Connection error</AlertTitle>
2222
Can{"'"}t connect to the Silex WS server at{" "}
23-
{process.env.REACT_APP_WS_SERVER}{" "}
23+
{import.meta.env.VITE_WS_SERVER}{" "}
2424
<strong>make sure it{"'"}s running or restart it</strong>
2525
</Alert>
2626
);

src/components/pages/HarvestPage/HarvestPage.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ const HarvestPage = (): JSX.Element => {
44
title="Harvest"
55
width="100%"
66
height="100%"
7-
src={process.env.REACT_APP_HARVEST_URL}
8-
frameBorder="0"
9-
style={{ height: "100vh" }}
7+
src={import.meta.env.VITE_HARVEST_URL}
8+
style={{ height: "100vh", border: "0px" }}
109
></iframe>
1110
);
1211
};

src/components/pages/LoginPage/LoginPage.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ const LoginPage = (): JSX.Element => {
8181
);
8282
} else {
8383
setError(
84-
`Zou server at ${process.env.REACT_APP_ZOU_API} is not reachable, check your internet connection or retry later`
84+
`Zou server at ${
85+
import.meta.env.VITE_ZOU_API
86+
} is not reachable, check your internet connection or retry later`
8587
);
8688
}
8789
});

src/components/pages/LogsPage/LogsPage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const LogFile = ({ fileName, title }: LogFileProps) => {
2626
const fetchLogs = useCallback(() => {
2727
axios
2828
.get<{ totalLines: number; lines: string[] }>(
29-
`${process.env.REACT_APP_WS_SERVER}/log/${fileName}?fromEnd=${lines}`
29+
`${import.meta.env.VITE_WS_SERVER}/log/${fileName}?fromEnd=${lines}`
3030
)
3131
.then((response) => {
3232
setLogs({
@@ -44,7 +44,7 @@ const LogFile = ({ fileName, title }: LogFileProps) => {
4444

4545
const handleClearLog = () => {
4646
axios
47-
.delete(`${process.env.REACT_APP_WS_SERVER}/log/${fileName}`)
47+
.delete(`${import.meta.env.VITE_WS_SERVER}/log/${fileName}`)
4848
.then(() => {
4949
enqueueSnackbar(`Cleared logfile ${fileName}`, { variant: "success" });
5050
fetchLogs();

src/components/pages/RunningJobsPage/ProcessRow.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const ProcessRow = ({ p }: { p: RunningJob }): JSX.Element => {
1515

1616
useEffect(() => {
1717
const fetchLogs = () => {
18-
const logsURL = `${process.env.REACT_APP_TRACTOR_LOG_URL}/${p.login}/J${p.jid}/T${p.tid}.log`;
18+
const logsURL = `${import.meta.env.VITE_TRACTOR_LOG_URL}/${p.login}/J${
19+
p.jid
20+
}/T${p.tid}.log`;
1921
axios
2022
.get<string>(logsURL)
2123
.then((response) =>

src/components/pages/TicketPage/TicketPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const TicketPage = (): JSX.Element => {
44
return (
55
<PageWrapper title="Ticket" goBack fullHeight>
66
<webview
7-
src={process.env.REACT_APP_TICKET_URL}
7+
src={import.meta.env.VITE_TICKET_URL}
88
style={{ width: "100%", height: "100%" }}
99
></webview>
1010
</PageWrapper>

src/components/pages/TractorPage/TractorPage.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ const TractorPage = (): JSX.Element => {
44
title="Tractor"
55
width="100%"
66
height="100%"
7-
src={process.env.REACT_APP_TRACTOR_URL}
8-
frameBorder="0"
9-
style={{ height: "100vh" }}
7+
src={import.meta.env.VITE_TRACTOR_URL}
8+
style={{ height: "100vh", border: "0px" }}
109
></iframe>
1110
);
1211
};

src/components/structure/Menu/Menu.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ const links = [
3737
to: "/tractor",
3838
exact: true,
3939
openInNewWindow: true,
40-
openTo: process.env.REACT_APP_TRACTOR_URL,
40+
openTo: import.meta.env.VITE_TRACTOR_URL,
4141
},
4242
{
4343
text: "👨‍🌾 Harvest",
4444
to: "/harvest",
4545
exact: true,
4646
openInNewWindow: true,
47-
openTo: process.env.REACT_APP_HARVEST_URL,
47+
openTo: import.meta.env.VITE_HARVEST_URL,
4848
},
4949
{
5050
text: "Ticket",
5151
to: "/ticket",
5252
exact: true,
5353
openInNewWindow: true,
54-
openTo: process.env.REACT_APP_TICKET_URL,
54+
openTo: import.meta.env.VITE_TICKET_URL,
5555
},
5656
];
5757

@@ -170,7 +170,7 @@ const Menu = ({ closeMenu, open }: MenuProps): JSX.Element => {
170170
}}
171171
>
172172
<Typography sx={{ color: "rgba(150, 149, 149, 0.5)" }} fontSize={12}>
173-
{process.env.REACT_APP_NAME} v{process.env.REACT_APP_VERSION}
173+
{import.meta.env.VITE_APP_NAME} v{import.meta.env.VITE_APP_VERSION}
174174
</Typography>
175175

176176
<div style={{ marginLeft: "10px" }}>

src/context/GraphQLClientContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const ProvideGraphQLClient = ({
2626
}: ProvideGraphQLClientProps): JSX.Element => {
2727
const [client] = useState(
2828
new ApolloClient({
29-
uri: process.env.REACT_APP_ZOU_API + "/api/graphql",
29+
uri: import.meta.env.VITE_ZOU_API + "/api/graphql",
3030
cache: new InMemoryCache(),
3131
})
3232
);

src/context/SocketContext.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface ProvideSocketProps {
3030

3131
// Initialize a global socket instance
3232
export const uiSocket: UINamespaceSocket = io(
33-
`${process.env.REACT_APP_WS_SERVER}/ui`,
33+
`${import.meta.env.VITE_WS_SERVER}/ui`,
3434
{ reconnectionDelay: 2000 }
3535
);
3636

@@ -61,7 +61,7 @@ export const ProvideSocket = ({
6161
});
6262

6363
enqueueSnackbar(
64-
`Connected to ${process.env.REACT_APP_WS_SERVER} (${response.msg})`,
64+
`Connected to ${import.meta.env.VITE_WS_SERVER} (${response.msg})`,
6565
{
6666
variant: "success",
6767
}
@@ -77,7 +77,7 @@ export const ProvideSocket = ({
7777
setDCCClients([]);
7878

7979
enqueueSnackbar(
80-
`WS server ${process.env.REACT_APP_WS_SERVER} disconnected`,
80+
`WS server ${import.meta.env.VITE_WS_SERVER} disconnected`,
8181
{
8282
variant: "error",
8383
}

src/env.d.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
readonly VITE_APP_NAME: string;
5+
readonly VITE_APP_VERSION: string;
6+
7+
/** Url of the Zou server */
8+
readonly VITE_ZOU_API: string;
9+
10+
/** Url of the silex websocket server */
11+
readonly VITE_WS_SERVER: string;
12+
13+
/** Url of the Tractor blade api */
14+
readonly VITE_TRACTOR_BLADE: string;
15+
16+
/** Url of the tractor TV */
17+
readonly VITE_TRACTOR_URL: string;
18+
19+
/** Url for Tractor logs retrieval */
20+
readonly VITE_TRACTOR_LOG_URL: string;
21+
22+
/** Url of your ticket system */
23+
readonly VITE_TICKET_URL: string;
24+
25+
/** Url of Harvest */
26+
readonly VITE_HARVEST_URL: string;
27+
}
28+
29+
interface ImportMeta {
30+
readonly env: ImportMetaEnv;
31+
}

src/types/modules/nodejs.d.ts

-28
This file was deleted.

src/utils/zou.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type PromiseResponse<T> = Promise<AxiosResponse<T>>;
2222
* @param path
2323
*/
2424
export function zouURL(path: string): string {
25-
return `${process.env.REACT_APP_ZOU_API}/${path}`;
25+
return `${import.meta.env.VITE_ZOU_API}/${path}`;
2626
}
2727

2828
/**
@@ -87,7 +87,7 @@ export function isAuthenticated(): PromiseResponse<{
8787
return new Promise((resolve, reject) => {
8888
// Check if the token is on the socket server side
8989
axios
90-
.get(`${process.env.REACT_APP_WS_SERVER}/auth/token`)
90+
.get(`${import.meta.env.VITE_WS_SERVER}/auth/token`)
9191
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9292
.then((_token) => {
9393
// Check if authenticated on the zou side
@@ -131,7 +131,7 @@ export function login(data: LoginInput): LoginResponse {
131131
return new Promise((resolve, reject) => {
132132
// Login to the WS server first
133133
axios
134-
.post(`${process.env.REACT_APP_WS_SERVER}/auth/login`, data)
134+
.post(`${import.meta.env.VITE_WS_SERVER}/auth/login`, data)
135135
// eslint-disable-next-line @typescript-eslint/no-unused-vars
136136
.then((_response) => {
137137
// Login directly to Zou for cookies
@@ -149,7 +149,7 @@ export function login(data: LoginInput): LoginResponse {
149149
* @returns logout if successfull
150150
*/
151151
export function logout(): PromiseResponse<{ logout: boolean }> {
152-
axios.post(`${process.env.REACT_APP_WS_SERVER}/auth/logout`);
152+
axios.post(`${import.meta.env.VITE_WS_SERVER}/auth/logout`);
153153
return getWithCredentials("auth/logout");
154154
}
155155

vite.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ export default defineConfig({
1010
},
1111
},
1212
plugins: [react()],
13+
define: {
14+
VITE_APP_NAME: JSON.stringify(process.env.npm_package_name),
15+
VITE_APP_VERSION: JSON.stringify(process.env.npm_package_version),
16+
},
1317
});

yarn.lock

+14-9
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,16 @@
947947
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
948948
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==
949949

950-
"@types/node@*", "@types/node@^18.15.11":
950+
"@types/node@*":
951951
version "18.15.11"
952952
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f"
953953
integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==
954954

955+
"@types/node@^18.15.12":
956+
version "18.15.12"
957+
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.12.tgz#833756634e78c829e1254db006468dadbb0c696b"
958+
integrity sha512-Wha1UwsB3CYdqUm2PPzh/1gujGCNtWVUYF0mB00fJFoR4gTyWTDPjSm+zBF787Ahw8vSGgBja90MkgFwvB86Dg==
959+
955960
"@types/normalize-package-data@^2.4.0":
956961
version "2.4.1"
957962
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
@@ -1332,10 +1337,10 @@ available-typed-arrays@^1.0.5:
13321337
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
13331338
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
13341339

1335-
axios@^1.3.5:
1336-
version "1.3.5"
1337-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.5.tgz#e07209b39a0d11848e3e341fa087acd71dadc542"
1338-
integrity sha512-glL/PvG/E+xCWwV8S6nCHcrfg1exGx7vxyUIivIA1iL7BIh6bePylCfVHwp6k13ao7SATxB6imau2kqY+I67kw==
1340+
axios@^1.3.6:
1341+
version "1.3.6"
1342+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.6.tgz#1ace9a9fb994314b5f6327960918406fa92c6646"
1343+
integrity sha512-PEcdkk7JcdPiMDkvM4K6ZBRYq9keuVJsToxm2zQIM70Qqo2WHTdJZMXcG9X+RmRp2VPNUQC8W1RAGbgt6b1yMg==
13391344
dependencies:
13401345
follow-redirects "^1.15.0"
13411346
form-data "^4.0.0"
@@ -2463,10 +2468,10 @@ graphql-tag@^2.12.6:
24632468
dependencies:
24642469
tslib "^2.1.0"
24652470

2466-
graphql@^15.6.0:
2467-
version "15.8.0"
2468-
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.8.0.tgz#33410e96b012fa3bdb1091cc99a94769db212b38"
2469-
integrity sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==
2471+
graphql@^16.6.0:
2472+
version "16.6.0"
2473+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb"
2474+
integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw==
24702475

24712476
hard-rejection@^2.1.0:
24722477
version "2.1.0"

0 commit comments

Comments
 (0)