Skip to content

Commit

Permalink
fix: broken placeholders, if docker is used
Browse files Browse the repository at this point in the history
  • Loading branch information
kay-schecker committed Apr 26, 2022
1 parent 01c4945 commit f3f431d
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions apps/generator-cli/src/app/services/generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ export class GeneratorService {
const dockerVolumes = {};
const absoluteSpecPath = specFile ? path.resolve(cwd, specFile) : String(params.inputSpec)

const ext = path.extname(absoluteSpecPath)
const name = path.basename(absoluteSpecPath, ext)

const placeholders: { [key: string]: string } = {
name,
Name: upperFirst(name),

cwd,

base: path.basename(absoluteSpecPath),
dir: specFile && path.dirname(absoluteSpecPath),
path: absoluteSpecPath,

relDir: specFile && path.dirname(specFile),
relPath: specFile,
ext: ext.split('.').slice(-1).pop()
}

const command = Object.entries({
inputSpec: absoluteSpecPath,
...params,
Expand All @@ -116,8 +134,9 @@ export class GeneratorService {
case 'boolean':
return undefined
default:

if (this.configService.useDocker) {
v = this.replacePlaceholders(placeholders, v);

if (key === 'output') {
fs.ensureDirSync(v);
}
Expand All @@ -133,37 +152,23 @@ export class GeneratorService {
})()

return value === undefined ? `--${key}` : `--${key}=${value}`
}).join(' ')

const ext = path.extname(absoluteSpecPath)
const name = path.basename(absoluteSpecPath, ext)

const placeholders: { [key: string]: string } = {
name,
Name: upperFirst(name),

cwd,

base: path.basename(absoluteSpecPath),
dir: specFile && path.dirname(absoluteSpecPath),
path: absoluteSpecPath,

relDir: specFile && path.dirname(specFile),
relPath: specFile,
ext: ext.split('.').slice(-1).pop()
}
}).join(' ');

return this.cmd(
customGenerator,
Object.entries(placeholders)
.filter(([, replacement]) => !!replacement)
.reduce((cmd, [search, replacement]) => {
return cmd.split(`#{${search}}`).join(replacement)
}, command),
this.replacePlaceholders(placeholders, command),
dockerVolumes,
)
}

private replacePlaceholders(placeholders: Record<string, string>, input: string) {
return Object.entries(placeholders)
.filter(([, replacement]) => !!replacement)
.reduce((acc, [search, replacement]) => {
return acc.split(`#{${search}}`).join(replacement)
}, input);
}

private cmd = (customGenerator: string | undefined, appendix: string, dockerVolumes = {}) => {

if (this.configService.useDocker) {
Expand Down

0 comments on commit f3f431d

Please sign in to comment.