MCPcopy Create free account
hub / github.com/ZToolsCenter/ZTools / getOpenFolderRegex

Function getOpenFolderRegex

tests/main/systemPluginOpenFolderRegex.test.ts:19–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17}
18
19function getOpenFolderRegex(): RegExp {
20 const pluginJsonPath = path.join(
21 process.cwd(),
22 'internal-plugins',
23 'system',
24 'public',
25 'plugin.json'
26 )
27 const pluginConfig = JSON.parse(readFileSync(pluginJsonPath, 'utf-8')) as PluginConfig
28 const feature = pluginConfig.features.find((item) => item.code === 'open-folder')
29 const regexCmd = feature?.cmds?.find(
30 (item): item is PluginFeatureCommand => typeof item !== 'string' && item.type === 'regex'
31 )
32 const regexString = regexCmd?.match
33 const match = typeof regexString === 'string' ? regexString.match(/^\/(.+)\/([gimuy]*)$/) : null
34
35 if (!match) {
36 throw new Error('open-folder regex command is missing or invalid')
37 }
38
39 return new RegExp(match[1], match[2])
40}
41
42describe('system plugin open-folder regex', () => {
43 const regex = getOpenFolderRegex()

Calls

no outgoing calls

Tested by

no test coverage detected