mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
clean
This commit is contained in:
parent
3a5af895a3
commit
0980990d0e
@ -14,7 +14,6 @@
|
||||
"@icons-pack/react-simple-icons": "^3.8.0",
|
||||
"@lingui/react": "^3.3.0",
|
||||
"@ragestudio/nodecore-api-lib": "^0.2.6",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/lodash": "^4.14.165",
|
||||
"antd": "^4.8.2",
|
||||
"axios": "^0.21.1",
|
||||
|
@ -1,51 +0,0 @@
|
||||
// @ts-nocheck
|
||||
|
||||
if (window.g_initWebpackHotDevClient) {
|
||||
function tryApplyUpdates(onHotUpdateSuccess?: Function) {
|
||||
// @ts-ignore
|
||||
if (!module.hot) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
function isUpdateAvailable() {
|
||||
// @ts-ignore
|
||||
return window.g_getMostRecentCompilationHash() !== __webpack_hash__;
|
||||
}
|
||||
|
||||
// TODO: is update available?
|
||||
// @ts-ignore
|
||||
if (!isUpdateAvailable() || module.hot.status() !== 'idle') {
|
||||
return;
|
||||
}
|
||||
|
||||
function handleApplyUpdates(err: Error | null, updatedModules: any) {
|
||||
if (err || !updatedModules || window.g_getHadRuntimeError()) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
onHotUpdateSuccess?.();
|
||||
|
||||
if (isUpdateAvailable()) {
|
||||
// While we were updating, there was a new update! Do it again.
|
||||
tryApplyUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
module.hot.check(true).then(
|
||||
function (updatedModules: any) {
|
||||
handleApplyUpdates(null, updatedModules);
|
||||
},
|
||||
function (err: Error) {
|
||||
handleApplyUpdates(err, null);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
window.g_initWebpackHotDevClient({
|
||||
tryApplyUpdates,
|
||||
});
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { createBrowserHistory } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/runtime';
|
||||
|
||||
let options = {
|
||||
"basename": "/"
|
||||
};
|
||||
if ((<any>window).routerBase) {
|
||||
options.basename = (<any>window).routerBase;
|
||||
}
|
||||
|
||||
// remove initial history because of ssr
|
||||
let history: any = process.env.__IS_SERVER ? null : createBrowserHistory(options);
|
||||
export const createHistory = (hotReload = false) => {
|
||||
if (!hotReload) {
|
||||
history = createBrowserHistory(options);
|
||||
}
|
||||
|
||||
return history;
|
||||
};
|
||||
|
||||
export { history };
|
@ -1,8 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { Plugin } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/runtime';
|
||||
|
||||
const plugin = new Plugin({
|
||||
validKeys: ['modifyClientRenderOpts','patchRoutes','rootContainer','render','onRouteChange','dva','getInitialState','initialStateConfig','request',],
|
||||
});
|
||||
|
||||
export { plugin };
|
209
packages/comty/src/.umi/core/pluginConfig.d.ts
vendored
209
packages/comty/src/.umi/core/pluginConfig.d.ts
vendored
@ -1,209 +0,0 @@
|
||||
/** Created by Umi Plugin **/
|
||||
|
||||
export interface IConfigFromPlugins {
|
||||
routes?: {
|
||||
/**
|
||||
* Any valid URL path
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* A React component to render only when the location matches.
|
||||
*/
|
||||
component?: string | (() => any);
|
||||
wrappers?: string[];
|
||||
/**
|
||||
* navigate to a new location
|
||||
*/
|
||||
redirect?: string;
|
||||
/**
|
||||
* When true, the active class/style will only be applied if the location is matched exactly.
|
||||
*/
|
||||
exact?: boolean;
|
||||
routes?: any[];
|
||||
[k: string]: any;
|
||||
}[];
|
||||
history?: {
|
||||
type?: "browser" | "hash" | "memory";
|
||||
options?: {};
|
||||
};
|
||||
polyfill?: {
|
||||
imports?: string[];
|
||||
};
|
||||
alias?: {};
|
||||
analyze?: {
|
||||
analyzerMode?: "server" | "static" | "disabled";
|
||||
analyzerHost?: string;
|
||||
analyzerPort?: any;
|
||||
openAnalyzer?: boolean;
|
||||
generateStatsFile?: boolean;
|
||||
statsFilename?: string;
|
||||
logLevel?: "info" | "warn" | "error" | "silent";
|
||||
defaultSizes?: "stat" | "parsed" | "gzip";
|
||||
[k: string]: any;
|
||||
};
|
||||
/**
|
||||
* postcss autoprefixer, default flexbox: no-2009
|
||||
*/
|
||||
autoprefixer?: {};
|
||||
base?: string;
|
||||
chainWebpack?: () => any;
|
||||
chunks?: string[];
|
||||
/**
|
||||
* more css-loader options see https://webpack.js.org/loaders/css-loader/#options
|
||||
*/
|
||||
cssLoader?: {
|
||||
url?: boolean | (() => any);
|
||||
import?: boolean | (() => any);
|
||||
modules?: boolean | string | {};
|
||||
sourceMap?: boolean;
|
||||
importLoaders?: number;
|
||||
onlyLocals?: boolean;
|
||||
esModule?: boolean;
|
||||
localsConvention?: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly";
|
||||
};
|
||||
cssModulesTypescriptLoader?: {
|
||||
mode?: "emit" | "verify";
|
||||
};
|
||||
cssnano?: {};
|
||||
copy?: any[];
|
||||
define?: {};
|
||||
devScripts?: {};
|
||||
/**
|
||||
* devServer configs
|
||||
*/
|
||||
devServer?: {
|
||||
/**
|
||||
* devServer port, default 8000
|
||||
*/
|
||||
port?: number;
|
||||
host?: string;
|
||||
https?:
|
||||
| {
|
||||
key?: string;
|
||||
cert?: string;
|
||||
[k: string]: any;
|
||||
}
|
||||
| boolean;
|
||||
headers?: {};
|
||||
writeToDisk?: boolean | (() => any);
|
||||
[k: string]: any;
|
||||
};
|
||||
devtool?: string;
|
||||
/**
|
||||
* Code splitting for performance optimization
|
||||
*/
|
||||
dynamicImport?: {
|
||||
/**
|
||||
* loading the component before loaded
|
||||
*/
|
||||
loading?: string;
|
||||
};
|
||||
exportStatic?: {
|
||||
htmlSuffix?: boolean;
|
||||
dynamicRoot?: boolean;
|
||||
/**
|
||||
* extra render paths only enable in ssr
|
||||
*/
|
||||
extraRoutePaths?: () => any;
|
||||
};
|
||||
externals?: {} | string | (() => any);
|
||||
extraBabelPlugins?: any[];
|
||||
extraBabelPresets?: any[];
|
||||
extraPostCSSPlugins?: any[];
|
||||
/**
|
||||
* fork-ts-checker-webpack-plugin options see https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#options
|
||||
*/
|
||||
forkTSChecker?: {
|
||||
async?: boolean;
|
||||
typescript?: boolean | {};
|
||||
eslint?: {};
|
||||
issue?: {};
|
||||
formatter?: string | {};
|
||||
logger?: {};
|
||||
[k: string]: any;
|
||||
};
|
||||
fastRefresh?: {};
|
||||
hash?: boolean;
|
||||
ignoreMomentLocale?: boolean;
|
||||
inlineLimit?: number;
|
||||
lessLoader?: {};
|
||||
manifest?: {
|
||||
fileName?: string;
|
||||
publicPath?: "";
|
||||
basePath?: string;
|
||||
writeToFileEmit?: boolean;
|
||||
};
|
||||
mountElementId?: "";
|
||||
mpa?: {};
|
||||
nodeModulesTransform?: {
|
||||
type?: "all" | "none";
|
||||
exclude?: string[];
|
||||
};
|
||||
outputPath?: "";
|
||||
plugins?: string[];
|
||||
postcssLoader?: {};
|
||||
presets?: string[];
|
||||
proxy?: {};
|
||||
publicPath?: string;
|
||||
runtimePublicPath?: boolean;
|
||||
ssr?: {
|
||||
/**
|
||||
* force execing Page getInitialProps functions
|
||||
*/
|
||||
forceInitial?: boolean;
|
||||
/**
|
||||
* remove window.g_initialProps in html
|
||||
*/
|
||||
removeWindowInitialProps?: boolean;
|
||||
/**
|
||||
* disable serve-side render in umi dev mode.
|
||||
*/
|
||||
devServerRender?: boolean;
|
||||
mode?: "stream" | "string";
|
||||
/**
|
||||
* static markup in static site
|
||||
*/
|
||||
staticMarkup?: boolean;
|
||||
};
|
||||
singular?: boolean;
|
||||
styleLoader?: {};
|
||||
targets?: {};
|
||||
terserOptions?: {};
|
||||
theme?: {};
|
||||
runtimeHistory?: {};
|
||||
favicon?: string;
|
||||
headScripts?: any[];
|
||||
links?: any[];
|
||||
metas?: any[];
|
||||
scripts?: any[];
|
||||
styles?: any[];
|
||||
title?: string;
|
||||
mock?: {
|
||||
exclude?: string[];
|
||||
};
|
||||
antd?: {
|
||||
dark?: boolean;
|
||||
compact?: boolean;
|
||||
config?: {};
|
||||
};
|
||||
dva?: {
|
||||
disableModelsReExport?: boolean;
|
||||
extraModels?: string[];
|
||||
hmr?: boolean;
|
||||
immer?: boolean;
|
||||
skipModelValidate?: boolean;
|
||||
};
|
||||
locale?: {
|
||||
default?: string;
|
||||
useLocalStorage?: boolean;
|
||||
baseNavigator?: boolean;
|
||||
title?: boolean;
|
||||
antd?: boolean;
|
||||
baseSeparator?: string;
|
||||
};
|
||||
layout?: {};
|
||||
request?: {
|
||||
dataField?: "";
|
||||
};
|
||||
[k: string]: any;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { plugin } from './plugin';
|
||||
import * as Plugin_0 from '/Users/srgooglo/repos/comty/packages/comty/src/.umi/plugin-dva/runtime.tsx';
|
||||
import * as Plugin_1 from '../plugin-initial-state/runtime';
|
||||
import * as Plugin_2 from '../plugin-model/runtime';
|
||||
|
||||
plugin.register({
|
||||
apply: Plugin_0,
|
||||
path: '/Users/srgooglo/repos/comty/packages/comty/src/.umi/plugin-dva/runtime.tsx',
|
||||
});
|
||||
plugin.register({
|
||||
apply: Plugin_1,
|
||||
path: '../plugin-initial-state/runtime',
|
||||
});
|
||||
plugin.register({
|
||||
apply: Plugin_2,
|
||||
path: '../plugin-model/runtime',
|
||||
});
|
@ -1,3 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import 'core-js';
|
||||
import 'regenerator-runtime/runtime';
|
@ -1,111 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { ApplyPluginsType, dynamic } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/runtime';
|
||||
import * as umiExports from './umiExports';
|
||||
import { plugin } from './plugin';
|
||||
import LoadingComponent from 'components/Loader';
|
||||
|
||||
export function getRoutes() {
|
||||
const routes = [
|
||||
{
|
||||
"path": "/",
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'layouts__index' */'@/layouts/index.js'), loading: LoadingComponent}),
|
||||
"routes": [
|
||||
{
|
||||
"path": "/404",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__404' */'@/pages/404.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/@/:user",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__@__user' */'@/pages/@/[user].js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/debug",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__debug__index' */'@/pages/debug/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/explore",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__explore__index' */'@/pages/explore/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/index.html",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__index' */'@/pages/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__index' */'@/pages/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/login/guest",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__login__guest' */'@/pages/login/guest.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/login",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__login__index' */'@/pages/login/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/login/login",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__login__login' */'@/pages/login/login.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/login/register",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__login__register' */'@/pages/login/register.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/logout",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__logout' */'@/pages/logout.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/new_streaming",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__new_streaming__index' */'@/pages/new_streaming/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/post",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__post' */'@/pages/post.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/saves",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__saves' */'@/pages/saves.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/settings",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__settings__index' */'@/pages/settings/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/streams",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__streams__index' */'@/pages/streams/index.js'), loading: LoadingComponent})
|
||||
},
|
||||
{
|
||||
"path": "/:indexer",
|
||||
"exact": true,
|
||||
"component": dynamic({ loader: () => import(/* webpackChunkName: 'p__indexer' */'@/pages/[indexer].js'), loading: LoadingComponent})
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// allow user to extend routes
|
||||
plugin.applyPlugins({
|
||||
key: 'patchRoutes',
|
||||
type: ApplyPluginsType.event,
|
||||
args: { routes },
|
||||
});
|
||||
|
||||
return routes;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// @ts-nocheck
|
||||
export { history } from './history';
|
||||
export { plugin } from './plugin';
|
||||
export * from '../plugin-dva/exports';
|
||||
export * from '../plugin-dva/connect';
|
||||
export * from '../plugin-initial-state/exports';
|
||||
export * from '../plugin-model/useModel';
|
||||
export * from '../plugin-request/request';
|
||||
export * from '../plugin-helmet/exports';
|
@ -1,87 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { IRoute } from '@umijs/core';
|
||||
import { AnyAction } from 'redux';
|
||||
import React from 'react';
|
||||
import { EffectsCommandMap, SubscriptionAPI } from 'dva';
|
||||
import { match } from 'react-router-dom';
|
||||
import { Location, LocationState, History } from 'history';
|
||||
|
||||
export * from '/Users/srgooglo/repos/comty/packages/comty/src/models/app';
|
||||
export * from '/Users/srgooglo/repos/comty/packages/comty/src/models/contextMenu';
|
||||
export * from '/Users/srgooglo/repos/comty/packages/comty/src/models/socket';
|
||||
export * from '/Users/srgooglo/repos/comty/packages/comty/src/models/streaming';
|
||||
export * from '/Users/srgooglo/repos/comty/packages/comty/src/models/user';
|
||||
|
||||
export interface Action<T = any> {
|
||||
type: T
|
||||
}
|
||||
|
||||
export type Reducer<S = any, A extends Action = AnyAction> = (
|
||||
state: S | undefined,
|
||||
action: A
|
||||
) => S;
|
||||
|
||||
export type ImmerReducer<S = any, A extends Action = AnyAction> = (
|
||||
state: S,
|
||||
action: A
|
||||
) => void;
|
||||
|
||||
export type Effect = (
|
||||
action: AnyAction,
|
||||
effects: EffectsCommandMap,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* @type P: Type of payload
|
||||
* @type C: Type of callback
|
||||
*/
|
||||
export type Dispatch = <P = any, C = (payload: P) => void>(action: {
|
||||
type: string;
|
||||
payload?: P;
|
||||
callback?: C;
|
||||
[key: string]: any;
|
||||
}) => any;
|
||||
|
||||
export type Subscription = (api: SubscriptionAPI, done: Function) => void | Function;
|
||||
|
||||
export interface Loading {
|
||||
global: boolean;
|
||||
effects: { [key: string]: boolean | undefined };
|
||||
models: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @type P: Params matched in dynamic routing
|
||||
*/
|
||||
export interface ConnectProps<
|
||||
P extends { [K in keyof P]?: string } = {},
|
||||
S = LocationState,
|
||||
T = {}
|
||||
> {
|
||||
dispatch?: Dispatch;
|
||||
// https://github.com/umijs/umi/pull/2194
|
||||
match?: match<P>;
|
||||
location: Location<S> & { query: T };
|
||||
history: History;
|
||||
route: IRoute;
|
||||
}
|
||||
|
||||
export type RequiredConnectProps<
|
||||
P extends { [K in keyof P]?: string } = {},
|
||||
S = LocationState,
|
||||
T = {}
|
||||
> = Required<ConnectProps<P, S, T>>
|
||||
|
||||
/**
|
||||
* @type T: React props
|
||||
* @type U: match props types
|
||||
*/
|
||||
export type ConnectRC<
|
||||
T = {},
|
||||
U = {},
|
||||
S = {},
|
||||
Q = {}
|
||||
> = React.ForwardRefRenderFunction<any, T & RequiredConnectProps<U, S, Q>>;
|
||||
|
@ -1,77 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { Component } from 'react';
|
||||
import { ApplyPluginsType } from 'umi';
|
||||
import dva from 'dva';
|
||||
// @ts-ignore
|
||||
import createLoading from '/Users/srgooglo/repos/comty/packages/comty/node_modules/dva-loading/dist/index.esm.js';
|
||||
import { plugin, history } from '../core/umiExports';
|
||||
import ModelApp0 from '/Users/srgooglo/repos/comty/packages/comty/src/models/app.js';
|
||||
import ModelContextMenu1 from '/Users/srgooglo/repos/comty/packages/comty/src/models/contextMenu.js';
|
||||
import ModelSocket2 from '/Users/srgooglo/repos/comty/packages/comty/src/models/socket.ts';
|
||||
import ModelStreaming3 from '/Users/srgooglo/repos/comty/packages/comty/src/models/streaming.js';
|
||||
import ModelUser4 from '/Users/srgooglo/repos/comty/packages/comty/src/models/user.ts';
|
||||
|
||||
let app:any = null;
|
||||
|
||||
export function _onCreate(options = {}) {
|
||||
const runtimeDva = plugin.applyPlugins({
|
||||
key: 'dva',
|
||||
type: ApplyPluginsType.modify,
|
||||
initialValue: {},
|
||||
});
|
||||
app = dva({
|
||||
history,
|
||||
|
||||
...(runtimeDva.config || {}),
|
||||
// @ts-ignore
|
||||
...(typeof window !== 'undefined' && window.g_useSSR ? { initialState: window.g_initialProps } : {}),
|
||||
...(options || {}),
|
||||
});
|
||||
|
||||
app.use(createLoading());
|
||||
app.use(require('/Users/srgooglo/repos/comty/packages/comty/node_modules/dva-immer/dist/index.js')());
|
||||
(runtimeDva.plugins || []).forEach((plugin:any) => {
|
||||
app.use(plugin);
|
||||
});
|
||||
app.model({ namespace: 'app', ...ModelApp0 });
|
||||
app.model({ namespace: 'contextMenu', ...ModelContextMenu1 });
|
||||
app.model({ namespace: 'socket', ...ModelSocket2 });
|
||||
app.model({ namespace: 'streaming', ...ModelStreaming3 });
|
||||
app.model({ namespace: 'user', ...ModelUser4 });
|
||||
return app;
|
||||
}
|
||||
|
||||
export function getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
export class _DvaContainer extends Component {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
// run only in client, avoid override server _onCreate()
|
||||
if (typeof window !== 'undefined') {
|
||||
_onCreate();
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
let app = getApp();
|
||||
app._models.forEach((model:any) => {
|
||||
app.unmodel(model.namespace);
|
||||
});
|
||||
app._models = [];
|
||||
try {
|
||||
// 释放 app,for gc
|
||||
// immer 场景 app 是 read-only 的,这里 try catch 一下
|
||||
app = null;
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const app = getApp();
|
||||
app.router(() => this.props.children);
|
||||
return app.start()();
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
// @ts-nocheck
|
||||
|
||||
export { connect, useDispatch, useStore, useSelector } from 'dva';
|
||||
export { getApp as getDvaApp } from './dva';
|
@ -1,8 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { _DvaContainer, getApp, _onCreate } from './dva';
|
||||
|
||||
export function rootContainer(container) {
|
||||
return React.createElement(_DvaContainer, null, container);
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
// @ts-nocheck
|
||||
// @ts-ignore
|
||||
export { Helmet } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/react-helmet';
|
@ -1,37 +0,0 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import React, { useRef, useEffect } from "react";
|
||||
import { plugin } from "../core/umiExports";
|
||||
import { ApplyPluginsType } from 'umi';
|
||||
import { useModel } from "../plugin-model/useModel";
|
||||
if (typeof useModel !== "function") {
|
||||
throw new Error(
|
||||
"[plugin-initial-state]: useModel is not a function, @umijs/plugin-model is required."
|
||||
);
|
||||
}
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
export default (props: Props) => {
|
||||
const { children } = props;
|
||||
const appLoaded = useRef(false);
|
||||
// 获取用户的配置,暂时只支持 loading
|
||||
const useRuntimeConfig =
|
||||
plugin.applyPlugins({
|
||||
key: "initialStateConfig",
|
||||
type: ApplyPluginsType.modify,
|
||||
initialValue: {},
|
||||
}) || {};
|
||||
const { loading = false } = useModel("@@initialState") || {};
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
appLoaded.current = true;
|
||||
}
|
||||
}, [loading]);
|
||||
// initial state loading 时,阻塞渲染
|
||||
if (loading && !appLoaded.current) {
|
||||
return useRuntimeConfig.loading || null;
|
||||
}
|
||||
return children;
|
||||
};
|
@ -1,7 +0,0 @@
|
||||
// @ts-nocheck
|
||||
|
||||
// @ts-ignore
|
||||
import { InitialState as InitialStateType } from '../plugin-initial-state/models/initialState';
|
||||
|
||||
export type InitialState = InitialStateType;
|
||||
export const __PLUGIN_INITIAL_STATE = 1;
|
@ -1,2 +0,0 @@
|
||||
// @ts-nocheck
|
||||
export default () => ({ loading: false, refresh: () => {} })
|
@ -1,13 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import Provider from './Provider';
|
||||
|
||||
export function rootContainer(container: React.ReactNode) {
|
||||
return React.createElement(
|
||||
// 这里的 plugin-initial-state 不能从 constant 里取,里面有 path 依赖
|
||||
// 但 webpack-5 没有 node 补丁(包括 path)
|
||||
Provider,
|
||||
null,
|
||||
container,
|
||||
);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import initialState from '/Users/srgooglo/repos/comty/packages/comty/src/.umi/plugin-initial-state/models/initialState';
|
||||
|
||||
// @ts-ignore
|
||||
import Dispatcher from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/plugin-model/lib/helpers/dispatcher';
|
||||
// @ts-ignore
|
||||
import Executor from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/plugin-model/lib/helpers/executor';
|
||||
// @ts-ignore
|
||||
import { UmiContext } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/plugin-model/lib/helpers/constant';
|
||||
|
||||
export const models = { '@@initialState': initialState, };
|
||||
|
||||
export type Model<T extends keyof typeof models> = {
|
||||
[key in keyof typeof models]: ReturnType<typeof models[T]>;
|
||||
};
|
||||
|
||||
export type Models<T extends keyof typeof models> = Model<T>[T]
|
||||
|
||||
const dispatcher = new Dispatcher!();
|
||||
const Exe = Executor!;
|
||||
|
||||
export default ({ children }: { children: React.ReactNode }) => {
|
||||
|
||||
return (
|
||||
<UmiContext.Provider value={dispatcher}>
|
||||
{
|
||||
Object.entries(models).map(pair => (
|
||||
<Exe key={pair[0]} namespace={pair[0]} hook={pair[1] as any} onUpdate={(val: any) => {
|
||||
const [ns] = pair as [keyof typeof models, any];
|
||||
dispatcher.data[ns] = val;
|
||||
dispatcher.update(ns);
|
||||
}} />
|
||||
))
|
||||
}
|
||||
{children}
|
||||
</UmiContext.Provider>
|
||||
)
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// @ts-nocheck
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
import React from 'react';
|
||||
import Provider from './Provider';
|
||||
|
||||
export function rootContainer(container: React.ReactNode) {
|
||||
return React.createElement(
|
||||
Provider,
|
||||
null,
|
||||
container,
|
||||
);
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { useState, useEffect, useContext, useRef } from 'react';
|
||||
// @ts-ignore
|
||||
import isEqual from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/plugin-model/node_modules/fast-deep-equal/index.js';
|
||||
// @ts-ignore
|
||||
import { UmiContext } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/plugin-model/lib/helpers/constant';
|
||||
import { Model, models } from './Provider';
|
||||
|
||||
export type Models<T extends keyof typeof models> = Model<T>[T]
|
||||
|
||||
export function useModel<T extends keyof Model<T>>(model: T): Model<T>[T]
|
||||
export function useModel<T extends keyof Model<T>, U>(model: T, selector: (model: Model<T>[T]) => U): U
|
||||
|
||||
export function useModel<T extends keyof Model<T>, U>(
|
||||
namespace: T,
|
||||
updater?: (model: Model<T>[T]) => U
|
||||
) : typeof updater extends undefined ? Model<T>[T] : ReturnType<NonNullable<typeof updater>>{
|
||||
|
||||
type RetState = typeof updater extends undefined ? Model<T>[T] : ReturnType<NonNullable<typeof updater>>
|
||||
const dispatcher = useContext<any>(UmiContext);
|
||||
const updaterRef = useRef(updater);
|
||||
updaterRef.current = updater;
|
||||
const [state, setState] = useState<RetState>(
|
||||
() => updaterRef.current ? updaterRef.current(dispatcher.data![namespace]) : dispatcher.data![namespace]
|
||||
);
|
||||
const stateRef = useRef<any>(state);
|
||||
stateRef.current = state;
|
||||
|
||||
const isMount = useRef(false);
|
||||
useEffect(() => {
|
||||
isMount.current = true;
|
||||
return () => {
|
||||
isMount.current = false;
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (e: any) => {
|
||||
if(!isMount.current) {
|
||||
// 如果 handler 执行过程中,组件被卸载了,则强制更新全局 data
|
||||
setTimeout(() => {
|
||||
dispatcher.data![namespace] = e;
|
||||
dispatcher.update(namespace);
|
||||
});
|
||||
} else {
|
||||
if(updater && updaterRef.current){
|
||||
const currentState = updaterRef.current(e);
|
||||
const previousState = stateRef.current
|
||||
if(!isEqual(currentState, previousState)){
|
||||
setState(currentState);
|
||||
}
|
||||
} else {
|
||||
setState(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
dispatcher.callbacks![namespace]!.add(handler);
|
||||
dispatcher.update(namespace);
|
||||
} catch (e) {
|
||||
dispatcher.callbacks![namespace] = new Set();
|
||||
dispatcher.callbacks![namespace]!.add(handler);
|
||||
dispatcher.update(namespace);
|
||||
}
|
||||
return () => {
|
||||
dispatcher.callbacks![namespace]!.delete(handler);
|
||||
}
|
||||
}, [namespace]);
|
||||
|
||||
return state;
|
||||
};
|
@ -1,276 +0,0 @@
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* Base on https://github.com/umijs//Users/srgooglo/repos/comty/packages/comty/node_modules/umi-request
|
||||
*/
|
||||
import {
|
||||
extend,
|
||||
Context,
|
||||
RequestOptionsInit,
|
||||
OnionMiddleware,
|
||||
RequestOptionsWithoutResponse,
|
||||
RequestMethod,
|
||||
RequestOptionsWithResponse,
|
||||
RequestResponse,
|
||||
RequestInterceptor,
|
||||
ResponseInterceptor,
|
||||
} from '/Users/srgooglo/repos/comty/packages/comty/node_modules/umi-request';
|
||||
// @ts-ignore
|
||||
|
||||
import { ApplyPluginsType } from 'umi';
|
||||
import { history, plugin } from '../core/umiExports';
|
||||
|
||||
// decoupling with antd UI library, you can using `alias` modify the ui methods
|
||||
// @ts-ignore
|
||||
import { message, notification } from '@umijs/plugin-request/lib/ui';
|
||||
import useUmiRequest, { UseRequestProvider } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@ahooksjs/use-request';
|
||||
import {
|
||||
BaseOptions,
|
||||
BasePaginatedOptions,
|
||||
BaseResult,
|
||||
CombineService,
|
||||
LoadMoreFormatReturn,
|
||||
LoadMoreOptions,
|
||||
LoadMoreOptionsWithFormat,
|
||||
LoadMoreParams,
|
||||
LoadMoreResult,
|
||||
OptionsWithFormat,
|
||||
PaginatedFormatReturn,
|
||||
PaginatedOptionsWithFormat,
|
||||
PaginatedParams,
|
||||
PaginatedResult,
|
||||
} from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@ahooksjs/use-request/lib/types';
|
||||
|
||||
type ResultWithData<T = any> = { data?: T; [key: string]: any };
|
||||
|
||||
function useRequest<
|
||||
R = any,
|
||||
P extends any[] = any,
|
||||
U = any,
|
||||
UU extends U = any
|
||||
>(
|
||||
service: CombineService<R, P>,
|
||||
options: OptionsWithFormat<R, P, U, UU>,
|
||||
): BaseResult<U, P>;
|
||||
function useRequest<R extends ResultWithData = any, P extends any[] = any>(
|
||||
service: CombineService<R, P>,
|
||||
options?: BaseOptions<R['data'], P>,
|
||||
): BaseResult<R['data'], P>;
|
||||
function useRequest<R extends LoadMoreFormatReturn = any, RR = any>(
|
||||
service: CombineService<RR, LoadMoreParams<R>>,
|
||||
options: LoadMoreOptionsWithFormat<R, RR>,
|
||||
): LoadMoreResult<R>;
|
||||
function useRequest<
|
||||
R extends ResultWithData<LoadMoreFormatReturn | any> = any,
|
||||
RR extends R = any
|
||||
>(
|
||||
service: CombineService<R, LoadMoreParams<R['data']>>,
|
||||
options: LoadMoreOptions<RR['data']>,
|
||||
): LoadMoreResult<R['data']>;
|
||||
|
||||
function useRequest<R = any, Item = any, U extends Item = any>(
|
||||
service: CombineService<R, PaginatedParams>,
|
||||
options: PaginatedOptionsWithFormat<R, Item, U>,
|
||||
): PaginatedResult<Item>;
|
||||
function useRequest<Item = any, U extends Item = any>(
|
||||
service: CombineService<
|
||||
ResultWithData<PaginatedFormatReturn<Item>>,
|
||||
PaginatedParams
|
||||
>,
|
||||
options: BasePaginatedOptions<U>,
|
||||
): PaginatedResult<Item>;
|
||||
function useRequest(service: any, options: any = {}) {
|
||||
return useUmiRequest(service, {
|
||||
formatResult: result => result?.data,
|
||||
requestMethod: (requestOptions: any) => {
|
||||
if (typeof requestOptions === 'string') {
|
||||
return request(requestOptions);
|
||||
}
|
||||
if (typeof requestOptions === 'object') {
|
||||
const { url, ...rest } = requestOptions;
|
||||
return request(url, rest);
|
||||
}
|
||||
throw new Error('request options error');
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
export interface RequestConfig extends RequestOptionsInit {
|
||||
errorConfig?: {
|
||||
errorPage?: string;
|
||||
adaptor?: (resData: any, ctx: Context) => ErrorInfoStructure;
|
||||
};
|
||||
middlewares?: OnionMiddleware[];
|
||||
requestInterceptors?: RequestInterceptor[];
|
||||
responseInterceptors?: ResponseInterceptor[];
|
||||
}
|
||||
|
||||
export enum ErrorShowType {
|
||||
SILENT = 0,
|
||||
WARN_MESSAGE = 1,
|
||||
ERROR_MESSAGE = 2,
|
||||
NOTIFICATION = 4,
|
||||
REDIRECT = 9,
|
||||
}
|
||||
|
||||
interface ErrorInfoStructure {
|
||||
success: boolean;
|
||||
data?: any;
|
||||
errorCode?: string;
|
||||
errorMessage?: string;
|
||||
showType?: ErrorShowType;
|
||||
traceId?: string;
|
||||
host?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface RequestError extends Error {
|
||||
data?: any;
|
||||
info?: ErrorInfoStructure;
|
||||
request?: Context['req'];
|
||||
response?: Context['res'];
|
||||
}
|
||||
|
||||
const DEFAULT_ERROR_PAGE = '/exception';
|
||||
|
||||
let requestMethodInstance: RequestMethod;
|
||||
const getRequestMethod = () => {
|
||||
if (requestMethodInstance) {
|
||||
// request method 已经示例化
|
||||
return requestMethodInstance;
|
||||
}
|
||||
|
||||
// runtime 配置可能应为依赖顺序的问题在模块初始化的时候无法获取,所以需要封装一层在异步调用后初始化相关方法
|
||||
// 当用户的 app.ts 中依赖了该文件的情况下就该模块的初始化时间就会被提前,无法获取到运行时配置
|
||||
const requestConfig: RequestConfig = plugin.applyPlugins({
|
||||
key: 'request',
|
||||
type: ApplyPluginsType.modify,
|
||||
initialValue: {},
|
||||
});
|
||||
|
||||
const errorAdaptor =
|
||||
requestConfig.errorConfig?.adaptor || (resData => resData);
|
||||
|
||||
requestMethodInstance = extend({
|
||||
errorHandler: (error: RequestError) => {
|
||||
// @ts-ignore
|
||||
if (error?.request?.options?.skipErrorHandler) {
|
||||
throw error;
|
||||
}
|
||||
let errorInfo: ErrorInfoStructure | undefined;
|
||||
if (error.name === 'ResponseError' && error.data && error.request) {
|
||||
const ctx: Context = {
|
||||
req: error.request,
|
||||
res: error.response,
|
||||
};
|
||||
errorInfo = errorAdaptor(error.data, ctx);
|
||||
error.message = errorInfo?.errorMessage || error.message;
|
||||
error.data = error.data;
|
||||
error.info = errorInfo;
|
||||
}
|
||||
errorInfo = error.info;
|
||||
|
||||
if (errorInfo) {
|
||||
const errorMessage = errorInfo?.errorMessage;
|
||||
const errorCode = errorInfo?.errorCode;
|
||||
const errorPage =
|
||||
requestConfig.errorConfig?.errorPage || DEFAULT_ERROR_PAGE;
|
||||
|
||||
switch (errorInfo?.showType) {
|
||||
case ErrorShowType.SILENT:
|
||||
// do nothing
|
||||
break;
|
||||
case ErrorShowType.WARN_MESSAGE:
|
||||
message.warn(errorMessage);
|
||||
break;
|
||||
case ErrorShowType.ERROR_MESSAGE:
|
||||
message.error(errorMessage);
|
||||
break;
|
||||
case ErrorShowType.NOTIFICATION:
|
||||
notification.open({
|
||||
message: errorMessage,
|
||||
});
|
||||
break;
|
||||
case ErrorShowType.REDIRECT:
|
||||
// @ts-ignore
|
||||
history.push({
|
||||
pathname: errorPage,
|
||||
query: { errorCode, errorMessage },
|
||||
});
|
||||
// redirect to error page
|
||||
break;
|
||||
default:
|
||||
message.error(errorMessage);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
message.error(error.message || 'Request error, please retry.');
|
||||
}
|
||||
throw error;
|
||||
},
|
||||
...requestConfig,
|
||||
});
|
||||
|
||||
// 中间件统一错误处理
|
||||
// 后端返回格式 { success: boolean, data: any }
|
||||
// 按照项目具体情况修改该部分逻辑
|
||||
requestMethodInstance.use(async (ctx, next) => {
|
||||
await next();
|
||||
const { req, res } = ctx;
|
||||
// @ts-ignore
|
||||
if (req.options?.skipErrorHandler) {
|
||||
return;
|
||||
}
|
||||
const { options } = req;
|
||||
const { getResponse } = options;
|
||||
const resData = getResponse ? res.data : res;
|
||||
const errorInfo = errorAdaptor(resData, ctx);
|
||||
if (errorInfo.success === false) {
|
||||
// 抛出错误到 errorHandler 中处理
|
||||
const error: RequestError = new Error(errorInfo.errorMessage);
|
||||
error.name = 'BizError';
|
||||
error.data = resData;
|
||||
error.info = errorInfo;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// Add user custom middlewares
|
||||
const customMiddlewares = requestConfig.middlewares || [];
|
||||
customMiddlewares.forEach(mw => {
|
||||
requestMethodInstance.use(mw);
|
||||
});
|
||||
|
||||
// Add user custom interceptors
|
||||
const requestInterceptors = requestConfig.requestInterceptors || [];
|
||||
const responseInterceptors = requestConfig.responseInterceptors || [];
|
||||
requestInterceptors.map(ri => {
|
||||
requestMethodInstance.interceptors.request.use(ri);
|
||||
});
|
||||
responseInterceptors.map(ri => {
|
||||
requestMethodInstance.interceptors.response.use(ri);
|
||||
});
|
||||
|
||||
return requestMethodInstance;
|
||||
};
|
||||
|
||||
interface RequestMethodInUmi<R = false> {
|
||||
<T = any>(
|
||||
url: string,
|
||||
options: RequestOptionsWithResponse & { skipErrorHandler?: boolean },
|
||||
): Promise<RequestResponse<T>>;
|
||||
<T = any>(
|
||||
url: string,
|
||||
options: RequestOptionsWithoutResponse & { skipErrorHandler?: boolean },
|
||||
): Promise<T>;
|
||||
<T = any>(
|
||||
url: string,
|
||||
options?: RequestOptionsInit & { skipErrorHandler?: boolean },
|
||||
): R extends true ? Promise<RequestResponse<T>> : Promise<T>;
|
||||
}
|
||||
const request: RequestMethodInUmi = (url: any, options: any) => {
|
||||
const requestMethod = getRequestMethod();
|
||||
return requestMethod(url, options);
|
||||
};
|
||||
|
||||
export { request, useRequest, UseRequestProvider };
|
@ -1,59 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import './core/polyfill';
|
||||
import '@@/core/devScripts';
|
||||
import { plugin } from './core/plugin';
|
||||
import './core/pluginRegister';
|
||||
import { createHistory } from './core/history';
|
||||
import { ApplyPluginsType } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/runtime';
|
||||
import { renderClient } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/renderer-react/dist/index.js';
|
||||
import { getRoutes } from './core/routes';
|
||||
|
||||
|
||||
|
||||
|
||||
const getClientRender = (args: { hot?: boolean; routes?: any[] } = {}) => plugin.applyPlugins({
|
||||
key: 'render',
|
||||
type: ApplyPluginsType.compose,
|
||||
initialValue: () => {
|
||||
const opts = plugin.applyPlugins({
|
||||
key: 'modifyClientRenderOpts',
|
||||
type: ApplyPluginsType.modify,
|
||||
initialValue: {
|
||||
routes: args.routes || getRoutes(),
|
||||
plugin,
|
||||
history: createHistory(args.hot),
|
||||
isServer: process.env.__IS_SERVER,
|
||||
dynamicImport: true,
|
||||
rootElement: 'root',
|
||||
defaultTitle: `Comty™`,
|
||||
},
|
||||
});
|
||||
return renderClient(opts);
|
||||
},
|
||||
args,
|
||||
});
|
||||
|
||||
const clientRender = getClientRender();
|
||||
export default clientRender();
|
||||
|
||||
|
||||
window.g_umi = {
|
||||
version: '3.3.2',
|
||||
};
|
||||
|
||||
|
||||
// hot module replacement
|
||||
// @ts-ignore
|
||||
if (module.hot) {
|
||||
// @ts-ignore
|
||||
module.hot.accept('./core/routes', () => {
|
||||
const ret = require('./core/routes');
|
||||
if (ret.then) {
|
||||
ret.then(({ getRoutes }) => {
|
||||
getClientRender({ hot: true, routes: getRoutes() })();
|
||||
});
|
||||
} else {
|
||||
getClientRender({ hot: true, routes: ret.getRoutes() })();
|
||||
}
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user