Skip to content

Commit

Permalink
#383 Added supported for multiple config names
Browse files Browse the repository at this point in the history
  • Loading branch information
cshawaus committed Jan 21, 2021
1 parent 41994a6 commit a22c867
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"arrow-body-style": "off",
"class-methods-use-this": "off",
"no-console": "off",
"no-continue": "off",
"no-process-exit": "off",
"strict": ["error", "safe"],

Expand Down
10 changes: 5 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,18 @@ export function getProjectPath<T extends ConfigurationType>(path: T): string {
export function getMavenConfiguration(): MavenConfigMap {
return {
appsPath: getMavenConfigurationValueByPath<string>({
path : 'package.appsPath',
pom : configuration[ConfigurationType.MAVEN_PROJECT],
paths : ['package.appsPath'],
pom : configuration[ConfigurationType.MAVEN_PROJECT],
}),

authorPort: getMavenConfigurationValueByPath<number>({
parser : (value) => parseInt(value[0], 10),
path : 'crx.port',
paths : ['aem.port', 'crx.port'],
}),

sharedAppsPath: getMavenConfigurationValueByPath<string>({
path : 'package.path.apps',
pom : configuration[ConfigurationType.MAVEN_PROJECT],
paths : ['package.path.apps'],
pom : configuration[ConfigurationType.MAVEN_PROJECT],
}),
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,26 @@ export interface ComposeIfUtils extends IfUtils {
/**
* Gets the Maven configuration from the file system and returns the value requested.
*/
export function getMavenConfigurationValueByPath<R>({ fallback, parser, path: propPath, pom }: MavenConfig<R>): R {
export function getMavenConfigurationValueByPath<R>({ fallback, parser, paths, pom }: MavenConfig<R>): R {
let value!: R

const file = pom ?? getConfiguration(ConfigurationType.MAVEN_PARENT)

xmlParser.parseString(getMavenConfigurationFromFile(file), (_: any, { project }: any) => {
const properties = project.properties[0]

value = _get(properties, propPath, fallback)
for (const path of paths) {
value = _get(properties, path)

if (parser) {
value = parser(value)
} else {
value = value[0]
if (!value || value === undefined || !Array.isArray(value)) {
continue
}

value = typeof parser === 'function' ? parser(value) : value[0]
}
})

return value
return value || fallback as R
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/types/maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface MavenConfigMap {
export interface MavenConfig<R> {
fallback?: R;
parser?: (value: any) => R;
path: string;
paths: string[];
pom?: string;
}

Expand Down

0 comments on commit a22c867

Please sign in to comment.