From 0980990d0e45c832398607f1f8731fefc93666ac Mon Sep 17 00:00:00 2001 From: srgooglo Date: Tue, 5 Jan 2021 08:11:12 +0100 Subject: [PATCH] clean --- packages/comty/package.json | 1 - packages/comty/src/.umi/core/devScripts.ts | 51 ---- packages/comty/src/.umi/core/history.ts | 21 -- packages/comty/src/.umi/core/plugin.ts | 8 - .../comty/src/.umi/core/pluginConfig.d.ts | 209 ------------- .../comty/src/.umi/core/pluginRegister.ts | 18 -- packages/comty/src/.umi/core/polyfill.ts | 3 - packages/comty/src/.umi/core/routes.ts | 111 ------- packages/comty/src/.umi/core/umiExports.ts | 9 - packages/comty/src/.umi/plugin-dva/connect.ts | 87 ------ packages/comty/src/.umi/plugin-dva/dva.ts | 77 ----- packages/comty/src/.umi/plugin-dva/exports.ts | 4 - .../comty/src/.umi/plugin-dva/runtime.tsx | 8 - .../comty/src/.umi/plugin-helmet/exports.ts | 3 - .../.umi/plugin-initial-state/Provider.tsx | 37 --- .../src/.umi/plugin-initial-state/exports.ts | 7 - .../models/initialState.ts | 2 - .../src/.umi/plugin-initial-state/runtime.tsx | 13 - .../comty/src/.umi/plugin-model/Provider.tsx | 39 --- .../comty/src/.umi/plugin-model/runtime.tsx | 12 - .../comty/src/.umi/plugin-model/useModel.tsx | 71 ----- .../comty/src/.umi/plugin-request/request.ts | 276 ------------------ packages/comty/src/.umi/umi.ts | 59 ---- 23 files changed, 1126 deletions(-) delete mode 100644 packages/comty/src/.umi/core/devScripts.ts delete mode 100644 packages/comty/src/.umi/core/history.ts delete mode 100644 packages/comty/src/.umi/core/plugin.ts delete mode 100644 packages/comty/src/.umi/core/pluginConfig.d.ts delete mode 100644 packages/comty/src/.umi/core/pluginRegister.ts delete mode 100644 packages/comty/src/.umi/core/polyfill.ts delete mode 100644 packages/comty/src/.umi/core/routes.ts delete mode 100644 packages/comty/src/.umi/core/umiExports.ts delete mode 100644 packages/comty/src/.umi/plugin-dva/connect.ts delete mode 100644 packages/comty/src/.umi/plugin-dva/dva.ts delete mode 100644 packages/comty/src/.umi/plugin-dva/exports.ts delete mode 100644 packages/comty/src/.umi/plugin-dva/runtime.tsx delete mode 100644 packages/comty/src/.umi/plugin-helmet/exports.ts delete mode 100644 packages/comty/src/.umi/plugin-initial-state/Provider.tsx delete mode 100644 packages/comty/src/.umi/plugin-initial-state/exports.ts delete mode 100644 packages/comty/src/.umi/plugin-initial-state/models/initialState.ts delete mode 100644 packages/comty/src/.umi/plugin-initial-state/runtime.tsx delete mode 100644 packages/comty/src/.umi/plugin-model/Provider.tsx delete mode 100644 packages/comty/src/.umi/plugin-model/runtime.tsx delete mode 100644 packages/comty/src/.umi/plugin-model/useModel.tsx delete mode 100644 packages/comty/src/.umi/plugin-request/request.ts delete mode 100644 packages/comty/src/.umi/umi.ts diff --git a/packages/comty/package.json b/packages/comty/package.json index 8abbefd8..60550647 100644 --- a/packages/comty/package.json +++ b/packages/comty/package.json @@ -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", diff --git a/packages/comty/src/.umi/core/devScripts.ts b/packages/comty/src/.umi/core/devScripts.ts deleted file mode 100644 index b4e80d16..00000000 --- a/packages/comty/src/.umi/core/devScripts.ts +++ /dev/null @@ -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, - }); -} - \ No newline at end of file diff --git a/packages/comty/src/.umi/core/history.ts b/packages/comty/src/.umi/core/history.ts deleted file mode 100644 index eb162433..00000000 --- a/packages/comty/src/.umi/core/history.ts +++ /dev/null @@ -1,21 +0,0 @@ -// @ts-nocheck -import { createBrowserHistory } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/@umijs/runtime'; - -let options = { - "basename": "/" -}; -if ((window).routerBase) { - options.basename = (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 }; diff --git a/packages/comty/src/.umi/core/plugin.ts b/packages/comty/src/.umi/core/plugin.ts deleted file mode 100644 index 9ec03e71..00000000 --- a/packages/comty/src/.umi/core/plugin.ts +++ /dev/null @@ -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 }; diff --git a/packages/comty/src/.umi/core/pluginConfig.d.ts b/packages/comty/src/.umi/core/pluginConfig.d.ts deleted file mode 100644 index faa0f696..00000000 --- a/packages/comty/src/.umi/core/pluginConfig.d.ts +++ /dev/null @@ -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; -} diff --git a/packages/comty/src/.umi/core/pluginRegister.ts b/packages/comty/src/.umi/core/pluginRegister.ts deleted file mode 100644 index 51b37488..00000000 --- a/packages/comty/src/.umi/core/pluginRegister.ts +++ /dev/null @@ -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', - }); diff --git a/packages/comty/src/.umi/core/polyfill.ts b/packages/comty/src/.umi/core/polyfill.ts deleted file mode 100644 index 5ff6c3d6..00000000 --- a/packages/comty/src/.umi/core/polyfill.ts +++ /dev/null @@ -1,3 +0,0 @@ -// @ts-nocheck -import 'core-js'; -import 'regenerator-runtime/runtime'; diff --git a/packages/comty/src/.umi/core/routes.ts b/packages/comty/src/.umi/core/routes.ts deleted file mode 100644 index 20878efb..00000000 --- a/packages/comty/src/.umi/core/routes.ts +++ /dev/null @@ -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; -} diff --git a/packages/comty/src/.umi/core/umiExports.ts b/packages/comty/src/.umi/core/umiExports.ts deleted file mode 100644 index 916f5b8a..00000000 --- a/packages/comty/src/.umi/core/umiExports.ts +++ /dev/null @@ -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'; diff --git a/packages/comty/src/.umi/plugin-dva/connect.ts b/packages/comty/src/.umi/plugin-dva/connect.ts deleted file mode 100644 index e5b27225..00000000 --- a/packages/comty/src/.umi/plugin-dva/connect.ts +++ /dev/null @@ -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 { - type: T -} - -export type Reducer = ( - state: S | undefined, - action: A -) => S; - -export type ImmerReducer = ( - 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 =

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

; - location: Location & { query: T }; - history: History; - route: IRoute; -} - -export type RequiredConnectProps< - P extends { [K in keyof P]?: string } = {}, - S = LocationState, - T = {} - > = Required> - -/** - * @type T: React props - * @type U: match props types - */ -export type ConnectRC< - T = {}, - U = {}, - S = {}, - Q = {} -> = React.ForwardRefRenderFunction>; - diff --git a/packages/comty/src/.umi/plugin-dva/dva.ts b/packages/comty/src/.umi/plugin-dva/dva.ts deleted file mode 100644 index 505ca26d..00000000 --- a/packages/comty/src/.umi/plugin-dva/dva.ts +++ /dev/null @@ -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()(); - } -} diff --git a/packages/comty/src/.umi/plugin-dva/exports.ts b/packages/comty/src/.umi/plugin-dva/exports.ts deleted file mode 100644 index 05933350..00000000 --- a/packages/comty/src/.umi/plugin-dva/exports.ts +++ /dev/null @@ -1,4 +0,0 @@ -// @ts-nocheck - -export { connect, useDispatch, useStore, useSelector } from 'dva'; -export { getApp as getDvaApp } from './dva'; diff --git a/packages/comty/src/.umi/plugin-dva/runtime.tsx b/packages/comty/src/.umi/plugin-dva/runtime.tsx deleted file mode 100644 index 25af9b08..00000000 --- a/packages/comty/src/.umi/plugin-dva/runtime.tsx +++ /dev/null @@ -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); -} - diff --git a/packages/comty/src/.umi/plugin-helmet/exports.ts b/packages/comty/src/.umi/plugin-helmet/exports.ts deleted file mode 100644 index 7c4c027f..00000000 --- a/packages/comty/src/.umi/plugin-helmet/exports.ts +++ /dev/null @@ -1,3 +0,0 @@ -// @ts-nocheck -// @ts-ignore -export { Helmet } from '/Users/srgooglo/repos/comty/packages/comty/node_modules/react-helmet'; diff --git a/packages/comty/src/.umi/plugin-initial-state/Provider.tsx b/packages/comty/src/.umi/plugin-initial-state/Provider.tsx deleted file mode 100644 index 72fef416..00000000 --- a/packages/comty/src/.umi/plugin-initial-state/Provider.tsx +++ /dev/null @@ -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; -}; diff --git a/packages/comty/src/.umi/plugin-initial-state/exports.ts b/packages/comty/src/.umi/plugin-initial-state/exports.ts deleted file mode 100644 index 8c0290e1..00000000 --- a/packages/comty/src/.umi/plugin-initial-state/exports.ts +++ /dev/null @@ -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; diff --git a/packages/comty/src/.umi/plugin-initial-state/models/initialState.ts b/packages/comty/src/.umi/plugin-initial-state/models/initialState.ts deleted file mode 100644 index 4ee992f2..00000000 --- a/packages/comty/src/.umi/plugin-initial-state/models/initialState.ts +++ /dev/null @@ -1,2 +0,0 @@ -// @ts-nocheck -export default () => ({ loading: false, refresh: () => {} }) \ No newline at end of file diff --git a/packages/comty/src/.umi/plugin-initial-state/runtime.tsx b/packages/comty/src/.umi/plugin-initial-state/runtime.tsx deleted file mode 100644 index 870ae68b..00000000 --- a/packages/comty/src/.umi/plugin-initial-state/runtime.tsx +++ /dev/null @@ -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, - ); -} diff --git a/packages/comty/src/.umi/plugin-model/Provider.tsx b/packages/comty/src/.umi/plugin-model/Provider.tsx deleted file mode 100644 index 348dc485..00000000 --- a/packages/comty/src/.umi/plugin-model/Provider.tsx +++ /dev/null @@ -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 = { - [key in keyof typeof models]: ReturnType; -}; - -export type Models = Model[T] - -const dispatcher = new Dispatcher!(); -const Exe = Executor!; - -export default ({ children }: { children: React.ReactNode }) => { - - return ( - - { - Object.entries(models).map(pair => ( - { - const [ns] = pair as [keyof typeof models, any]; - dispatcher.data[ns] = val; - dispatcher.update(ns); - }} /> - )) - } - {children} - - ) -} diff --git a/packages/comty/src/.umi/plugin-model/runtime.tsx b/packages/comty/src/.umi/plugin-model/runtime.tsx deleted file mode 100644 index fbfa5f6c..00000000 --- a/packages/comty/src/.umi/plugin-model/runtime.tsx +++ /dev/null @@ -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, - ); -} diff --git a/packages/comty/src/.umi/plugin-model/useModel.tsx b/packages/comty/src/.umi/plugin-model/useModel.tsx deleted file mode 100644 index e6e7adc2..00000000 --- a/packages/comty/src/.umi/plugin-model/useModel.tsx +++ /dev/null @@ -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 = Model[T] - -export function useModel>(model: T): Model[T] -export function useModel, U>(model: T, selector: (model: Model[T]) => U): U - -export function useModel, U>( - namespace: T, - updater?: (model: Model[T]) => U -) : typeof updater extends undefined ? Model[T] : ReturnType>{ - - type RetState = typeof updater extends undefined ? Model[T] : ReturnType> - const dispatcher = useContext(UmiContext); - const updaterRef = useRef(updater); - updaterRef.current = updater; - const [state, setState] = useState( - () => updaterRef.current ? updaterRef.current(dispatcher.data![namespace]) : dispatcher.data![namespace] - ); - const stateRef = useRef(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; -}; diff --git a/packages/comty/src/.umi/plugin-request/request.ts b/packages/comty/src/.umi/plugin-request/request.ts deleted file mode 100644 index b5d04a61..00000000 --- a/packages/comty/src/.umi/plugin-request/request.ts +++ /dev/null @@ -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 = { data?: T; [key: string]: any }; - -function useRequest< - R = any, - P extends any[] = any, - U = any, - UU extends U = any ->( - service: CombineService, - options: OptionsWithFormat, -): BaseResult; -function useRequest( - service: CombineService, - options?: BaseOptions, -): BaseResult; -function useRequest( - service: CombineService>, - options: LoadMoreOptionsWithFormat, -): LoadMoreResult; -function useRequest< - R extends ResultWithData = any, - RR extends R = any ->( - service: CombineService>, - options: LoadMoreOptions, -): LoadMoreResult; - -function useRequest( - service: CombineService, - options: PaginatedOptionsWithFormat, -): PaginatedResult; -function useRequest( - service: CombineService< - ResultWithData>, - PaginatedParams - >, - options: BasePaginatedOptions, -): PaginatedResult; -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 { - ( - url: string, - options: RequestOptionsWithResponse & { skipErrorHandler?: boolean }, - ): Promise>; - ( - url: string, - options: RequestOptionsWithoutResponse & { skipErrorHandler?: boolean }, - ): Promise; - ( - url: string, - options?: RequestOptionsInit & { skipErrorHandler?: boolean }, - ): R extends true ? Promise> : Promise; -} -const request: RequestMethodInUmi = (url: any, options: any) => { - const requestMethod = getRequestMethod(); - return requestMethod(url, options); -}; - -export { request, useRequest, UseRequestProvider }; diff --git a/packages/comty/src/.umi/umi.ts b/packages/comty/src/.umi/umi.ts deleted file mode 100644 index 914da49f..00000000 --- a/packages/comty/src/.umi/umi.ts +++ /dev/null @@ -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() })(); - } - }); -}