Skip to content

Commit 739c08c

Browse files
authored
Merge pull request #83 from frouriojs/fix-226
feat: show the error when multiple path param folders made
2 parents 8c6d27d + b071dbf commit 739c08c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/createControllersText.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,21 @@ const createFiles = (
156156
params
157157
)
158158

159-
fs.readdirSync(input, { withFileTypes: true }).forEach(
160-
d =>
161-
d.isDirectory() &&
162-
createFiles(
163-
appDir,
164-
path.posix.join(dirPath, d.name),
165-
d.name.startsWith('_')
166-
? [...params, [d.name.slice(1).split('@')[0], d.name.split('@')[1] ?? 'string']]
167-
: params,
168-
appText,
169-
additionalReqs
170-
)
159+
const dirs = fs.readdirSync(input, { withFileTypes: true }).filter(d => d.isDirectory())
160+
if (dirs.filter(d => d.name.startsWith('_')).length >= 2) {
161+
throw new Error('There are two ore more path param folders.')
162+
}
163+
164+
dirs.forEach(d =>
165+
createFiles(
166+
appDir,
167+
path.posix.join(dirPath, d.name),
168+
d.name.startsWith('_')
169+
? [...params, [d.name.slice(1).split('@')[0], d.name.split('@')[1] ?? 'string']]
170+
: params,
171+
appText,
172+
additionalReqs
173+
)
171174
)
172175
}
173176

0 commit comments

Comments
 (0)