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 { Router, NavigationGuard } from 'vue-router';
import { Ref } from 'vue';
declare module "@fesjs/fes" { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
access: { access?:
rules: Record<string, []>; | {
}; rules: Record<string, []>;
}
| false;
} }
interface PluginRuntimeConfig { interface PluginRuntimeConfig {
access: { access?: {
noFoundHandler: (param: { router: Router } & NavigationGuard) => void; noFoundHandler: (param: { router: Router } & NavigationGuard) => void;
unAccessHandler: (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 { interface EnumExtend {
key: string; key: string;
@ -7,20 +8,18 @@ interface EnumExtend {
interface EnumApi { interface EnumApi {
get(name: string, key?: string, extend?: EnumExtend): any; 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; remove(name: string): void;
concat(name: string, _enum: [] | object, option?: {keyName: string; valueName: string, before: boolean, extend: EnumExtend}): 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; convert(name: string, _enum?: [] | object, option?: { keyName: string; valueName: string }): any;
} }
declare module "@fesjs/fes" { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
enums: { enums?: {
[key: string]: [string | number, string | number][] [key: string]: [string | number, string | number][];
} } | false;
} }
export const enums: EnumApi; export const enums: EnumApi;
} }

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-icon", "description": "@fesjs/plugin-icon",
"main": "lib/index.js", "main": "lib/index.js",
"files": [ "files": [
"lib" "lib",
"types.d.ts"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -31,5 +32,6 @@
}, },
"dependencies": { "dependencies": {
"svgo": "^2.3.1" "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'; import { Router, NavigationGuard } from 'vue-router';
interface Menu { interface Menu {
@ -7,31 +7,33 @@ interface Menu {
match: string[]; match: string[];
title: string; title: string;
icon: string | Component; icon: string | Component;
children?: Menu[] children?: Menu[];
} }
declare module "@fesjs/fes" { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
layout: { layout?:
footer: string; | {
theme: 'dark' | 'light'; footer: string;
navigation: 'side' | 'top' | 'mixin' | 'left-right'; theme: 'dark' | 'light';
title: string; navigation: 'side' | 'top' | 'mixin' | 'left-right';
isFixedHeader: boolean; title: string;
isFixedSidebar: boolean; isFixedHeader: boolean;
logo: string; isFixedSidebar: boolean;
multiTabs: boolean; logo: string;
sideWidth: number; multiTabs: boolean;
menus: Menu[]; sideWidth: number;
menuProps: { menus: Menu[];
expandedKeys: string[]; menuProps: {
defaultExpandAll: boolean; expandedKeys: string[];
accordion: boolean; defaultExpandAll: boolean;
}; accordion: boolean;
}; };
}
| false;
} }
interface PluginRuntimeConfig { interface PluginRuntimeConfig {
layout: { layout?: {
footer: string; footer: string;
theme: 'dark' | 'light'; theme: 'dark' | 'light';
navigation: 'side' | 'top' | 'mixin' | 'left-right'; navigation: 'side' | 'top' | 'mixin' | 'left-right';
@ -41,15 +43,17 @@ declare module "@fesjs/fes" {
logo: string; logo: string;
multiTabs: boolean; multiTabs: boolean;
sideWidth: number; sideWidth: number;
menus: Menu[] | (()=> (Ref<Menu[]> | Menu[])); menus: Menu[] | (() => Ref<Menu[]> | Menu[]);
menuProps: { menuProps: {
expandedKeys: string[]; expandedKeys: string[];
defaultExpandAll: boolean; defaultExpandAll: boolean;
accordion: boolean; accordion: boolean;
}; };
renderCustom: ()=> VNode[], renderCustom: () => VNode[];
noFoundHandler: (param: { router: Router } & NavigationGuard) => void; noFoundHandler: (param: { router: Router } & NavigationGuard) => void;
unAccessHandler: (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 { interface PluginBuildConfig {
locale: { locale?:
locale: string; | {
fallbackLocale: string; locale: string;
baseNavigator: boolean; fallbackLocale: string;
legacy: boolean; 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", "description": "@fesjs/plugin-model",
"main": "lib/index.js", "main": "lib/index.js",
"files": [ "files": [
"lib" "lib",
"types.d.ts"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -32,5 +33,6 @@
"peerDependencies": { "peerDependencies": {
"@fesjs/fes": "^3.0.0-beta.0", "@fesjs/fes": "^3.0.0-beta.0",
"vue": "^3.0.5" "vue": "^3.0.5"
} },
"typings": "./types.d.ts"
} }

View File

@ -1,5 +1,6 @@
import { readFileSync } from 'fs'; import { readFileSync } from 'fs';
import { join } from 'path'; import { join } from 'path';
import { name } from '../package.json';
const namespace = 'plugin-model'; const namespace = 'plugin-model';
@ -70,4 +71,8 @@ export default (api) => {
source: absCoreFilePath, 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 { EditorLanguage } from 'monaco-editor-webpack-plugin/out/languages';
import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features'; import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
declare module "@fesjs/fes" { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
monacoEditor: { monacoEditor?: {
filename: string; filename: string;
publicPath: string; publicPath: string;
languages: EditorLanguage[]; languages: EditorLanguage[];
features: EditorFeature[]; features: EditorFeature[];
globalAPI: boolean; globalAPI: boolean;
}; } | false;
} }
export const MonacoEditor: Component;
} }

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-pinia", "description": "@fesjs/plugin-pinia",
"main": "lib/index.js", "main": "lib/index.js",
"files": [ "files": [
"lib" "lib",
"types.d.ts"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -33,5 +34,6 @@
"@fesjs/fes": "^3.0.0-beta.0", "@fesjs/fes": "^3.0.0-beta.0",
"pinia": "^2.0.11", "pinia": "^2.0.11",
"vue": "^3.0.5" "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'; import { FrameworkLifeCycles, MicroApp } from 'qiankun';
interface AppOption { interface AppOption {
@ -6,16 +7,20 @@ interface AppOption {
props: Record<string, any>; props: Record<string, any>;
} }
declare module '@fesjs/fes' {
declare module "@fesjs/fes" {
interface PluginBuildConfig { interface PluginBuildConfig {
qiankun: { qiankun?:
main: { | {
apps: AppOption[]; main?: {
lifeCycles?: FrameworkLifeCycles<MicroApp>; apps: AppOption[];
[key: string]: any; 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" { declare module "@fesjs/fes" {
interface PluginRuntimeConfig { interface PluginRuntimeConfig {
request: { request?: {
dataHandler?(data: any, response: AxiosResponse): any; dataHandler?(data: any, response: AxiosResponse): any;
errorHandler?(error: AxiosError | {type: string, msg: string, [key: string]: string}): void; errorHandler?(error: AxiosError | {type: string, msg: string, [key: string]: string}): void;
requestInterceptors?: RequestInterceptor[]; requestInterceptors?: RequestInterceptor[];

View File

@ -4,7 +4,8 @@
"description": "@fesjs/plugin-sass", "description": "@fesjs/plugin-sass",
"main": "lib/index.js", "main": "lib/index.js",
"files": [ "files": [
"lib" "lib",
"types.d.ts"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -32,5 +33,6 @@
}, },
"peerDependencies": { "peerDependencies": {
"@fesjs/fes": "^3.0.0-beta.0" "@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 @@
import '@fesjs/fes';
declare module '@fesjs/fes' {
declare module "@fesjs/fes" {
interface PluginBuildConfig { interface PluginBuildConfig {
vuex: { vuex?:
strict: boolean; | {
devtools: boolean; 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", "description": "@fesjs/plugin-watermark",
"main": "lib/index.js", "main": "lib/index.js",
"files": [ "files": [
"lib" "lib",
"types.d.ts"
], ],
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
@ -33,5 +34,6 @@
"peerDependencies": { "peerDependencies": {
"@fesjs/fes": "^3.0.0-beta.0", "@fesjs/fes": "^3.0.0-beta.0",
"vue": "^3.0.5" "vue": "^3.0.5"
} },
"typings": "./types.d.ts"
} }

View File

@ -1,4 +1,5 @@
import { join } from 'path'; import { join } from 'path';
import { name } from '../package.json';
const namespace = 'plugin-watermark'; const namespace = 'plugin-watermark';
@ -8,11 +9,11 @@ export default (api) => {
config: { config: {
schema(joi) { schema(joi) {
return joi.object({ return joi.object({
disabled: joi.boolean() disabled: joi.boolean(),
}); });
}, },
default: {} default: {},
} },
}); });
const absoluteFilePath = join(namespace, 'core.js'); const absoluteFilePath = join(namespace, 'core.js');
@ -23,23 +24,26 @@ export default (api) => {
defineConfig.WATERMARK_DISABLED = memo.watermark.disabled ?? false; defineConfig.WATERMARK_DISABLED = memo.watermark.disabled ?? false;
return { return {
...memo, ...memo,
define: defineConfig define: defineConfig,
}; };
}); });
api.onGenerateFiles(() => { api.onGenerateFiles(() => {
api.copyTmpFiles({ api.copyTmpFiles({
namespace, namespace,
path: join(__dirname, 'runtime'), path: join(__dirname, 'runtime'),
ignore: ['.tpl'] ignore: ['.tpl'],
}); });
}); });
api.addPluginExports(() => [ api.addPluginExports(() => [
{ {
specifiers: ['createWatermark', 'destroyWatermark'], 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'; import type { Config } from 'windicss/types/interfaces';
declare module "@fesjs/fes" { declare module '@fesjs/fes' {
interface PluginBuildConfig { interface PluginBuildConfig {
windicss: { windicss?:
config: Config | {
} config: Config;
}
| false;
} }
} }

View File

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

View File

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