From 975154d82ddcefb3283fce9970324b91285aee8c Mon Sep 17 00:00:00 2001 From: Xc Date: Thu, 27 Jun 2024 18:38:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E9=80=BB=E8=BE=91=E5=92=8C=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/create.js | 48 +++---- lib/interface.d.ts | 2 + lib/rename.js | 5 + src/create.ts | 45 ++++--- src/interface.ts | 2 + src/rename.ts | 6 + template/src/context/BackendRuntimeContext.ts | 12 -- .../src/context/FrontendRuntimeContext.ts | 17 --- template/src/initialize.ts | 2 +- template/web/public/index.html | 2 +- template/web/src/App.less | 1 - template/web/src/App.tsx | 19 --- template/web/src/AppContainer.tsx | 24 ---- template/web/src/AppError.tsx | 121 ------------------ template/web/src/AppRouter.tsx | 99 -------------- template/web/src/index.less | 4 +- template/web/src/index.tsx | 58 +-------- template/web/src/logo.svg | 1 - template/web/src/reportWebVitals.ts | 15 --- template/web/src/setupTests.ts | 5 - template/web/src/types/router.ts | 51 -------- template/web/src/utils/env.ts | 6 - template/web/src/utils/polyfill.ts | 15 --- templateFiles/BackendRuntimeContext.ts | 11 ++ templateFiles/FrontendRuntimeContext.ts | 11 ++ templateFiles/initialize.frontend.ts | 6 +- templateFiles/initialize.server.ts | 1 + templateFiles/initializeFeatures.ts | 8 +- 28 files changed, 105 insertions(+), 492 deletions(-) delete mode 100644 template/src/context/BackendRuntimeContext.ts delete mode 100644 template/src/context/FrontendRuntimeContext.ts delete mode 100644 template/web/src/App.less delete mode 100644 template/web/src/App.tsx delete mode 100644 template/web/src/AppContainer.tsx delete mode 100644 template/web/src/AppError.tsx delete mode 100644 template/web/src/AppRouter.tsx delete mode 100644 template/web/src/logo.svg delete mode 100644 template/web/src/reportWebVitals.ts delete mode 100644 template/web/src/setupTests.ts delete mode 100644 template/web/src/types/router.ts delete mode 100644 template/web/src/utils/env.ts delete mode 100644 template/web/src/utils/polyfill.ts create mode 100644 templateFiles/BackendRuntimeContext.ts create mode 100644 templateFiles/FrontendRuntimeContext.ts diff --git a/lib/create.js b/lib/create.js index ee1727c..e5736e5 100644 --- a/lib/create.js +++ b/lib/create.js @@ -25,16 +25,22 @@ const prompt = [ message: 'version', default: '1.0.0', }, - { - type: 'input', - name: 'title', - message: 'title of the project shown in App/Html' - }, { type: 'input', name: 'description', message: 'description', }, + { + name: 'useOgb', + type: 'confirm', + message: 'add oak-general-business into dependency?', + default: true, + }, { + name: 'moreDeps', + type: 'input', + message: 'do you have more dependent oak-family libraries? type their names, use comma as separator.', + default: '', + } ]; /** * 将项目的依赖关系加入 @@ -137,10 +143,16 @@ async function create(dirName, cmd) { message: `name`, default: dirName, }; - prompt.unshift(nameOption); + const titleOption = { + type: 'input', + name: 'title', + message: 'title of the project shown in App/Html', + default: dirName, + }; + prompt.unshift(nameOption, titleOption); const isDev = cmd.dev ? true : false; const isModule = cmd.module ? true : false; - const { name, version, title, description } = await inquirer_1.default.prompt(prompt); + const { name, version, title, description, useOgb, moreDeps } = await inquirer_1.default.prompt(prompt); // 获取tsconfig.json内容 const tsconfigJson = (0, template_1.tsConfigJsonContent)(); const tsConfigBuildJson = (0, template_1.tsConfigBuildJsonContent)(); @@ -197,27 +209,16 @@ async function create(dirName, cmd) { (0, file_handle_1.copyFolder)(currentPath, rootPath); await createWechatMpBoilplate(weChatMpRootPath, isDev); await createWebBoilplate(webRootPath, isDev); - if (!shelljs_1.default.which('npm')) { - (0, tip_style_1.Warn)((0, tip_style_1.warn)('Sorry, this script requires npm! Please install npm!')); - shelljs_1.default.exit(1); + /* if (!shell.which('npm')) { + Warn(warn('Sorry, this script requires npm! Please install npm!')); + shell.exit(1); } - /* Success(`${success(`Waiting...`)}`); + + Success(`${success(`Waiting...`)}`); Success(`${success(`Dependencies are now being installed`)}`); shell.cd(dirName).exec('npm install'); */ - (0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); } (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Successfully created project ${(0, tip_style_1.primary)(name)}, directory name is ${(0, tip_style_1.primary)(dirName)}`)}`); - const { useOgb, moreDeps } = await inquirer_1.default.prompt([{ - name: 'useOgb', - type: 'confirm', - message: 'add oak-general-business into dependency?', - default: true, - }, { - name: 'moreDeps', - type: 'input', - message: 'do you have more dependent oak-family libraries? type their names, use comma as separator.', - default: '', - }]); const deps = []; if (useOgb) { deps.push('oak-general-business'); @@ -242,6 +243,7 @@ async function create(dirName, cmd) { }); // 创建package.json (0, file_handle_1.checkFileExistsAndCreate)(packageJsonPath, packageJson, enum_1.checkFileExistsAndCreateType.FILE); + (0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Ok, type 'npm install' to install libs, then start!`)}`); } catch (err) { diff --git a/lib/interface.d.ts b/lib/interface.d.ts index b60b1c2..87b833f 100644 --- a/lib/interface.d.ts +++ b/lib/interface.d.ts @@ -23,6 +23,8 @@ export interface PromptInput { version: string; description: string; title: string; + useOgb: boolean; + moreDeps: string; } /** * @name project.config.json diff --git a/lib/rename.js b/lib/rename.js index dc58ef6..5216ee9 100644 --- a/lib/rename.js +++ b/lib/rename.js @@ -18,6 +18,11 @@ async function renameProject(dir, name, title, placeholderName, placeholderTitle const htmlContent = (0, fs_1.readFileSync)(htmlFilePath, 'utf-8'); const newHtmlContent = htmlContent.replace(new RegExp(placeholderTitle, 'g'), title).replace(new RegExp(placeholderTitle.toLowerCase(), 'g'), title.toLowerCase()); (0, fs_1.writeFileSync)(htmlFilePath, newHtmlContent, 'utf-8'); + // index.tsx下的title + const indexTsxPath = (0, path_1.join)(dir, 'web', 'src/index.tsx'); + const tsxContent = (0, fs_1.readFileSync)(indexTsxPath, 'utf-8'); + const newTsxlContent = tsxContent.replace(new RegExp(placeholderName, 'g'), name).replace(new RegExp(placeholderName.toLowerCase(), 'g'), name.toLowerCase()); + (0, fs_1.writeFileSync)(indexTsxPath, newTsxlContent, 'utf-8'); // replace wechatMp下project.config.json中的projectname // todo,现在这个是在wechatMp/src目录下的,可能是搞错了,待修正 const pcjFilePath = (0, path_1.join)(dir, 'wechatMp', 'src', 'project.config.json'); diff --git a/src/create.ts b/src/create.ts index a7702c3..89d7751 100644 --- a/src/create.ts +++ b/src/create.ts @@ -56,16 +56,22 @@ const prompt = [ message: 'version', default: '1.0.0', }, - { - type: 'input', - name: 'title', - message: 'title of the project shown in App/Html' - }, { type: 'input', name: 'description', message: 'description', }, + { + name: 'useOgb', + type: 'confirm', + message: 'add oak-general-business into dependency?', + default: true, + }, { + name: 'moreDeps', + type: 'input', + message: 'do you have more dependent oak-family libraries? type their names, use comma as separator.', + default: '', + } ]; /** @@ -220,11 +226,17 @@ export async function create(dirName: string, cmd: any) { message: `name`, default: dirName, }; - prompt.unshift(nameOption); + const titleOption = { + type: 'input', + name: 'title', + message: 'title of the project shown in App/Html', + default: dirName, + }; + prompt.unshift(nameOption, titleOption); const isDev = cmd.dev ? true : false; const isModule = cmd.module ? true : false; - const { name, version, title, description }: PromptInput = await inquirer.prompt( + const { name, version, title, description, useOgb, moreDeps }: PromptInput = await inquirer.prompt( prompt ); @@ -311,19 +323,16 @@ export async function create(dirName: string, cmd: any) { await createWechatMpBoilplate(weChatMpRootPath, isDev); await createWebBoilplate(webRootPath, isDev); - if (!shell.which('npm')) { + /* if (!shell.which('npm')) { Warn(warn('Sorry, this script requires npm! Please install npm!')); shell.exit(1); } - /* Success(`${success(`Waiting...`)}`); + Success(`${success(`Waiting...`)}`); Success(`${success(`Dependencies are now being installed`)}`); shell.cd(dirName).exec('npm install'); */ - - renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); } - Success( `${success( `Successfully created project ${primary( @@ -332,17 +341,6 @@ export async function create(dirName: string, cmd: any) { )}` ); - const { useOgb, moreDeps } = await inquirer.prompt([{ - name: 'useOgb', - type: 'confirm', - message: 'add oak-general-business into dependency?', - default: true, - }, { - name: 'moreDeps', - type: 'input', - message: 'do you have more dependent oak-family libraries? type their names, use comma as separator.', - default: '', - }]); const deps = [] as string[]; if (useOgb) { deps.push('oak-general-business'); @@ -381,6 +379,7 @@ export async function create(dirName: string, cmd: any) { checkFileExistsAndCreateType.FILE ); + renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); Success( `${success( `Ok, type 'npm install' to install libs, then start!` diff --git a/src/interface.ts b/src/interface.ts index 0c6dd53..885e7e8 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -26,6 +26,8 @@ export interface PromptInput { version: string, description: string, title: string, + useOgb: boolean; + moreDeps: string; } /** diff --git a/src/rename.ts b/src/rename.ts index 15c8b81..54ae08a 100644 --- a/src/rename.ts +++ b/src/rename.ts @@ -26,6 +26,12 @@ export async function renameProject(dir: string, name: string, title: string, pl const newHtmlContent = htmlContent.replace(new RegExp(placeholderTitle, 'g'), title).replace(new RegExp(placeholderTitle.toLowerCase(), 'g'), title.toLowerCase()); writeFileSync(htmlFilePath, newHtmlContent, 'utf-8'); + // index.tsx下的title + const indexTsxPath = join(dir, 'web', 'src/index.tsx'); + const tsxContent = readFileSync(indexTsxPath, 'utf-8'); + const newTsxlContent = tsxContent.replace(new RegExp(placeholderName, 'g'), name).replace(new RegExp(placeholderName.toLowerCase(), 'g'), name.toLowerCase()); + writeFileSync(indexTsxPath, newTsxlContent, 'utf-8'); + // replace wechatMp下project.config.json中的projectname // todo,现在这个是在wechatMp/src目录下的,可能是搞错了,待修正 const pcjFilePath = join(dir, 'wechatMp', 'src', 'project.config.json'); diff --git a/template/src/context/BackendRuntimeContext.ts b/template/src/context/BackendRuntimeContext.ts deleted file mode 100644 index e52e6bf..0000000 --- a/template/src/context/BackendRuntimeContext.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { EntityDict } from '@project/oak-app-domain'; -import { RuntimeContext } from './RuntimeContext'; -import { BackendRuntimeContext as DependentBackendRuntimeContext } from './DependentContext'; - -export class BackendRuntimeContext extends DependentBackendRuntimeContext implements RuntimeContext { - async toString() { - const data = await this.getSerializedData(); - return JSON.stringify(data); - } -}; - -export default BackendRuntimeContext; \ No newline at end of file diff --git a/template/src/context/FrontendRuntimeContext.ts b/template/src/context/FrontendRuntimeContext.ts deleted file mode 100644 index 40e97f9..0000000 --- a/template/src/context/FrontendRuntimeContext.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { EntityDict } from '@project/oak-app-domain'; -import { - FrontendRuntimeContext as DependentFrontendRuntimeContext, -} from './DependentContext'; -import { RuntimeContext } from './RuntimeContext'; - -export class FrontendRuntimeContext - extends DependentFrontendRuntimeContext - implements RuntimeContext -{ - async toString() { - const data = await this.getSerializedData(); - return JSON.stringify(data); - } -} - -export default FrontendRuntimeContext; \ No newline at end of file diff --git a/template/src/initialize.ts b/template/src/initialize.ts index 34c4a48..4e469da 100644 --- a/template/src/initialize.ts +++ b/template/src/initialize.ts @@ -1,4 +1,4 @@ -import initialize from './initialize.dev'; +import initialize from './initialize.frontend'; export default initialize; console.log('不应该走到这里'); diff --git a/template/web/public/index.html b/template/web/public/index.html index c5a80e4..bd189ab 100644 --- a/template/web/public/index.html +++ b/template/web/public/index.html @@ -81,7 +81,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - + oak template project diff --git a/template/web/src/App.less b/template/web/src/App.less deleted file mode 100644 index 77472d6..0000000 --- a/template/web/src/App.less +++ /dev/null @@ -1 +0,0 @@ -@import '@project/config/styles/web/index.less'; // 少量公共样式 diff --git a/template/web/src/App.tsx b/template/web/src/App.tsx deleted file mode 100644 index db9d8af..0000000 --- a/template/web/src/App.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; - -import './App.less'; -import AppContainer from './AppContainer'; -import AppRouter from './AppRouter'; -import AppError from './AppError'; - -function App(props: { error?: any }) { - if (props.error) { - return ; - } - return ( - - - - ); -} - -export default App; diff --git a/template/web/src/AppContainer.tsx b/template/web/src/AppContainer.tsx deleted file mode 100644 index 314e509..0000000 --- a/template/web/src/AppContainer.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React, { lazy } from 'react'; -const Message = lazy(() => import('oak-frontend-base/es/components/message')); -const DebugPanel = lazy(() => import('oak-frontend-base/es/components/func/debugPanel')); - -type AppContainerProps = { - children?: React.ReactNode; -}; - -const AppContainer = (props: AppContainerProps) => { - const { children } = props; - return ( - - }> - - - {children} - }> - {process.env.NODE_ENV === 'development' && } - - - ); -}; - -export default AppContainer; diff --git a/template/web/src/AppError.tsx b/template/web/src/AppError.tsx deleted file mode 100644 index f59eac7..0000000 --- a/template/web/src/AppError.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import React, { lazy } from 'react'; -import { Button, Space } from 'antd'; - -import { - OakException, - OakExternalException, - OakNetworkException, - OakServerProxyException, -} from 'oak-domain/lib/types/Exception'; -import { ECode } from 'oak-frontend-base/es/types/ErrorPage'; -const ErrorPage = lazy(() => import('oak-frontend-base/es/components/errorPage')); - -interface ErrorProps { - error: any; -} - -function Error(props: ErrorProps) { - const { error } = props; - - if (error instanceof OakException) { - if (error instanceof OakNetworkException) { - // 网络中断出现的异常 - return ( - - - - - ); - } - if (error instanceof OakServerProxyException) { - // 服务器代理异常 - return ( - - - - - ); - } - - return ( - - - - - ); - } - - return ( - - - - - ); -} - -function ErrorMessage(props: { error: any }) { - const { error } = props; - if (process.env.NODE_ENV === 'development') { - return ( - - {typeof error === 'object' ? error.message : error} - - ); - } - return null; -} - -export default Error; diff --git a/template/web/src/AppRouter.tsx b/template/web/src/AppRouter.tsx deleted file mode 100644 index f9581f1..0000000 --- a/template/web/src/AppRouter.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import React from 'react'; -import { Routes, Route, Outlet, useLocation } from 'react-router-dom'; -import { IRouter, IBrowserRouterProps, IMeta } from './types/router'; -import routers from './app/routers'; -import Loading from './app/components/Loading'; -import useFeatures from '@project/hooks/useFeatures'; - -type TRenderRoutes = ( - routes?: IRouter[], - breadcrumbs?: string[] -) => React.ReactNode[] | null; - -/** - * 渲染应用路由 - * @param routes - * @param breadcrumb - */ -const renderRoutes: TRenderRoutes = (routes = [], breadcrumb = []) => { - if (routes.length === 0) return null; - return routes.map((route, index: number) => { - const { Component, children, namespace, meta, isFirst, customRouter } = - route; - let currentBreadcrumb = breadcrumb; - let props = {}; - if (isFirst) { - props = { - index: true, - }; - } else { - props = { - path: route.path, - }; - } - return ( - - } - > - {renderRoutes(children, currentBreadcrumb)} - - ); - }); -}; - -const Guard = React.memo( - (props: { - Component?: React.FC | (() => any); - namespace?: string; - meta?: IMeta; - breadcrumb: string[]; - customRouter?: boolean; - }) => { - const { Component, namespace, meta, breadcrumb, customRouter } = props; - const features = useFeatures(); - const location = useLocation(); - const { pathname } = location; - const path = namespace ? pathname.slice(namespace.length) : pathname; - const i18nNs = `taicang-p-${ - path.startsWith('/') - ? path.slice(1).replaceAll(/\//g, '-') - : path.replaceAll(/\//g, '-') - }`; - - if (i18nNs) { - const windowTitle = features.locales.hasKey(`${i18nNs}.pageTitle`); - if (windowTitle) { - breadcrumb.push(windowTitle); - window.document.title = windowTitle; - } - } - - return Component ? ( - }> - - - ) : ( - - ); - } -); - -const AppRouter = React.memo(() => ( - {renderRoutes(routers)} -)); - -export default AppRouter; diff --git a/template/web/src/index.less b/template/web/src/index.less index 833d4fe..46de38f 100644 --- a/template/web/src/index.less +++ b/template/web/src/index.less @@ -1,3 +1,5 @@ +@import '@project/config/styles/web/index.less'; // 少量公共样式 + body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', @@ -16,4 +18,4 @@ html, body, #root { height: 100%; -} \ No newline at end of file +} diff --git a/template/web/src/index.tsx b/template/web/src/index.tsx index 489d8ea..ae247b6 100644 --- a/template/web/src/index.tsx +++ b/template/web/src/index.tsx @@ -1,26 +1,12 @@ -import './utils/polyfill'; import React from 'react'; -import ReactDOM from 'react-dom/client'; -import { createBrowserHistory } from 'history'; -import { unstable_HistoryRouter as HistoryRouter } from 'react-router-dom'; -import { ConfigProvider } from 'antd'; -import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs'; -import dayjs from 'dayjs'; -import 'dayjs/locale/zh-cn'; -import zhCN from 'antd/locale/zh_CN'; - -import { - ResponsiveProvider, - FeaturesProvider, -} from 'oak-frontend-base/es/platforms/web'; +import { EntityDict } from '@project/oak-app-domain'; import './index.less'; -import App from './App'; -import reportWebVitals from './reportWebVitals'; import { handler as exceptionHandler } from '@project/exceptionHandler'; import initializeFeatures from '@project/initializeFeatures'; +import initialize from 'oak-frontend-base/es/platforms/web/initialize'; +import routers from './app/routers'; import { features } from './initialize'; -dayjs.locale('zh-cn'); window.addEventListener('unhandledrejection', async (event) => { // 全局捕获异常处理 @@ -31,13 +17,6 @@ window.addEventListener('unhandledrejection', async (event) => { } }); -const root = ReactDOM.createRoot( - document.getElementById('root') as HTMLElement -); - -const history = createBrowserHistory(); -features.navigator.setHistory(history); - const init = async () => { let error; try { @@ -45,33 +24,8 @@ const init = async () => { } catch (err) { error = err; } - // 抓到异常处理 1、token过期 2、网络断了 3、接口请求失败 - root.render( - - - - - - - - - - - - - ); + + initialize(features, 'oak_template', routers, undefined, error); }; -init(); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); +init(); \ No newline at end of file diff --git a/template/web/src/logo.svg b/template/web/src/logo.svg deleted file mode 100644 index 9dfc1c0..0000000 --- a/template/web/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/template/web/src/reportWebVitals.ts b/template/web/src/reportWebVitals.ts deleted file mode 100644 index 49a2a16..0000000 --- a/template/web/src/reportWebVitals.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ReportHandler } from 'web-vitals'; - -const reportWebVitals = (onPerfEntry?: ReportHandler) => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/template/web/src/setupTests.ts b/template/web/src/setupTests.ts deleted file mode 100644 index 8f2609b..0000000 --- a/template/web/src/setupTests.ts +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom'; diff --git a/template/web/src/types/router.ts b/template/web/src/types/router.ts deleted file mode 100644 index 2b70b28..0000000 --- a/template/web/src/types/router.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { BrowserRouterProps } from 'react-router-dom'; - -export interface IBrowserRouterProps extends BrowserRouterProps { - namespace: string; - oakDisablePulldownRefresh?: boolean; - navigationBarTitleText?: string; - customRouter?: boolean; //表示自定义路由 -} - -export type IMeta = { - navigationBarTitleText?: string; - Icon?: React.FC; - oakDisablePulldownRefresh?: boolean; -} - -export interface IRouter { - path: string; - /** - * 是否为根路由 - */ - isFirst?: boolean; - namespace?: string; - customRouter?: boolean; //表示自定义路由 - Component?: React.FC | (() => any); - /** - * 当前路由是否全屏显示 - */ - isFullPage?: boolean; - /** - * meta - */ - meta?: IMeta; - children?: IRouter[]; -} - - -// 文件path -type FilePath = string; - -// 路由path 如果不传 就直接 文件Path当作路由path -type RoutePath = string | undefined | null; - -// 设置根路由 -type IsFirst = boolean; - -// 项目路径别名 -export type Project = '@project'; - - -// [项目别名, 文件path,[嵌套路由顶层path],设置根路由, 路由path] -export type Page = [Project, FilePath, Array?, IsFirst?, RoutePath?]; diff --git a/template/web/src/utils/env.ts b/template/web/src/utils/env.ts deleted file mode 100644 index 88e2d4b..0000000 --- a/template/web/src/utils/env.ts +++ /dev/null @@ -1,6 +0,0 @@ -export function getAppType() { - if (/MicroMessenger/i.test(window.navigator.userAgent)) { - return 'wechatPublic'; - } - return 'web'; -} \ No newline at end of file diff --git a/template/web/src/utils/polyfill.ts b/template/web/src/utils/polyfill.ts deleted file mode 100644 index 1fac444..0000000 --- a/template/web/src/utils/polyfill.ts +++ /dev/null @@ -1,15 +0,0 @@ - -Object.assign(global, { - fetch: fetch, - getRandomValues: async function getRandomValues(length: number) { - if (length > 65536) { - throw new Error('Can only request a maximum of 65536 bytes'); - } - const randomValues = window.crypto.getRandomValues( - new Uint8Array(length) - ); - - - return new Uint8Array(randomValues); - }, -}); diff --git a/templateFiles/BackendRuntimeContext.ts b/templateFiles/BackendRuntimeContext.ts new file mode 100644 index 0000000..2ae4c51 --- /dev/null +++ b/templateFiles/BackendRuntimeContext.ts @@ -0,0 +1,11 @@ +import { EntityDict } from '@project/oak-app-domain'; +import { RuntimeContext } from './RuntimeContext'; + +export class BackendRuntimeContext extends BaseBackendRuntimeContext implements RuntimeContext { + async toString() { + const data = await this.getSerializedData(); + return JSON.stringify(data); + } +}; + +export default BackendRuntimeContext; \ No newline at end of file diff --git a/templateFiles/FrontendRuntimeContext.ts b/templateFiles/FrontendRuntimeContext.ts new file mode 100644 index 0000000..6e204f4 --- /dev/null +++ b/templateFiles/FrontendRuntimeContext.ts @@ -0,0 +1,11 @@ +import { EntityDict } from '@project/oak-app-domain'; +import { RuntimeContext } from './RuntimeContext'; + +export class FrontendRuntimeContext extends BaseFrontendRuntimeContext implements RuntimeContext { + async toString() { + const data = await this.getSerializedData(); + return JSON.stringify(data); + } +} + +export default FrontendRuntimeContext; \ No newline at end of file diff --git a/templateFiles/initialize.frontend.ts b/templateFiles/initialize.frontend.ts index d10b506..02bc6ef 100644 --- a/templateFiles/initialize.frontend.ts +++ b/templateFiles/initialize.frontend.ts @@ -29,8 +29,7 @@ export default function initialize() { totalData = mergeConcatMany([data] as Array)!, totalImportations = mergeConcatMany([importations] as Array)!, totalExportations = mergeConcatMany([exportations] as Array)!, - totalCommon = mergeConcatMany([common] as Array)!, - totalRender = mergeConcatMany([render] as Array)!; + totalCommon = mergeConcatMany([common] as Array)!; const debugConnector = new DebugConnector( storageSchema, @@ -48,13 +47,14 @@ export default function initialize() { ); const totalFeatures = {} as FeatureDict & BasicFeatures; + // @ts-ignore const { features } = initFrontend( storageSchema, (store) => new FrontendRuntimeContext(store, totalFeatures), debugConnector, totalCheckers, totalCommon, - totalRender + render ); Object.assign(totalFeatures, features); diff --git a/templateFiles/initialize.server.ts b/templateFiles/initialize.server.ts index 5940088..6cc3c9e 100644 --- a/templateFiles/initialize.server.ts +++ b/templateFiles/initialize.server.ts @@ -24,6 +24,7 @@ export default function initialize() { totalRender = mergeConcatMany([render] as Array)!; const totalFeatures = {} as FeatureDict & BasicFeatures; + // @ts-ignore const { features } = initFrontend( storageSchema, (store) => new FrontendRuntimeContext(store, totalFeatures), diff --git a/templateFiles/initializeFeatures.ts b/templateFiles/initializeFeatures.ts index f33bcae..28c2e93 100644 --- a/templateFiles/initializeFeatures.ts +++ b/templateFiles/initializeFeatures.ts @@ -2,7 +2,11 @@ import { FeatureDict } from '@project/features'; import { BasicFeatures } from 'oak-frontend-base/es/features'; import { EntityDict } from '@project/oak-app-domain'; - +/** + * Initialize your features when app loads. + * If you use the oak-general-business, then remember to call the initial function in "oak-general-business/es/features/index". + * @param features + */ export default async function initialize(features: FeatureDict & BasicFeatures) { - // 项目自己的features如果有初始化写在这里 + } \ No newline at end of file