Skip to content

Commit

Permalink
refactoring Eugeny#8528
Browse files Browse the repository at this point in the history
  • Loading branch information
Clem-Fern committed Jun 7, 2023
1 parent 629555a commit 174dceb
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions app/src/plugins.ts
Expand Up @@ -98,17 +98,24 @@ const LEGACY_PLUGIN_PREFIX = 'terminus-'
async function getCandidateLocationsInPluginDir (pluginDir: any): Promise<{ pluginDir: string, packageName: string }[]> {
const candidateLocations: { pluginDir: string, packageName: string }[] = []

if (await fs.exists(pluginDir)) {
const pluginNames = await fs.readdir(pluginDir)
if (await fs.exists(path.join(pluginDir, 'package.json'))) {
candidateLocations.push({
pluginDir: path.dirname(pluginDir),
packageName: path.basename(pluginDir),
})
return fs.exists(pluginDir).then((result) => {
if (result) {
return fs.readdir(pluginDir)
} else {
return Promise.resolve([])
}

}).then((pluginNames) => {
const promises = []

promises.push(fs.exists(path.join(pluginDir, 'package.json')).then((result) => {
if (result) {
candidateLocations.push({
pluginDir: path.dirname(pluginDir),
packageName: path.basename(pluginDir),
})
}
}))

for (const packageName of pluginNames) {
if ((packageName.startsWith(PLUGIN_PREFIX) || packageName.startsWith(LEGACY_PLUGIN_PREFIX)) && !PLUGIN_BLACKLIST.includes(packageName)) {
const pluginPath = path.join(pluginDir, packageName)
Expand All @@ -121,10 +128,13 @@ async function getCandidateLocationsInPluginDir (pluginDir: any): Promise<{ plug
}
}

await Promise.all(promises)
}
return Promise.all(promises)
}).then(() => {
return candidateLocations
}).catch(() => {
return candidateLocations
})

return candidateLocations
}

async function getPluginCandidateLocation (paths: any): Promise<{ pluginDir: string, packageName: string }[]> {
Expand Down

0 comments on commit 174dceb

Please sign in to comment.