From 91888f694ba65a8fbb48fdc8de17fe89ed61afbf Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 21 May 2021 17:04:29 +0200 Subject: [PATCH] [plugin][core] Fixed entry point, work on plugin definitions * Entry point is now in source, no need to compile, this is done by Flaschengeist when included * Added `id` property to plugins * Required modules now support version dependencies --- package.json | 13 ++++--- src/index.d.ts | 2 -- src/index.ts | 1 - tsconfig.json | 3 +- {src => types}/flaschengeist.d.ts | 0 types/index.d.ts | 3 ++ {src => types}/plugin.d.ts | 57 +++++++++++++++++++------------ 7 files changed, 45 insertions(+), 34 deletions(-) delete mode 100644 src/index.d.ts delete mode 100644 src/index.ts rename {src => types}/flaschengeist.d.ts (100%) create mode 100644 types/index.d.ts rename {src => types}/plugin.d.ts (66%) diff --git a/package.json b/package.json index f857d18..fc3646a 100644 --- a/package.json +++ b/package.json @@ -13,20 +13,19 @@ "type": "git", "url": "https://flaschengeist.dev/Flaschengeist/flaschengeist-typings" }, - "main": "dist/index.js", - "typings": "dist/index.d.ts", + "typings": "types/index.d.ts", "scripts": { - "build": "tsc", + "valid": "tsc --noEmit", "pretty": "prettier --config ./package.json --write '{,!(node_modules)/**/}*.ts'" }, "devDependencies": { "prettier": "^2.3.0", - "typescript": "^4.2.4", - "vue": "^3.0.11", - "vue-router": "^4.0.8" + "typescript": "^4.2.4" }, "peerDependencies": { - "flaschengeist": "^2.0.0-alpha.1" + "flaschengeist": "^2.0.0-alpha.1", + "vue": "^3.0.11", + "vue-router": "^4.0.8" }, "prettier": { "singleQuote": true, diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index 0f87dc5..0000000 --- a/src/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -/// -/// \ No newline at end of file diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index a022b03..0000000 --- a/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -/// \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 5311e73..ded90b4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,9 +4,8 @@ "target": "esnext", "module": "esnext", "declaration": true, - "outDir": "./dist", "strict": true, - "moduleResolution": "node" + "moduleResolution": "Node" }, "exclude": [ "node_modules", diff --git a/src/flaschengeist.d.ts b/types/flaschengeist.d.ts similarity index 100% rename from src/flaschengeist.d.ts rename to types/flaschengeist.d.ts diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..9784f83 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,3 @@ +/// + +export * from "./plugin" diff --git a/src/plugin.d.ts b/types/plugin.d.ts similarity index 66% rename from src/plugin.d.ts rename to types/plugin.d.ts index d041af8..2ad5cc8 100644 --- a/src/plugin.d.ts +++ b/types/plugin.d.ts @@ -1,18 +1,31 @@ -import { RouteLocationRaw, RouteRecordRaw, RouteRecordName } from 'vue-router'; -import { Component } from 'vue'; +import type { RouteLocationRaw, RouteRecordRaw, RouteRecordName } from 'vue-router'; +import type { Component } from '@vue/runtime-core'; -declare namespace FG_Plugin { +type Join = + T extends [] ? '' : + T extends [string | number | boolean | bigint] ? `${T[0]}` : + T extends [string | number | boolean | bigint, ...infer U] ? `${T[0]}${D}${Join}` : + string; +type BVersion = Join<[number, number], '.'> | Join<[number, number, number], '.'> +type Version = BVersion | Join<[BVersion, string], '-'> + +export namespace FG_Plugin { /** * Interface defining a Flaschengeist plugin */ - interface Plugin { + export interface Plugin { + /** Unique identifier for this plugin, we recommend using a FQN like com.example.my_plugin */ + id: string, + /** Arbitrary name of the plugin used inside admin view etc */ name: string; + /** Version of this plugin, used for dependencies. MUST be semver parsable */ version: string; + /** Widgets provided by this plugin */ widgets: Widget[]; - /** Pther frontend modules needed for this plugin to work correctly */ - requiredModules: string[]; + /** Other frontend modules needed for this plugin to work correctly */ + requiredModules: [string, Version?][]; /** Backend modules needed for this plugin to work correctly */ - requiredBackendModules: string[]; + requiredBackendModules: [string, Version?][]; /** Menu entries for authenticated users */ innerRoutes?: MenuRoute[]; /** Public menu entries (without authentification) */ @@ -26,7 +39,7 @@ declare namespace FG_Plugin { /** * Defines the loaded state of the Flaschengeist */ - interface Flaschengeist { + export interface Flaschengeist { /** All loaded plugins */ plugins: LoadedPlugin[]; /** All routes, combined from all plugins */ @@ -44,7 +57,7 @@ declare namespace FG_Plugin { /** * Interface for a frontend notification */ - interface Notification extends FG.Notification { + export interface Notification extends FG.Notification { /** If set a button for accepting will be shown, this function will get called before deleting the notification */ accept?(): Promise; /** If set this function is called before the notification gets deleted */ @@ -67,30 +80,30 @@ declare namespace FG_Plugin { /** * Defines a shortcut link */ - interface Shortcut { + export interface Shortcut { link: RouteRecordName; icon: string; permissions?: string[]; } - /** - * Defines a main menu entry along with the route - * Used when defining a plugin - */ - interface MenuRoute extends MenuEntry { - route: NamedRouteRecordRaw; - shortcut?: boolean; - children?: this[]; - } - type NamedRouteRecordRaw = RouteRecordRaw & { name: RouteRecordName; }; + /** + * Defines a main menu entry along with the route + * Used when defining a plugin + */ + export interface MenuRoute extends MenuEntry { + route: NamedRouteRecordRaw; + shortcut?: boolean; + children?: this[]; + } + /** * Defines a menu entry in the main menu */ - interface MenuLink extends MenuEntry { + export interface MenuLink extends MenuEntry { /** Name of the target route */ link: RouteRecordName; } @@ -108,7 +121,7 @@ declare namespace FG_Plugin { /** * Widget object for the dashboard */ - interface Widget { + export interface Widget { name: string; priority: number; permissions: FG.Permission[];