@igniter-js/cli 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +12 -1
- package/dist/templates/copilot.feature.instructions.hbs +145 -0
- package/dist/templates/copilot.igniter.instructions.hbs +753 -0
- package/dist/templates/copilot.next.instructions.hbs +67 -0
- package/dist/templates/copilot.review.instructions.hbs +42 -0
- package/dist/templates/copilot.test.instructions.hbs +55 -0
- package/dist/templates/eslintrc.hbs +5 -2
- package/dist/templates/feature.controller.hbs +3 -1
- package/dist/templates/feature.interface.hbs +32 -22
- package/dist/templates/feature.procedure.hbs +4 -3
- package/dist/templates/globals.hbs +1 -1
- package/dist/templates/layout.hbs +15 -22
- package/dist/templates/page.hbs +76 -239
- package/dist/templates/route.hbs +4 -0
- package/dist/templates/vscode.settings.hbs +50 -0
- package/dist/utils/consts.d.ts +5 -7
- package/dist/utils/consts.js +11 -8
- package/dist/utils/handlebars-helpers.js +20 -0
- package/dist/utils/prisma-schema-parser.d.ts +1 -0
- package/dist/utils/prisma-schema-parser.js +92 -29
- package/package.json +1 -1
|
@@ -49,7 +49,17 @@ class PrismaSchemaParser {
|
|
|
49
49
|
return [];
|
|
50
50
|
}
|
|
51
51
|
const fieldsContent = modelMatch[1].trim();
|
|
52
|
-
|
|
52
|
+
const fields = this.parseFields(fieldsContent);
|
|
53
|
+
// Transform parsed fields to include relationship info
|
|
54
|
+
return fields.map(field => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
return ({
|
|
57
|
+
...field,
|
|
58
|
+
isRelation: !!field.relations || this.schemaContent.includes(`model ${field.type} {`),
|
|
59
|
+
isList: field.isList || (((_a = field.relations) === null || _a === void 0 ? void 0 : _a.type) === 'one-to-many' || ((_b = field.relations) === null || _b === void 0 ? void 0 : _b.type) === 'many-to-many'),
|
|
60
|
+
isOptional: field.hasDefault || field.isOptional
|
|
61
|
+
});
|
|
62
|
+
});
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
55
65
|
* Parses field strings into structured field objects
|
|
@@ -64,6 +74,7 @@ class PrismaSchemaParser {
|
|
|
64
74
|
continue;
|
|
65
75
|
const field = this.parseFieldLine(trimmedLine);
|
|
66
76
|
if (field) {
|
|
77
|
+
console.log(field);
|
|
67
78
|
fields.push(field);
|
|
68
79
|
}
|
|
69
80
|
}
|
|
@@ -75,7 +86,7 @@ class PrismaSchemaParser {
|
|
|
75
86
|
parseFieldLine(line) {
|
|
76
87
|
this.loadSchema();
|
|
77
88
|
// Basic field pattern: name type modifiers
|
|
78
|
-
const fieldPattern = /^(\w+)\s+(\w+)(
|
|
89
|
+
const fieldPattern = /^(\w+)\s+(\w+)(?:\?|\[\])?\s*(@[^\n]+)?$/;
|
|
79
90
|
const match = line.match(fieldPattern);
|
|
80
91
|
if (!match)
|
|
81
92
|
return null;
|
|
@@ -83,31 +94,42 @@ class PrismaSchemaParser {
|
|
|
83
94
|
const modifiers = line.slice(match[0].length).trim();
|
|
84
95
|
const isOptional = line.includes('?');
|
|
85
96
|
const isList = line.includes('[]');
|
|
86
|
-
const hasDefault =
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
// Verifica se é um enum
|
|
92
|
-
const isEnum = this.schemaContent.includes(`enum ${type} {`);
|
|
97
|
+
const hasDefault = line.includes('@default');
|
|
98
|
+
// Check if type is a model (potential relation)
|
|
99
|
+
const isModelType = this.schemaContent.includes(`model ${type} {`);
|
|
93
100
|
// Parse relations
|
|
94
101
|
let relations = undefined;
|
|
95
|
-
|
|
102
|
+
let isRelation = false;
|
|
103
|
+
if (line.includes('@relation') || isModelType) {
|
|
96
104
|
const relationMatch = line.match(/@relation\([^)]*\)/);
|
|
97
105
|
if (relationMatch) {
|
|
98
106
|
relations = this.parseRelation(relationMatch[0], isList);
|
|
107
|
+
isRelation = true;
|
|
108
|
+
}
|
|
109
|
+
else if (isModelType) {
|
|
110
|
+
// If it's a model type but doesn't have @relation, create a default relation
|
|
111
|
+
relations = {
|
|
112
|
+
type: isList ? 'one-to-many' : 'one-to-one',
|
|
113
|
+
model: type,
|
|
114
|
+
fields: [name + 'Id'],
|
|
115
|
+
references: ['id']
|
|
116
|
+
};
|
|
117
|
+
isRelation = true;
|
|
99
118
|
}
|
|
100
119
|
}
|
|
120
|
+
// Verifica se é um enum
|
|
121
|
+
const isEnum = this.schemaContent.includes(`enum ${type} {`);
|
|
101
122
|
return {
|
|
102
123
|
name,
|
|
103
124
|
type,
|
|
104
|
-
zodType: this.getZodType(type, isOptional, isList),
|
|
125
|
+
zodType: this.getZodType(type, isOptional || hasDefault, isList),
|
|
105
126
|
description: `${name} field`,
|
|
106
|
-
isOptional,
|
|
127
|
+
isOptional: isOptional || hasDefault,
|
|
107
128
|
isList,
|
|
108
129
|
hasDefault,
|
|
109
130
|
isEnum,
|
|
110
|
-
relations
|
|
131
|
+
relations,
|
|
132
|
+
isRelation
|
|
111
133
|
};
|
|
112
134
|
}
|
|
113
135
|
/**
|
|
@@ -115,22 +137,63 @@ class PrismaSchemaParser {
|
|
|
115
137
|
*/
|
|
116
138
|
parseRelation(relationString, isList) {
|
|
117
139
|
var _a;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
model
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
try {
|
|
141
|
+
// Extract details from @relation(...) string
|
|
142
|
+
const relationDetails = (_a = relationString.match(/@relation\(([^)]+)\)/)) === null || _a === void 0 ? void 0 : _a[1].trim();
|
|
143
|
+
if (!relationDetails)
|
|
144
|
+
return undefined;
|
|
145
|
+
// Extract fields and references from the relation
|
|
146
|
+
const fieldsMatch = relationDetails.match(/fields:\s*\[\s*([^\]]+)\s*\]/);
|
|
147
|
+
const referencesMatch = relationDetails.match(/references:\s*\[\s*([^\]]+)\s*\]/);
|
|
148
|
+
if (fieldsMatch && referencesMatch) {
|
|
149
|
+
// Get fields and references
|
|
150
|
+
const fields = fieldsMatch[1].split(',').map(f => f.trim().replace(/['"]/g, ''));
|
|
151
|
+
const references = referencesMatch[1].split(',').map(r => r.trim().replace(/['"]/g, ''));
|
|
152
|
+
// Try to find referenced model from the context
|
|
153
|
+
let model = '';
|
|
154
|
+
// Check if there's an explicit model name attribute
|
|
155
|
+
const modelMatch = relationDetails.match(/name:\s*['"]?(\w+)['"]?/);
|
|
156
|
+
if (modelMatch) {
|
|
157
|
+
model = modelMatch[1];
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// Infer model from schema by looking at field references
|
|
161
|
+
// This is a simplification - in a real implementation you might need to look at
|
|
162
|
+
// the other side of the relation in the schema
|
|
163
|
+
const referenceField = references[0].replace(/['"]/g, '');
|
|
164
|
+
if (referenceField === 'id') {
|
|
165
|
+
// Try to find "@relation(fields: [categoryId], references: [id])"
|
|
166
|
+
// Where categoryId indicates a Category model
|
|
167
|
+
const possibleModelField = fields[0];
|
|
168
|
+
if (possibleModelField && possibleModelField.toLowerCase().endsWith('id')) {
|
|
169
|
+
// Extract model name by removing the 'Id' suffix
|
|
170
|
+
model = possibleModelField.substring(0, possibleModelField.length - 2);
|
|
171
|
+
// Convert first letter to uppercase for proper model name format
|
|
172
|
+
model = model.charAt(0).toUpperCase() + model.slice(1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Determine relation type based on list status and fields/references count
|
|
177
|
+
let relationType;
|
|
178
|
+
if (fields.length > 1 || references.length > 1) {
|
|
179
|
+
relationType = 'many-to-many';
|
|
180
|
+
}
|
|
181
|
+
else if (isList) {
|
|
182
|
+
relationType = 'one-to-many';
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
relationType = 'one-to-one';
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
type: relationType,
|
|
189
|
+
model,
|
|
190
|
+
fields,
|
|
191
|
+
references
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
console.log(`Error parsing relation: ${error}`);
|
|
134
197
|
}
|
|
135
198
|
return undefined;
|
|
136
199
|
}
|