-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
208 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**/*.ts | ||
|
||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
|
||
module.exports = { | ||
extends: [ | ||
'@webank/eslint-config-webank/vue.js' | ||
], | ||
extends: ['@webank/eslint-config-webank/vue.js'], | ||
globals: { | ||
// 这里填入你的项目需要的全局变量 | ||
// 这里值为 false 表示这个全局变量不允许被重新赋值,比如: | ||
// | ||
// Vue: false | ||
__DEV__: false | ||
__DEV__: false, | ||
}, | ||
rules: { | ||
'vue/comment-directive': 'off', | ||
'global-require': 'off', | ||
'import/no-unresolved': 'off', | ||
'no-restricted-syntax': 'off', | ||
'no-undefined': 'off', | ||
'vue/valid-template-root': 'off' | ||
'vue/valid-template-root': 'off', | ||
}, | ||
env: { | ||
jest: true | ||
} | ||
jest: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,6 @@ | |
"@fesjs/compiler": "^2.0.5", | ||
"@fesjs/utils": "^2.0.4", | ||
"axios": "0.21.1" | ||
} | ||
} | ||
}, | ||
"typings": "./types.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
|
||
export interface RequestBuildConfig { | ||
request: { | ||
dataField: string | ||
} | ||
} | ||
|
||
|
||
type RequestInterceptor = (value: AxiosRequestConfig) => AxiosRequestConfig | [(value: AxiosRequestConfig) => AxiosRequestConfig, (error: any) => any]; | ||
type ResponseInterceptor = (value: AxiosResponse) => AxiosResponse | [(value: AxiosResponse) => AxiosResponse, (error: any) => any]; | ||
|
||
|
||
export interface RequestRuntimeConfig { | ||
request: { | ||
responseDataAdaptor?<T>(data: T): T; | ||
closeResDataCheck?: boolean; | ||
requestInterceptors?: RequestInterceptor[]; | ||
responseInterceptors?: ResponseInterceptor[]; | ||
errorHandler: { | ||
[key: string]: (error: { response: AxiosResponse } | AxiosResponse) => void; | ||
}; | ||
} & AxiosRequestConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/fes-preset-built-in/src/plugins/generateFiles/genType.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function importsToStr(imports) { | ||
return imports.map((imp) => { | ||
const { source, specifier } = imp; | ||
if (specifier) { | ||
return `import {${specifier.join(', ')}} from '${source}';`; | ||
} | ||
return ''; | ||
}); | ||
} | ||
|
||
function genTypeContent(name, imports) { | ||
return { | ||
TYP_NAME: name, | ||
TYPES: imports.reduce((previousValue, currentValue) => previousValue.concat(currentValue.specifier || []), []).join(' & '), | ||
imports: importsToStr(imports).join('\n'), | ||
}; | ||
} | ||
|
||
export default function (api) { | ||
const { | ||
utils: { Mustache }, | ||
} = api; | ||
|
||
api.onGenerateFiles(async () => { | ||
const runtimeTypeName = 'PluginRuntimeConfig'; | ||
const buildTypeName = 'PluginBuildConfig'; | ||
const typeTpl = ` | ||
{{{ imports }}} | ||
export type {{{TYP_NAME}}} = {{{TYPES}}} | ||
`; | ||
const runtimeImportSources = await api.applyPlugins({ | ||
key: 'addRuntimeType', | ||
type: api.ApplyPluginsType.add, | ||
initialValue: [], | ||
}); | ||
api.writeTmpFile({ | ||
path: 'runtime.d.ts', | ||
content: Mustache.render(typeTpl, genTypeContent(runtimeTypeName, runtimeImportSources)), | ||
}); | ||
|
||
const buildImportSources = await api.applyPlugins({ | ||
key: 'addBuildType', | ||
type: api.ApplyPluginsType.add, | ||
initialValue: [], | ||
}); | ||
api.writeTmpFile({ | ||
path: 'build.d.ts', | ||
content: Mustache.render(typeTpl, genTypeContent(buildTypeName, buildImportSources)), | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
export const request = { | ||
errorHandler: { | ||
111() { | ||
console.log('root:111'); | ||
}, | ||
500() { | ||
console.log('500 error'); | ||
}, | ||
default(error) { | ||
console.log(error); | ||
const msg = error?.data?.msg || error?.msg; | ||
console.log(msg); | ||
} | ||
} | ||
}; | ||
import { defineRuntimeConfig } from '@fesjs/fes'; | ||
|
||
export function patchRoutes() { | ||
console.log('patchRoutes'); | ||
} | ||
export default defineRuntimeConfig({ | ||
request: { | ||
errorHandler: { | ||
111() { | ||
console.log('root:111'); | ||
}, | ||
500() { | ||
console.log('500 error'); | ||
}, | ||
default(error) { | ||
console.log(error); | ||
const msg = error?.data?.msg || error?.msg; | ||
console.log(msg); | ||
}, | ||
}, | ||
}, | ||
patchRoutes: () => { | ||
console.log('patchRoutes'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
|
||
export * from '@@/core/coreExports'; | ||
// @ts-ignore | ||
export * from '@@/core/pluginExports'; | ||
|
||
export function defineBuildConfig(params) { | ||
return params; | ||
} | ||
|
||
export function defineRuntimeConfig(params) { | ||
return params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
import { Component, DefineComponent, App } from 'vue'; | ||
import { RouteRecordRaw, Router } from 'vue-router'; | ||
import { Plugin } from '@fesjs/runtime'; | ||
import { PluginRuntimeConfig } from '@@/runtime'; | ||
|
||
// @ts-ignore | ||
export * from '@@/core/coreExports'; | ||
// @ts-ignore | ||
export * from '@@/core/pluginExports'; | ||
|
||
export declare function defineRouteMeta(routeMeta: { | ||
interface RouteMeta { | ||
name?: string; | ||
title?: string; | ||
layout?: boolean | { sidebar?: boolean; header?: boolean; logo?: boolean }; | ||
}); | ||
} | ||
|
||
export declare function defineRouteMeta(routeMeta: RouteMeta): RouteMeta; | ||
|
||
|
||
interface BeforeRenderConfig { | ||
loading: Component; | ||
action: () => Promise<any>; | ||
} | ||
|
||
interface ClientRenderOption { | ||
routes: RouteRecordRaw[]; | ||
rootElement: string; | ||
defaultTitle: string; | ||
plugin: Plugin; | ||
} | ||
|
||
type RenderFunc = () => Promise<App> | ||
|
||
interface InnerRuntimeConfig { | ||
beforeRender?: (option: BeforeRenderConfig) => BeforeRenderConfig; | ||
patchRoutes?: ({ routes }: { routes: RouteRecordRaw[] }) => void; | ||
modifyClientRenderOpts?: (option: ClientRenderOption) => ClientRenderOption; | ||
rootContainer?: (component: DefineComponent, option: { routes: RouteRecordRaw[], plugin: Plugin }) => DefineComponent; | ||
onAppCreated?: ({ app, routes }: { app: App, routes: RouteRecordRaw[] }) => void; | ||
render?: (defaultRender: RenderFunc) => RenderFunc; | ||
onRouterCreated?: ({ router }: { router: Router }) => void; | ||
} | ||
|
||
export function defineRuntimeConfig(config: InnerRuntimeConfig & PluginRuntimeConfig): InnerRuntimeConfig & PluginRuntimeConfig; | ||
|