Skip to content

Commit 41b6729

Browse files
authored
Merge pull request #8 from ShtibsDev/bugfix/whitespace-tokens-not-ignored
Fixed whitespace tokens not ignored
2 parents 3a30e4d + c61cf9c commit 41b6729

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prisma-enum-validator-generator",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "This will generate utility functions to validate enums in the Prisma schema file.",
55
"main": "./dist/index.js",
66
"bin": "./dist/index.js",

src/generate.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,21 @@ function parseEnums(dataModel: string) {
2727
return name;
2828
}) ?? [];
2929

30-
console.log('All enums', enums);
31-
3230
const enumUsage: any = {};
3331
enums.forEach((e) => (enumUsage[e] = 0));
3432

33+
const ignoreTokens = ['@@', '//'];
34+
3535
for (const modelString of modelStrings ?? []) {
3636
const fieldsString = modelString.substring(modelString.indexOf('{')).replace('{', '').replace('}', '').trim();
3737
const fields = fieldsString
3838
.split('\n')
3939
.map((f) => f.trim())
40-
.filter((f) => !f.startsWith('@@'));
40+
.filter((f) => f && !ignoreTokens.some((it) => f.startsWith(it)));
4141
for (const field of fields) {
42-
const fieldType = field.split(/\s/)[1] ?? null;
42+
const tokens = field.split(/\s/).filter(Boolean);
43+
44+
const fieldType = tokens[1] ?? null;
4345

4446
if (!fieldType) continue;
4547

@@ -84,7 +86,6 @@ export default async (options: GeneratorOptions) => {
8486

8587
const output = options.generator.output?.value || `./prisma/enum-validators.${isTs ? 'ts' : 'js'}`;
8688
const enums = parseEnums(options.datamodel);
87-
console.log('filtered', enums);
8889

8990
const fileContent = generateFileContent(enums, isTs);
9091

0 commit comments

Comments
 (0)