@strapi/generators 5.29.0 → 5.30.1

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.
Files changed (55) hide show
  1. package/dist/index.d.ts.map +1 -1
  2. package/dist/index.js +1 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +1 -2
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/plops/api.d.ts.map +1 -1
  7. package/dist/plops/api.js +79 -11
  8. package/dist/plops/api.js.map +1 -1
  9. package/dist/plops/api.mjs +79 -11
  10. package/dist/plops/api.mjs.map +1 -1
  11. package/dist/plops/content-type.d.ts.map +1 -1
  12. package/dist/plops/content-type.js +98 -2
  13. package/dist/plops/content-type.js.map +1 -1
  14. package/dist/plops/content-type.mjs +98 -2
  15. package/dist/plops/content-type.mjs.map +1 -1
  16. package/dist/plops/controller.d.ts.map +1 -1
  17. package/dist/plops/controller.js +35 -2
  18. package/dist/plops/controller.js.map +1 -1
  19. package/dist/plops/controller.mjs +35 -2
  20. package/dist/plops/controller.mjs.map +1 -1
  21. package/dist/plops/middleware.d.ts.map +1 -1
  22. package/dist/plops/middleware.js +35 -2
  23. package/dist/plops/middleware.js.map +1 -1
  24. package/dist/plops/middleware.mjs +35 -2
  25. package/dist/plops/middleware.mjs.map +1 -1
  26. package/dist/plops/migration.js.map +1 -1
  27. package/dist/plops/migration.mjs.map +1 -1
  28. package/dist/plops/policy.d.ts.map +1 -1
  29. package/dist/plops/policy.js +35 -2
  30. package/dist/plops/policy.js.map +1 -1
  31. package/dist/plops/policy.mjs +35 -2
  32. package/dist/plops/policy.mjs.map +1 -1
  33. package/dist/plops/service.d.ts.map +1 -1
  34. package/dist/plops/service.js +35 -2
  35. package/dist/plops/service.js.map +1 -1
  36. package/dist/plops/service.mjs +35 -2
  37. package/dist/plops/service.mjs.map +1 -1
  38. package/dist/plops/utils/extend-plugin-index-files.d.ts +8 -0
  39. package/dist/plops/utils/extend-plugin-index-files.d.ts.map +1 -0
  40. package/dist/plops/utils/extend-plugin-index-files.js +356 -0
  41. package/dist/plops/utils/extend-plugin-index-files.js.map +1 -0
  42. package/dist/plops/utils/extend-plugin-index-files.mjs +335 -0
  43. package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -0
  44. package/dist/plops/utils/get-file-path.d.ts +1 -1
  45. package/dist/plops/utils/get-file-path.js +2 -2
  46. package/dist/plops/utils/get-file-path.js.map +1 -1
  47. package/dist/plops/utils/get-file-path.mjs +2 -2
  48. package/dist/plops/utils/get-file-path.mjs.map +1 -1
  49. package/dist/templates/js/plugin/plugin.index.js.hbs +3 -0
  50. package/dist/templates/js/plugin/plugin.routes.index.js.hbs +12 -0
  51. package/dist/templates/js/plugin/plugin.routes.type.index.js.hbs +6 -0
  52. package/dist/templates/ts/plugin/plugin.index.ts.hbs +1 -0
  53. package/dist/templates/ts/plugin/plugin.routes.index.ts.hbs +9 -0
  54. package/dist/templates/ts/plugin/plugin.routes.type.index.ts.hbs +4 -0
  55. package/package.json +9 -5
@@ -0,0 +1,356 @@
1
+ 'use strict';
2
+
3
+ var jscodeshift = require('jscodeshift');
4
+ var camelCase = require('lodash/camelCase');
5
+
6
+ function _interopNamespaceDefault(e) {
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var jscodeshift__namespace = /*#__PURE__*/_interopNamespaceDefault(jscodeshift);
24
+
25
+ const j = jscodeshift__namespace.withParser('tsx');
26
+ // Helper to check if a string is a valid JavaScript identifier
27
+ const isValidIdentifier = (str)=>{
28
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str);
29
+ };
30
+ // Helper to create the appropriate property based on type
31
+ const createProperty = (config)=>{
32
+ const { type, singularName } = config;
33
+ const camelCaseName = camelCase(singularName);
34
+ const varName = type === 'content-type' ? `${camelCaseName}Schema` : camelCaseName;
35
+ // Use string literal for key only if singularName is not a valid identifier
36
+ const keyNode = isValidIdentifier(singularName) ? j.identifier(singularName) : j.literal(singularName);
37
+ switch(type){
38
+ case 'content-type':
39
+ return j.objectProperty(keyNode, j.objectExpression([
40
+ j.objectProperty(j.identifier('schema'), j.identifier(varName))
41
+ ]));
42
+ case 'index':
43
+ return j.objectProperty(keyNode, j.identifier(varName));
44
+ case 'routes':
45
+ return j.spreadElement(j.memberExpression(j.identifier(varName), j.identifier('routes')));
46
+ default:
47
+ throw new Error(`Unknown append type: ${type}`);
48
+ }
49
+ };
50
+ // Helper to check if property already exists
51
+ const hasExistingProperty = (obj, config)=>{
52
+ const { type, singularName } = config;
53
+ if (!obj?.properties && !j.ArrayExpression.check(obj)) return false;
54
+ const elements = j.ArrayExpression.check(obj) ? obj.elements : obj.properties;
55
+ if (!elements) return false;
56
+ if (type === 'routes') {
57
+ // Check for spread elements ...camelCaseName.routes
58
+ const camelCaseName = camelCase(singularName);
59
+ return elements.some((element)=>j.SpreadElement.check(element) && j.MemberExpression.check(element.argument) && j.Identifier.check(element.argument.object) && element.argument.object.name === camelCaseName && j.Identifier.check(element.argument.property) && element.argument.property.name === 'routes');
60
+ }
61
+ // For content-type and index, check for object property (both identifier and literal keys)
62
+ return elements.some((prop)=>j.ObjectProperty.check(prop) && (j.Identifier.check(prop.key) && prop.key.name === singularName || j.Literal.check(prop.key) && prop.key.value === singularName));
63
+ };
64
+ // Helper to add property to object if it doesn't exist
65
+ const addPropertyToObject = (obj, config)=>{
66
+ if (!obj || hasExistingProperty(obj, config)) return;
67
+ if (config.type === 'routes' && j.ArrayExpression.check(obj)) {
68
+ obj.elements.push(createRoutesElement(config));
69
+ } else if (obj.properties?.length >= 0) {
70
+ obj.properties.push(createProperty(config));
71
+ }
72
+ };
73
+ // Helper to find and add to routes array
74
+ const handleRoutesArray = (obj, config)=>{
75
+ if (!obj?.properties) return false;
76
+ const routesProp = obj.properties.find((prop)=>j.ObjectProperty.check(prop) && (j.Identifier.check(prop.key) && prop.key.name === 'routes' || j.Literal.check(prop.key) && prop.key.value === 'routes') && j.ArrayExpression.check(prop.value));
77
+ if (routesProp?.value) {
78
+ const routesArray = routesProp.value;
79
+ if (!hasExistingProperty(routesArray, config)) {
80
+ routesArray.elements = routesArray.elements || [];
81
+ routesArray.elements.push(createRoutesElement(config));
82
+ }
83
+ return true;
84
+ }
85
+ return false;
86
+ };
87
+ // Helper to create routes array element (always returns SpreadElement for routes)
88
+ const createRoutesElement = (config)=>{
89
+ const { singularName } = config;
90
+ const camelCaseName = camelCase(singularName);
91
+ return j.spreadElement(j.memberExpression(j.identifier(camelCaseName), j.identifier('routes')));
92
+ };
93
+ // Helper to create new export for routes
94
+ const createRoutesExport = (config)=>{
95
+ return j.arrowFunctionExpression([], j.objectExpression([
96
+ j.objectProperty(j.identifier('type'), j.literal('content-api')),
97
+ j.objectProperty(j.identifier('routes'), j.arrayExpression([
98
+ createRoutesElement(config)
99
+ ]))
100
+ ]));
101
+ };
102
+ // Unified append function for all types
103
+ const appendToFile = (template, config)=>{
104
+ if (!config?.singularName || !config?.type) {
105
+ throw new Error('Invalid config: singularName and type are required');
106
+ }
107
+ const normalizedTemplate = template?.trim() || '';
108
+ const root = normalizedTemplate ? j(normalizedTemplate) : j(j.program([]));
109
+ const { type, singularName } = config;
110
+ const isEsm = detectModuleFormat(normalizedTemplate) === 'esm';
111
+ const camelCaseName = camelCase(singularName);
112
+ const varName = type === 'content-type' ? `${camelCaseName}Schema` : camelCaseName;
113
+ const source = type === 'content-type' ? `./${singularName}/schema.json` : `./${singularName}`;
114
+ addImportIfMissing(root, varName, source, isEsm);
115
+ if (isEsm) {
116
+ handleEsmExport(root, config, type);
117
+ } else {
118
+ handleCjsExport(root, config, type);
119
+ }
120
+ return root.toSource({
121
+ quote: 'single'
122
+ });
123
+ };
124
+ // Helper to detect module format
125
+ const detectModuleFormat = (template)=>{
126
+ const hasImport = /^import\s/.test(template) || template.includes('import ');
127
+ const hasExportDefault = template.includes('export default');
128
+ const hasRequire = template.includes('require(');
129
+ const hasModuleExports = template.includes('module.exports');
130
+ if (hasImport || hasExportDefault) return 'esm';
131
+ if (hasRequire || hasModuleExports) return 'cjs';
132
+ return 'esm'; // Default to ESM
133
+ };
134
+ // Helper to insert statement at appropriate location
135
+ const insertStatement = (root, statement, preferredLocation)=>{
136
+ if (preferredLocation && preferredLocation.length > 0) {
137
+ preferredLocation.at(-1).insertAfter(statement);
138
+ } else {
139
+ const firstStatement = root.find(j.Statement).at(0);
140
+ if (firstStatement.length > 0) {
141
+ firstStatement.insertBefore(statement);
142
+ } else {
143
+ handleEmptyFile(root, statement);
144
+ }
145
+ }
146
+ };
147
+ // Helper to add import/require if missing
148
+ const addImportIfMissing = (root, varName, source, isEsm)=>{
149
+ if (isEsm) {
150
+ if (root.find(j.ImportDeclaration, {
151
+ source: {
152
+ value: source
153
+ }
154
+ }).length === 0) {
155
+ const importDecl = j.importDeclaration([
156
+ j.importDefaultSpecifier(j.identifier(varName))
157
+ ], j.literal(source));
158
+ insertStatement(root, importDecl, root.find(j.ImportDeclaration));
159
+ }
160
+ } else if (root.find(j.VariableDeclarator, {
161
+ id: {
162
+ name: varName
163
+ },
164
+ init: {
165
+ type: 'CallExpression',
166
+ callee: {
167
+ name: 'require'
168
+ },
169
+ arguments: [
170
+ {
171
+ value: source
172
+ }
173
+ ]
174
+ }
175
+ }).length === 0) {
176
+ const requireStmt = j.variableDeclaration('const', [
177
+ j.variableDeclarator(j.identifier(varName), j.callExpression(j.identifier('require'), [
178
+ j.literal(source)
179
+ ]))
180
+ ]);
181
+ const requires = root.find(j.VariableDeclaration).filter((path)=>path.value.declarations.some((decl)=>j.CallExpression.check(decl.init) && decl.init.callee?.name === 'require'));
182
+ const useStrict = root.find(j.ExpressionStatement).filter((path)=>j.Literal.check(path.value.expression) && /use strict/.test(String(path.value.expression.value)));
183
+ insertStatement(root, requireStmt, requires.length > 0 ? requires : useStrict);
184
+ }
185
+ };
186
+ // Helper to safely handle empty files
187
+ const handleEmptyFile = (root, firstStatement)=>{
188
+ try {
189
+ // Check if we have any paths in the collection
190
+ const paths = root.paths();
191
+ if (paths.length === 0) {
192
+ // Completely empty collection - create new program
193
+ const newProgram = j.program([
194
+ firstStatement
195
+ ]);
196
+ // Replace the entire root with new program
197
+ return root.replaceWith(newProgram);
198
+ }
199
+ // Get the first path (should be the program)
200
+ const rootPath = paths[0];
201
+ if (!rootPath || !rootPath.value) {
202
+ // Invalid root path - create new program
203
+ const newProgram = j.program([
204
+ firstStatement
205
+ ]);
206
+ return root.replaceWith(newProgram);
207
+ }
208
+ // Check if it's a valid program node
209
+ if (j.Program.check(rootPath.value)) {
210
+ // Ensure body exists and add statement
211
+ if (!rootPath.value.body) {
212
+ rootPath.value.body = [];
213
+ }
214
+ rootPath.value.body.push(firstStatement);
215
+ } else {
216
+ // Not a program node - replace with new program
217
+ const newProgram = j.program([
218
+ firstStatement
219
+ ]);
220
+ rootPath.replace(newProgram);
221
+ }
222
+ } catch (error) {
223
+ // Ultimate fallback - create a minimal working file
224
+ console.warn('Failed to handle empty file, creating new program:', error.message);
225
+ const newProgram = j.program([
226
+ firstStatement
227
+ ]);
228
+ try {
229
+ root.replaceWith(newProgram);
230
+ } catch (replaceError) {
231
+ // Last resort - throw descriptive error
232
+ throw new Error(`Unable to add statement to empty file: ${error.message}. Root collection may be invalid.`);
233
+ }
234
+ }
235
+ };
236
+ // Helper to find the exported object regardless of export pattern
237
+ const findExportedObject = (root, exportedValue)=>{
238
+ // Case 1: Direct object export
239
+ if (j.ObjectExpression.check(exportedValue)) {
240
+ return exportedValue;
241
+ }
242
+ // Case 2: Function that returns an object
243
+ if (j.FunctionExpression.check(exportedValue) || j.ArrowFunctionExpression.check(exportedValue) || j.FunctionDeclaration.check(exportedValue)) {
244
+ const body = exportedValue.body;
245
+ // Arrow function with object expression body: () => ({...})
246
+ if (j.ObjectExpression.check(body)) {
247
+ return body;
248
+ }
249
+ // Function with return statement in block
250
+ if (j.BlockStatement.check(body)) {
251
+ for (const stmt of body.body){
252
+ if (j.ReturnStatement.check(stmt) && j.ObjectExpression.check(stmt.argument)) {
253
+ return stmt.argument;
254
+ }
255
+ }
256
+ }
257
+ }
258
+ // Case 3: Identifier reference to a variable
259
+ if (j.Identifier.check(exportedValue)) {
260
+ const varName = exportedValue.name;
261
+ // Find the variable declaration
262
+ const varDeclaration = root.find(j.VariableDeclarator, {
263
+ id: {
264
+ name: varName
265
+ }
266
+ });
267
+ if (varDeclaration.length > 0) {
268
+ const init = varDeclaration.get().value.init;
269
+ // If it's an object, return it
270
+ if (j.ObjectExpression.check(init)) {
271
+ return init;
272
+ }
273
+ // If it's a function, recursively check its return value
274
+ if (j.FunctionExpression.check(init) || j.ArrowFunctionExpression.check(init)) {
275
+ return findExportedObject(root, init);
276
+ }
277
+ }
278
+ }
279
+ return null;
280
+ };
281
+ // Helper to handle object export (common logic for ESM and CJS)
282
+ const handleObjectExport = (obj, config, type, setExport)=>{
283
+ if (type === 'routes') {
284
+ if (!handleRoutesArray(obj, config)) {
285
+ setExport(createRoutesExport(config));
286
+ }
287
+ } else {
288
+ addPropertyToObject(obj, config);
289
+ }
290
+ };
291
+ // Handle ESM export default
292
+ const handleEsmExport = (root, config, type)=>{
293
+ const exports = root.find(j.ExportDefaultDeclaration);
294
+ if (exports.length === 0) {
295
+ const newExport = type === 'routes' ? createRoutesExport(config) : j.objectExpression([
296
+ createProperty(config)
297
+ ]);
298
+ insertStatement(root, j.exportDefaultDeclaration(newExport), root.find(j.Statement));
299
+ } else {
300
+ exports.forEach((path)=>{
301
+ const decl = path.value.declaration;
302
+ // Find the actual object being exported
303
+ const exportedObject = findExportedObject(root, decl);
304
+ if (exportedObject) {
305
+ handleObjectExport(exportedObject, config, type, (newExport)=>{
306
+ path.value.declaration = newExport;
307
+ });
308
+ } else {
309
+ // Fallback: replace the entire export
310
+ path.value.declaration = type === 'routes' ? createRoutesExport(config) : j.objectExpression([
311
+ createProperty(config)
312
+ ]);
313
+ }
314
+ });
315
+ }
316
+ };
317
+ // Handle CJS module.exports
318
+ const handleCjsExport = (root, config, type)=>{
319
+ const exports = root.find(j.AssignmentExpression, {
320
+ left: {
321
+ type: 'MemberExpression',
322
+ object: {
323
+ name: 'module'
324
+ },
325
+ property: {
326
+ name: 'exports'
327
+ }
328
+ }
329
+ });
330
+ if (exports.length === 0) {
331
+ const newExport = type === 'routes' ? createRoutesExport(config) : j.objectExpression([
332
+ createProperty(config)
333
+ ]);
334
+ const moduleExportStmt = j.expressionStatement(j.assignmentExpression('=', j.memberExpression(j.identifier('module'), j.identifier('exports')), newExport));
335
+ insertStatement(root, moduleExportStmt, root.find(j.Statement));
336
+ } else {
337
+ exports.forEach((path)=>{
338
+ const right = path.value.right;
339
+ // Find the actual object being exported
340
+ const exportedObject = findExportedObject(root, right);
341
+ if (exportedObject) {
342
+ handleObjectExport(exportedObject, config, type, (newExport)=>{
343
+ path.value.right = newExport;
344
+ });
345
+ } else {
346
+ // Fallback: replace the entire export
347
+ path.value.right = type === 'routes' ? createRoutesExport(config) : j.objectExpression([
348
+ createProperty(config)
349
+ ]);
350
+ }
351
+ });
352
+ }
353
+ };
354
+
355
+ exports.appendToFile = appendToFile;
356
+ //# sourceMappingURL=extend-plugin-index-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extend-plugin-index-files.js","sources":["../../../src/plops/utils/extend-plugin-index-files.ts"],"sourcesContent":["import * as jscodeshift from 'jscodeshift';\nimport camelCase from 'lodash/camelCase';\n\nconst j = jscodeshift.withParser('tsx');\n\ntype AppendType = 'content-type' | 'index' | 'routes';\n\ninterface AppendConfig {\n type: AppendType;\n singularName: string;\n}\n\n// Helper to check if a string is a valid JavaScript identifier\nconst isValidIdentifier = (str: string): boolean => {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str);\n};\n\n// Helper to create the appropriate property based on type\nconst createProperty = (config: AppendConfig) => {\n const { type, singularName } = config;\n const camelCaseName = camelCase(singularName);\n const varName = type === 'content-type' ? `${camelCaseName}Schema` : camelCaseName;\n\n // Use string literal for key only if singularName is not a valid identifier\n const keyNode = isValidIdentifier(singularName)\n ? j.identifier(singularName)\n : j.literal(singularName);\n\n switch (type) {\n case 'content-type':\n return j.objectProperty(\n keyNode,\n j.objectExpression([j.objectProperty(j.identifier('schema'), j.identifier(varName))])\n );\n case 'index':\n return j.objectProperty(keyNode, j.identifier(varName));\n case 'routes':\n return j.spreadElement(j.memberExpression(j.identifier(varName), j.identifier('routes')));\n default:\n throw new Error(`Unknown append type: ${type}`);\n }\n};\n\n// Helper to check if property already exists\nconst hasExistingProperty = (obj: any, config: AppendConfig): boolean => {\n const { type, singularName } = config;\n if (!obj?.properties && !j.ArrayExpression.check(obj)) return false;\n\n const elements = j.ArrayExpression.check(obj) ? obj.elements : obj.properties;\n if (!elements) return false;\n\n if (type === 'routes') {\n // Check for spread elements ...camelCaseName.routes\n const camelCaseName = camelCase(singularName);\n return elements.some(\n (element: any) =>\n j.SpreadElement.check(element) &&\n j.MemberExpression.check(element.argument) &&\n j.Identifier.check(element.argument.object) &&\n element.argument.object.name === camelCaseName &&\n j.Identifier.check(element.argument.property) &&\n element.argument.property.name === 'routes'\n );\n }\n\n // For content-type and index, check for object property (both identifier and literal keys)\n return elements.some(\n (prop: any) =>\n j.ObjectProperty.check(prop) &&\n ((j.Identifier.check(prop.key) && prop.key.name === singularName) ||\n (j.Literal.check(prop.key) && prop.key.value === singularName))\n );\n};\n\n// Helper to add property to object if it doesn't exist\nconst addPropertyToObject = (obj: any, config: AppendConfig) => {\n if (!obj || hasExistingProperty(obj, config)) return;\n\n if (config.type === 'routes' && j.ArrayExpression.check(obj)) {\n obj.elements.push(createRoutesElement(config));\n } else if (obj.properties?.length >= 0) {\n obj.properties.push(createProperty(config));\n }\n};\n\n// Helper to find and add to routes array\nconst handleRoutesArray = (obj: any, config: AppendConfig) => {\n if (!obj?.properties) return false;\n\n const routesProp = obj.properties.find(\n (prop: any) =>\n j.ObjectProperty.check(prop) &&\n ((j.Identifier.check(prop.key) && prop.key.name === 'routes') ||\n (j.Literal.check(prop.key) && prop.key.value === 'routes')) &&\n j.ArrayExpression.check(prop.value)\n );\n\n if (routesProp?.value) {\n const routesArray = routesProp.value;\n if (!hasExistingProperty(routesArray, config)) {\n routesArray.elements = routesArray.elements || [];\n routesArray.elements.push(createRoutesElement(config));\n }\n return true;\n }\n\n return false;\n};\n\n// Helper to create routes array element (always returns SpreadElement for routes)\nconst createRoutesElement = (config: AppendConfig) => {\n const { singularName } = config;\n const camelCaseName = camelCase(singularName);\n return j.spreadElement(j.memberExpression(j.identifier(camelCaseName), j.identifier('routes')));\n};\n\n// Helper to create new export for routes\nconst createRoutesExport = (config: AppendConfig) => {\n return j.arrowFunctionExpression(\n [],\n j.objectExpression([\n j.objectProperty(j.identifier('type'), j.literal('content-api')),\n j.objectProperty(j.identifier('routes'), j.arrayExpression([createRoutesElement(config)])),\n ])\n );\n};\n\n// Unified append function for all types\nexport const appendToFile = (template: string, config: AppendConfig): string => {\n if (!config?.singularName || !config?.type) {\n throw new Error('Invalid config: singularName and type are required');\n }\n\n const normalizedTemplate = template?.trim() || '';\n const root = normalizedTemplate ? j(normalizedTemplate) : j(j.program([]));\n const { type, singularName } = config;\n const isEsm = detectModuleFormat(normalizedTemplate) === 'esm';\n\n const camelCaseName = camelCase(singularName);\n const varName = type === 'content-type' ? `${camelCaseName}Schema` : camelCaseName;\n const source = type === 'content-type' ? `./${singularName}/schema.json` : `./${singularName}`;\n\n addImportIfMissing(root, varName, source, isEsm);\n\n if (isEsm) {\n handleEsmExport(root, config, type);\n } else {\n handleCjsExport(root, config, type);\n }\n\n return root.toSource({ quote: 'single' });\n};\n\n// Helper to detect module format\nconst detectModuleFormat = (template: string): 'esm' | 'cjs' => {\n const hasImport = /^import\\s/.test(template) || template.includes('import ');\n const hasExportDefault = template.includes('export default');\n const hasRequire = template.includes('require(');\n const hasModuleExports = template.includes('module.exports');\n\n if (hasImport || hasExportDefault) return 'esm';\n if (hasRequire || hasModuleExports) return 'cjs';\n return 'esm'; // Default to ESM\n};\n\n// Helper to insert statement at appropriate location\nconst insertStatement = (\n root: jscodeshift.Collection<any>,\n statement: any,\n preferredLocation?: jscodeshift.Collection<any>\n) => {\n if (preferredLocation && preferredLocation.length > 0) {\n preferredLocation.at(-1).insertAfter(statement);\n } else {\n const firstStatement = root.find(j.Statement).at(0);\n if (firstStatement.length > 0) {\n firstStatement.insertBefore(statement);\n } else {\n handleEmptyFile(root, statement);\n }\n }\n};\n\n// Helper to add import/require if missing\nconst addImportIfMissing = (\n root: jscodeshift.Collection<any>,\n varName: string,\n source: string,\n isEsm: boolean\n) => {\n if (isEsm) {\n if (root.find(j.ImportDeclaration, { source: { value: source } }).length === 0) {\n const importDecl = j.importDeclaration(\n [j.importDefaultSpecifier(j.identifier(varName))],\n j.literal(source)\n );\n insertStatement(root, importDecl, root.find(j.ImportDeclaration));\n }\n } else if (\n root.find(j.VariableDeclarator, {\n id: { name: varName },\n init: { type: 'CallExpression', callee: { name: 'require' }, arguments: [{ value: source }] },\n }).length === 0\n ) {\n const requireStmt = j.variableDeclaration('const', [\n j.variableDeclarator(\n j.identifier(varName),\n j.callExpression(j.identifier('require'), [j.literal(source)])\n ),\n ]);\n\n const requires = root\n .find(j.VariableDeclaration)\n .filter((path) =>\n path.value.declarations.some(\n (decl: any) => j.CallExpression.check(decl.init) && decl.init.callee?.name === 'require'\n )\n );\n\n const useStrict = root\n .find(j.ExpressionStatement)\n .filter(\n (path: any) =>\n j.Literal.check(path.value.expression) &&\n /use strict/.test(String(path.value.expression.value))\n );\n\n insertStatement(root, requireStmt, requires.length > 0 ? requires : useStrict);\n }\n};\n\n// Helper to safely handle empty files\nconst handleEmptyFile = (root: jscodeshift.Collection<any>, firstStatement: any) => {\n try {\n // Check if we have any paths in the collection\n const paths = root.paths();\n if (paths.length === 0) {\n // Completely empty collection - create new program\n const newProgram = j.program([firstStatement]);\n // Replace the entire root with new program\n return root.replaceWith(newProgram);\n }\n\n // Get the first path (should be the program)\n const rootPath = paths[0];\n if (!rootPath || !rootPath.value) {\n // Invalid root path - create new program\n const newProgram = j.program([firstStatement]);\n return root.replaceWith(newProgram);\n }\n\n // Check if it's a valid program node\n if (j.Program.check(rootPath.value)) {\n // Ensure body exists and add statement\n if (!rootPath.value.body) {\n rootPath.value.body = [];\n }\n rootPath.value.body.push(firstStatement);\n } else {\n // Not a program node - replace with new program\n const newProgram = j.program([firstStatement]);\n rootPath.replace(newProgram);\n }\n } catch (error: any) {\n // Ultimate fallback - create a minimal working file\n console.warn('Failed to handle empty file, creating new program:', error.message);\n const newProgram = j.program([firstStatement]);\n try {\n root.replaceWith(newProgram);\n } catch (replaceError) {\n // Last resort - throw descriptive error\n throw new Error(\n `Unable to add statement to empty file: ${error.message}. Root collection may be invalid.`\n );\n }\n }\n};\n\n// Helper to find the exported object regardless of export pattern\nconst findExportedObject = (root: jscodeshift.Collection<any>, exportedValue: any): any => {\n // Case 1: Direct object export\n if (j.ObjectExpression.check(exportedValue)) {\n return exportedValue;\n }\n\n // Case 2: Function that returns an object\n if (\n j.FunctionExpression.check(exportedValue) ||\n j.ArrowFunctionExpression.check(exportedValue) ||\n j.FunctionDeclaration.check(exportedValue)\n ) {\n const body = exportedValue.body;\n // Arrow function with object expression body: () => ({...})\n if (j.ObjectExpression.check(body)) {\n return body;\n }\n // Function with return statement in block\n if (j.BlockStatement.check(body)) {\n for (const stmt of body.body) {\n if (j.ReturnStatement.check(stmt) && j.ObjectExpression.check(stmt.argument)) {\n return stmt.argument;\n }\n }\n }\n }\n\n // Case 3: Identifier reference to a variable\n if (j.Identifier.check(exportedValue)) {\n const varName = exportedValue.name;\n\n // Find the variable declaration\n const varDeclaration = root.find(j.VariableDeclarator, {\n id: { name: varName },\n });\n\n if (varDeclaration.length > 0) {\n const init = varDeclaration.get().value.init;\n\n // If it's an object, return it\n if (j.ObjectExpression.check(init)) {\n return init;\n }\n\n // If it's a function, recursively check its return value\n if (j.FunctionExpression.check(init) || j.ArrowFunctionExpression.check(init)) {\n return findExportedObject(root, init);\n }\n }\n }\n\n return null;\n};\n\n// Helper to handle object export (common logic for ESM and CJS)\nconst handleObjectExport = (\n obj: any,\n config: AppendConfig,\n type: AppendType,\n setExport: (newExport: any) => void\n) => {\n if (type === 'routes') {\n if (!handleRoutesArray(obj, config)) {\n setExport(createRoutesExport(config));\n }\n } else {\n addPropertyToObject(obj, config);\n }\n};\n\n// Handle ESM export default\nconst handleEsmExport = (\n root: jscodeshift.Collection<any>,\n config: AppendConfig,\n type: AppendType\n) => {\n const exports = root.find(j.ExportDefaultDeclaration);\n\n if (exports.length === 0) {\n const newExport =\n type === 'routes' ? createRoutesExport(config) : j.objectExpression([createProperty(config)]);\n insertStatement(root, j.exportDefaultDeclaration(newExport), root.find(j.Statement));\n } else {\n exports.forEach((path: any) => {\n const decl = path.value.declaration;\n\n // Find the actual object being exported\n const exportedObject = findExportedObject(root, decl);\n\n if (exportedObject) {\n handleObjectExport(exportedObject, config, type, (newExport) => {\n path.value.declaration = newExport;\n });\n } else {\n // Fallback: replace the entire export\n path.value.declaration =\n type === 'routes'\n ? createRoutesExport(config)\n : j.objectExpression([createProperty(config)]);\n }\n });\n }\n};\n\n// Handle CJS module.exports\nconst handleCjsExport = (\n root: jscodeshift.Collection<any>,\n config: AppendConfig,\n type: AppendType\n) => {\n const exports = root.find(j.AssignmentExpression, {\n left: { type: 'MemberExpression', object: { name: 'module' }, property: { name: 'exports' } },\n });\n\n if (exports.length === 0) {\n const newExport =\n type === 'routes' ? createRoutesExport(config) : j.objectExpression([createProperty(config)]);\n const moduleExportStmt = j.expressionStatement(\n j.assignmentExpression(\n '=',\n j.memberExpression(j.identifier('module'), j.identifier('exports')),\n newExport\n )\n );\n insertStatement(root, moduleExportStmt, root.find(j.Statement));\n } else {\n exports.forEach((path: any) => {\n const right = path.value.right;\n\n // Find the actual object being exported\n const exportedObject = findExportedObject(root, right);\n\n if (exportedObject) {\n handleObjectExport(exportedObject, config, type, (newExport) => {\n path.value.right = newExport;\n });\n } else {\n // Fallback: replace the entire export\n path.value.right =\n type === 'routes'\n ? createRoutesExport(config)\n : j.objectExpression([createProperty(config)]);\n }\n });\n }\n};\n"],"names":["j","jscodeshift","withParser","isValidIdentifier","str","test","createProperty","config","type","singularName","camelCaseName","camelCase","varName","keyNode","identifier","literal","objectProperty","objectExpression","spreadElement","memberExpression","Error","hasExistingProperty","obj","properties","ArrayExpression","check","elements","some","element","SpreadElement","MemberExpression","argument","Identifier","object","name","property","prop","ObjectProperty","key","Literal","value","addPropertyToObject","push","createRoutesElement","length","handleRoutesArray","routesProp","find","routesArray","createRoutesExport","arrowFunctionExpression","arrayExpression","appendToFile","template","normalizedTemplate","trim","root","program","isEsm","detectModuleFormat","source","addImportIfMissing","handleEsmExport","handleCjsExport","toSource","quote","hasImport","includes","hasExportDefault","hasRequire","hasModuleExports","insertStatement","statement","preferredLocation","at","insertAfter","firstStatement","Statement","insertBefore","handleEmptyFile","ImportDeclaration","importDecl","importDeclaration","importDefaultSpecifier","VariableDeclarator","id","init","callee","arguments","requireStmt","variableDeclaration","variableDeclarator","callExpression","requires","VariableDeclaration","filter","path","declarations","decl","CallExpression","useStrict","ExpressionStatement","expression","String","paths","newProgram","replaceWith","rootPath","Program","body","replace","error","console","warn","message","replaceError","findExportedObject","exportedValue","ObjectExpression","FunctionExpression","ArrowFunctionExpression","FunctionDeclaration","BlockStatement","stmt","ReturnStatement","varDeclaration","get","handleObjectExport","setExport","exports","ExportDefaultDeclaration","newExport","exportDefaultDeclaration","forEach","declaration","exportedObject","AssignmentExpression","left","moduleExportStmt","expressionStatement","assignmentExpression","right"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAMA,CAAAA,GAAIC,sBAAYC,CAAAA,UAAU,CAAC,KAAA,CAAA;AASjC;AAC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