-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27466 from mshima/configs
internal: always load main generators configs
- Loading branch information
Showing
2 changed files
with
18 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
import { dirname, join } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { fileURLToPath, pathToFileURL } from 'url'; | ||
import { glob } from 'glob'; | ||
import type { JHipsterConfig, JHipsterConfigs } from './types.js'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
const cwd = join(__dirname, '../..'); | ||
let jdlConfigs: JHipsterConfigs; | ||
let jhipsterConfigs: JHipsterConfigs; | ||
|
||
export const lookupCommandsConfigs = async (options?: { filter: (config: JHipsterConfig) => boolean }): Promise<JHipsterConfigs> => { | ||
if (jdlConfigs) { | ||
return jdlConfigs; | ||
if (jhipsterConfigs) { | ||
return jhipsterConfigs; | ||
} | ||
const { filter = () => true } = options ?? {}; | ||
jdlConfigs = {}; | ||
jhipsterConfigs = {}; | ||
const files = [...(await glob('generators/*/index.{j,t}s', { cwd })), ...(await glob('generators/*/generators/*/index.{j,t}s', { cwd }))]; | ||
for (const file of files) { | ||
const index = await import(`${cwd}/${file}`); | ||
const configs: JHipsterConfigs = index.command?.configs ?? {}; | ||
for (const [key, value] of Object.entries(configs)) { | ||
if (filter(value)) { | ||
jdlConfigs[key] = value; | ||
} | ||
const index = await import(pathToFileURL(`${cwd}/${file}`).toString()); | ||
if (index.command?.configs) { | ||
Object.assign(jhipsterConfigs, index.command?.configs); | ||
} | ||
} | ||
return jdlConfigs; | ||
return Object.fromEntries(Object.entries(jhipsterConfigs).filter(([_key, value]) => filter(value))); | ||
}; |