Skip to content

Commit

Permalink
refactor: use env.config
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidZORO committed Jan 10, 2021
1 parent 3c010f8 commit 57463bf
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `.env.local` always overrides the defaults set.
# see more https://nextjs.org/docs/basic-features/environment-variables
NEXT_PUBLIC_SITE_NAME=mkn
12 changes: 9 additions & 3 deletions src/components/FooterNav/FooterNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import cx from 'classnames';

import { pkgConfig, envConfig } from '@/configs';

import styles from './style.module.less';

interface IProps {
Expand All @@ -20,9 +22,13 @@ export const FooterNav: React.FC<IProps> = (props) => (
style={props.style}
>
© {new Date().getFullYear()}
<a href="https://github.com/SolidZORO/mkn" target="_blank" rel="noreferrer">
mkn
<a
href={`https://github.com/SolidZORO/${pkgConfig.name}`}
target="_blank"
rel="noreferrer"
>
{envConfig.NEXT_PUBLIC_SITE_NAME}
</a>{' '}
by Jason
by {pkgConfig.author.split(' ')[0]}
</div>
);
6 changes: 5 additions & 1 deletion src/components/HtmlMeta/HtmlMeta.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { Helmet } from 'react-helmet-async';

import { envConfig } from '@/configs';

interface IProps {
title: React.ReactNode;
disableSiteName?: boolean;
Expand All @@ -11,7 +13,9 @@ interface IProps {
}

export const HtmlMeta: React.FC<IProps> = (props) => {
const siteName = props.disableSiteName ? '' : ` - mkn`;
const siteName = props.disableSiteName
? ''
: ` - ${envConfig.NEXT_PUBLIC_SITE_NAME}`;

return (
<Helmet>
Expand Down
12 changes: 0 additions & 12 deletions src/configs/build.config.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/configs/env.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IDotEnv } from '@/interfaces';

// can't pass { ...env } parsing, MUST correspond to 1 to 1
export const envConfig: IDotEnv = {
NEXT_PUBLIC_SITE_NAME: (process.env as IDotEnv).NEXT_PUBLIC_SITE_NAME,
};
3 changes: 2 additions & 1 deletion src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './env.config';
export * from './build.config';
// export * from './build.config';
export * from './pkg.config';
13 changes: 2 additions & 11 deletions src/configs/pkg.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import { IBuild, IDotEnv } from '@/interfaces';
import pkg from '../../package.json';

const envConfig: IDotEnv = (process.env as unknown) as IDotEnv;

export const buildConfig: IBuild = envConfig?.BUILD_DATA || {
BUILDTIME: '',
MODE: '',
VERSION: '',
VERSION_DASH: '',
VERSION_HASH: '',
VERSION_NUMBER: '',
};
export const pkgConfig = pkg;
2 changes: 1 addition & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as useDarkMode } from './useDarkMode';
export { useDarkMode } from './useDarkMode';
13 changes: 13 additions & 0 deletions src/interfaces/config.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface IDotEnv {
NEXT_PUBLIC_SITE_NAME?: string;
// NEXT_PUBLIC_BUILD_DATA?: IBuild;
}

export interface IBuild {
MODE: string;
VERSION: string;
VERSION_DASH: string;
VERSION_NUMBER: string;
VERSION_HASH: string;
BUILDTIME: string;
}
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './router.interface';
export * from './config.interface';
2 changes: 1 addition & 1 deletion src/layouts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* eslint-disable max-len, import/prefer-default-export */
export { default as MasterLayout } from './MasterLayout/MasterLayout';
export { MasterLayout } from './MasterLayout/MasterLayout';
1 change: 1 addition & 0 deletions src/page-components/about/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export const About: React.FC<IProps> = (props) => (
<HtmlMeta title="About" />

<HugeIcon icon={<FiPercent />} />
{JSON.stringify(process.env.NEXT_PUBLIC_SITE_NAME)}
</PageContainer>
);
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function CustomApp({ Component, pageProps }: any) {

return (
<ErrorBoundary>
<div className="app">
<div id="root">
<HelmetProvider>{layoutDom}</HelmetProvider>
</div>
</ErrorBoundary>
Expand Down
2 changes: 1 addition & 1 deletion src/styles/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ html,
body,
#root,
#__next,
.app {
#app {
height: 100%;
}

Expand Down

0 comments on commit 57463bf

Please sign in to comment.