feat: 配置插件api提示

This commit is contained in:
wanchun 2022-06-22 19:15:40 +08:00
parent de60bc9578
commit 9963b5eed6
24 changed files with 246 additions and 106 deletions

View File

@ -1,16 +1,29 @@
import { Router, NavigationGuard } from 'vue-router';
import { Ref } from 'vue';
declare module "@fesjs/fes" {
declare module '@fesjs/fes' {
interface PluginBuildConfig {
access: {
access?:
| {
rules: Record<string, []>;
};
}
| false;
}
interface PluginRuntimeConfig {
access: {
access?: {
noFoundHandler: (param: { router: Router } & NavigationGuard) => void;
unAccessHandler: (param: { router: Router } & NavigationGuard) => void;
};
}
export function access(): {
hasAccess(accessId: string | number): Promise<boolean>;
isDataReady(): boolean;
setRole(roleId: string | Promise<string>): void;
setAccess(accessIds: Array<string | number> | Promise<Array<string | number>>): void;
getAccess(): string[];
};
export function useAccess(accessId: Array<string | number>): Ref<boolean>;
}

View File

@ -1,3 +1,4 @@
import '@fesjs/fes';
interface EnumExtend {
key: string;
@ -7,20 +8,18 @@ interface EnumExtend {
interface EnumApi {
get(name: string, key?: string, extend?: EnumExtend): any;
push(name: string, _enum?: [] | object, option?: {keyName: string; valueName: string}): any;
push(name: string, _enum?: [] | object, option?: { keyName: string; valueName: string }): any;
remove(name: string): void;
concat(name: string, _enum: [] | object, option?: {keyName: string; valueName: string, before: boolean, extend: EnumExtend}): any;
convert(name: string, _enum?: [] | object, option?: {keyName: string; valueName: string}): any;
concat(name: string, _enum: [] | object, option?: { keyName: string; valueName: string; before: boolean; extend: EnumExtend }): any;
convert(name: string, _enum?: [] | object, option?: { keyName: string; valueName: string }): any;
}
declare module "@fesjs/fes" {
declare module '@fesjs/fes' {
interface PluginBuildConfig {
enums: {
[key: string]: [string | number, string | number][]
}
enums?: {
[key: string]: [string | number, string | number][];
} | false;
}
export const enums: EnumApi;
}

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-icon",
"main": "lib/index.js",
"files": [
"lib"
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@ -31,5 +32,6 @@
},
"dependencies": {
"svgo": "^2.3.1"
}
},
"typings": "./types.d.ts"
}

7
packages/fes-plugin-icon/types.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import '@fesjs/fes';
declare module '@fesjs/fes' {
interface PluginBuildConfig {
icon?: {} | false;
}
}

View File

@ -1,4 +1,4 @@
import {Component, VNode, Ref } from 'vue';
import { Component, VNode, Ref } from 'vue';
import { Router, NavigationGuard } from 'vue-router';
interface Menu {
@ -7,12 +7,13 @@ interface Menu {
match: string[];
title: string;
icon: string | Component;
children?: Menu[]
children?: Menu[];
}
declare module "@fesjs/fes" {
declare module '@fesjs/fes' {
interface PluginBuildConfig {
layout: {
layout?:
| {
footer: string;
theme: 'dark' | 'light';
navigation: 'side' | 'top' | 'mixin' | 'left-right';
@ -28,10 +29,11 @@ declare module "@fesjs/fes" {
defaultExpandAll: boolean;
accordion: boolean;
};
};
}
| false;
}
interface PluginRuntimeConfig {
layout: {
layout?: {
footer: string;
theme: 'dark' | 'light';
navigation: 'side' | 'top' | 'mixin' | 'left-right';
@ -41,15 +43,17 @@ declare module "@fesjs/fes" {
logo: string;
multiTabs: boolean;
sideWidth: number;
menus: Menu[] | (()=> (Ref<Menu[]> | Menu[]));
menus: Menu[] | (() => Ref<Menu[]> | Menu[]);
menuProps: {
expandedKeys: string[];
defaultExpandAll: boolean;
accordion: boolean;
};
renderCustom: ()=> VNode[],
renderCustom: () => VNode[];
noFoundHandler: (param: { router: Router } & NavigationGuard) => void;
unAccessHandler: (param: { router: Router } & NavigationGuard) => void;
};
}
export const Page: Component;
}

View File

@ -1,10 +1,23 @@
declare module "@fesjs/fes" {
import '@fesjs/fes';
declare module '@fesjs/fes' {
interface PluginBuildConfig {
locale: {
locale?:
| {
locale: string;
fallbackLocale: string;
baseNavigator: boolean;
legacy: boolean;
};
}
| false;
}
// export * from 'vue-i18n';
export const locale: {
setLocale({ locale }: { locale: string }): void;
addLocale({ locale, messages }: { locale: string; messages: object }): void;
getAllLocales(): string[];
messages: Record<string, object>;
};
}

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-model",
"main": "lib/index.js",
"files": [
"lib"
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@ -32,5 +33,6 @@
"peerDependencies": {
"@fesjs/fes": "^3.0.0-beta.0",
"vue": "^3.0.5"
}
},
"typings": "./types.d.ts"
}

View File

@ -1,5 +1,6 @@
import { readFileSync } from 'fs';
import { join } from 'path';
import { name } from '../package.json';
const namespace = 'plugin-model';
@ -70,4 +71,8 @@ export default (api) => {
source: absCoreFilePath,
},
]);
api.addConfigType(() => ({
source: name,
}));
};

10
packages/fes-plugin-model/types.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
import '@fesjs/fes';
declare module '@fesjs/fes' {
interface PluginBuildConfig {
model?: {} | false;
}
export function useModel(moduleId: string): any;
}

View File

@ -1,14 +1,17 @@
import type { Component } from 'vue';
import type { EditorLanguage } from 'monaco-editor-webpack-plugin/out/languages';
import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
declare module "@fesjs/fes" {
declare module '@fesjs/fes' {
interface PluginBuildConfig {
monacoEditor: {
monacoEditor?: {
filename: string;
publicPath: string;
languages: EditorLanguage[];
features: EditorFeature[];
globalAPI: boolean;
};
} | false;
}
export const MonacoEditor: Component;
}

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-pinia",
"main": "lib/index.js",
"files": [
"lib"
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@ -33,5 +34,6 @@
"@fesjs/fes": "^3.0.0-beta.0",
"pinia": "^2.0.11",
"vue": "^3.0.5"
}
},
"typings": "./types.d.ts"
}

9
packages/fes-plugin-pinia/types.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import type { Pinia } from 'pinia';
declare module '@fesjs/fes' {
interface PluginBuildConfig {
pinia?: {} | false;
}
export const pinia: Pinia;
}

View File

@ -1,3 +1,4 @@
import { Component } from 'vue';
import { FrameworkLifeCycles, MicroApp } from 'qiankun';
interface AppOption {
@ -6,16 +7,20 @@ interface AppOption {
props: Record<string, any>;
}
declare module "@fesjs/fes" {
declare module '@fesjs/fes' {
interface PluginBuildConfig {
qiankun: {
main: {
qiankun?:
| {
main?: {
apps: AppOption[];
lifeCycles?: FrameworkLifeCycles<MicroApp>;
[key: string]: any;
};
micro: {}
};
micro?: {};
}
| false;
}
export const MicroApp: Component;
export const MicroAppWithMemoHistory: Component;
}

View File

@ -15,7 +15,7 @@ interface RequestPluginOption {
declare module "@fesjs/fes" {
interface PluginRuntimeConfig {
request: {
request?: {
dataHandler?(data: any, response: AxiosResponse): any;
errorHandler?(error: AxiosError | {type: string, msg: string, [key: string]: string}): void;
requestInterceptors?: RequestInterceptor[];

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-sass",
"main": "lib/index.js",
"files": [
"lib"
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@ -32,5 +33,6 @@
},
"peerDependencies": {
"@fesjs/fes": "^3.0.0-beta.0"
}
},
"typings": "./types.d.ts"
}

14
packages/fes-plugin-sass/types.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
import '@fesjs/fes';
declare module '@fesjs/fes' {
interface PluginBuildConfig {
sass?:
| {
implementation: any;
sassOptions: object;
sourceMap: boolean;
webpackImporter: boolean;
}
| false;
}
}

View File

@ -1,12 +1,19 @@
declare module "@fesjs/fes" {
import '@fesjs/fes';
declare module '@fesjs/fes' {
interface PluginBuildConfig {
vuex: {
vuex?:
| {
strict: boolean;
devtools: boolean;
}
| false;
}
export const MUTATION_TYPES: object;
export const ACTION_TYPES: object;
export const GETTER_TYPES: object;
export const store: object;
}

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-watermark",
"main": "lib/index.js",
"files": [
"lib"
"lib",
"types.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
@ -33,5 +34,6 @@
"peerDependencies": {
"@fesjs/fes": "^3.0.0-beta.0",
"vue": "^3.0.5"
}
},
"typings": "./types.d.ts"
}

View File

@ -1,4 +1,5 @@
import { join } from 'path';
import { name } from '../package.json';
const namespace = 'plugin-watermark';
@ -8,11 +9,11 @@ export default (api) => {
config: {
schema(joi) {
return joi.object({
disabled: joi.boolean()
disabled: joi.boolean(),
});
},
default: {}
}
default: {},
},
});
const absoluteFilePath = join(namespace, 'core.js');
@ -23,23 +24,26 @@ export default (api) => {
defineConfig.WATERMARK_DISABLED = memo.watermark.disabled ?? false;
return {
...memo,
define: defineConfig
define: defineConfig,
};
});
api.onGenerateFiles(() => {
api.copyTmpFiles({
namespace,
path: join(__dirname, 'runtime'),
ignore: ['.tpl']
ignore: ['.tpl'],
});
});
api.addPluginExports(() => [
{
specifiers: ['createWatermark', 'destroyWatermark'],
source: absoluteFilePath
}
source: absoluteFilePath,
},
]);
api.addConfigType(() => ({
source: name,
}));
};

View File

@ -0,0 +1,27 @@
import '@fesjs/fes';
interface WatermarkParam {
content: string;
container: HTMLElement;
width: number;
height: number;
textAlign: 'left' | 'right' | 'center' | 'start' | 'end';
textBaseline: 'top' | 'hanging' | 'middle' | 'alphabetic' | 'ideographic' | 'bottom';
fontSize: string;
fontFamily: string;
fillStyle: string;
rotate: number;
zIndex: number;
timestamp: string;
}
declare module '@fesjs/fes' {
interface PluginBuildConfig {
watermark?: {
disable: boolean;
} | false;
}
export function createWatermark(param: WatermarkParam): void;
export function destroyWatermark(): void;
}

View File

@ -1,9 +1,11 @@
import type { Config } from 'windicss/types/interfaces';
declare module "@fesjs/fes" {
declare module '@fesjs/fes' {
interface PluginBuildConfig {
windicss: {
config: Config
windicss?:
| {
config: Config;
}
| false;
}
}

View File

@ -1,6 +1,5 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
export default {
import { defineBuildConfig } from '@fesjs/fes'
export default defineBuildConfig({
// exportStatic: {},
define: {
__DEV__: false
@ -98,4 +97,4 @@ export default {
presets: [
require.resolve('../fes-builder-webpack/lib'),
]
};
});

View File

@ -3,7 +3,10 @@
"outDir": "build/dist",
"module": "esnext",
"target": "esnext",
"lib": ["esnext", "dom"],
"lib": [
"esnext",
"dom"
],
"sourceMap": true,
"baseUrl": ".",
"jsx": "preserve",
@ -14,25 +17,31 @@
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"strict": true,
"paths": {
"@/*": ["./src/*"],
"@@/*": ["./src/.fes/*"]
"@/*": [
"./src/*"
],
"@@/*": [
"./src/.fes/*"
]
}
},
"include": [
"*.js",
".fes.js",
"src/**/*",
"tests/**/*",
"test/**/*",
"__test__/**/*",
"typings/**/*",
"config/**/*",
".eslintrc.js",
".stylelintrc.js",
".prettierrc.js",
"src/.fes/configType.d.ts"
],
"exclude": ["node_modules", "build", "dist", "scripts", "src/.fes/*", "webpack", "jest"]
"exclude": [
"build",
"dist",
"scripts",
"webpack",
"jest",
"node_modules"
]
}

View File

@ -15,7 +15,7 @@ export interface PluginBuildConfig {}
export declare function defineRouteMeta(routeMeta: RouteMeta): RouteMeta;
export function defineBuildConfig(config: PluginBuildConfig ): PluginBuildConfig;
export declare function defineBuildConfig(config: PluginBuildConfig ): PluginBuildConfig;
export function defineRuntimeConfig(config: PluginRuntimeConfig): PluginRuntimeConfig;
export declare function defineRuntimeConfig(config: PluginRuntimeConfig): PluginRuntimeConfig;