mirror of
https://github.com/Mastermindzh/react-starter-kit.git
synced 2025-08-02 15:45:12 +02:00
Added the possibility to override partial configs during deployments
Added default output to jest (for terminal output...) Upgraded npm packages. Left jest on 27 because of breaking changes in 28
This commit is contained in:
4
src/config/RunTimeConfig.ts
Normal file
4
src/config/RunTimeConfig.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface RunTimeConfig {
|
||||
version: number;
|
||||
name: string;
|
||||
}
|
15
src/config/config.ts
Normal file
15
src/config/config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import deepmerge from "deepmerge";
|
||||
|
||||
/**
|
||||
* gets and merges both the regular config and the override config from the window
|
||||
* into window.mergedConfig
|
||||
*/
|
||||
export const mergeConfigs = () => {
|
||||
if (!window.mergedConfig) {
|
||||
window.mergedConfig = deepmerge(window.defaultConfig, window.configOverride ?? {});
|
||||
}
|
||||
};
|
||||
|
||||
mergeConfigs();
|
||||
|
||||
export const Config = window.mergedConfig;
|
1
src/config/index.ts
Normal file
1
src/config/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./config";
|
@@ -1,5 +0,0 @@
|
||||
type RunTimeConfig = {
|
||||
version: number;
|
||||
};
|
||||
|
||||
export const Config = (window as any).config as RunTimeConfig;
|
@@ -2,7 +2,7 @@ import { DateTime } from "luxon";
|
||||
import { FunctionComponent } from "react";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Config } from "../config";
|
||||
import { Config } from "../../config";
|
||||
import "./Navbar.css";
|
||||
type Props = {};
|
||||
|
||||
@@ -13,7 +13,7 @@ export const Navbar: FunctionComponent<Props> = () => {
|
||||
<h1>{translate("navBar.intro")}</h1>
|
||||
<p>
|
||||
{/* trans can also be used to translate */}
|
||||
<Trans i18nKey="navBar.version">App version:</Trans>
|
||||
{Config.name} <Trans i18nKey="navBar.version">version:</Trans>
|
||||
{JSON.stringify(Config.version)}
|
||||
</p>
|
||||
|
||||
|
36
src/react-app-env.d.ts
vendored
36
src/react-app-env.d.ts
vendored
@@ -4,68 +4,68 @@
|
||||
|
||||
declare namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
readonly NODE_ENV: 'development' | 'production' | 'test';
|
||||
readonly NODE_ENV: "development" | "production" | "test";
|
||||
readonly PUBLIC_URL: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare module '*.avif' {
|
||||
declare module "*.avif" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.bmp' {
|
||||
declare module "*.bmp" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.gif' {
|
||||
declare module "*.gif" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.jpg' {
|
||||
declare module "*.jpg" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.jpeg' {
|
||||
declare module "*.jpeg" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.png' {
|
||||
declare module "*.png" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.webp' {
|
||||
const src: string;
|
||||
export default src;
|
||||
declare module "*.webp" {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.svg' {
|
||||
import * as React from 'react';
|
||||
declare module "*.svg" {
|
||||
import * as React from "react";
|
||||
|
||||
export const ReactComponent: React.FunctionComponent<React.SVGProps<
|
||||
SVGSVGElement
|
||||
> & { title?: string }>;
|
||||
export const ReactComponent: React.FunctionComponent<
|
||||
React.SVGProps<SVGSVGElement> & { title?: string }
|
||||
>;
|
||||
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.module.css' {
|
||||
declare module "*.module.css" {
|
||||
const classes: { readonly [key: string]: string };
|
||||
export default classes;
|
||||
}
|
||||
|
||||
declare module '*.module.scss' {
|
||||
declare module "*.module.scss" {
|
||||
const classes: { readonly [key: string]: string };
|
||||
export default classes;
|
||||
}
|
||||
|
||||
declare module '*.module.sass' {
|
||||
declare module "*.module.sass" {
|
||||
const classes: { readonly [key: string]: string };
|
||||
export default classes;
|
||||
}
|
||||
|
@@ -4,4 +4,5 @@
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
(window as any).config = require("./../public/config");
|
||||
window.defaultConfig = require("./../public/config");
|
||||
window.configOverride = require("./../public/configOverride");
|
||||
|
11
src/types/globals.d.ts
vendored
Normal file
11
src/types/globals.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { RunTimeConfig } from "./../config/RunTimeConfig";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
mergedConfig: RunTimeConfig;
|
||||
defaultConfig: RunTimeConfig;
|
||||
configOverride: Partial<RunTimeConfig>;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
Reference in New Issue
Block a user