Skip to content

Commit 6e0f5bd

Browse files
committed
refactor(*): use babel-loader instead of awesome-typescript-loader for typescript
1 parent ddd0d92 commit 6e0f5bd

26 files changed

+576
-276
lines changed

.babelrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
2-
"presets": ["@babel/preset-env", "@babel/preset-react"]
3-
}
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-react",
5+
"@babel/preset-typescript"
6+
],
7+
"plugins": [
8+
"@babel/plugin-transform-runtime",
9+
"@babel/proposal-class-properties",
10+
"@babel/proposal-object-rest-spread"
11+
]
12+
}

package-lock.json

Lines changed: 447 additions & 163 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@
5555
},
5656
"devDependencies": {
5757
"@babel/core": "^7.4.3",
58+
"@babel/plugin-proposal-class-properties": "^7.12.1",
59+
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
60+
"@babel/plugin-transform-runtime": "^7.12.1",
5861
"@babel/preset-env": "^7.4.3",
5962
"@babel/preset-react": "^7.0.0",
63+
"@babel/preset-typescript": "^7.12.1",
6064
"@bndynet/header-injection-webpack-plugin": "^4.0.1",
65+
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.2",
6166
"@types/classnames": "^2.2.6",
6267
"@types/lodash-es": "^4.17.3",
6368
"@types/react": "^16.8.17",
@@ -70,7 +75,6 @@
7075
"@typescript-eslint/eslint-plugin": "^1.9.0",
7176
"@typescript-eslint/parser": "^1.9.0",
7277
"autoprefixer": "^9.5.0",
73-
"awesome-typescript-loader": "^5.2.1",
7478
"babel-loader": "^8.0.4",
7579
"base-href-webpack-plugin": "^2.0.0",
7680
"clean-webpack-plugin": "^1.0.1",
@@ -91,6 +95,7 @@
9195
"postcss-loader": "^3.0.0",
9296
"prettier": "^1.17.1",
9397
"print-time-webpack": "^2.0.3",
98+
"react-refresh": "^0.9.0",
9499
"redux-devtools-extension": "^2.13.8",
95100
"redux-logger": "^3.0.6",
96101
"sass-loader": "^7.0.1",

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
LinearProgress,
1212
} from '@material-ui/core';
1313

14-
import { routes } from 'app/config';
14+
import { routes } from './routers/routes';
1515
import { themeConfig } from 'app/theme';
1616
import { Notifier, NotifierOptions, Overlay, Loading } from 'app/ui';
1717
import { actions as globalActions } from 'app/service/global';

src/config/app.common.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Config } from '.';
1+
import { Config } from './types';
22

3-
const config: Config = {
3+
export const config: Config = {
44
title: 'admin.brand',
55
logoUri: 'https://static.bndy.net/images/logo_white.svg',
66
resourceBaseUri: APP_BASEHREF || '/',
@@ -19,5 +19,3 @@ const config: Config = {
1919
},
2020
],
2121
};
22-
23-
module.exports = config;

src/config/app.dev.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import config = require('./app.mock');
2-
3-
module.exports = config;
1+
export { config } from './app.mock';

src/config/app.github.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Config, AuthType } from '.';
1+
import { Config, AuthType } from './types';
22

33
const config: Config = {
44
authType: AuthType.OAuth,

src/config/app.mock.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Config, AuthType } from '.';
1+
import { Config, AuthType } from './types';
22

3-
const config: Config = {
3+
export const config: Config = {
44
authType: AuthType.Mock,
55
userConverter: (mockUser: any) => {
66
return {
@@ -11,5 +11,3 @@ const config: Config = {
1111
};
1212
},
1313
};
14-
15-
module.exports = config;

src/config/app.oauth-code.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Config, AuthType } from '.';
1+
import { Config, AuthType } from './types';
22

3-
const config: Config = {
3+
export const config: Config = {
44
authType: AuthType.OAuth,
55
authConfig: {
66
clientId: 'foo',
@@ -26,5 +26,3 @@ const config: Config = {
2626
};
2727
},
2828
};
29-
30-
module.exports = config;

src/config/app.oauth-password.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Config, AuthType } from '.';
1+
import { Config, AuthType } from './types';
22

3-
const config: Config = {
3+
export const config: Config = {
44
authType: AuthType.OAuthPassword,
55
authConfig: {
66
clientId: 'foo',
@@ -19,5 +19,3 @@ const config: Config = {
1919
};
2020
},
2121
};
22-
23-
module.exports = config;

src/config/app.prod.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import config = require('./app.mock');
2-
module.exports = config;
1+
export { config } from './app.mock';
32

43
// import _merge from 'lodash-es/merge';
5-
// import config = require('./app.oauth-code');
6-
// module.exports = _merge(config, {
4+
// import { Config } from './types';
5+
// import { config as oauthCodeConfig } from './app.oauth-code';
6+
7+
// export const config: Config = _merge(oauthCodeConfig, {
78
// authConfig: {
89
// clientId: '188c0da703',
910
// clientSecret: 'f3dd317369ae622113f0',

src/config/index.tsx

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,43 @@
11
import _merge from 'lodash-es/merge';
2-
import { UserInfo, AuthState } from 'app/service/auth';
2+
import { Config } from './types';
3+
import { config as commonConfig } from './app.common';
4+
import { config as prodConfig } from './app.prod';
5+
import { config as mockConfig } from './app.mock';
36

47
// Uncomment or define it in index.html to specify your environment.
58
// window.__APP_ENV__ = 'github';
69

7-
export enum AuthType {
8-
OAuth, // alias for OAuthCode
9-
OAuthCode,
10-
OAuthPassword,
11-
Custom,
12-
Mock,
13-
}
14-
15-
export interface Config {
16-
title?: string;
17-
logoUri?: string;
18-
resourceBaseUri?: string;
19-
defaultLocale?: string;
20-
locales?: { name: string; value: string; messages?: any }[];
21-
authType?: AuthType;
22-
authConfig?: OAuthConfig;
23-
userConverter?: (backendUser: any) => UserInfo;
24-
logoutHandler?: (url: string, authState: AuthState) => void;
25-
}
26-
27-
export interface OAuthConfig {
28-
clientId: string;
29-
clientSecret: string;
30-
authorizationUri: string;
31-
accessTokenUri?: string;
32-
userProfileUri: string;
33-
logoutUri: string;
34-
callbackUri?: string;
35-
scope?: string;
36-
}
10+
let config: Config;
11+
export function getConfig(): Config {
12+
if (config) {
13+
return config;
14+
}
3715

38-
const getConfig = (): Config => {
3916
const env = window.__APP_ENV__ || process.env.NODE_ENV;
4017

4118
// eslint-disable-next-line no-console
4219
console.info(`Application is running in '${env}' mode.`);
4320

4421
switch (env) {
4522
case 'production':
46-
return (window.__APP_CONF__ = _merge(
47-
require('./app.common'),
48-
require('./app.dev'),
49-
require('./app.prod'),
50-
));
23+
config = window.__APP_CONF__ = _merge(commonConfig, prodConfig);
24+
break;
5125

5226
case 'development':
53-
return (window.__APP_CONF__ = _merge(
54-
require('./app.common'),
55-
require('./app.dev'),
56-
));
27+
config = window.__APP_CONF__ = _merge(commonConfig, mockConfig);
28+
break;
5729

5830
default:
59-
return (window.__APP_CONF__ = _merge(
31+
config = window.__APP_CONF__ = _merge(
6032
require('./app.common'),
6133
require(`./app.${env}`),
62-
));
34+
);
35+
break;
6336
}
64-
};
37+
return config;
38+
}
6539

66-
export const config = getConfig();
67-
export { default as routes } from './routes';
40+
export * from './types';
6841
export { default as adminRoutes } from './routes.admin';
6942
export { default as adminMenus } from './menus.admin';
7043
export { default as userMenus } from './menus.user';

src/config/types.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { UserInfo, AuthState } from 'app/service/auth';
2+
3+
export enum AuthType {
4+
OAuth = 'oauth', // alias for OAuthCode
5+
OAuthCode = 'oauthCode',
6+
OAuthPassword = 'oauthPassword',
7+
Custom = 'custom',
8+
Mock = 'mock',
9+
}
10+
11+
export interface Config {
12+
title?: string;
13+
logoUri?: string;
14+
resourceBaseUri?: string;
15+
defaultLocale?: string;
16+
locales?: { name: string; value: string; messages?: any }[];
17+
authType?: AuthType;
18+
authConfig?: OAuthConfig;
19+
userConverter?: (backendUser: any) => UserInfo;
20+
logoutHandler?: (url: string, authState: AuthState) => void;
21+
}
22+
23+
export interface OAuthConfig {
24+
clientId: string;
25+
clientSecret: string;
26+
authorizationUri: string;
27+
accessTokenUri?: string;
28+
userProfileUri: string;
29+
logoutUri: string;
30+
callbackUri?: string;
31+
scope?: string;
32+
}

src/pages/admin/core/Header.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import MoreVertIcon from '@material-ui/icons/MoreVert';
2929

3030
import { HorizontalMenu, SlidePanel } from 'app/ui';
3131
import { themeConfig } from 'app/theme';
32-
import { config, adminMenus } from 'app/config';
32+
import { getConfig, adminMenus } from 'app/config';
3333
import { actions as globalActions } from 'app/service/global';
3434
import { onAppThemeChanged } from '../../../app.events';
3535
import SidePanelContent from './SidePanelContent';
@@ -141,6 +141,7 @@ class Header extends React.PureComponent<HeaderProps, HeaderState> {
141141
}
142142

143143
public render() {
144+
const config = getConfig();
144145
const { classes, isDarkTheme, hideBrand } = this.props;
145146
const { avatarPopupAnchor } = this.state;
146147
const user = this.props.user || {};

src/pages/admin/core/Sidebar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
AppTheme,
2323
isPopular,
2424
} from 'app/theme';
25-
import { config, adminMenus, userMenus } from 'app/config';
25+
import { getConfig, adminMenus, userMenus } from 'app/config';
2626
import { UserInfo } from 'app/service/auth';
2727
import { MenuItem } from 'app/types/MenuItem';
2828

@@ -141,6 +141,7 @@ class Sidebar extends React.PureComponent<SidebarProps> {
141141
}
142142

143143
public render() {
144+
const config = getConfig();
144145
const { classes, open } = this.props;
145146
const theme = getCurrentTheme();
146147
const isPopularTheme = isPopular();

src/pages/public/Home.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { service as resourceService } from 'app/service/resource';
2121
import { actions as authActions, getState } from 'app/service/auth';
2222
import { actions as globalActions } from 'app/service/global';
2323

24-
import { config } from 'app/config';
24+
import { getConfig } from 'app/config';
2525
import { setLocale } from 'app/service/locales';
2626

2727
const styles = (theme: Theme) =>
@@ -95,6 +95,7 @@ class Home extends React.Component<HomeComponentProps, HomeComponentState> {
9595
}
9696

9797
public render() {
98+
const config = getConfig();
9899
const { classes } = this.props;
99100
const btn = this.props.user ? (
100101
<Tooltip title={this.props.user.name}>

src/config/routes.tsx renamed to src/routers/routes.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Admin } from 'app/pages/admin';
66
import { Login, Logout, Callback } from 'app/pages/auth';
77
import { RouteConfig } from 'react-router-config';
88

9-
const routes: RouteConfig[] = [
9+
export const routes: RouteConfig[] = [
1010
{
1111
path: '/',
1212
exact: true,
@@ -33,6 +33,7 @@ const routes: RouteConfig[] = [
3333
return <Admin />;
3434
} else {
3535
if (
36+
getAuthUri() &&
3637
!getAuthUri()
3738
.toLowerCase()
3839
.startsWith('http')
@@ -48,5 +49,3 @@ const routes: RouteConfig[] = [
4849
component: NotFound,
4950
},
5051
];
51-
52-
export default routes;

src/service/auth.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { AxiosPromise } from 'axios';
33
import { Ajax, AjaxError } from '../helpers/ajax';
44
import { store } from '../redux';
5-
import { config, AuthType } from '../config';
5+
import { getConfig, AuthType } from '../config';
66
import { push } from 'connected-react-router';
77
import { call, put, takeLatest } from 'redux-saga/effects';
88
import { actions as globalActions } from './global';
@@ -120,6 +120,8 @@ export function reducer(state: AuthState = {}, action): AuthState {
120120
}
121121
}
122122

123+
const config = getConfig();
124+
123125
export const service = {
124126
login: (data: LoginData) => {
125127
switch (config.authType) {

src/service/locales.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as intl from 'react-intl-universal';
2-
import { config } from 'app/config';
2+
import { getConfig } from 'app/config';
33
import storage from 'app/helpers/storage';
44
import ajax from 'app/helpers/ajax';
55
import { onAppLocaleChanged } from '../app.events';
66

7+
const config = getConfig();
78
const KEY_LOCALE = 'locale';
89
function getCurrentLocale() {
910
return (

src/service/resource.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { notify } from '@bndynet/dialog';
2-
import { config } from '../config';
2+
import { getConfig } from '../config';
33
import { Ajax } from '../helpers/ajax';
44
import { getState } from './auth';
55

66
class ResourceService extends Ajax {
77
public constructor() {
8+
const config = getConfig();
9+
console.debug(config);
810
super({
911
headerAuthorization: () => {
1012
if (getState().token) {

0 commit comments

Comments
 (0)