Skip to content

Commit f3f431d

Browse files
committed
fix: broken placeholders, if docker is used
1 parent 01c4945 commit f3f431d

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

apps/generator-cli/src/app/services/generator.service.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ export class GeneratorService {
100100
const dockerVolumes = {};
101101
const absoluteSpecPath = specFile ? path.resolve(cwd, specFile) : String(params.inputSpec)
102102

103+
const ext = path.extname(absoluteSpecPath)
104+
const name = path.basename(absoluteSpecPath, ext)
105+
106+
const placeholders: { [key: string]: string } = {
107+
name,
108+
Name: upperFirst(name),
109+
110+
cwd,
111+
112+
base: path.basename(absoluteSpecPath),
113+
dir: specFile && path.dirname(absoluteSpecPath),
114+
path: absoluteSpecPath,
115+
116+
relDir: specFile && path.dirname(specFile),
117+
relPath: specFile,
118+
ext: ext.split('.').slice(-1).pop()
119+
}
120+
103121
const command = Object.entries({
104122
inputSpec: absoluteSpecPath,
105123
...params,
@@ -116,8 +134,9 @@ export class GeneratorService {
116134
case 'boolean':
117135
return undefined
118136
default:
119-
120137
if (this.configService.useDocker) {
138+
v = this.replacePlaceholders(placeholders, v);
139+
121140
if (key === 'output') {
122141
fs.ensureDirSync(v);
123142
}
@@ -133,37 +152,23 @@ export class GeneratorService {
133152
})()
134153

135154
return value === undefined ? `--${key}` : `--${key}=${value}`
136-
}).join(' ')
137-
138-
const ext = path.extname(absoluteSpecPath)
139-
const name = path.basename(absoluteSpecPath, ext)
140-
141-
const placeholders: { [key: string]: string } = {
142-
name,
143-
Name: upperFirst(name),
144-
145-
cwd,
146-
147-
base: path.basename(absoluteSpecPath),
148-
dir: specFile && path.dirname(absoluteSpecPath),
149-
path: absoluteSpecPath,
150-
151-
relDir: specFile && path.dirname(specFile),
152-
relPath: specFile,
153-
ext: ext.split('.').slice(-1).pop()
154-
}
155+
}).join(' ');
155156

156157
return this.cmd(
157158
customGenerator,
158-
Object.entries(placeholders)
159-
.filter(([, replacement]) => !!replacement)
160-
.reduce((cmd, [search, replacement]) => {
161-
return cmd.split(`#{${search}}`).join(replacement)
162-
}, command),
159+
this.replacePlaceholders(placeholders, command),
163160
dockerVolumes,
164161
)
165162
}
166163

164+
private replacePlaceholders(placeholders: Record<string, string>, input: string) {
165+
return Object.entries(placeholders)
166+
.filter(([, replacement]) => !!replacement)
167+
.reduce((acc, [search, replacement]) => {
168+
return acc.split(`#{${search}}`).join(replacement)
169+
}, input);
170+
}
171+
167172
private cmd = (customGenerator: string | undefined, appendix: string, dockerVolumes = {}) => {
168173

169174
if (this.configService.useDocker) {

0 commit comments

Comments
 (0)