mirror of
https://github.com/nocobase/nocobase
synced 2024-11-17 03:26:07 +00:00
08c5383bee
* refactor: core/build and cli/build.js * fix: build * fix: bug * fix: replaceAll to replace * fix: node version check * fix: add require check * fix: esbuild other ext * fix: process json * fix: exlude jsx-runtime * feat: split chunk * fix: minify plugin client bundle * fix: compatibility * fix: support import() * feat: update docs * fix: server deps * feat: demo * fix: remove cjs treeshake * fix: local error * fix: bug * fix: lazy load * fix: rewrites * fix: remove dynamic import function * feat: doc demo * fix: codesanbox vite template * fix: codesanbox demo * fix: hide stackblitz * fix: revert rspack * fix: test bug * fix: delete console * fix: import dayjs locale --------- Co-authored-by: chenos <chenlinxh@gmail.com>
48 lines
967 B
TypeScript
48 lines
967 B
TypeScript
import minimatch from 'minimatch';
|
|
|
|
export type SnippetOptions = {
|
|
name: string;
|
|
actions: Array<string>;
|
|
};
|
|
|
|
class Snippet {
|
|
constructor(
|
|
public name: string,
|
|
public actions: Array<string>,
|
|
) {}
|
|
}
|
|
|
|
export type SnippetGroup = {
|
|
name: string;
|
|
snippets: SnippetOptions[];
|
|
};
|
|
|
|
class SnippetManager {
|
|
public snippets: Map<string, Snippet> = new Map();
|
|
|
|
register(snippet: SnippetOptions) {
|
|
this.snippets.set(snippet.name, snippet);
|
|
}
|
|
|
|
allow(actionPath: string, snippetName: string) {
|
|
const negated = snippetName.startsWith('!');
|
|
snippetName = negated ? snippetName.slice(1) : snippetName;
|
|
|
|
const snippet = this.snippets.get(snippetName);
|
|
|
|
if (!snippet) {
|
|
throw new Error(`Snippet ${snippetName} not found`);
|
|
}
|
|
|
|
const matched = snippet.actions.some((action) => minimatch(actionPath, action));
|
|
|
|
if (matched) {
|
|
return negated ? false : true;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export default SnippetManager;
|