diff --git a/.vscode/settings.json b/.vscode/settings.json index 245938f0..363f89d8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -155,14 +155,16 @@ "workbench.editor.customLabels.enabled": true, "workbench.editor.customLabels.patterns": { "src/app/**/*.ts": "${dirname}/${filename}", - "test/**/*": "${dirname}/${filename}.${extname} - test", - "dist/**/*": "${dirname}/${filename}.${extname} - dist", - "packages/**/src/app/**": "${dirname(1)}/${dirname}/${filename}", - "packages/**/src/*": "${dirname(1)}/${dirname}/${filename}.${extname}", - "packages/**/test/*": "${dirname(1)}/${dirname}/${filename}.${extname}", - "packages/**/src/**/*": "${dirname(1)}/${dirname}/${filename}.${extname} - ${dirname(2)}", - "packages/**/test/**/*": "${dirname(1)}/${dirname}/${filename}.${extname} - ${dirname(2)}", - "packages/**/*": "${dirname(1)}/${dirname}/${filename}.${extname}", - "**/*": "${dirname}/${filename}.${extname}" + "src/**": "${dirname}/${filename}.${extname}" + "test/**": "${dirname}/${filename}.${extname} - test", + "dist/**": "${dirname}/${filename}.${extname} - dist", + "packages/*/src/app/**": "${dirname(1)}/${dirname}/${filename} src", + "packages/*/src/*.*": "${filename}.${extname} src", + "packages/*/test/*.*": "${filename}.${extname} test", + "packages/*/src/**": "${dirname}/${filename}.${extname} - src", + "packages/*/test/**": "${dirname}/${filename}.${extname} - test", + "packages/*/*.*": "${dirname}/${filename}.${extname}", + "packages/*/**": "${dirname(1)}/${dirname}/${filename}.${extname}", + "**/node_modules/**/*": "${filename}.${extname} - ${dirname(2)}/${dirname(1)}/${dirname}" } } diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example index d0082f40..77cfbbcd 100644 --- a/.vscode/settings.json.example +++ b/.vscode/settings.json.example @@ -155,14 +155,16 @@ "workbench.editor.customLabels.enabled": true, "workbench.editor.customLabels.patterns": { "src/app/**/*.ts": "${dirname}/${filename}", - "test/**/*": "${dirname}/${filename}.${extname} - test", - "dist/**/*": "${dirname}/${filename}.${extname} - dist", - "packages/**/src/app/**": "${dirname(1)}/${dirname}/${filename}", - "packages/**/src/*": "${dirname(1)}/${dirname}/${filename}.${extname}", - "packages/**/test/*": "${dirname(1)}/${dirname}/${filename}.${extname}", - "packages/**/src/**/*": "${dirname(1)}/${dirname}/${filename}.${extname} - ${dirname(2)}", - "packages/**/test/**/*": "${dirname(1)}/${dirname}/${filename}.${extname} - ${dirname(2)}", - "packages/**/*": "${dirname(1)}/${dirname}/${filename}.${extname}", - "**/*": "${dirname}/${filename}.${extname}" + "src/**": "${dirname}/${filename}.${extname}" + "test/**": "${dirname}/${filename}.${extname} - test", + "dist/**": "${dirname}/${filename}.${extname} - dist", + "packages/*/src/app/**": "${dirname(1)}/${dirname}/${filename} src", + "packages/*/src/*.*": "${filename}.${extname} src", + "packages/*/test/*.*": "${filename}.${extname} test", + "packages/*/src/**": "${dirname}/${filename}.${extname} - src", + "packages/*/test/**": "${dirname}/${filename}.${extname} - test", + "packages/*/*.*": "${dirname}/${filename}.${extname}", + "packages/*/**": "${dirname(1)}/${dirname}/${filename}.${extname}", + "**/node_modules/**/*": "${filename}.${extname} - ${dirname(2)}/${dirname(1)}/${dirname}" } } diff --git a/packages/mw-demo/src/index.ts b/packages/mw-demo/src/index.ts index 6e2eaa36..0541cc0e 100644 --- a/packages/mw-demo/src/index.ts +++ b/packages/mw-demo/src/index.ts @@ -8,14 +8,9 @@ import { export { AutoConfiguration as Configuration } from './configuration.js' export * from './app/index.controller.js' +export * from './interface.js' export * from './lib/index.js' export * from './middleware/index.middleware.js' -export { - getComponentConfig, - getMiddlewareConfig, -} from './util/common.js' - -export * from './interface.js' // @ts-expect-error for midway declare module '@midwayjs/core/dist/interface' { diff --git a/packages/mw-demo/src/util/common.ts b/packages/mw-demo/src/util/common.ts deleted file mode 100644 index db60c9a7..00000000 --- a/packages/mw-demo/src/util/common.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type { Application, Context } from '@mwcp/share' -import { isPathMatchRules } from '@waiting/shared-core' - -import { - Config, - ConfigKey, - MiddlewareConfig, -} from '##/lib/types.js' - - -/** - * Return true if rules of match and ignore empty - */ -export function matchFunc(ctx?: Context): boolean { - if (! ctx) { - return false - } - - const mwConfig = getMiddlewareConfig(ctx.app) - const { enableMiddleware, match, ignore } = mwConfig - - if (! enableMiddleware) { - return false - } - - if (Array.isArray(ignore) && ignore.length) { - const matched = isPathMatchRules(ctx.path, ignore) - return ! matched - } - else if (Array.isArray(match) && match.length) { - const matched = isPathMatchRules(ctx.path, ignore) - return matched - } - else { - return true - } -} - - -export function getComponentConfig( - app: Application, - key: ConfigKey = ConfigKey.config, -): T { - - const config = getConfigFromApp(app, key) - return config -} - -export function getMiddlewareConfig( - app: Application, - key: ConfigKey = ConfigKey.middlewareConfig, -): T { - - const config = getConfigFromApp(app, key) - return config -} - -function getConfigFromApp(app: Application, key: ConfigKey): T { - const config = app.getConfig(key) as T - return config -} -