@payloadcms/figma 0.0.1-alpha.3 → 0.0.1-alpha.31

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 (229) hide show
  1. package/dist/api/control-plane.d.ts +22 -1
  2. package/dist/api/control-plane.d.ts.map +1 -1
  3. package/dist/api/control-plane.js +54 -15
  4. package/dist/api/control-plane.js.map +1 -1
  5. package/dist/api/figma-api.d.ts.map +1 -1
  6. package/dist/api/figma-api.js +42 -12
  7. package/dist/api/figma-api.js.map +1 -1
  8. package/dist/auth/callback-server.d.ts.map +1 -1
  9. package/dist/auth/callback-server.js +2 -1
  10. package/dist/auth/callback-server.js.map +1 -1
  11. package/dist/auth/crypto-utils.d.ts.map +1 -1
  12. package/dist/auth/crypto-utils.js +5 -5
  13. package/dist/auth/crypto-utils.js.map +1 -1
  14. package/dist/auth/oauth-flow.d.ts +1 -1
  15. package/dist/auth/oauth-flow.d.ts.map +1 -1
  16. package/dist/auth/oauth-flow.js +5 -5
  17. package/dist/auth/oauth-flow.js.map +1 -1
  18. package/dist/auth/project-token.d.ts.map +1 -1
  19. package/dist/auth/project-token.js +9 -4
  20. package/dist/auth/project-token.js.map +1 -1
  21. package/dist/auth/token-store.d.ts +10 -0
  22. package/dist/auth/token-store.d.ts.map +1 -1
  23. package/dist/auth/token-store.js +20 -0
  24. package/dist/auth/token-store.js.map +1 -1
  25. package/dist/cli.js +3 -0
  26. package/dist/cli.js.map +1 -1
  27. package/dist/commands/deploy.d.ts +4 -0
  28. package/dist/commands/deploy.d.ts.map +1 -1
  29. package/dist/commands/deploy.js +68 -126
  30. package/dist/commands/deploy.js.map +1 -1
  31. package/dist/commands/init.d.ts +1 -5
  32. package/dist/commands/init.d.ts.map +1 -1
  33. package/dist/commands/init.js +90 -85
  34. package/dist/commands/init.js.map +1 -1
  35. package/dist/commands/list-tokens.js +2 -2
  36. package/dist/commands/list-tokens.js.map +1 -1
  37. package/dist/commands/login.d.ts +8 -1
  38. package/dist/commands/login.d.ts.map +1 -1
  39. package/dist/commands/login.js +12 -6
  40. package/dist/commands/login.js.map +1 -1
  41. package/dist/commands/logout.js +2 -2
  42. package/dist/commands/logout.js.map +1 -1
  43. package/dist/config/oauth.d.ts +5 -0
  44. package/dist/config/oauth.d.ts.map +1 -1
  45. package/dist/config/oauth.js +9 -4
  46. package/dist/config/oauth.js.map +1 -1
  47. package/dist/db-content-api/README.md +108 -0
  48. package/dist/db-content-api/generated/content-api-types.d.ts +3702 -0
  49. package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -0
  50. package/dist/db-content-api/generated/content-api-types.js +7 -0
  51. package/dist/db-content-api/generated/content-api-types.js.map +1 -0
  52. package/dist/db-content-api/index.d.ts +18 -0
  53. package/dist/db-content-api/index.d.ts.map +1 -0
  54. package/dist/db-content-api/index.js +572 -0
  55. package/dist/db-content-api/index.js.map +1 -0
  56. package/dist/db-content-api/temp-utilities/pagination.d.ts +13 -0
  57. package/dist/db-content-api/temp-utilities/pagination.d.ts.map +1 -0
  58. package/dist/db-content-api/temp-utilities/pagination.js +45 -0
  59. package/dist/db-content-api/temp-utilities/pagination.js.map +1 -0
  60. package/dist/db-content-api/temp-utilities/slug.d.ts +2 -0
  61. package/dist/db-content-api/temp-utilities/slug.d.ts.map +1 -0
  62. package/dist/db-content-api/temp-utilities/slug.js +3 -0
  63. package/dist/db-content-api/temp-utilities/slug.js.map +1 -0
  64. package/dist/db-content-api/temp-utilities/sorting.d.ts +7 -0
  65. package/dist/db-content-api/temp-utilities/sorting.d.ts.map +1 -0
  66. package/dist/db-content-api/temp-utilities/sorting.js +71 -0
  67. package/dist/db-content-api/temp-utilities/sorting.js.map +1 -0
  68. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +4 -0
  69. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts.map +1 -0
  70. package/dist/db-content-api/temp-utilities/unwrapDocument.js +53 -0
  71. package/dist/db-content-api/temp-utilities/unwrapDocument.js.map +1 -0
  72. package/dist/db-content-api/utilities/auth.d.ts +30 -0
  73. package/dist/db-content-api/utilities/auth.d.ts.map +1 -0
  74. package/dist/db-content-api/utilities/auth.js +81 -0
  75. package/dist/db-content-api/utilities/auth.js.map +1 -0
  76. package/dist/db-content-api/utilities/data/applyDefaults.d.ts +7 -0
  77. package/dist/db-content-api/utilities/data/applyDefaults.d.ts.map +1 -0
  78. package/dist/db-content-api/utilities/data/applyDefaults.js +59 -0
  79. package/dist/db-content-api/utilities/data/applyDefaults.js.map +1 -0
  80. package/dist/db-content-api/utilities/data/castFieldValue.d.ts +11 -0
  81. package/dist/db-content-api/utilities/data/castFieldValue.d.ts.map +1 -0
  82. package/dist/db-content-api/utilities/data/castFieldValue.js +66 -0
  83. package/dist/db-content-api/utilities/data/castFieldValue.js.map +1 -0
  84. package/dist/db-content-api/utilities/data/index.d.ts +28 -0
  85. package/dist/db-content-api/utilities/data/index.d.ts.map +1 -0
  86. package/dist/db-content-api/utilities/data/index.js +166 -0
  87. package/dist/db-content-api/utilities/data/index.js.map +1 -0
  88. package/dist/db-content-api/utilities/data/stripFields.d.ts +48 -0
  89. package/dist/db-content-api/utilities/data/stripFields.d.ts.map +1 -0
  90. package/dist/db-content-api/utilities/data/stripFields.js +195 -0
  91. package/dist/db-content-api/utilities/data/stripFields.js.map +1 -0
  92. package/dist/db-content-api/utilities/joins.d.ts +55 -0
  93. package/dist/db-content-api/utilities/joins.d.ts.map +1 -0
  94. package/dist/db-content-api/utilities/joins.js +130 -0
  95. package/dist/db-content-api/utilities/joins.js.map +1 -0
  96. package/dist/db-content-api/utilities/where.d.ts +12 -0
  97. package/dist/db-content-api/utilities/where.d.ts.map +1 -0
  98. package/dist/db-content-api/utilities/where.js +107 -0
  99. package/dist/db-content-api/utilities/where.js.map +1 -0
  100. package/dist/endpoints/health.d.ts +3 -0
  101. package/dist/endpoints/health.d.ts.map +1 -0
  102. package/dist/endpoints/health.js +11 -0
  103. package/dist/endpoints/health.js.map +1 -0
  104. package/dist/exports/client.d.ts +4 -0
  105. package/dist/exports/client.d.ts.map +1 -0
  106. package/dist/exports/client.js +5 -0
  107. package/dist/exports/client.js.map +1 -0
  108. package/dist/index.d.ts +2 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +3 -1
  111. package/dist/index.js.map +1 -1
  112. package/dist/oauth/components/LoginButton/index.d.ts.map +1 -1
  113. package/dist/oauth/components/LoginButton/index.js +50 -6
  114. package/dist/oauth/components/LoginButton/index.js.map +1 -1
  115. package/dist/oauth/components/LoginButton/index.scss +50 -3
  116. package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -1
  117. package/dist/oauth/components/LogoutButton/index.js +0 -1
  118. package/dist/oauth/components/LogoutButton/index.js.map +1 -1
  119. package/dist/oauth/defaults.d.ts.map +1 -1
  120. package/dist/oauth/defaults.js +29 -5
  121. package/dist/oauth/defaults.js.map +1 -1
  122. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
  123. package/dist/oauth/endpoints/getLoginEndpoint.js +1 -1
  124. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
  125. package/dist/oauth/index.d.ts.map +1 -1
  126. package/dist/oauth/index.js +42 -6
  127. package/dist/oauth/index.js.map +1 -1
  128. package/dist/oauth/strategy/index.d.ts.map +1 -1
  129. package/dist/oauth/strategy/index.js +6 -2
  130. package/dist/oauth/strategy/index.js.map +1 -1
  131. package/dist/oauth/types.d.ts +6 -6
  132. package/dist/oauth/types.d.ts.map +1 -1
  133. package/dist/oauth/types.js.map +1 -1
  134. package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -1
  135. package/dist/oauth/utilities/createCookieOptions.js.map +1 -1
  136. package/dist/oauth/utilities/isDuplicateKeyError.d.ts +7 -0
  137. package/dist/oauth/utilities/isDuplicateKeyError.d.ts.map +1 -0
  138. package/dist/oauth/utilities/isDuplicateKeyError.js +14 -0
  139. package/dist/oauth/utilities/isDuplicateKeyError.js.map +1 -0
  140. package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -1
  141. package/dist/oauth/utilities/refreshTokens.js +1 -1
  142. package/dist/oauth/utilities/refreshTokens.js.map +1 -1
  143. package/dist/plugin/build-config.d.ts +21 -4
  144. package/dist/plugin/build-config.d.ts.map +1 -1
  145. package/dist/plugin/build-config.js +103 -9
  146. package/dist/plugin/build-config.js.map +1 -1
  147. package/dist/storage-content-api/api-types.d.ts +161 -0
  148. package/dist/storage-content-api/api-types.d.ts.map +1 -0
  149. package/dist/storage-content-api/api-types.js +6 -0
  150. package/dist/storage-content-api/api-types.js.map +1 -0
  151. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts +9 -0
  152. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts.map +1 -0
  153. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +42 -0
  154. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js.map +1 -0
  155. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts +13 -0
  156. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts.map +1 -0
  157. package/dist/storage-content-api/client-uploads/generateSignedURL.js +31 -0
  158. package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +1 -0
  159. package/dist/storage-content-api/client.d.ts +6 -0
  160. package/dist/storage-content-api/client.d.ts.map +1 -0
  161. package/dist/storage-content-api/client.js +36 -0
  162. package/dist/storage-content-api/client.js.map +1 -0
  163. package/dist/storage-content-api/generateURL.d.ts +7 -0
  164. package/dist/storage-content-api/generateURL.d.ts.map +1 -0
  165. package/dist/storage-content-api/generateURL.js +7 -0
  166. package/dist/storage-content-api/generateURL.js.map +1 -0
  167. package/dist/storage-content-api/handleDelete.d.ts +8 -0
  168. package/dist/storage-content-api/handleDelete.d.ts.map +1 -0
  169. package/dist/storage-content-api/handleDelete.js +15 -0
  170. package/dist/storage-content-api/handleDelete.js.map +1 -0
  171. package/dist/storage-content-api/handleUpload.d.ts +11 -0
  172. package/dist/storage-content-api/handleUpload.d.ts.map +1 -0
  173. package/dist/storage-content-api/handleUpload.js +136 -0
  174. package/dist/storage-content-api/handleUpload.js.map +1 -0
  175. package/dist/storage-content-api/index.d.ts +5 -0
  176. package/dist/storage-content-api/index.d.ts.map +1 -0
  177. package/dist/storage-content-api/index.js +31 -0
  178. package/dist/storage-content-api/index.js.map +1 -0
  179. package/dist/storage-content-api/staticHandler.d.ts +10 -0
  180. package/dist/storage-content-api/staticHandler.d.ts.map +1 -0
  181. package/dist/storage-content-api/staticHandler.js +55 -0
  182. package/dist/storage-content-api/staticHandler.js.map +1 -0
  183. package/dist/storage-content-api/types.d.ts +10 -0
  184. package/dist/storage-content-api/types.d.ts.map +1 -0
  185. package/dist/storage-content-api/types.js +3 -0
  186. package/dist/storage-content-api/types.js.map +1 -0
  187. package/dist/templates/README.md +19 -0
  188. package/dist/utils/env-management.d.ts +9 -8
  189. package/dist/utils/env-management.d.ts.map +1 -1
  190. package/dist/utils/env-management.js +73 -74
  191. package/dist/utils/env-management.js.map +1 -1
  192. package/dist/utils/formatter.d.ts.map +1 -1
  193. package/dist/utils/formatter.js +1 -7
  194. package/dist/utils/formatter.js.map +1 -1
  195. package/dist/utils/lambda-config.d.ts.map +1 -1
  196. package/dist/utils/lambda-config.js +1 -0
  197. package/dist/utils/lambda-config.js.map +1 -1
  198. package/dist/utils/messages.d.ts.map +1 -1
  199. package/dist/utils/messages.js +5 -7
  200. package/dist/utils/messages.js.map +1 -1
  201. package/dist/utils/payload-config-ast.d.ts +22 -3
  202. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  203. package/dist/utils/payload-config-ast.js +89 -31
  204. package/dist/utils/payload-config-ast.js.map +1 -1
  205. package/dist/utils/payload-config-finder.d.ts +2 -2
  206. package/dist/utils/payload-config-finder.d.ts.map +1 -1
  207. package/dist/utils/payload-config-finder.js +48 -9
  208. package/dist/utils/payload-config-finder.js.map +1 -1
  209. package/dist/utils/payload-config-modifier.d.ts.map +1 -1
  210. package/dist/utils/payload-config-modifier.js +33 -4
  211. package/dist/utils/payload-config-modifier.js.map +1 -1
  212. package/dist/utils/payload-package-check.d.ts +5 -0
  213. package/dist/utils/payload-package-check.d.ts.map +1 -1
  214. package/dist/utils/payload-package-check.js +48 -4
  215. package/dist/utils/payload-package-check.js.map +1 -1
  216. package/dist/utils/project.d.ts.map +1 -1
  217. package/dist/utils/project.js +8 -6
  218. package/dist/utils/project.js.map +1 -1
  219. package/dist/utils/s3-upload.d.ts +0 -1
  220. package/dist/utils/s3-upload.d.ts.map +1 -1
  221. package/dist/utils/s3-upload.js +10 -3
  222. package/dist/utils/s3-upload.js.map +1 -1
  223. package/dist/utils/token-display.d.ts.map +1 -1
  224. package/dist/utils/token-display.js +11 -5
  225. package/dist/utils/token-display.js.map +1 -1
  226. package/dist/utils/typescript-validator.d.ts.map +1 -1
  227. package/dist/utils/typescript-validator.js +1 -6
  228. package/dist/utils/typescript-validator.js.map +1 -1
  229. package/package.json +24 -7
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/payload-config-ast.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph'\n\nimport { Node, SyntaxKind } from 'ts-morph'\n\nimport * as log from './log.js'\n\nexport type DetectionResult = {\n dbProperty?: {\n adapter: string\n importSource: string\n }\n editorProperty?: {\n importSource: string\n isDefault: boolean\n }\n figmaObjectExists: boolean\n hasAlias: boolean\n hasBuildConfig?: boolean\n hasOtherPayloadImports: boolean\n needsImportChange: boolean\n secretProperty?: boolean\n}\n\n/**\n * Detect what changes are needed in the payload config file\n */\nexport function detectRequiredChanges(sourceFile: SourceFile): DetectionResult {\n const result: DetectionResult = {\n figmaObjectExists: false,\n hasAlias: false,\n hasOtherPayloadImports: false,\n needsImportChange: false,\n }\n\n // Find buildConfig import\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'payload' ||\n imp.getModuleSpecifierValue() === '@payloadcms/figma',\n )\n\n if (!payloadImport) {\n log.debug('No payload or @payloadcms/figma import found')\n result.hasBuildConfig = false\n return result\n }\n\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n\n const moduleSpecifier = payloadImport.getModuleSpecifierValue()\n const namedImports = payloadImport.getNamedImports()\n\n // Check if buildConfig is imported\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n\n if (!buildConfigImport) {\n result.hasBuildConfig = false\n return result\n }\n\n // Check for alias and get the actual name used in code\n const aliasNode = buildConfigImport.getAliasNode()\n const buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n if (aliasNode) {\n result.hasAlias = true\n }\n\n // Check if import needs change\n if (moduleSpecifier === 'payload') {\n result.needsImportChange = true\n\n // Check if there are other imports from payload\n if (namedImports.length > 1) {\n result.hasOtherPayloadImports = true\n }\n }\n\n // Find buildConfig call in export default\n // First try to find export default with the buildConfig call\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n // Look for buildConfig call in the export default\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n result.hasBuildConfig = false\n return result\n }\n\n // Get config object\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return result\n }\n\n // Check for db property\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n const dbValue = dbProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (dbValue) {\n const adapterName = dbValue.getExpression().getText()\n\n // Find the import source for this adapter\n const adapterImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === adapterName),\n )\n\n if (adapterImport) {\n result.dbProperty = {\n adapter: adapterName,\n importSource: adapterImport.getModuleSpecifierValue(),\n }\n }\n }\n }\n\n // Check for secret property\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n result.secretProperty = true\n }\n\n // Check for editor property\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n const editorValue = editorProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (editorValue) {\n const editorName = editorValue.getExpression().getText()\n\n // Find the import source\n const editorImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === editorName),\n )\n\n if (editorImport && editorName === 'lexicalEditor') {\n // Check if it has arguments\n const args = editorValue.getArguments()\n const isDefault = args.length === 0\n\n result.editorProperty = {\n importSource: editorImport.getModuleSpecifierValue(),\n isDefault,\n }\n }\n }\n }\n\n // Check for figma property\n const figmaProperty = configArg.getProperty('figma')\n if (figmaProperty) {\n result.figmaObjectExists = true\n }\n\n return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\n}\n\n/**\n * Remove all comments\n * @returns true if any comments were removed\n */\nfunction removeAllComments(sourceFile: SourceFile): boolean {\n const ranges: Array<[number, number]> = []\n\n // Recursively collect comments from node and ALL children (including tokens)\n const collectComments = (node: Node) => {\n node.getLeadingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n node.getTrailingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n\n // Process ALL children including token nodes (commas, braces, etc.)\n node.getChildren().forEach(collectComments)\n }\n\n collectComments(sourceFile)\n\n if (ranges.length === 0) {\n return false\n }\n\n // Remove duplicates and sort in reverse order to avoid position shifts\n const uniqueRanges = Array.from(new Set(ranges.map((r) => JSON.stringify(r)))).map(\n (r) => JSON.parse(r) as [number, number],\n )\n uniqueRanges.sort((a, b) => b[0] - a[0])\n\n // Remove each comment range\n for (const [pos, end] of uniqueRanges) {\n sourceFile.removeText(pos, end)\n }\n\n return true\n}\n\n/**\n * Apply modifications to the source file based on detection result\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function applyModifications(\n sourceFile: SourceFile,\n detection: DetectionResult,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n if (detection.hasBuildConfig === false || detection.hasAlias) {\n log.debug(\n `Skipping modifications: hasBuildConfig=${detection.hasBuildConfig}, hasAlias=${detection.hasAlias}`,\n )\n return { changes: [], modified: false }\n }\n\n // 1. Remove all comments FIRST (before AST modifications that might shift positions)\n const hadComments = removeAllComments(sourceFile)\n if (hadComments) {\n changes.push('Removed comments')\n modified = true\n }\n\n // Find the import declarations\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find((imp) => imp.getModuleSpecifierValue() === 'payload')\n\n // Get the buildConfig name (could be aliased)\n let buildConfigName = 'buildConfig'\n if (payloadImport) {\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n const aliasNode = buildConfigImport.getAliasNode()\n buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n }\n }\n\n // Find buildConfig call in export default (prefer export default)\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n return { changes: [], modified: false }\n }\n\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return { changes: [], modified: false }\n }\n\n // 1. Remove db property\n if (detection.dbProperty) {\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n dbProperty.remove()\n changes.push('Removed db property')\n modified = true\n }\n }\n\n // 2. Remove secret property\n if (detection.secretProperty) {\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n secretProperty.remove()\n changes.push('Removed secret property')\n modified = true\n }\n }\n\n // 3. Remove editor if default\n if (detection.editorProperty?.isDefault) {\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n editorProperty.remove()\n changes.push('Removed default editor property')\n modified = true\n }\n }\n\n // 4. Update buildConfig import\n if (detection.needsImportChange) {\n if (payloadImport) {\n if (detection.hasOtherPayloadImports) {\n // Remove buildConfig from payload import, add new figma import\n const namedImports = payloadImport.getNamedImports()\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n buildConfigImport.remove()\n\n // If payload import is now empty, remove it\n if (payloadImport.getNamedImports().length === 0) {\n payloadImport.remove()\n }\n }\n\n // Add new import at the top\n sourceFile.addImportDeclaration({\n moduleSpecifier: '@payloadcms/figma',\n namedImports: ['buildConfig'],\n })\n\n changes.push('Split buildConfig import to @payloadcms/figma')\n } else {\n // Replace entire import\n payloadImport.setModuleSpecifier('@payloadcms/figma')\n changes.push('Changed buildConfig import to @payloadcms/figma')\n }\n modified = true\n }\n }\n\n // 5. Remove orphaned imports\n // Re-fetch imports after each removal to avoid stale references\n if (detection.dbProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const dbImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.dbProperty?.importSource,\n )\n if (dbImport) {\n dbImport.remove()\n changes.push(`Removed ${detection.dbProperty.adapter} import`)\n modified = true\n }\n }\n\n if (detection.editorProperty?.isDefault) {\n const currentImports = sourceFile.getImportDeclarations()\n const editorImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.editorProperty?.importSource,\n )\n if (editorImport) {\n editorImport.remove()\n changes.push('Removed lexicalEditor import')\n modified = true\n }\n }\n\n return { changes, modified }\n}\n\nexport type FigmaPropertyConfig = {\n region: string\n tenantId: string\n useContentSystem: boolean\n}\n\n/**\n * Add figma property to buildConfig if it doesn't exist\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function addFigmaProperty(\n sourceFile: SourceFile,\n config: FigmaPropertyConfig,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n // Find buildConfig call\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildConfig' || text.endsWith('.buildConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildConfig call found')\n return { changes: [], modified: false }\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return { changes: [], modified: false }\n }\n\n // Check if figma property already exists\n const existingFigmaProperty = configArg.getProperty('figma')\n if (existingFigmaProperty) {\n log.debug('figma property already exists, skipping')\n return { changes: ['Skipped: figma property already exists'], modified: false }\n }\n\n // Add figma property\n configArg.addPropertyAssignment({\n name: 'figma',\n initializer: `{\n region: '${config.region}',\n tenantId: '${config.tenantId}',\n useContentSystem: ${config.useContentSystem},\n }`,\n })\n\n changes.push(\n `Added figma property (region: ${config.region}, tenantId: ${config.tenantId}, useContentSystem: ${config.useContentSystem})`,\n )\n modified = true\n\n return { changes, modified }\n}\n\n/**\n * Read figma configuration from payload.config.ts\n * Returns the figma object if it exists, null otherwise\n */\nexport function readFigmaConfig(sourceFile: SourceFile): FigmaPropertyConfig | null {\n // Find buildConfig call\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildConfig' || text.endsWith('.buildConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildConfig call found')\n return null\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return null\n }\n\n // Find figma property\n const figmaProperty = configArg.getProperty('figma')\n if (!figmaProperty || !Node.isPropertyAssignment(figmaProperty)) {\n log.debug('No figma property found in buildConfig')\n return null\n }\n\n // Get initializer (the object value)\n const initializer = figmaProperty.getInitializer()\n if (!initializer || !Node.isObjectLiteralExpression(initializer)) {\n log.debug('figma property is not an object literal')\n return null\n }\n\n // Extract values\n const regionProp = initializer.getProperty('region')\n const tenantIdProp = initializer.getProperty('tenantId')\n const useContentSystemProp = initializer.getProperty('useContentSystem')\n\n if (!regionProp || !tenantIdProp) {\n log.debug('Missing required figma properties (region or tenantId)')\n return null\n }\n\n // Extract string values (remove quotes)\n const region = Node.isPropertyAssignment(regionProp)\n ? regionProp\n .getInitializer()\n ?.getText()\n .replace(/['\"]/g, '')\n : undefined\n\n const tenantId = Node.isPropertyAssignment(tenantIdProp)\n ? tenantIdProp\n .getInitializer()\n ?.getText()\n .replace(/['\"]/g, '')\n : undefined\n\n const useContentSystem = Node.isPropertyAssignment(useContentSystemProp)\n ? useContentSystemProp.getInitializer()?.getText() === 'true'\n : true // Default to true if not specified\n\n if (!region || !tenantId) {\n log.debug('Could not extract region or tenantId values')\n return null\n }\n\n return {\n region,\n tenantId,\n useContentSystem,\n }\n}\n"],"names":["Node","SyntaxKind","log","detectRequiredChanges","sourceFile","result","figmaObjectExists","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","hasBuildConfig","moduleSpecifier","namedImports","getNamedImports","buildConfigImport","ni","getName","aliasNode","getAliasNode","buildConfigName","getText","length","exportAssignment","getFirstDescendantByKind","ExportAssignment","buildConfigCall","callExpressions","getDescendantsOfKind","CallExpression","ce","expr","getExpression","configArg","getArguments","isObjectLiteralExpression","dbProperty","getProperty","dbValue","getChildrenOfKind","adapterName","adapterImport","some","adapter","importSource","secretProperty","editorProperty","editorValue","editorName","editorImport","args","isDefault","figmaProperty","removeAllComments","ranges","collectComments","node","getLeadingCommentRanges","forEach","range","push","getPos","getEnd","getTrailingCommentRanges","getChildren","uniqueRanges","Array","from","Set","map","r","JSON","stringify","parse","sort","a","b","pos","end","removeText","applyModifications","detection","changes","modified","hadComments","remove","addImportDeclaration","setModuleSpecifier","currentImports","dbImport","addFigmaProperty","config","text","endsWith","existingFigmaProperty","addPropertyAssignment","name","initializer","region","tenantId","useContentSystem","readFigmaConfig","isPropertyAssignment","getInitializer","regionProp","tenantIdProp","useContentSystemProp","replace","undefined"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAE3C,YAAYC,SAAS,WAAU;AAmB/B;;CAEC,GACD,OAAO,SAASC,sBAAsBC,UAAsB;IAC1D,MAAMC,SAA0B;QAC9BC,mBAAmB;QACnBC,UAAU;QACVC,wBAAwB;QACxBC,mBAAmB;IACrB;IAEA,0BAA0B;IAC1B,MAAMC,UAAUN,WAAWO,qBAAqB;IAChD,MAAMC,gBAAgBF,QAAQG,IAAI,CAChC,CAACC,MACCA,IAAIC,uBAAuB,OAAO,aAClCD,IAAIC,uBAAuB,OAAO;IAGtC,IAAI,CAACH,eAAe;QAClBV,IAAIc,KAAK,CAAC;QACVX,OAAOY,cAAc,GAAG;QACxB,OAAOZ;IACT;IAEAH,IAAIc,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,cAAcG,uBAAuB,IAAI;IAEzE,MAAMG,kBAAkBN,cAAcG,uBAAuB;IAC7D,MAAMI,eAAeP,cAAcQ,eAAe;IAElD,mCAAmC;IACnC,MAAMC,oBAAoBF,aAAaN,IAAI,CAAC,CAACS,KAAOA,GAAGC,OAAO,OAAO;IAErE,IAAI,CAACF,mBAAmB;QACtBhB,OAAOY,cAAc,GAAG;QACxB,OAAOZ;IACT;IAEA,uDAAuD;IACvD,MAAMmB,YAAYH,kBAAkBI,YA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5DrC,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,sBAAsB;IACtB,MAAM0C,gBAAgBnB,UAAUI,WAAW,CAAC;IAC5C,IAAI,CAACe,iBAAiB,CAAC1D,KAAK4G,oBAAoB,CAAClD,gBAAgB;QAC/DxD,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,qCAAqC;IACrC,MAAMuF,cAAc7C,cAAcmD,cAAc;IAChD,IAAI,CAACN,eAAe,CAACvG,KAAKyC,yBAAyB,CAAC8D,cAAc;QAChErG,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,iBAAiB;IACjB,MAAM8F,aAAaP,YAAY5D,WAAW,CAAC;IAC3C,MAAMoE,eAAeR,YAAY5D,WAAW,CAAC;IAC7C,MAAMqE,uBAAuBT,YAAY5D,WAAW,CAAC;IAErD,IAAI,CAACmE,cAAc,CAACC,cAAc;QAChC7G,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,wCAAwC;IACxC,MAAMwF,SAASxG,KAAK4G,oBAAoB,CAACE,cACrCA,WACGD,cAAc,IACblF,UACDsF,QAAQ,SAAS,MACpBC;IAEJ,MAAMT,WAAWzG,KAAK4G,oBAAoB,CAACG,gBACvCA,aACGF,cAAc,IACblF,UACDsF,QAAQ,SAAS,MACpBC;IAEJ,MAAMR,mBAAmB1G,KAAK4G,oBAAoB,CAACI,wBAC/CA,qBAAqBH,cAAc,IAAIlF,cAAc,SACrD,KAAK,mCAAmC;;IAE5C,IAAI,CAAC6E,UAAU,CAACC,UAAU;QACxBvG,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACLwF;QACAC;QACAC;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/utils/payload-config-ast.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph'\n\nimport { Node, SyntaxKind } from 'ts-morph'\n\nimport * as log from './log.js'\n\n/**\n * Result of detecting what changes are needed in a payload config file\n */\nexport type DetectionResult = {\n /** Database adapter configuration if present */\n dbProperty?: {\n /** Name of the adapter function (e.g., 'mongooseAdapter', 'postgresAdapter') */\n adapter: string\n /** NPM package the adapter is imported from (e.g., '@payloadcms/db-mongodb') */\n importSource: string\n }\n /** Editor configuration if present */\n editorProperty?: {\n /** NPM package the editor is imported from (e.g., '@payloadcms/richtext-lexical') */\n importSource: string\n /** Whether this is a default editor with no custom configuration */\n isDefault: boolean\n }\n /** Whether the config already has a `figma` property */\n figmaObjectExists: boolean\n /** Whether buildConfig/buildFigmaConfig uses an import alias (e.g., 'buildConfig as createConfig') */\n hasAlias: boolean\n /** Whether a buildConfig or buildFigmaConfig call was found (undefined if not checked) */\n hasBuildConfig?: boolean\n /** Whether there are other imports from 'payload' besides buildConfig (e.g., types) */\n hasOtherPayloadImports: boolean\n /** Whether the import needs to be changed from 'payload' to '@payloadcms/figma' */\n needsImportChange: boolean\n /** Whether a `secret` property exists in the config */\n secretProperty?: boolean\n /** Sharp configuration if present */\n sharpProperty?: {\n /** NPM package sharp is imported from (always 'sharp') */\n importSource: string\n }\n}\n\n/**\n * Detect what changes are needed in the payload config file\n */\nexport function detectRequiredChanges(sourceFile: SourceFile): DetectionResult {\n const result: DetectionResult = {\n figmaObjectExists: false,\n hasAlias: false,\n hasOtherPayloadImports: false,\n needsImportChange: false,\n }\n\n // Find buildConfig import\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'payload' ||\n imp.getModuleSpecifierValue() === '@payloadcms/figma',\n )\n\n if (!payloadImport) {\n log.debug('No payload or @payloadcms/figma import found')\n result.hasBuildConfig = false\n return result\n }\n\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n\n const moduleSpecifier = payloadImport.getModuleSpecifierValue()\n const namedImports = payloadImport.getNamedImports()\n\n // Determine which function name to look for based on the import source\n // - From 'payload': look for buildConfig (needs migration)\n // - From '@payloadcms/figma': look for buildFigmaConfig (already migrated)\n const expectedFunctionName = moduleSpecifier === 'payload' ? 'buildConfig' : 'buildFigmaConfig'\n\n const buildConfigImport = namedImports.find((ni) => ni.getName() === expectedFunctionName)\n\n if (!buildConfigImport) {\n result.hasBuildConfig = false\n return result\n }\n\n // Check for alias and get the actual name used in code\n const aliasNode = buildConfigImport.getAliasNode()\n const buildConfigName = aliasNode ? aliasNode.getText() : expectedFunctionName\n if (aliasNode) {\n result.hasAlias = true\n }\n\n // Check if import needs change\n if (moduleSpecifier === 'payload') {\n result.needsImportChange = true\n\n // Check if there are other imports from payload\n if (namedImports.length > 1) {\n result.hasOtherPayloadImports = true\n }\n }\n\n // Find buildConfig call in export default\n // First try to find export default with the buildConfig call\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n // Look for buildConfig call in the export default\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n result.hasBuildConfig = false\n return result\n }\n\n // Get config object\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return result\n }\n\n // Check for db property\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n const dbValue = dbProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (dbValue) {\n const adapterName = dbValue.getExpression().getText()\n\n // Find the import source for this adapter\n const adapterImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === adapterName),\n )\n\n if (adapterImport) {\n result.dbProperty = {\n adapter: adapterName,\n importSource: adapterImport.getModuleSpecifierValue(),\n }\n }\n }\n }\n\n // Check for secret property\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n result.secretProperty = true\n }\n\n // Check for editor property\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n const editorValue = editorProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (editorValue) {\n const editorName = editorValue.getExpression().getText()\n\n // Find the import source\n const editorImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === editorName),\n )\n\n if (editorImport && editorName === 'lexicalEditor') {\n // Check if it has arguments\n const args = editorValue.getArguments()\n const isDefault = args.length === 0\n\n result.editorProperty = {\n importSource: editorImport.getModuleSpecifierValue(),\n isDefault,\n }\n }\n }\n }\n\n // Check for sharp property\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n // Find the import source for sharp\n const sharpImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'sharp' ||\n imp.getNamedImports().some((ni) => ni.getName() === 'sharp'),\n )\n\n result.sharpProperty = {\n importSource: sharpImport?.getModuleSpecifierValue() || 'sharp',\n }\n }\n\n // Check for figma property\n const figmaProperty = configArg.getProperty('figma')\n if (figmaProperty) {\n result.figmaObjectExists = true\n }\n\n return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\n}\n\n/**\n * Remove all comments\n * @returns true if any comments were removed\n */\nfunction removeAllComments(sourceFile: SourceFile): boolean {\n const ranges: Array<[number, number]> = []\n\n // Recursively collect comments from node and ALL children (including tokens)\n const collectComments = (node: Node) => {\n node.getLeadingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n node.getTrailingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n\n // Process ALL children including token nodes (commas, braces, etc.)\n node.getChildren().forEach(collectComments)\n }\n\n collectComments(sourceFile)\n\n if (ranges.length === 0) {\n return false\n }\n\n // Remove duplicates and sort in reverse order to avoid position shifts\n const uniqueRanges = Array.from(new Set(ranges.map((r) => JSON.stringify(r)))).map(\n (r) => JSON.parse(r) as [number, number],\n )\n uniqueRanges.sort((a, b) => b[0] - a[0])\n\n // Remove each comment range\n for (const [pos, end] of uniqueRanges) {\n sourceFile.removeText(pos, end)\n }\n\n return true\n}\n\n/**\n * Apply modifications to the source file based on detection result\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function applyModifications(\n sourceFile: SourceFile,\n detection: DetectionResult,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n if (detection.hasBuildConfig === false || detection.hasAlias) {\n log.debug(\n `Skipping modifications: hasBuildConfig=${detection.hasBuildConfig}, hasAlias=${detection.hasAlias}`,\n )\n return { changes: [], modified: false }\n }\n\n // 1. Remove all comments FIRST (before AST modifications that might shift positions)\n const hadComments = removeAllComments(sourceFile)\n if (hadComments) {\n changes.push('Removed comments')\n modified = true\n }\n\n // Find the import declarations\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find((imp) => imp.getModuleSpecifierValue() === 'payload')\n\n // Get the buildConfig name (could be aliased)\n let buildConfigName = 'buildConfig'\n if (payloadImport) {\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n const aliasNode = buildConfigImport.getAliasNode()\n buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n }\n }\n\n // Find buildConfig call in export default (prefer export default)\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n return { changes: [], modified: false }\n }\n\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return { changes: [], modified: false }\n }\n\n // 1. Remove db property\n if (detection.dbProperty) {\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n dbProperty.remove()\n changes.push('Removed db property')\n modified = true\n }\n }\n\n // 2. Remove secret property\n if (detection.secretProperty) {\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n secretProperty.remove()\n changes.push('Removed secret property')\n modified = true\n }\n }\n\n // 3. Remove editor if default\n if (detection.editorProperty?.isDefault) {\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n editorProperty.remove()\n changes.push('Removed default editor property')\n modified = true\n }\n }\n\n // 4. Remove sharp property\n if (detection.sharpProperty) {\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n sharpProperty.remove()\n changes.push('Removed sharp property')\n modified = true\n }\n }\n\n // 5. Update buildConfig import\n if (detection.needsImportChange) {\n if (payloadImport) {\n if (detection.hasOtherPayloadImports) {\n // Remove buildConfig from payload import, add new figma import\n const namedImports = payloadImport.getNamedImports()\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n buildConfigImport.remove()\n\n // If payload import is now empty, remove it\n if (payloadImport.getNamedImports().length === 0) {\n payloadImport.remove()\n }\n }\n\n // Add new import at the top\n sourceFile.addImportDeclaration({\n moduleSpecifier: '@payloadcms/figma',\n namedImports: ['buildFigmaConfig'],\n })\n\n changes.push('Split buildConfig import to @payloadcms/figma')\n } else {\n // Replace entire import: change module specifier and rename all references\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n // Change the import name\n buildConfigImport.setName('buildFigmaConfig')\n\n // Find and rename all usages of 'buildConfig' in the file\n const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)\n identifiers.forEach((identifier) => {\n if (identifier.getText() === 'buildConfig') {\n identifier.replaceWithText('buildFigmaConfig')\n }\n })\n }\n payloadImport.setModuleSpecifier('@payloadcms/figma')\n changes.push('Changed buildConfig import to @payloadcms/figma')\n }\n modified = true\n }\n }\n\n // 6. Remove orphaned imports\n // Re-fetch imports after each removal to avoid stale references\n if (detection.dbProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const dbImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.dbProperty?.importSource,\n )\n if (dbImport) {\n dbImport.remove()\n changes.push(`Removed ${detection.dbProperty.adapter} import`)\n modified = true\n }\n }\n\n if (detection.editorProperty?.isDefault) {\n const currentImports = sourceFile.getImportDeclarations()\n const editorImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.editorProperty?.importSource,\n )\n if (editorImport) {\n editorImport.remove()\n changes.push('Removed lexicalEditor import')\n modified = true\n }\n }\n\n if (detection.sharpProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const sharpImport = currentImports.find((imp) => imp.getModuleSpecifierValue() === 'sharp')\n if (sharpImport) {\n sharpImport.remove()\n changes.push('Removed sharp import')\n modified = true\n }\n }\n\n return { changes, modified }\n}\n\nexport type FigmaPropertyConfig = {\n contentSystemId: string\n useContentSystem?: boolean\n}\n\n/**\n * Add figma property to buildConfig if it doesn't exist\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function addFigmaProperty(\n sourceFile: SourceFile,\n config: FigmaPropertyConfig,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return { changes: [], modified: false }\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return { changes: [], modified: false }\n }\n\n // Check if figma property already exists\n const existingFigmaProperty = configArg.getProperty('figma')\n if (existingFigmaProperty) {\n log.debug('figma property already exists, skipping')\n return { changes: ['Skipped: figma property already exists'], modified: false }\n }\n\n // Add figma property\n // Note: useContentSystem is optional and defaults to true, so we don't generate it during init\n // contentSystemId is stored in .env file and referenced via process.env with non-null assertion\n const figmaObj =\n config.useContentSystem === false\n ? `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n useContentSystem: false,\n }`\n : `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n }`\n\n configArg.addPropertyAssignment({\n name: 'figma',\n initializer: figmaObj,\n })\n\n changes.push(`Added figma property (contentSystemId: ${config.contentSystemId})`)\n modified = true\n\n return { changes, modified }\n}\n\n/**\n * Read figma configuration from payload.config.ts\n * Returns the figma object if it exists, null otherwise\n */\nexport function readFigmaConfig(sourceFile: SourceFile): FigmaPropertyConfig | null {\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return null\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return null\n }\n\n // Find figma property\n const figmaProperty = configArg.getProperty('figma')\n if (!figmaProperty || !Node.isPropertyAssignment(figmaProperty)) {\n log.debug('No figma property found in buildConfig')\n return null\n }\n\n // Get initializer (the object value)\n const initializer = figmaProperty.getInitializer()\n if (!initializer || !Node.isObjectLiteralExpression(initializer)) {\n log.debug('figma property is not an object literal')\n return null\n }\n\n // Extract values\n const contentSystemIdProp = initializer.getProperty('contentSystemId')\n const useContentSystemProp = initializer.getProperty('useContentSystem')\n\n if (!contentSystemIdProp) {\n log.debug('Missing required figma property: contentSystemId')\n return null\n }\n\n // Extract contentSystemId - support both literal strings and env var references\n let contentSystemId: string | undefined\n if (Node.isPropertyAssignment(contentSystemIdProp)) {\n const initializer = contentSystemIdProp.getInitializer()\n const text = initializer?.getText() || ''\n\n // Support both patterns:\n // 1. Literal string: 'cms_abc123' or \"cms_abc123\"\n // 2. Environment variable: process.env.FIGMA_CONTENT_SYSTEM_ID\n if (text.includes('process.env.FIGMA_CONTENT_SYSTEM_ID')) {\n // For env var reference, return a marker that indicates it's from env\n // The actual value will be read at runtime\n contentSystemId = 'process.env.FIGMA_CONTENT_SYSTEM_ID'\n } else {\n // Remove quotes for literal strings\n contentSystemId = text.replace(/['\"]/g, '')\n }\n }\n\n const useContentSystem = Node.isPropertyAssignment(useContentSystemProp)\n ? useContentSystemProp.getInitializer()?.getText() === 'true'\n : undefined // Optional: undefined if not specified\n\n if (!contentSystemId) {\n log.debug('Could not extract contentSystemId value')\n return null\n }\n\n return {\n contentSystemId,\n useContentSystem,\n }\n}\n"],"names":["Node","SyntaxKind","log","detectRequiredChanges","sourceFile","result","figmaObjectExists","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","hasBuildConfig","moduleSpecifier","namedImports","getNamedImports","expectedFunctionName","buildConfigImport","ni","getName","aliasNode","getAliasNode","buildConfigName","getText","length","exportAssignment","getFirstDescendantByKind","ExportAssignment","buildConfigCall","callExpressions","getDescendantsOfKind","CallExpression","ce","expr","getExpression","configArg","getArguments","isObjectLiteralExpression","dbProperty","getProperty","dbValue","getChildrenOfKind","adapterName","adapterImport","some","adapter","importSource","secretProperty","editorProperty","editorValue","editorName","editorImport","args","isDefault","sharpProperty","sharpImport","figmaProperty","removeAllComments","ranges","collectComments","node","getLeadingCommentRanges","forEach","range","push","getPos","getEnd","getTrailingCommentRanges","getChildren","uniqueRanges","Array","from","Set","map","r","JSON","stringify","parse","sort","a","b","pos","end","removeText","applyModifications","detection","changes","modified","hadComments","remove","addImportDeclaration","setName","identifiers","Identifier","identifier","replaceWithText","setModuleSpecifier","currentImports","dbImport","addFigmaProperty","config","text","endsWith","existingFigmaProperty","figmaObj","useContentSystem","addPropertyAssignment","name","initializer","contentSystemId","readFigmaConfig","isPropertyAssignment","getInitializer","contentSystemIdProp","useContentSystemProp","includes","replace","undefined"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAE3C,YAAYC,SAAS,WAAU;AAuC/B;;CAEC,GACD,OAAO,SAASC,sBAAsBC,UAAsB;IAC1D,MAAMC,SAA0B;QAC9BC,mBAAmB;QACnBC,UAAU;QACVC,wBAAwB;QACxBC,mBAAmB;IACrB;IAEA,0BAA0B;IAC1B,MAAMC,UAAUN,WAAWO,qBAAqB;IAChD,MAAMC,gBAAgBF,QAAQG,IAAI,CAChC,CAACC,MACCA,IAAIC,uBAAuB,OAAO,aAClCD,IAAIC,uBAAuB,OAAO;IAGtC,IAAI,CAACH,eAAe;QAClBV,IAAIc,KAAK,CAAC;QACVX,OAAOY,cAAc,GAAG;QACxB,OAAOZ;IACT;IAEAH,IAAIc,KAAK,CAAC,CAAC,mBAAmB,EAAEJ,cAAcG,uBAAuB,IAAI;IAEzE,MAAMG,kBAAkBN,cAAcG,uBAAuB;IAC7D,MAAMI,eAAeP,cAAcQ,eAAe;IAElD,uEAAuE;IACvE,2DAA2D;IAC3D,2EAA2E;IAC3E,MAAMC,uBAAuBH,oBAAoB,YAAY,gBAAgB;IAE7E,MAAMI,oBAAoBH,aAAaN,IAAI,CAAC,CAACU,KAAOA,GAAGC,OAAO,OAAOH;IAErE,IAAI,CAACC,mBAAmB;QACtBjB,OAAOY,cAAc,GAAG;QACxB,OAAOZ;IACT;IAEA,uDAAuD;IACvD,MAAMoB,YAAYH,kBAAkBI,YAAY;IAChD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Ic,KAAK,CAAC;QACV,OAAO;IACT;IAEA,qCAAqC;IACrC,MAAMiG,cAAcpD,cAAcwD,cAAc;IAChD,IAAI,CAACJ,eAAe,CAACjH,KAAK0C,yBAAyB,CAACuE,cAAc;QAChE/G,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,iBAAiB;IACjB,MAAMsG,sBAAsBL,YAAYrE,WAAW,CAAC;IACpD,MAAM2E,uBAAuBN,YAAYrE,WAAW,CAAC;IAErD,IAAI,CAAC0E,qBAAqB;QACxBpH,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,gFAAgF;IAChF,IAAIkG;IACJ,IAAIlH,KAAKoH,oBAAoB,CAACE,sBAAsB;QAClD,MAAML,cAAcK,oBAAoBD,cAAc;QACtD,MAAMX,OAAOO,aAAarF,aAAa;QAEvC,yBAAyB;QACzB,kDAAkD;QAClD,+DAA+D;QAC/D,IAAI8E,KAAKc,QAAQ,CAAC,wCAAwC;YACxD,sEAAsE;YACtE,2CAA2C;YAC3CN,kBAAkB;QACpB,OAAO;YACL,oCAAoC;YACpCA,kBAAkBR,KAAKe,OAAO,CAAC,SAAS;QAC1C;IACF;IAEA,MAAMX,mBAAmB9G,KAAKoH,oBAAoB,CAACG,wBAC/CA,qBAAqBF,cAAc,IAAIzF,cAAc,SACrD8F,UAAU,uCAAuC;;IAErD,IAAI,CAACR,iBAAiB;QACpBhH,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACLkG;QACAJ;IACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Find the Payload config file using Payload's built-in finder
3
- * Changes to project directory temporarily and restores afterward
2
+ * Find the Payload config file using Payload's built-in finder when available,
3
+ * with fallback to simple file search for npx environments where payload isn't installed.
4
4
  *
5
5
  * @param projectPath - Absolute path to project directory
6
6
  * @returns Absolute path to config file, or null if not found
@@ -1 +1 @@
1
- {"version":3,"file":"payload-config-finder.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-finder.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAmBnF"}
1
+ {"version":3,"file":"payload-config-finder.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-finder.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAWnF"}
@@ -1,26 +1,65 @@
1
- import { findConfig } from 'payload/node';
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import * as log from './log.js';
4
+ // Standard Payload config file names in priority order
5
+ const CONFIG_FILES = [
6
+ 'payload.config.ts',
7
+ 'payload.config.js',
8
+ 'src/payload.config.ts',
9
+ 'src/payload.config.js'
10
+ ];
2
11
  /**
3
- * Find the Payload config file using Payload's built-in finder
4
- * Changes to project directory temporarily and restores afterward
12
+ * Find the Payload config file using Payload's built-in finder when available,
13
+ * with fallback to simple file search for npx environments where payload isn't installed.
5
14
  *
6
15
  * @param projectPath - Absolute path to project directory
7
16
  * @returns Absolute path to config file, or null if not found
8
17
  */ export async function findPayloadConfig(projectPath) {
18
+ // First, try using Payload's official config finder (if payload is installed)
19
+ const configFromPayload = await findConfigWithPayload(projectPath);
20
+ if (configFromPayload) {
21
+ return configFromPayload;
22
+ }
23
+ // Fallback: Simple file search for standard config locations
24
+ // This works when running via npx before payload is installed
25
+ log.debug('Payload not available, using fallback config finder');
26
+ return findConfigFallback(projectPath);
27
+ }
28
+ /**
29
+ * Try to find config using Payload's findConfig function.
30
+ * Returns null if payload is not installed (dynamic import fails).
31
+ */ async function findConfigWithPayload(projectPath) {
9
32
  const originalCwd = process.cwd();
10
33
  try {
34
+ // Dynamic import - will fail gracefully if payload is not installed
35
+ const { findConfig } = await import('payload/node');
11
36
  // findConfig requires being in the project directory
12
37
  process.chdir(projectPath);
13
- // Use Payload's official config finder
14
38
  const configPath = findConfig();
15
- // Wrap in Promise.resolve to satisfy async requirement
16
- return await Promise.resolve(configPath || null);
17
- } catch {
18
- // Config not found or error occurred
39
+ return configPath || null;
40
+ } catch (error) {
41
+ // payload not installed or other error - return null to use fallback
42
+ log.debug(`Could not use Payload findConfig: ${error instanceof Error ? error.message : 'unknown'}`);
19
43
  return null;
20
44
  } finally{
21
- // Always restore original working directory
22
45
  process.chdir(originalCwd);
23
46
  }
24
47
  }
48
+ /**
49
+ * Fallback config finder that checks standard locations.
50
+ * Used when payload is not installed (e.g., running via npx).
51
+ */ async function findConfigFallback(projectPath) {
52
+ for (const configFile of CONFIG_FILES){
53
+ const fullPath = path.join(projectPath, configFile);
54
+ try {
55
+ await fs.access(fullPath);
56
+ log.debug(`Found config at: ${fullPath}`);
57
+ return fullPath;
58
+ } catch {
59
+ // File doesn't exist, try next
60
+ }
61
+ }
62
+ return null;
63
+ }
25
64
 
26
65
  //# sourceMappingURL=payload-config-finder.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/payload-config-finder.ts"],"sourcesContent":["import { findConfig } from 'payload/node'\n\n/**\n * Find the Payload config file using Payload's built-in finder\n * Changes to project directory temporarily and restores afterward\n *\n * @param projectPath - Absolute path to project directory\n * @returns Absolute path to config file, or null if not found\n */\nexport async function findPayloadConfig(projectPath: string): Promise<null | string> {\n const originalCwd = process.cwd()\n\n try {\n // findConfig requires being in the project directory\n process.chdir(projectPath)\n\n // Use Payload's official config finder\n const configPath = findConfig()\n\n // Wrap in Promise.resolve to satisfy async requirement\n return await Promise.resolve(configPath || null)\n } catch {\n // Config not found or error occurred\n return null\n } finally {\n // Always restore original working directory\n process.chdir(originalCwd)\n }\n}\n"],"names":["findConfig","findPayloadConfig","projectPath","originalCwd","process","cwd","chdir","configPath","Promise","resolve"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAc;AAEzC;;;;;;CAMC,GACD,OAAO,eAAeC,kBAAkBC,WAAmB;IACzD,MAAMC,cAAcC,QAAQC,GAAG;IAE/B,IAAI;QACF,qDAAqD;QACrDD,QAAQE,KAAK,CAACJ;QAEd,uCAAuC;QACvC,MAAMK,aAAaP;QAEnB,uDAAuD;QACvD,OAAO,MAAMQ,QAAQC,OAAO,CAACF,cAAc;IAC7C,EAAE,OAAM;QACN,qCAAqC;QACrC,OAAO;IACT,SAAU;QACR,4CAA4C;QAC5CH,QAAQE,KAAK,CAACH;IAChB;AACF"}
1
+ {"version":3,"sources":["../../src/utils/payload-config-finder.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\nimport * as log from './log.js'\n\n// Standard Payload config file names in priority order\nconst CONFIG_FILES = [\n 'payload.config.ts',\n 'payload.config.js',\n 'src/payload.config.ts',\n 'src/payload.config.js',\n]\n\n/**\n * Find the Payload config file using Payload's built-in finder when available,\n * with fallback to simple file search for npx environments where payload isn't installed.\n *\n * @param projectPath - Absolute path to project directory\n * @returns Absolute path to config file, or null if not found\n */\nexport async function findPayloadConfig(projectPath: string): Promise<null | string> {\n // First, try using Payload's official config finder (if payload is installed)\n const configFromPayload = await findConfigWithPayload(projectPath)\n if (configFromPayload) {\n return configFromPayload\n }\n\n // Fallback: Simple file search for standard config locations\n // This works when running via npx before payload is installed\n log.debug('Payload not available, using fallback config finder')\n return findConfigFallback(projectPath)\n}\n\n/**\n * Try to find config using Payload's findConfig function.\n * Returns null if payload is not installed (dynamic import fails).\n */\nasync function findConfigWithPayload(projectPath: string): Promise<null | string> {\n const originalCwd = process.cwd()\n\n try {\n // Dynamic import - will fail gracefully if payload is not installed\n const { findConfig } = await import('payload/node')\n\n // findConfig requires being in the project directory\n process.chdir(projectPath)\n const configPath = findConfig()\n return configPath || null\n } catch (error) {\n // payload not installed or other error - return null to use fallback\n log.debug(\n `Could not use Payload findConfig: ${error instanceof Error ? error.message : 'unknown'}`,\n )\n return null\n } finally {\n process.chdir(originalCwd)\n }\n}\n\n/**\n * Fallback config finder that checks standard locations.\n * Used when payload is not installed (e.g., running via npx).\n */\nasync function findConfigFallback(projectPath: string): Promise<null | string> {\n for (const configFile of CONFIG_FILES) {\n const fullPath = path.join(projectPath, configFile)\n try {\n await fs.access(fullPath)\n log.debug(`Found config at: ${fullPath}`)\n return fullPath\n } catch {\n // File doesn't exist, try next\n }\n }\n\n return null\n}\n"],"names":["fs","path","log","CONFIG_FILES","findPayloadConfig","projectPath","configFromPayload","findConfigWithPayload","debug","findConfigFallback","originalCwd","process","cwd","findConfig","chdir","configPath","error","Error","message","configFile","fullPath","join","access"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB,YAAYC,SAAS,WAAU;AAE/B,uDAAuD;AACvD,MAAMC,eAAe;IACnB;IACA;IACA;IACA;CACD;AAED;;;;;;CAMC,GACD,OAAO,eAAeC,kBAAkBC,WAAmB;IACzD,8EAA8E;IAC9E,MAAMC,oBAAoB,MAAMC,sBAAsBF;IACtD,IAAIC,mBAAmB;QACrB,OAAOA;IACT;IAEA,6DAA6D;IAC7D,8DAA8D;IAC9DJ,IAAIM,KAAK,CAAC;IACV,OAAOC,mBAAmBJ;AAC5B;AAEA;;;CAGC,GACD,eAAeE,sBAAsBF,WAAmB;IACtD,MAAMK,cAAcC,QAAQC,GAAG;IAE/B,IAAI;QACF,oEAAoE;QACpE,MAAM,EAAEC,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC;QAEpC,qDAAqD;QACrDF,QAAQG,KAAK,CAACT;QACd,MAAMU,aAAaF;QACnB,OAAOE,cAAc;IACvB,EAAE,OAAOC,OAAO;QACd,qEAAqE;QACrEd,IAAIM,KAAK,CACP,CAAC,kCAAkC,EAAEQ,iBAAiBC,QAAQD,MAAME,OAAO,GAAG,WAAW;QAE3F,OAAO;IACT,SAAU;QACRP,QAAQG,KAAK,CAACJ;IAChB;AACF;AAEA;;;CAGC,GACD,eAAeD,mBAAmBJ,WAAmB;IACnD,KAAK,MAAMc,cAAchB,aAAc;QACrC,MAAMiB,WAAWnB,KAAKoB,IAAI,CAAChB,aAAac;QACxC,IAAI;YACF,MAAMnB,GAAGsB,MAAM,CAACF;YAChBlB,IAAIM,KAAK,CAAC,CAAC,iBAAiB,EAAEY,UAAU;YACxC,OAAOA;QACT,EAAE,OAAM;QACN,+BAA+B;QACjC;IACF;IAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;AAKhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,mBAAmB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAqL7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwC9D"}
1
+ {"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;AAKhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,mBAAmB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CA4N7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwC9D"}
@@ -103,13 +103,42 @@ import { runTypeScriptCheck } from './typescript-validator.js';
103
103
  if (modified) {
104
104
  await sourceFile.save();
105
105
  log.debug('Config file saved');
106
- // 7. Uninstall orphaned packages
106
+ // 7. Handle package management
107
107
  const packagesToUninstall = [];
108
+ // Uninstall db adapter (buildFigmaConfig provides its own)
108
109
  if (detection.dbProperty) {
109
110
  packagesToUninstall.push(detection.dbProperty.importSource);
110
111
  }
111
- if (detection.editorProperty?.isDefault) {
112
- packagesToUninstall.push(detection.editorProperty.importSource);
112
+ // Uninstall sharp (Figma infrastructure handles image processing)
113
+ if (detection.sharpProperty) {
114
+ packagesToUninstall.push('sharp');
115
+ }
116
+ // Ensure lexical is installed if user doesn't have a custom editor
117
+ // (buildFigmaConfig uses lexicalEditor() as default)
118
+ if (!detection.editorProperty) {
119
+ log.debug('No editor property detected - will ensure lexical is installed for default editor');
120
+ } else if (detection.editorProperty.isDefault) {
121
+ log.debug('Default lexicalEditor() detected - will ensure lexical is installed');
122
+ } else {
123
+ log.debug(`Custom editor detected (${detection.editorProperty.importSource}) - skipping lexical installation`);
124
+ }
125
+ if (!detection.editorProperty || detection.editorProperty.isDefault) {
126
+ log.debug('Checking if @payloadcms/richtext-lexical is installed...');
127
+ const hasLexical = await checkPackageInstalled(projectPath, '@payloadcms/richtext-lexical');
128
+ if (!hasLexical) {
129
+ log.debug('@payloadcms/richtext-lexical not found, installing...');
130
+ try {
131
+ await installPackage(projectPath, '@payloadcms/richtext-lexical', packageManager);
132
+ changes.push('Installed @payloadcms/richtext-lexical (default editor)');
133
+ log.debug('Successfully installed @payloadcms/richtext-lexical');
134
+ } catch (error) {
135
+ log.debug(`Failed to install @payloadcms/richtext-lexical: ${error instanceof Error ? error.message : 'Unknown error'}`);
136
+ // Don't fail on install error - user can install manually if needed
137
+ warnings.push('Could not install @payloadcms/richtext-lexical - you may need to install it manually');
138
+ }
139
+ } else {
140
+ log.debug('@payloadcms/richtext-lexical already installed, skipping');
141
+ }
113
142
  }
114
143
  if (packagesToUninstall.length > 0) {
115
144
  log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`);
@@ -185,7 +214,7 @@ ${pc.bold('Required changes:')}
185
214
 
186
215
  1. Replace buildConfig import:
187
216
  ${pc.dim('- FROM: ')}${pc.cyan("import { buildConfig } from 'payload'")}
188
- ${pc.dim('- TO: ')}${pc.cyan("import { buildConfig } from '@payloadcms/figma'")}
217
+ ${pc.dim('- TO: ')}${pc.cyan("import { buildFigmaConfig } from '@payloadcms/figma'")}
189
218
 
190
219
  2. Remove these properties from buildConfig():
191
220
  • db
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/payload-config-modifier.ts"],"sourcesContent":["import pc from 'picocolors'\nimport { Project } from 'ts-morph'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport { formatFile } from './formatter.js'\nimport * as log from './log.js'\nimport {\n addFigmaProperty,\n applyModifications,\n detectRequiredChanges,\n type FigmaPropertyConfig,\n} from './payload-config-ast.js'\nimport { findPayloadConfig } from './payload-config-finder.js'\nimport { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js'\nimport { runTypeScriptCheck } from './typescript-validator.js'\n\nexport type ModificationResult = {\n changes: string[]\n error?: string\n modified: boolean\n success: boolean\n warnings?: string[]\n}\n\n/**\n * Main orchestrator for payload config modification\n * Checks package, detects needed changes, applies modifications\n */\nexport async function ensurePayloadFigmaConfig(\n projectPath: string,\n packageManager: PackageManager,\n figmaConfig?: FigmaPropertyConfig,\n): Promise<ModificationResult> {\n const changes: string[] = []\n const warnings: string[] = []\n let modified = false\n\n try {\n log.debug(`Starting payload config modification for: ${projectPath}`)\n\n // 1. Find config file\n const configPath = await findPayloadConfig(projectPath)\n if (!configPath) {\n log.debug(`Config file not found in: ${projectPath}`)\n return {\n changes: [],\n error: 'payload.config.ts not found in project',\n modified: false,\n success: false,\n }\n }\n\n log.debug(`Found config file: ${configPath}`)\n\n // 2. Check/install @payloadcms/figma package\n const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma')\n if (!isInstalled) {\n log.debug('@payloadcms/figma not installed, attempting installation...')\n try {\n await installPackage(projectPath, '@payloadcms/figma', packageManager)\n changes.push('Installed @payloadcms/figma')\n modified = true\n log.debug('@payloadcms/figma installed successfully')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n return {\n changes: [],\n error: 'Failed to install @payloadcms/figma',\n modified: false,\n success: false,\n }\n }\n } else {\n log.debug('@payloadcms/figma already installed')\n }\n\n // 3. Parse config with ts-morph\n log.debug('Parsing config file with ts-morph...')\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n })\n const sourceFile = project.addSourceFileAtPath(configPath)\n\n // 4. Detect required changes\n log.debug('Detecting required changes...')\n const detection = detectRequiredChanges(sourceFile)\n\n log.debug(\n `Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, hasBuildConfig=${detection.hasBuildConfig}`,\n )\n\n // Handle failure modes\n if (detection.hasAlias) {\n log.debug('Config uses import alias (e.g., buildConfig as X)')\n return {\n changes,\n error: 'Config uses import alias - manual modification required',\n modified,\n success: false,\n }\n }\n\n if (detection.hasBuildConfig === false) {\n log.debug('No buildConfig call found in config file')\n return {\n changes,\n error: 'Config structure not recognized (no buildConfig call found)',\n modified,\n success: false,\n }\n }\n\n // 5. Apply modifications\n log.debug('Applying modifications...')\n const modResult = applyModifications(sourceFile, detection)\n if (modResult.modified) {\n changes.push(...modResult.changes)\n modified = true\n\n log.debug(`Applied ${modResult.changes.length} modifications`)\n }\n\n // 6. Add figma property if config provided and doesn't exist\n if (figmaConfig && !detection.figmaObjectExists) {\n log.debug('Adding figma property to buildConfig...')\n const figmaResult = addFigmaProperty(sourceFile, figmaConfig)\n if (figmaResult.modified) {\n changes.push(...figmaResult.changes)\n modified = true\n log.debug(`Added figma property`)\n } else {\n log.debug('Figma property not added (may already exist)')\n }\n } else if (detection.figmaObjectExists) {\n log.debug('Figma property already exists, skipping')\n }\n\n // Save file if any modifications were made\n if (modified) {\n await sourceFile.save()\n log.debug('Config file saved')\n\n // 7. Uninstall orphaned packages\n const packagesToUninstall: string[] = []\n\n if (detection.dbProperty) {\n packagesToUninstall.push(detection.dbProperty.importSource)\n }\n\n if (detection.editorProperty?.isDefault) {\n packagesToUninstall.push(detection.editorProperty.importSource)\n }\n\n if (packagesToUninstall.length > 0) {\n log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`)\n }\n\n for (const pkg of packagesToUninstall) {\n try {\n await uninstallPackage(projectPath, pkg, packageManager)\n changes.push(`Uninstalled ${pkg}`)\n log.debug(`Uninstalled ${pkg}`)\n } catch (error) {\n log.debug(\n `Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on uninstall errors - orphaned package is better than broken config\n }\n }\n\n // 8. Format file\n log.debug('Formatting config file...')\n const formatResult = await formatFile(configPath, packageManager)\n if (!formatResult.success && formatResult.warning) {\n warnings.push(formatResult.warning)\n log.debug(`Formatting warning: ${formatResult.warning}`)\n }\n\n // 9. Run TypeScript validation\n log.debug('Running TypeScript validation...')\n const tsResult = await runTypeScriptCheck(projectPath, packageManager)\n if (!tsResult.success && tsResult.errors.length > 0) {\n warnings.push(\"TypeScript validation found issues - run 'pnpm build' for details\")\n log.debug(`TypeScript validation found ${tsResult.errors.length} issues`)\n }\n } else {\n log.debug('No modifications needed - config already correct')\n }\n\n log.debug('Payload config modification completed successfully')\n\n return {\n changes,\n modified,\n success: true,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n log.debug(\n `Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n if (error instanceof Error && error.stack) {\n log.debug(`Stack trace: ${error.stack}`)\n }\n return {\n changes,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n modified,\n success: false,\n }\n }\n}\n\n/**\n * Display manual configuration instructions\n */\nexport function displayManualInstructions(reason: string): void {\n const leftLineWrap = (message: string): string => {\n // Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line\n return message\n .split('\\n')\n .map((line, index, arr) => {\n if (index === 0) {\n return `${pc.dim('┌ ')}${line}`\n } else if (index === arr.length - 1) {\n return `${pc.dim('└ ')}${line}`\n } else {\n return `${pc.dim('│ ')}${line}`\n }\n })\n .join('\\n')\n }\n\n const message = leftLineWrap(`${pc.cyan(pc.bold('Manual Configuration Required'))}\n\nUnable to automatically modify payload.config.ts\nReason: ${pc.yellow(reason)}\n\n${pc.bold('Required changes:')}\n\n1. Replace buildConfig import:\n ${pc.dim('- FROM: ')}${pc.cyan(\"import { buildConfig } from 'payload'\")}\n ${pc.dim('- TO: ')}${pc.cyan(\"import { buildConfig } from '@payloadcms/figma'\")}\n\n2. Remove these properties from buildConfig():\n • db\n • secret\n • editor (if using default lexicalEditor())\n\n3. Install package:\n ${pc.cyan('pnpm add @payloadcms/figma')}\n\nThen run: ${pc.cyan('npx @payloadcms/figma init')}`)\n\n // eslint-disable-next-line no-console\n console.log(message)\n}\n"],"names":["pc","Project","formatFile","log","addFigmaProperty","applyModifications","detectRequiredChanges","findPayloadConfig","checkPackageInstalled","installPackage","uninstallPackage","runTypeScriptCheck","ensurePayloadFigmaConfig","projectPath","packageManager","figmaConfig","changes","warnings","modified","debug","configPath","error","success","isInstalled","push","Error","message","project","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPath","detection","needsImportChange","hasAlias","hasBuildConfig","modResult","length","figmaObjectExists","figmaResult","save","packagesToUninstall","dbProperty","importSource","editorProperty","isDefault","pkg","formatResult","warning","tsResult","errors","undefined","stack","displayManualInstructions","reason","leftLineWrap","split","map","line","index","arr","dim","join","cyan","bold","yellow","console"],"mappings":"AAAA,OAAOA,QAAQ,aAAY;AAC3B,SAASC,OAAO,QAAQ,WAAU;AAIlC,SAASC,UAAU,QAAQ,iBAAgB;AAC3C,YAAYC,SAAS,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,qBAAqB,QAEhB,0BAAyB;AAChC,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,qBAAqB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,6BAA4B;AACpG,SAASC,kBAAkB,QAAQ,4BAA2B;AAU9D;;;CAGC,GACD,OAAO,eAAeC,yBACpBC,WAAmB,EACnBC,cAA8B,EAC9BC,WAAiC;IAEjC,MAAMC,UAAoB,EAAE;IAC5B,MAAMC,WAAqB,EAAE;IAC7B,IAAIC,WAAW;IAEf,IAAI;QACFf,IAAIgB,KAAK,CAAC,CAAC,0CAA0C,EAAEN,aAAa;QAEpE,sBAAsB;QACtB,MAAMO,aAAa,MAAMb,kBAAkBM;QAC3C,IAAI,CAACO,YAAY;YACfjB,IAAIgB,KAAK,CAAC,CAAC,0BAA0B,EAAEN,aAAa;YACpD,OAAO;gBACLG,SAAS,EAAE;gBACXK,OAAO;gBACPH,UAAU;gBACVI,SAAS;YACX;QACF;QAEAnB,IAAIgB,KAAK,CAAC,CAAC,mBAAmB,EAAEC,YAAY;QAE5C,6CAA6C;QAC7C,MAAMG,cAAc,MAAMf,sBAAsBK,aAAa;QAC7D,IAAI,CAACU,aAAa;YAChBpB,IAAIgB,KAAK,CAAC;YACV,IAAI;gBACF,MAAMV,eAAeI,aAAa,qBAAqBC;gBACvDE,QAAQQ,IAAI,CAAC;gBACbN,WAAW;gBACXf,IAAIgB,KAAK,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C,SAASH,MAAM;YAClC,OAAO,IAAIC,UAAUC,IAAIvB,MAAM,GAAG,GAAG;gBACnC,OAAO,GAAGpC,GAAG4D,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO;gBACL,OAAO,GAAGzD,GAAG4D,GAAG,CAAC,SAASH,MAAM;YAClC;QACF,GACCI,IAAI,CAAC;IACV;IAEA,MAAMnC,UAAU4B,aAAa,GAAGtD,GAAG8D,IAAI,CAAC9D,GAAG+D,IAAI,CAAC,kCAAkC;;;QAG5E,EAAE/D,GAAGgE,MAAM,CAACX,QAAQ;;AAE5B,EAAErD,GAAG+D,IAAI,CAAC,qBAAqB;;;GAG5B,EAAE/D,GAAG4D,GAAG,CAAC,cAAc5D,GAAG8D,IAAI,CAAC,yCAAyC;GACxE,EAAE9D,GAAG4D,GAAG,CAAC,cAAc5D,GAAG8D,IAAI,CAAC,mDAAmD;;;;;;;;GAQlF,EAAE9D,GAAG8D,IAAI,CAAC,8BAA8B;;UAEjC,EAAE9D,GAAG8D,IAAI,CAAC,+BAA+B;IAEjD,sCAAsC;IACtCG,QAAQ9D,GAAG,CAACuB;AACd"}
1
+ {"version":3,"sources":["../../src/utils/payload-config-modifier.ts"],"sourcesContent":["import pc from 'picocolors'\nimport { Project } from 'ts-morph'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport { formatFile } from './formatter.js'\nimport * as log from './log.js'\nimport {\n addFigmaProperty,\n applyModifications,\n detectRequiredChanges,\n type FigmaPropertyConfig,\n} from './payload-config-ast.js'\nimport { findPayloadConfig } from './payload-config-finder.js'\nimport { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js'\nimport { runTypeScriptCheck } from './typescript-validator.js'\n\nexport type ModificationResult = {\n changes: string[]\n error?: string\n modified: boolean\n success: boolean\n warnings?: string[]\n}\n\n/**\n * Main orchestrator for payload config modification\n * Checks package, detects needed changes, applies modifications\n */\nexport async function ensurePayloadFigmaConfig(\n projectPath: string,\n packageManager: PackageManager,\n figmaConfig?: FigmaPropertyConfig,\n): Promise<ModificationResult> {\n const changes: string[] = []\n const warnings: string[] = []\n let modified = false\n\n try {\n log.debug(`Starting payload config modification for: ${projectPath}`)\n\n // 1. Find config file\n const configPath = await findPayloadConfig(projectPath)\n if (!configPath) {\n log.debug(`Config file not found in: ${projectPath}`)\n return {\n changes: [],\n error: 'payload.config.ts not found in project',\n modified: false,\n success: false,\n }\n }\n\n log.debug(`Found config file: ${configPath}`)\n\n // 2. Check/install @payloadcms/figma package\n const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma')\n if (!isInstalled) {\n log.debug('@payloadcms/figma not installed, attempting installation...')\n try {\n await installPackage(projectPath, '@payloadcms/figma', packageManager)\n changes.push('Installed @payloadcms/figma')\n modified = true\n log.debug('@payloadcms/figma installed successfully')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n return {\n changes: [],\n error: 'Failed to install @payloadcms/figma',\n modified: false,\n success: false,\n }\n }\n } else {\n log.debug('@payloadcms/figma already installed')\n }\n\n // 3. Parse config with ts-morph\n log.debug('Parsing config file with ts-morph...')\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n })\n const sourceFile = project.addSourceFileAtPath(configPath)\n\n // 4. Detect required changes\n log.debug('Detecting required changes...')\n const detection = detectRequiredChanges(sourceFile)\n\n log.debug(\n `Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, hasBuildConfig=${detection.hasBuildConfig}`,\n )\n\n // Handle failure modes\n if (detection.hasAlias) {\n log.debug('Config uses import alias (e.g., buildConfig as X)')\n return {\n changes,\n error: 'Config uses import alias - manual modification required',\n modified,\n success: false,\n }\n }\n\n if (detection.hasBuildConfig === false) {\n log.debug('No buildConfig call found in config file')\n return {\n changes,\n error: 'Config structure not recognized (no buildConfig call found)',\n modified,\n success: false,\n }\n }\n\n // 5. Apply modifications\n log.debug('Applying modifications...')\n const modResult = applyModifications(sourceFile, detection)\n if (modResult.modified) {\n changes.push(...modResult.changes)\n modified = true\n\n log.debug(`Applied ${modResult.changes.length} modifications`)\n }\n\n // 6. Add figma property if config provided and doesn't exist\n if (figmaConfig && !detection.figmaObjectExists) {\n log.debug('Adding figma property to buildConfig...')\n const figmaResult = addFigmaProperty(sourceFile, figmaConfig)\n if (figmaResult.modified) {\n changes.push(...figmaResult.changes)\n modified = true\n log.debug(`Added figma property`)\n } else {\n log.debug('Figma property not added (may already exist)')\n }\n } else if (detection.figmaObjectExists) {\n log.debug('Figma property already exists, skipping')\n }\n\n // Save file if any modifications were made\n if (modified) {\n await sourceFile.save()\n log.debug('Config file saved')\n\n // 7. Handle package management\n const packagesToUninstall: string[] = []\n\n // Uninstall db adapter (buildFigmaConfig provides its own)\n if (detection.dbProperty) {\n packagesToUninstall.push(detection.dbProperty.importSource)\n }\n\n // Uninstall sharp (Figma infrastructure handles image processing)\n if (detection.sharpProperty) {\n packagesToUninstall.push('sharp')\n }\n\n // Ensure lexical is installed if user doesn't have a custom editor\n // (buildFigmaConfig uses lexicalEditor() as default)\n if (!detection.editorProperty) {\n log.debug(\n 'No editor property detected - will ensure lexical is installed for default editor',\n )\n } else if (detection.editorProperty.isDefault) {\n log.debug('Default lexicalEditor() detected - will ensure lexical is installed')\n } else {\n log.debug(\n `Custom editor detected (${detection.editorProperty.importSource}) - skipping lexical installation`,\n )\n }\n\n if (!detection.editorProperty || detection.editorProperty.isDefault) {\n log.debug('Checking if @payloadcms/richtext-lexical is installed...')\n const hasLexical = await checkPackageInstalled(projectPath, '@payloadcms/richtext-lexical')\n if (!hasLexical) {\n log.debug('@payloadcms/richtext-lexical not found, installing...')\n try {\n await installPackage(projectPath, '@payloadcms/richtext-lexical', packageManager)\n changes.push('Installed @payloadcms/richtext-lexical (default editor)')\n log.debug('Successfully installed @payloadcms/richtext-lexical')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/richtext-lexical: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on install error - user can install manually if needed\n warnings.push(\n 'Could not install @payloadcms/richtext-lexical - you may need to install it manually',\n )\n }\n } else {\n log.debug('@payloadcms/richtext-lexical already installed, skipping')\n }\n }\n\n if (packagesToUninstall.length > 0) {\n log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`)\n }\n\n for (const pkg of packagesToUninstall) {\n try {\n await uninstallPackage(projectPath, pkg, packageManager)\n changes.push(`Uninstalled ${pkg}`)\n log.debug(`Uninstalled ${pkg}`)\n } catch (error) {\n log.debug(\n `Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on uninstall errors - orphaned package is better than broken config\n }\n }\n\n // 8. Format file\n log.debug('Formatting config file...')\n const formatResult = await formatFile(configPath, packageManager)\n if (!formatResult.success && formatResult.warning) {\n warnings.push(formatResult.warning)\n log.debug(`Formatting warning: ${formatResult.warning}`)\n }\n\n // 9. Run TypeScript validation\n log.debug('Running TypeScript validation...')\n const tsResult = await runTypeScriptCheck(projectPath, packageManager)\n if (!tsResult.success && tsResult.errors.length > 0) {\n warnings.push(\"TypeScript validation found issues - run 'pnpm build' for details\")\n log.debug(`TypeScript validation found ${tsResult.errors.length} issues`)\n }\n } else {\n log.debug('No modifications needed - config already correct')\n }\n\n log.debug('Payload config modification completed successfully')\n\n return {\n changes,\n modified,\n success: true,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n log.debug(\n `Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n if (error instanceof Error && error.stack) {\n log.debug(`Stack trace: ${error.stack}`)\n }\n return {\n changes,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n modified,\n success: false,\n }\n }\n}\n\n/**\n * Display manual configuration instructions\n */\nexport function displayManualInstructions(reason: string): void {\n const leftLineWrap = (message: string): string => {\n // Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line\n return message\n .split('\\n')\n .map((line, index, arr) => {\n if (index === 0) {\n return `${pc.dim('┌ ')}${line}`\n } else if (index === arr.length - 1) {\n return `${pc.dim('└ ')}${line}`\n } else {\n return `${pc.dim('│ ')}${line}`\n }\n })\n .join('\\n')\n }\n\n const message = leftLineWrap(`${pc.cyan(pc.bold('Manual Configuration Required'))}\n\nUnable to automatically modify payload.config.ts\nReason: ${pc.yellow(reason)}\n\n${pc.bold('Required changes:')}\n\n1. Replace buildConfig import:\n ${pc.dim('- FROM: ')}${pc.cyan(\"import { buildConfig } from 'payload'\")}\n ${pc.dim('- TO: ')}${pc.cyan(\"import { buildFigmaConfig } from '@payloadcms/figma'\")}\n\n2. Remove these properties from buildConfig():\n • db\n • secret\n • editor (if using default lexicalEditor())\n\n3. Install package:\n ${pc.cyan('pnpm add @payloadcms/figma')}\n\nThen run: ${pc.cyan('npx @payloadcms/figma init')}`)\n\n // eslint-disable-next-line no-console\n console.log(message)\n}\n"],"names":["pc","Project","formatFile","log","addFigmaProperty","applyModifications","detectRequiredChanges","findPayloadConfig","checkPackageInstalled","installPackage","uninstallPackage","runTypeScriptCheck","ensurePayloadFigmaConfig","projectPath","packageManager","figmaConfig","changes","warnings","modified","debug","configPath","error","success","isInstalled","push","Error","message","project","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPath","detection","needsImportChange","hasAlias","hasBuildConfig","modResult","length","figmaObjectExists","figmaResult","save","packagesToUninstall","dbProperty","importSource","sharpProperty","editorProperty","isDefault","hasLexical","pkg","formatResult","warning","tsResult","errors","undefined","stack","displayManualInstructions","reason","leftLineWrap","split","map","line","index","arr","dim","join","cyan","bold","yellow","console"],"mappings":"AAAA,OAAOA,QAAQ,aAAY;AAC3B,SAASC,OAAO,QAAQ,WAAU;AAIlC,SAASC,UAAU,QAAQ,iBAAgB;AAC3C,YAAYC,SAAS,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,qBAAqB,QAEhB,0BAAyB;AAChC,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,qB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D,IAAIgB,KAAK,CAAC,CAAC,aAAa,EAAEE,MAAMgC,KAAK,EAAE;QACzC;QACA,OAAO;YACLrC;YACAK,OAAOA,iBAAiBI,QAAQJ,MAAMK,OAAO,GAAG;YAChDR;YACAI,SAAS;QACX;IACF;AACF;AAEA;;CAEC,GACD,OAAO,SAASgC,0BAA0BC,MAAc;IACtD,MAAMC,eAAe,CAAC9B;QACpB,oFAAoF;QACpF,OAAOA,QACJ+B,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,MAAMC,OAAOC;YACjB,IAAID,UAAU,GAAG;gBACf,OAAO,GAAG5D,GAAG8D,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO,IAAIC,UAAUC,IAAIzB,MAAM,GAAG,GAAG;gBACnC,OAAO,GAAGpC,GAAG8D,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO;gBACL,OAAO,GAAG3D,GAAG8D,GAAG,CAAC,SAASH,MAAM;YAClC;QACF,GACCI,IAAI,CAAC;IACV;IAEA,MAAMrC,UAAU8B,aAAa,GAAGxD,GAAGgE,IAAI,CAAChE,GAAGiE,IAAI,CAAC,kCAAkC;;;QAG5E,EAAEjE,GAAGkE,MAAM,CAACX,QAAQ;;AAE5B,EAAEvD,GAAGiE,IAAI,CAAC,qBAAqB;;;GAG5B,EAAEjE,GAAG8D,GAAG,CAAC,cAAc9D,GAAGgE,IAAI,CAAC,yCAAyC;GACxE,EAAEhE,GAAG8D,GAAG,CAAC,cAAc9D,GAAGgE,IAAI,CAAC,wDAAwD;;;;;;;;GAQvF,EAAEhE,GAAGgE,IAAI,CAAC,8BAA8B;;UAEjC,EAAEhE,GAAGgE,IAAI,CAAC,+BAA+B;IAEjD,sCAAsC;IACtCG,QAAQhE,GAAG,CAACuB;AACd"}
@@ -12,4 +12,9 @@ export declare function installPackage(projectPath: string, packageName: string,
12
12
  * Does not throw on failure - orphaned package is better than broken config
13
13
  */
14
14
  export declare function uninstallPackage(projectPath: string, packageName: string, packageManager: PackageManager): Promise<void>;
15
+ /**
16
+ * Run an npm script from package.json
17
+ * Does not throw on failure - logs warning and continues
18
+ */
19
+ export declare function runScript(projectPath: string, scriptName: string, packageManager: PackageManager): Promise<boolean>;
15
20
  //# sourceMappingURL=payload-package-check.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"payload-package-check.d.ts","sourceRoot":"","sources":["../../src/utils/payload-package-check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAelB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,IAAI,CAAC,CA6Cf;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
1
+ {"version":3,"file":"payload-package-check.d.ts","sourceRoot":"","sources":["../../src/utils/payload-package-check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAelB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,IAAI,CAAC,CA8Cf;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,OAAO,CAAC,CAyClB"}
@@ -31,9 +31,10 @@ import * as log from './log.js';
31
31
  if (packageManager === 'npm') {
32
32
  args[0] = 'install';
33
33
  }
34
- log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
34
+ const fullCommand = `${command} ${args.join(' ')}`;
35
+ log.debug(`Running: ${fullCommand} in ${projectPath}`);
35
36
  let stderr = '';
36
- const child = spawn(command, args, {
37
+ const child = spawn(fullCommand, {
37
38
  cwd: projectPath,
38
39
  shell: true,
39
40
  stdio: 'pipe'
@@ -76,8 +77,9 @@ import * as log from './log.js';
76
77
  if (packageManager === 'npm') {
77
78
  args[0] = 'uninstall';
78
79
  }
79
- log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
80
- const child = spawn(command, args, {
80
+ const fullCommand = `${command} ${args.join(' ')}`;
81
+ log.debug(`Running: ${fullCommand} in ${projectPath}`);
82
+ const child = spawn(fullCommand, {
81
83
  cwd: projectPath,
82
84
  shell: true,
83
85
  stdio: 'pipe'
@@ -93,5 +95,47 @@ import * as log from './log.js';
93
95
  });
94
96
  });
95
97
  }
98
+ /**
99
+ * Run an npm script from package.json
100
+ * Does not throw on failure - logs warning and continues
101
+ */ export async function runScript(projectPath, scriptName, packageManager) {
102
+ return new Promise((resolve)=>{
103
+ const command = packageManager;
104
+ // yarn doesn't need 'run' prefix, but it works with it too
105
+ const args = [
106
+ 'run',
107
+ scriptName
108
+ ];
109
+ const fullCommand = `${command} ${args.join(' ')}`;
110
+ log.debug(`Running script: ${fullCommand} in ${projectPath}`);
111
+ let stderr = '';
112
+ const child = spawn(fullCommand, {
113
+ cwd: projectPath,
114
+ shell: true,
115
+ stdio: 'pipe'
116
+ });
117
+ if (child.stderr) {
118
+ child.stderr.on('data', (data)=>{
119
+ stderr += data.toString();
120
+ });
121
+ }
122
+ child.on('error', (error)=>{
123
+ log.debug(`Failed to run script ${scriptName}: ${error.message}`);
124
+ resolve(false);
125
+ });
126
+ child.on('close', (code)=>{
127
+ if (code === 0) {
128
+ log.debug(`Successfully ran script: ${scriptName}`);
129
+ resolve(true);
130
+ } else {
131
+ log.debug(`Script ${scriptName} failed (exit code: ${code})`);
132
+ if (stderr) {
133
+ log.debug(`stderr: ${stderr}`);
134
+ }
135
+ resolve(false);
136
+ }
137
+ });
138
+ });
139
+ }
96
140
 
97
141
  //# sourceMappingURL=payload-package-check.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/payload-package-check.ts"],"sourcesContent":["import { spawn } from 'child_process'\nimport fs from 'fs/promises'\nimport path from 'path'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport * as log from './log.js'\n\n/**\n * Check if a package is installed in dependencies (not devDependencies)\n */\nexport async function checkPackageInstalled(\n projectPath: string,\n packageName: string,\n): Promise<boolean> {\n try {\n const pkgJsonPath = path.join(projectPath, 'package.json')\n log.debug(`Checking if ${packageName} is installed in: ${pkgJsonPath}`)\n const pkgJsonContent = await fs.readFile(pkgJsonPath, 'utf-8')\n const pkgJson = JSON.parse(pkgJsonContent)\n const isInstalled = !!pkgJson.dependencies?.[packageName]\n log.debug(`${packageName} is ${isInstalled ? 'installed' : 'not installed'}`)\n return isInstalled\n } catch (error) {\n log.debug(\n `Error checking package installation: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n return false\n }\n}\n\n/**\n * Install a package as a production dependency\n */\nexport async function installPackage(\n projectPath: string,\n packageName: string,\n packageManager: PackageManager,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const command = packageManager\n const args = ['add', packageName]\n\n // npm uses 'install' instead of 'add'\n if (packageManager === 'npm') {\n args[0] = 'install'\n }\n\n log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`)\n\n let stderr = ''\n\n const child = spawn(command, args, {\n cwd: projectPath,\n shell: true,\n stdio: 'pipe',\n })\n\n // Capture stderr for debug logging\n if (child.stderr) {\n child.stderr.on('data', (data) => {\n stderr += data.toString()\n })\n }\n\n child.on('error', (error) => {\n log.debug(`Spawn error for ${command}: ${error.message}`)\n reject(new Error(`Failed to spawn ${command}: ${error.message}`))\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n log.debug(`Successfully installed ${packageName}`)\n resolve()\n } else {\n log.debug(`Failed to install ${packageName} (exit code: ${code})`)\n if (stderr) {\n log.debug(`stderr: ${stderr}`)\n }\n reject(new Error(`Failed to install ${packageName}`))\n }\n })\n })\n}\n\n/**\n * Uninstall a package\n * Does not throw on failure - orphaned package is better than broken config\n */\nexport async function uninstallPackage(\n projectPath: string,\n packageName: string,\n packageManager: PackageManager,\n): Promise<void> {\n return new Promise((resolve) => {\n const command = packageManager\n const args = ['remove', packageName]\n\n // npm uses 'uninstall' instead of 'remove'\n if (packageManager === 'npm') {\n args[0] = 'uninstall'\n }\n\n log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`)\n\n const child = spawn(command, args, {\n cwd: projectPath,\n shell: true,\n stdio: 'pipe',\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n log.debug(`Successfully uninstalled ${packageName}`)\n } else {\n log.debug(`Failed to uninstall ${packageName} (exit code: ${code}), continuing anyway`)\n }\n // Always resolve, even on error\n resolve()\n })\n })\n}\n"],"names":["spawn","fs","path","log","checkPackageInstalled","projectPath","packageName","pkgJsonPath","join","debug","pkgJsonContent","readFile","pkgJson","JSON","parse","isInstalled","dependencies","error","Error","message","installPackage","packageManager","Promise","resolve","reject","command","args","stderr","child","cwd","shell","stdio","on","data","toString","code","uninstallPackage"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAe;AACrC,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAIvB,YAAYC,SAAS,WAAU;AAE/B;;CAEC,GACD,OAAO,eAAeC,sBACpBC,WA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gC;YAChCZ;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/utils/payload-package-check.ts"],"sourcesContent":["import { spawn } from 'child_process'\nimport fs from 'fs/promises'\nimport path from 'path'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport * as log from './log.js'\n\n/**\n * Check if a package is installed in dependencies (not devDependencies)\n */\nexport async function checkPackageInstalled(\n projectPath: string,\n packageName: string,\n): Promise<boolean> {\n try {\n const pkgJsonPath = path.join(projectPath, 'package.json')\n log.debug(`Checking if ${packageName} is installed in: ${pkgJsonPath}`)\n const pkgJsonContent = await fs.readFile(pkgJsonPath, 'utf-8')\n const pkgJson = JSON.parse(pkgJsonContent)\n const isInstalled = !!pkgJson.dependencies?.[packageName]\n log.debug(`${packageName} is ${isInstalled ? 'installed' : 'not installed'}`)\n return isInstalled\n } catch (error) {\n log.debug(\n `Error checking package installation: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n return false\n }\n}\n\n/**\n * Install a package as a production dependency\n */\nexport async function installPackage(\n projectPath: string,\n packageName: string,\n packageManager: PackageManager,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const command = packageManager\n const args = ['add', packageName]\n\n // npm uses 'install' instead of 'add'\n if (packageManager === 'npm') {\n args[0] = 'install'\n }\n\n const fullCommand = `${command} ${args.join(' ')}`\n log.debug(`Running: ${fullCommand} in ${projectPath}`)\n\n let stderr = ''\n\n const child = spawn(fullCommand, {\n cwd: projectPath,\n shell: true,\n stdio: 'pipe',\n })\n\n // Capture stderr for debug logging\n if (child.stderr) {\n child.stderr.on('data', (data) => {\n stderr += data.toString()\n })\n }\n\n child.on('error', (error) => {\n log.debug(`Spawn error for ${command}: ${error.message}`)\n reject(new Error(`Failed to spawn ${command}: ${error.message}`))\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n log.debug(`Successfully installed ${packageName}`)\n resolve()\n } else {\n log.debug(`Failed to install ${packageName} (exit code: ${code})`)\n if (stderr) {\n log.debug(`stderr: ${stderr}`)\n }\n reject(new Error(`Failed to install ${packageName}`))\n }\n })\n })\n}\n\n/**\n * Uninstall a package\n * Does not throw on failure - orphaned package is better than broken config\n */\nexport async function uninstallPackage(\n projectPath: string,\n packageName: string,\n packageManager: PackageManager,\n): Promise<void> {\n return new Promise((resolve) => {\n const command = packageManager\n const args = ['remove', packageName]\n\n // npm uses 'uninstall' instead of 'remove'\n if (packageManager === 'npm') {\n args[0] = 'uninstall'\n }\n\n const fullCommand = `${command} ${args.join(' ')}`\n log.debug(`Running: ${fullCommand} in ${projectPath}`)\n\n const child = spawn(fullCommand, {\n cwd: projectPath,\n shell: true,\n stdio: 'pipe',\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n log.debug(`Successfully uninstalled ${packageName}`)\n } else {\n log.debug(`Failed to uninstall ${packageName} (exit code: ${code}), continuing anyway`)\n }\n // Always resolve, even on error\n resolve()\n })\n })\n}\n\n/**\n * Run an npm script from package.json\n * Does not throw on failure - logs warning and continues\n */\nexport async function runScript(\n projectPath: string,\n scriptName: string,\n packageManager: PackageManager,\n): Promise<boolean> {\n return new Promise((resolve) => {\n const command = packageManager\n // yarn doesn't need 'run' prefix, but it works with it too\n const args = ['run', scriptName]\n\n const fullCommand = `${command} ${args.join(' ')}`\n log.debug(`Running script: ${fullCommand} in ${projectPath}`)\n\n let stderr = ''\n\n const child = spawn(fullCommand, {\n cwd: projectPath,\n shell: true,\n stdio: 'pipe',\n })\n\n if (child.stderr) {\n child.stderr.on('data', (data) => {\n stderr += data.toString()\n })\n }\n\n child.on('error', (error) => {\n log.debug(`Failed to run script ${scriptName}: ${error.message}`)\n resolve(false)\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n log.debug(`Successfully ran script: ${scriptName}`)\n resolve(true)\n } else {\n log.debug(`Script ${scriptName} failed (exit code: ${code})`)\n if (stderr) {\n log.debug(`stderr: ${stderr}`)\n }\n resolve(false)\n }\n })\n })\n}\n"],"names":["spawn","fs","path","log","checkPackageInstalled","projectPath","packageName","pkgJsonPath","join","debug","pkgJsonContent","readFile","pkgJson","JSON","parse","isInstalled","dependencies","error","Error","message","installPackage","packageManager","Promise","resolve","reject","command","args","fullCommand","stderr","child","cwd","shell","stdio","on","data","toString","code","uninstallPackage","runScript","scriptName"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAe;AACrC,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAIvB,YAAYC,SAAS,WAAU;AAE/B;;CAEC,GACD,OAAO,eAAeC,sBACpBC,WAAmB,EACnBC,WAAmB;IAEnB,IAAI;QACF,MAAMC,cAAcL,KAAKM,IAAI,CAACH,aAAa;QAC3CF,IAAIM,KAAK,CAAC,CAAC,YAAY,EAAEH,YAAY,kBAAkB,EAAEC,aAAa;QACtE,MAAMG,iBAAiB,MAAMT,GAAGU,QAAQ,CAACJ,aAAa;QACtD,MAAMK,UAAUC,KAAKC,KAAK,CAACJ;QAC3B,MAAMK,cAAc,CAAC,CAACH,QAAQI,YAAY,EAAE,CAACV,YAAY;QACzDH,IAAIM,KAAK,CAAC,GAAGH,YAAY,IAAI,EAAES,cAAc,cAAc,iBAAiB;QAC5E,OAAOA;IACT,EAAE,OAAOE,OAAO;QACdd,IAAIM,KAAK,CACP,CAAC,qCAAqC,EAAEQ,iBAAiBC,QAAQD,MAAME,OAAO,GAAG,iBAAiB;QAEpG,OAAO;IACT;AACF;AAEA;;CAEC,GACD,OAAO,eAAeC,eACpBf,WAAmB,EACnBC,WAAmB,EACnBe,cAA8B;IAE9B,OAAO,IAAIC,QAAQ,CAACC,SAASC;QAC3B,MAAMC,UAAUJ;QAChB,MAAMK,OAAO;YAAC;YAAOpB;SAAY;QAEjC,sCAAsC;QACtC,IAAIe,mBAAmB,OAAO;YAC5BK,IAAI,CAAC,EAAE,GAAG;QACZ;QAEA,MAAMC,cAAc,GAAGF,QAAQ,CAAC,EAAEC,KAAKlB,IAAI,CAAC,MAAM;QAClDL,IAAIM,KAAK,CAAC,CAAC,SAAS,EAAEkB,YAAY,I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hB,QAAQ;YACV,OAAO;gBACLpB,IAAIM,KAAK,CAAC,CAAC,OAAO,EAAE8B,WAAW,oBAAoB,EAAEH,KAAK,CAAC,CAAC;gBAC5D,IAAIR,QAAQ;oBACVzB,IAAIM,KAAK,CAAC,CAAC,QAAQ,EAAEmB,QAAQ;gBAC/B;gBACAL,QAAQ;YACV;QACF;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/utils/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAQrD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,GAAE,MAAsB,GAClC,OAAO,CAAC,WAAW,CAAC,CAwCtB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAS/D;AAiED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0C7F;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,KAAK,GAAG,MAAM,GAAG,MAAc,GAC9C,OAAO,CAAC,IAAI,CAAC,CAsCf;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAenF;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQhG"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/utils/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAOrD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,GAAE,MAAsB,GAClC,OAAO,CAAC,WAAW,CAAC,CAwCtB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAS/D;AAiED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8C7F;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,KAAK,GAAG,MAAM,GAAG,MAAc,GAC9C,OAAO,CAAC,IAAI,CAAC,CAsCf;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAenF;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQhG"}
@@ -3,9 +3,9 @@
3
3
  */ import { spawn } from 'child_process';
4
4
  import fs from 'fs/promises';
5
5
  import path from 'path';
6
+ import { fileURLToPath } from 'url';
6
7
  import { ensureGitignore } from './config.js';
7
8
  import { downloadTemplateFromGitHub } from './download-template.js';
8
- import { manageEnvFiles } from './env-management.js';
9
9
  import { tryInitRepoAndCommit } from './git.js';
10
10
  import { applyLambdaModifications } from './lambda-config.js';
11
11
  /**
@@ -151,14 +151,18 @@ import { applyLambdaModifications } from './lambda-config.js';
151
151
  // Replace workspace:* versions with actual versions
152
152
  replaceWorkspaceVersions(packageJson, latestVersion);
153
153
  await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
154
- // Manage environment files (generate PAYLOAD_SECRET)
155
- await manageEnvFiles(projectPath);
156
154
  // Ensure .gitignore has required entries
155
+ // Note: .env file is created by init command with FIGMA_CONTENT_SYSTEM_ID
157
156
  await ensureGitignore(projectPath, [
158
157
  '.env',
159
158
  '.env.local',
160
159
  'lambda.zip'
161
160
  ]);
161
+ // Replace README with Figma-specific version
162
+ const readmeTemplatePath = fileURLToPath(new URL('../templates/README.md', import.meta.url));
163
+ let readmeContent = await fs.readFile(readmeTemplatePath, 'utf-8');
164
+ readmeContent = readmeContent.replace(/\{\{PROJECT_NAME\}\}/g, projectName);
165
+ await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent, 'utf-8');
162
166
  }
163
167
  /**
164
168
  * Initialize git repository after all setup is complete
@@ -177,9 +181,7 @@ import { applyLambdaModifications } from './lambda-config.js';
177
181
  * @returns Promise that resolves when installation completes
178
182
  */ export async function installDependencies(projectPath, packageManager = 'npm') {
179
183
  return new Promise((resolve, reject)=>{
180
- const child = spawn(packageManager, [
181
- 'install'
182
- ], {
184
+ const child = spawn(`${packageManager} install`, {
183
185
  cwd: projectPath,
184
186
  shell: true,
185
187
  stdio: 'pipe'