()
| 17 | } |
| 18 | |
| 19 | function 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 | |
| 42 | describe('system plugin open-folder regex', () => { |
| 43 | const regex = getOpenFolderRegex() |
no outgoing calls
no test coverage detected