Skip to content

Commit a5d5ce6

Browse files
authoredAug 10, 2023
dev: dynamic app name and icon (#8)
* feat: added dynamic pws name and icon * feat: added env badge
1 parent 3cc45d6 commit a5d5ce6

9 files changed

+39
-4
lines changed
 
23.5 KB
Loading
24.6 KB
Loading
25.1 KB
Loading
97.7 KB
Loading
103 KB
Loading
104 KB
Loading

‎src/components/Header/Header.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { createStyles, Group, Image, Stack, Tabs, Text } from "@mantine/core";
1+
import {
2+
Badge,
3+
createStyles,
4+
Group,
5+
Image,
6+
Stack,
7+
Tabs,
8+
Text,
9+
} from "@mantine/core";
210
import { useLocation, useNavigate } from "react-router-dom";
311

412
import { ROUTES } from "../../constants";
@@ -12,6 +20,14 @@ const tabs = [
1220
ROUTES.OTHER_TOOLS,
1321
];
1422

23+
const isProd = ENVIRONMENT === "production";
24+
25+
const BADGE_COLOR_MAP = {
26+
local: "pink",
27+
dev: "orange",
28+
stage: "cyan",
29+
};
30+
1531
const useStyles = createStyles((theme) => ({
1632
header: {
1733
paddingTop: theme.spacing.sm,
@@ -52,6 +68,11 @@ export default function Header() {
5268
<Text size="xl" weight={700}>
5369
RMG Utils for Stellaris
5470
</Text>
71+
{!isProd && (
72+
<Badge color={BADGE_COLOR_MAP[ENVIRONMENT]} variant="outline">
73+
{ENVIRONMENT}
74+
</Badge>
75+
)}
5576
</Group>
5677
<ColorSchemeTogle />
5778
</Group>

‎src/vite-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="vite/client" />
22
declare const APP_VERSION: string;
3+
declare const ENVIRONMENT: "local" | "dev" | "stage" | "production";
34

45
interface ImportMetaEnv {
56
readonly VITE_NETLIFY_FUNCTIONS_LOCAL_SERVER: string;

‎vite.config.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,38 @@ import { defineConfig } from "vite";
22
import react from "@vitejs/plugin-react";
33
import { VitePWA } from "vite-plugin-pwa";
44

5+
const env =
6+
process.env.NODE_ENV === "development" ? "local" : process.env.NODE_ENV;
7+
8+
const PWA_TITLE_MAP = {
9+
local: "RMG Utils (local)",
10+
production: "RMG Utilities for Stellaris",
11+
stage: "RMG Utils (stage)",
12+
dev: "RMG Utils (dev)",
13+
};
14+
15+
const PWA_ICONS_TYPE = env === "production" ? "" : "_" + env;
16+
517
// https://vitejs.dev/config/
618
export default defineConfig({
719
plugins: [
820
react(),
921
VitePWA({
1022
registerType: "autoUpdate",
1123
manifest: {
12-
name: "RMG Utilities for Stellaris",
24+
name: PWA_TITLE_MAP[env],
1325
short_name: "RMG Utils",
1426
description:
1527
"RMG Utils is an application that RMG is using to expediate some parts of the mod-making process.",
1628
theme_color: "#25262b",
1729
icons: [
1830
{
19-
src: "/assets/images/rmg_logo_192.png",
31+
src: `/assets/images/rmg_logo_192${PWA_ICONS_TYPE}.png`,
2032
sizes: "192x192",
2133
type: "image/png",
2234
},
2335
{
24-
src: "/assets/images/rmg_logo_512.png",
36+
src: `/assets/images/rmg_logo_512${PWA_ICONS_TYPE}.png`,
2537
sizes: "512x512",
2638
type: "image/png",
2739
},
@@ -46,5 +58,6 @@ export default defineConfig({
4658
],
4759
define: {
4860
APP_VERSION: JSON.stringify(process.env.npm_package_version),
61+
ENVIRONMENT: JSON.stringify(env),
4962
},
5063
});

0 commit comments

Comments
 (0)
Please sign in to comment.