@payloadcms/figma 0.0.1-alpha.1 → 0.0.1-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +11 -16
- package/dist/api/control-plane.js.map +1 -1
- package/dist/api/figma-api.js +3 -3
- package/dist/api/figma-api.js.map +1 -1
- package/dist/auth/jwt-validator.js.map +1 -1
- package/dist/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +3 -6
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/project-token.d.ts.map +1 -1
- package/dist/auth/project-token.js +1 -4
- package/dist/auth/project-token.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +19 -28
- package/dist/auth/refresh.js.map +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +17 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +21 -85
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +6 -5
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts +2 -11
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +4 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/db-adapter.d.ts +17 -0
- package/dist/db-adapter.d.ts.map +1 -0
- package/dist/db-adapter.js +757 -0
- package/dist/db-adapter.js.map +1 -0
- package/dist/endpoints/health.d.ts +3 -0
- package/dist/endpoints/health.d.ts.map +1 -0
- package/dist/endpoints/health.js +11 -0
- package/dist/endpoints/health.js.map +1 -0
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.d.ts +9 -0
- package/dist/oauth/components/LoginButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LoginButton/index.js +52 -0
- package/dist/oauth/components/LoginButton/index.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.scss +10 -0
- package/dist/oauth/components/LogoutButton/index.d.ts +7 -0
- package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LogoutButton/index.js +67 -0
- package/dist/oauth/components/LogoutButton/index.js.map +1 -0
- package/dist/oauth/components/LogoutButton/index.scss +10 -0
- package/dist/oauth/defaults.d.ts +10 -0
- package/dist/oauth/defaults.d.ts.map +1 -0
- package/dist/oauth/defaults.js +91 -0
- package/dist/oauth/defaults.js.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js +237 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +12 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js +99 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js +25 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +21 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +1 -0
- package/dist/oauth/exports/client.d.ts +3 -0
- package/dist/oauth/exports/client.d.ts.map +1 -0
- package/dist/oauth/exports/client.js +4 -0
- package/dist/oauth/exports/client.js.map +1 -0
- package/dist/oauth/hooks/afterLogout.d.ts +8 -0
- package/dist/oauth/hooks/afterLogout.d.ts.map +1 -0
- package/dist/oauth/hooks/afterLogout.js +27 -0
- package/dist/oauth/hooks/afterLogout.js.map +1 -0
- package/dist/oauth/hooks/me.d.ts +5 -0
- package/dist/oauth/hooks/me.d.ts.map +1 -0
- package/dist/oauth/hooks/me.js +55 -0
- package/dist/oauth/hooks/me.js.map +1 -0
- package/dist/oauth/hooks/refresh.d.ts +8 -0
- package/dist/oauth/hooks/refresh.d.ts.map +1 -0
- package/dist/oauth/hooks/refresh.js +91 -0
- package/dist/oauth/hooks/refresh.js.map +1 -0
- package/dist/oauth/index.d.ts +4 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +222 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/strategy/index.d.ts +54 -0
- package/dist/oauth/strategy/index.d.ts.map +1 -0
- package/dist/oauth/strategy/index.js +280 -0
- package/dist/oauth/strategy/index.js.map +1 -0
- package/dist/oauth/types.d.ts +192 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/types.js +3 -0
- package/dist/oauth/types.js.map +1 -0
- package/dist/oauth/utilities/clearCookie.d.ts +9 -0
- package/dist/oauth/utilities/clearCookie.d.ts.map +1 -0
- package/dist/oauth/utilities/clearCookie.js +21 -0
- package/dist/oauth/utilities/clearCookie.js.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts +10 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.js +42 -0
- package/dist/oauth/utilities/createCookieOptions.js.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts +4 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.js +16 -0
- package/dist/oauth/utilities/createDebugLogger.js.map +1 -0
- package/dist/oauth/utilities/extractOrigin.d.ts +2 -0
- package/dist/oauth/utilities/extractOrigin.d.ts.map +1 -0
- package/dist/oauth/utilities/extractOrigin.js +12 -0
- package/dist/oauth/utilities/extractOrigin.js.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +3 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js +18 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +1 -0
- package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
- package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminPath.js +9 -0
- package/dist/oauth/utilities/getAdminPath.js.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +17 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +45 -0
- package/dist/oauth/utilities/getAuthorizeURL.js.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts +4 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.js +11 -0
- package/dist/oauth/utilities/getCookieExpiration.js.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +2 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js +7 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getTokenExp.d.ts +6 -0
- package/dist/oauth/utilities/getTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getTokenExp.js +20 -0
- package/dist/oauth/utilities/getTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getUsernameField.d.ts +9 -0
- package/dist/oauth/utilities/getUsernameField.d.ts.map +1 -0
- package/dist/oauth/utilities/getUsernameField.js +20 -0
- package/dist/oauth/utilities/getUsernameField.js.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +8 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js +25 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts +2 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.js +37 -0
- package/dist/oauth/utilities/mergeHeaders.js.map +1 -0
- package/dist/oauth/utilities/refreshTokens.d.ts +16 -0
- package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -0
- package/dist/oauth/utilities/refreshTokens.js +67 -0
- package/dist/oauth/utilities/refreshTokens.js.map +1 -0
- package/dist/plugin/build-config.d.ts +7 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +53 -3
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types/config.d.ts +0 -11
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/utils/config.d.ts +0 -22
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -46
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/messages.js +11 -11
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +17 -1
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +166 -14
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts +2 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +50 -79
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +14 -33
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -5
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/s3-upload.d.ts.map +1 -1
- package/dist/utils/s3-upload.js +3 -8
- package/dist/utils/s3-upload.js.map +1 -1
- package/dist/utils/token-display.d.ts.map +1 -1
- package/dist/utils/token-display.js +3 -2
- package/dist/utils/token-display.js.map +1 -1
- package/package.json +9 -3
- package/dist/api/control-plane.spec.d.ts +0 -2
- package/dist/api/control-plane.spec.d.ts.map +0 -1
- package/dist/api/control-plane.spec.js +0 -296
- package/dist/api/control-plane.spec.js.map +0 -1
- package/dist/api/figma-api.spec.d.ts +0 -14
- package/dist/api/figma-api.spec.d.ts.map +0 -1
- package/dist/api/figma-api.spec.js +0 -201
- package/dist/api/figma-api.spec.js.map +0 -1
- package/dist/auth/__tests__/fixtures.d.ts +0 -26
- package/dist/auth/__tests__/fixtures.d.ts.map +0 -1
- package/dist/auth/__tests__/fixtures.js +0 -67
- package/dist/auth/__tests__/fixtures.js.map +0 -1
- package/dist/auth/__tests__/mocks.d.ts +0 -33
- package/dist/auth/__tests__/mocks.d.ts.map +0 -1
- package/dist/auth/__tests__/mocks.js +0 -63
- package/dist/auth/__tests__/mocks.js.map +0 -1
- package/dist/auth/callback-server.spec.d.ts +0 -2
- package/dist/auth/callback-server.spec.d.ts.map +0 -1
- package/dist/auth/callback-server.spec.js +0 -85
- package/dist/auth/callback-server.spec.js.map +0 -1
- package/dist/auth/crypto-utils.spec.d.ts +0 -2
- package/dist/auth/crypto-utils.spec.d.ts.map +0 -1
- package/dist/auth/crypto-utils.spec.js +0 -36
- package/dist/auth/crypto-utils.spec.js.map +0 -1
- package/dist/auth/jwt-validator.spec.d.ts +0 -10
- package/dist/auth/jwt-validator.spec.d.ts.map +0 -1
- package/dist/auth/jwt-validator.spec.js +0 -236
- package/dist/auth/jwt-validator.spec.js.map +0 -1
- package/dist/auth/oauth-flow.spec.d.ts +0 -2
- package/dist/auth/oauth-flow.spec.d.ts.map +0 -1
- package/dist/auth/oauth-flow.spec.js +0 -134
- package/dist/auth/oauth-flow.spec.js.map +0 -1
- package/dist/auth/pkce.spec.d.ts +0 -2
- package/dist/auth/pkce.spec.d.ts.map +0 -1
- package/dist/auth/pkce.spec.js +0 -32
- package/dist/auth/pkce.spec.js.map +0 -1
- package/dist/auth/project-token.spec.d.ts +0 -2
- package/dist/auth/project-token.spec.d.ts.map +0 -1
- package/dist/auth/project-token.spec.js +0 -332
- package/dist/auth/project-token.spec.js.map +0 -1
- package/dist/auth/refresh.spec.d.ts +0 -2
- package/dist/auth/refresh.spec.d.ts.map +0 -1
- package/dist/auth/refresh.spec.js +0 -105
- package/dist/auth/refresh.spec.js.map +0 -1
- package/dist/auth/token-store.spec.d.ts +0 -2
- package/dist/auth/token-store.spec.d.ts.map +0 -1
- package/dist/auth/token-store.spec.js +0 -276
- package/dist/auth/token-store.spec.js.map +0 -1
- package/dist/commands/__tests__/test-utils.d.ts +0 -28
- package/dist/commands/__tests__/test-utils.d.ts.map +0 -1
- package/dist/commands/__tests__/test-utils.js +0 -34
- package/dist/commands/__tests__/test-utils.js.map +0 -1
- package/dist/commands/deploy.spec.d.ts +0 -2
- package/dist/commands/deploy.spec.d.ts.map +0 -1
- package/dist/commands/deploy.spec.js +0 -18
- package/dist/commands/deploy.spec.js.map +0 -1
- package/dist/commands/init.spec.d.ts +0 -2
- package/dist/commands/init.spec.d.ts.map +0 -1
- package/dist/commands/init.spec.js +0 -283
- package/dist/commands/init.spec.js.map +0 -1
- package/dist/plugin/build-config.spec.d.ts +0 -2
- package/dist/plugin/build-config.spec.d.ts.map +0 -1
- package/dist/plugin/build-config.spec.js +0 -72
- package/dist/plugin/build-config.spec.js.map +0 -1
- package/dist/utils/asset-collection.spec.d.ts +0 -2
- package/dist/utils/asset-collection.spec.d.ts.map +0 -1
- package/dist/utils/asset-collection.spec.js +0 -155
- package/dist/utils/asset-collection.spec.js.map +0 -1
- package/dist/utils/build-detection.spec.d.ts +0 -2
- package/dist/utils/build-detection.spec.d.ts.map +0 -1
- package/dist/utils/build-detection.spec.js +0 -110
- package/dist/utils/build-detection.spec.js.map +0 -1
- package/dist/utils/config.spec.d.ts +0 -2
- package/dist/utils/config.spec.d.ts.map +0 -1
- package/dist/utils/config.spec.js +0 -167
- package/dist/utils/config.spec.js.map +0 -1
- package/dist/utils/download-template.spec.d.ts +0 -2
- package/dist/utils/download-template.spec.d.ts.map +0 -1
- package/dist/utils/download-template.spec.js +0 -76
- package/dist/utils/download-template.spec.js.map +0 -1
- package/dist/utils/env-management.spec.d.ts +0 -2
- package/dist/utils/env-management.spec.d.ts.map +0 -1
- package/dist/utils/env-management.spec.js +0 -123
- package/dist/utils/env-management.spec.js.map +0 -1
- package/dist/utils/git.spec.d.ts +0 -2
- package/dist/utils/git.spec.d.ts.map +0 -1
- package/dist/utils/git.spec.js +0 -99
- package/dist/utils/git.spec.js.map +0 -1
- package/dist/utils/lambda-config.spec.d.ts +0 -2
- package/dist/utils/lambda-config.spec.d.ts.map +0 -1
- package/dist/utils/lambda-config.spec.js +0 -141
- package/dist/utils/lambda-config.spec.js.map +0 -1
- package/dist/utils/payload-config-ast.spec.d.ts +0 -2
- package/dist/utils/payload-config-ast.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.spec.js +0 -303
- package/dist/utils/payload-config-ast.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.int.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.js +0 -116
- package/dist/utils/payload-config-modifier.int.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.spec.js +0 -162
- package/dist/utils/payload-config-modifier.spec.js.map +0 -1
- package/dist/utils/payload-package-check.spec.d.ts +0 -2
- package/dist/utils/payload-package-check.spec.d.ts.map +0 -1
- package/dist/utils/payload-package-check.spec.js +0 -148
- package/dist/utils/payload-package-check.spec.js.map +0 -1
- package/dist/utils/project.spec.d.ts +0 -2
- package/dist/utils/project.spec.d.ts.map +0 -1
- package/dist/utils/project.spec.js +0 -222
- package/dist/utils/project.spec.js.map +0 -1
- package/dist/utils/s3-upload.spec.d.ts +0 -2
- package/dist/utils/s3-upload.spec.d.ts.map +0 -1
- package/dist/utils/s3-upload.spec.js +0 -140
- package/dist/utils/s3-upload.spec.js.map +0 -1
|
@@ -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 { isDebug } from './is-debug.js'\nimport * as log from './log.js'\n\nexport type DetectionResult = {\n buildConfigNotFound?: boolean\n dbProperty?: {\n adapter: string\n importSource: string\n }\n editorProperty?: {\n importSource: string\n isDefault: boolean\n }\n hasAlias: 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 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 if (isDebug()) {\n log.debug('No payload or @payloadcms/figma import found')\n }\n result.buildConfigNotFound = true\n return result\n }\n\n if (isDebug()) {\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n }\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.buildConfigNotFound = true\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.buildConfigNotFound = true\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 return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\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.buildConfigNotFound || detection.hasAlias) {\n if (isDebug()) {\n log.debug(\n `Skipping modifications: buildConfigNotFound=${detection.buildConfigNotFound}, hasAlias=${detection.hasAlias}`,\n )\n }\n return { changes: [], modified: false }\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"],"names":["Node","SyntaxKind","isDebug","log","detectRequiredChanges","sourceFile","result","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","buildConfigNotFound","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","applyModifications","detection","changes","modified","remove","push","addImportDeclaration","setModuleSpecifier","currentImports","dbImport"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAE3C,SAASC,OAAO,QAAQ,gBAAe;AACvC,YAAYC,SAAS,WAAU;AAkB/B;;CAEC,GACD,OAAO,SAASC,sBAAsBC,UAAsB;IAC1D,MAAMC,SAA0B;QAC9BC,UAAU;QACVC,wBAAwB;QACxBC,mBAAmB;IACrB;IAEA,0BAA0B;IAC1B,MAAMC,UAAUL,WAAWM,qBAAqB;IAChD,M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,cAAc,EAAEF;QAEvE,IAAIK,cAAc;YAChBA,aAAaO,MAAM;YACnBF,QAAQG,IAAI,CAAC;YACbF,WAAW;QACb;IACF;IAEA,OAAO;QAAED;QAASC;IAAS;AAC7B"}
|
|
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,EA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AAMoE,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,4 +1,5 @@
|
|
|
1
1
|
import type { PackageManager } from './package-manager.js';
|
|
2
|
+
import { type FigmaPropertyConfig } from './payload-config-ast.js';
|
|
2
3
|
export type ModificationResult = {
|
|
3
4
|
changes: string[];
|
|
4
5
|
error?: string;
|
|
@@ -10,7 +11,7 @@ export type ModificationResult = {
|
|
|
10
11
|
* Main orchestrator for payload config modification
|
|
11
12
|
* Checks package, detects needed changes, applies modifications
|
|
12
13
|
*/
|
|
13
|
-
export declare function ensurePayloadFigmaConfig(projectPath: string, packageManager: PackageManager): Promise<ModificationResult>;
|
|
14
|
+
export declare function ensurePayloadFigmaConfig(projectPath: string, packageManager: PackageManager, figmaConfig?: FigmaPropertyConfig): Promise<ModificationResult>;
|
|
14
15
|
/**
|
|
15
16
|
* Display manual configuration instructions
|
|
16
17
|
*/
|
|
@@ -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;
|
|
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,29 +1,24 @@
|
|
|
1
1
|
import pc from 'picocolors';
|
|
2
2
|
import { Project } from 'ts-morph';
|
|
3
3
|
import { formatFile } from './formatter.js';
|
|
4
|
-
import { isDebug } from './is-debug.js';
|
|
5
4
|
import * as log from './log.js';
|
|
6
|
-
import { applyModifications, detectRequiredChanges } from './payload-config-ast.js';
|
|
5
|
+
import { addFigmaProperty, applyModifications, detectRequiredChanges } from './payload-config-ast.js';
|
|
7
6
|
import { findPayloadConfig } from './payload-config-finder.js';
|
|
8
7
|
import { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js';
|
|
9
8
|
import { runTypeScriptCheck } from './typescript-validator.js';
|
|
10
9
|
/**
|
|
11
10
|
* Main orchestrator for payload config modification
|
|
12
11
|
* Checks package, detects needed changes, applies modifications
|
|
13
|
-
*/ export async function ensurePayloadFigmaConfig(projectPath, packageManager) {
|
|
12
|
+
*/ export async function ensurePayloadFigmaConfig(projectPath, packageManager, figmaConfig) {
|
|
14
13
|
const changes = [];
|
|
15
14
|
const warnings = [];
|
|
16
15
|
let modified = false;
|
|
17
16
|
try {
|
|
18
|
-
|
|
19
|
-
log.debug(`Starting payload config modification for: ${projectPath}`);
|
|
20
|
-
}
|
|
17
|
+
log.debug(`Starting payload config modification for: ${projectPath}`);
|
|
21
18
|
// 1. Find config file
|
|
22
19
|
const configPath = await findPayloadConfig(projectPath);
|
|
23
20
|
if (!configPath) {
|
|
24
|
-
|
|
25
|
-
log.debug(`Config file not found in: ${projectPath}`);
|
|
26
|
-
}
|
|
21
|
+
log.debug(`Config file not found in: ${projectPath}`);
|
|
27
22
|
return {
|
|
28
23
|
changes: [],
|
|
29
24
|
error: 'payload.config.ts not found in project',
|
|
@@ -31,26 +26,18 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
31
26
|
success: false
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
log.debug(`Found config file: ${configPath}`);
|
|
36
|
-
}
|
|
29
|
+
log.debug(`Found config file: ${configPath}`);
|
|
37
30
|
// 2. Check/install @payloadcms/figma package
|
|
38
31
|
const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma');
|
|
39
32
|
if (!isInstalled) {
|
|
40
|
-
|
|
41
|
-
log.debug('@payloadcms/figma not installed, attempting installation...');
|
|
42
|
-
}
|
|
33
|
+
log.debug('@payloadcms/figma not installed, attempting installation...');
|
|
43
34
|
try {
|
|
44
35
|
await installPackage(projectPath, '@payloadcms/figma', packageManager);
|
|
45
36
|
changes.push('Installed @payloadcms/figma');
|
|
46
37
|
modified = true;
|
|
47
|
-
|
|
48
|
-
log.debug('@payloadcms/figma installed successfully');
|
|
49
|
-
}
|
|
38
|
+
log.debug('@payloadcms/figma installed successfully');
|
|
50
39
|
} catch (error) {
|
|
51
|
-
|
|
52
|
-
log.debug(`Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
53
|
-
}
|
|
40
|
+
log.debug(`Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
54
41
|
return {
|
|
55
42
|
changes: [],
|
|
56
43
|
error: 'Failed to install @payloadcms/figma',
|
|
@@ -58,30 +45,22 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
58
45
|
success: false
|
|
59
46
|
};
|
|
60
47
|
}
|
|
61
|
-
} else
|
|
48
|
+
} else {
|
|
62
49
|
log.debug('@payloadcms/figma already installed');
|
|
63
50
|
}
|
|
64
51
|
// 3. Parse config with ts-morph
|
|
65
|
-
|
|
66
|
-
log.debug('Parsing config file with ts-morph...');
|
|
67
|
-
}
|
|
52
|
+
log.debug('Parsing config file with ts-morph...');
|
|
68
53
|
const project = new Project({
|
|
69
54
|
skipAddingFilesFromTsConfig: true
|
|
70
55
|
});
|
|
71
56
|
const sourceFile = project.addSourceFileAtPath(configPath);
|
|
72
57
|
// 4. Detect required changes
|
|
73
|
-
|
|
74
|
-
log.debug('Detecting required changes...');
|
|
75
|
-
}
|
|
58
|
+
log.debug('Detecting required changes...');
|
|
76
59
|
const detection = detectRequiredChanges(sourceFile);
|
|
77
|
-
|
|
78
|
-
log.debug(`Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, buildConfigNotFound=${detection.buildConfigNotFound}`);
|
|
79
|
-
}
|
|
60
|
+
log.debug(`Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, hasBuildConfig=${detection.hasBuildConfig}`);
|
|
80
61
|
// Handle failure modes
|
|
81
62
|
if (detection.hasAlias) {
|
|
82
|
-
|
|
83
|
-
log.debug('Config uses import alias (e.g., buildConfig as X)');
|
|
84
|
-
}
|
|
63
|
+
log.debug('Config uses import alias (e.g., buildConfig as X)');
|
|
85
64
|
return {
|
|
86
65
|
changes,
|
|
87
66
|
error: 'Config uses import alias - manual modification required',
|
|
@@ -89,10 +68,8 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
89
68
|
success: false
|
|
90
69
|
};
|
|
91
70
|
}
|
|
92
|
-
if (detection.
|
|
93
|
-
|
|
94
|
-
log.debug('No buildConfig call found in config file');
|
|
95
|
-
}
|
|
71
|
+
if (detection.hasBuildConfig === false) {
|
|
72
|
+
log.debug('No buildConfig call found in config file');
|
|
96
73
|
return {
|
|
97
74
|
changes,
|
|
98
75
|
error: 'Config structure not recognized (no buildConfig call found)',
|
|
@@ -101,22 +78,32 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
101
78
|
};
|
|
102
79
|
}
|
|
103
80
|
// 5. Apply modifications
|
|
104
|
-
|
|
105
|
-
log.debug('Applying modifications...');
|
|
106
|
-
}
|
|
81
|
+
log.debug('Applying modifications...');
|
|
107
82
|
const modResult = applyModifications(sourceFile, detection);
|
|
108
83
|
if (modResult.modified) {
|
|
109
84
|
changes.push(...modResult.changes);
|
|
110
85
|
modified = true;
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
log.debug(`Applied ${modResult.changes.length} modifications`);
|
|
87
|
+
}
|
|
88
|
+
// 6. Add figma property if config provided and doesn't exist
|
|
89
|
+
if (figmaConfig && !detection.figmaObjectExists) {
|
|
90
|
+
log.debug('Adding figma property to buildConfig...');
|
|
91
|
+
const figmaResult = addFigmaProperty(sourceFile, figmaConfig);
|
|
92
|
+
if (figmaResult.modified) {
|
|
93
|
+
changes.push(...figmaResult.changes);
|
|
94
|
+
modified = true;
|
|
95
|
+
log.debug(`Added figma property`);
|
|
96
|
+
} else {
|
|
97
|
+
log.debug('Figma property not added (may already exist)');
|
|
113
98
|
}
|
|
114
|
-
|
|
99
|
+
} else if (detection.figmaObjectExists) {
|
|
100
|
+
log.debug('Figma property already exists, skipping');
|
|
101
|
+
}
|
|
102
|
+
// Save file if any modifications were made
|
|
103
|
+
if (modified) {
|
|
115
104
|
await sourceFile.save();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
// 6. Uninstall orphaned packages
|
|
105
|
+
log.debug('Config file saved');
|
|
106
|
+
// 7. Uninstall orphaned packages
|
|
120
107
|
const packagesToUninstall = [];
|
|
121
108
|
if (detection.dbProperty) {
|
|
122
109
|
packagesToUninstall.push(detection.dbProperty.importSource);
|
|
@@ -124,51 +111,37 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
124
111
|
if (detection.editorProperty?.isDefault) {
|
|
125
112
|
packagesToUninstall.push(detection.editorProperty.importSource);
|
|
126
113
|
}
|
|
127
|
-
if (packagesToUninstall.length > 0
|
|
114
|
+
if (packagesToUninstall.length > 0) {
|
|
128
115
|
log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`);
|
|
129
116
|
}
|
|
130
117
|
for (const pkg of packagesToUninstall){
|
|
131
118
|
try {
|
|
132
119
|
await uninstallPackage(projectPath, pkg, packageManager);
|
|
133
120
|
changes.push(`Uninstalled ${pkg}`);
|
|
134
|
-
|
|
135
|
-
log.debug(`Uninstalled ${pkg}`);
|
|
136
|
-
}
|
|
121
|
+
log.debug(`Uninstalled ${pkg}`);
|
|
137
122
|
} catch (error) {
|
|
138
|
-
|
|
139
|
-
log.debug(`Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
140
|
-
}
|
|
123
|
+
log.debug(`Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
141
124
|
// Don't fail on uninstall errors - orphaned package is better than broken config
|
|
142
125
|
}
|
|
143
126
|
}
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
log.debug('Formatting config file...');
|
|
147
|
-
}
|
|
127
|
+
// 8. Format file
|
|
128
|
+
log.debug('Formatting config file...');
|
|
148
129
|
const formatResult = await formatFile(configPath, packageManager);
|
|
149
130
|
if (!formatResult.success && formatResult.warning) {
|
|
150
131
|
warnings.push(formatResult.warning);
|
|
151
|
-
|
|
152
|
-
log.debug(`Formatting warning: ${formatResult.warning}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// 8. Run TypeScript validation
|
|
156
|
-
if (isDebug()) {
|
|
157
|
-
log.debug('Running TypeScript validation...');
|
|
132
|
+
log.debug(`Formatting warning: ${formatResult.warning}`);
|
|
158
133
|
}
|
|
134
|
+
// 9. Run TypeScript validation
|
|
135
|
+
log.debug('Running TypeScript validation...');
|
|
159
136
|
const tsResult = await runTypeScriptCheck(projectPath, packageManager);
|
|
160
137
|
if (!tsResult.success && tsResult.errors.length > 0) {
|
|
161
138
|
warnings.push("TypeScript validation found issues - run 'pnpm build' for details");
|
|
162
|
-
|
|
163
|
-
log.debug(`TypeScript validation found ${tsResult.errors.length} issues`);
|
|
164
|
-
}
|
|
139
|
+
log.debug(`TypeScript validation found ${tsResult.errors.length} issues`);
|
|
165
140
|
}
|
|
166
|
-
} else
|
|
141
|
+
} else {
|
|
167
142
|
log.debug('No modifications needed - config already correct');
|
|
168
143
|
}
|
|
169
|
-
|
|
170
|
-
log.debug('Payload config modification completed successfully');
|
|
171
|
-
}
|
|
144
|
+
log.debug('Payload config modification completed successfully');
|
|
172
145
|
return {
|
|
173
146
|
changes,
|
|
174
147
|
modified,
|
|
@@ -176,11 +149,9 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
176
149
|
warnings: warnings.length > 0 ? warnings : undefined
|
|
177
150
|
};
|
|
178
151
|
} catch (error) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
log.debug(`Stack trace: ${error.stack}`);
|
|
183
|
-
}
|
|
152
|
+
log.debug(`Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
153
|
+
if (error instanceof Error && error.stack) {
|
|
154
|
+
log.debug(`Stack trace: ${error.stack}`);
|
|
184
155
|
}
|
|
185
156
|
return {
|
|
186
157
|
changes,
|
|
@@ -224,7 +195,7 @@ ${pc.bold('Required changes:')}
|
|
|
224
195
|
3. Install package:
|
|
225
196
|
${pc.cyan('pnpm add @payloadcms/figma')}
|
|
226
197
|
|
|
227
|
-
Then run: ${pc.cyan('@payloadcms/figma init')}`);
|
|
198
|
+
Then run: ${pc.cyan('npx @payloadcms/figma init')}`);
|
|
228
199
|
// eslint-disable-next-line no-console
|
|
229
200
|
console.log(message);
|
|
230
201
|
}
|
|
@@ -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 { isDebug } from './is-debug.js'\nimport * as log from './log.js'\nimport { applyModifications, detectRequiredChanges } 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): Promise<ModificationResult> {\n const changes: string[] = []\n const warnings: string[] = []\n let modified = false\n\n try {\n if (isDebug()) {\n log.debug(`Starting payload config modification for: ${projectPath}`)\n }\n\n // 1. Find config file\n const configPath = await findPayloadConfig(projectPath)\n if (!configPath) {\n if (isDebug()) {\n log.debug(`Config file not found in: ${projectPath}`)\n }\n return {\n changes: [],\n error: 'payload.config.ts not found in project',\n modified: false,\n success: false,\n }\n }\n\n if (isDebug()) {\n log.debug(`Found config file: ${configPath}`)\n }\n\n // 2. Check/install @payloadcms/figma package\n const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma')\n if (!isInstalled) {\n if (isDebug()) {\n log.debug('@payloadcms/figma not installed, attempting installation...')\n }\n try {\n await installPackage(projectPath, '@payloadcms/figma', packageManager)\n changes.push('Installed @payloadcms/figma')\n modified = true\n if (isDebug()) {\n log.debug('@payloadcms/figma installed successfully')\n }\n } catch (error) {\n if (isDebug()) {\n log.debug(\n `Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n return {\n changes: [],\n error: 'Failed to install @payloadcms/figma',\n modified: false,\n success: false,\n }\n }\n } else if (isDebug()) {\n log.debug('@payloadcms/figma already installed')\n }\n\n // 3. Parse config with ts-morph\n if (isDebug()) {\n log.debug('Parsing config file with ts-morph...')\n }\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n })\n const sourceFile = project.addSourceFileAtPath(configPath)\n\n // 4. Detect required changes\n if (isDebug()) {\n log.debug('Detecting required changes...')\n }\n const detection = detectRequiredChanges(sourceFile)\n\n if (isDebug()) {\n log.debug(\n `Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, buildConfigNotFound=${detection.buildConfigNotFound}`,\n )\n }\n\n // Handle failure modes\n if (detection.hasAlias) {\n if (isDebug()) {\n log.debug('Config uses import alias (e.g., buildConfig as X)')\n }\n return {\n changes,\n error: 'Config uses import alias - manual modification required',\n modified,\n success: false,\n }\n }\n\n if (detection.buildConfigNotFound) {\n if (isDebug()) {\n log.debug('No buildConfig call found in config file')\n }\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 if (isDebug()) {\n log.debug('Applying modifications...')\n }\n const modResult = applyModifications(sourceFile, detection)\n if (modResult.modified) {\n changes.push(...modResult.changes)\n modified = true\n\n if (isDebug()) {\n log.debug(`Applied ${modResult.changes.length} modifications`)\n }\n\n // Save file\n await sourceFile.save()\n if (isDebug()) {\n log.debug('Config file saved')\n }\n\n // 6. 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 && isDebug()) {\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 if (isDebug()) {\n log.debug(`Uninstalled ${pkg}`)\n }\n } catch (error) {\n if (isDebug()) {\n log.debug(\n `Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n // Don't fail on uninstall errors - orphaned package is better than broken config\n }\n }\n\n // 7. Format file\n if (isDebug()) {\n log.debug('Formatting config file...')\n }\n const formatResult = await formatFile(configPath, packageManager)\n if (!formatResult.success && formatResult.warning) {\n warnings.push(formatResult.warning)\n if (isDebug()) {\n log.debug(`Formatting warning: ${formatResult.warning}`)\n }\n }\n\n // 8. Run TypeScript validation\n if (isDebug()) {\n log.debug('Running TypeScript validation...')\n }\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 if (isDebug()) {\n log.debug(`TypeScript validation found ${tsResult.errors.length} issues`)\n }\n }\n } else if (isDebug()) {\n log.debug('No modifications needed - config already correct')\n }\n\n if (isDebug()) {\n log.debug('Payload config modification completed successfully')\n }\n\n return {\n changes,\n modified,\n success: true,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n if (isDebug()) {\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 }\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('@payloadcms/figma init')}`)\n\n // eslint-disable-next-line no-console\n console.log(message)\n}\n"],"names":["pc","Project","formatFile","isDebug","log","applyModifications","detectRequiredChanges","findPayloadConfig","checkPackageInstalled","installPackage","uninstallPackage","runTypeScriptCheck","ensurePayloadFigmaConfig","projectPath","packageManager","changes","warnings","modified","debug","configPath","error","success","isInstalled","push","Error","message","project","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPath","detection","needsImportChange","hasAlias","buildConfigNotFound","modResult","length","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,SAASC,OAAO,QAAQ,gBAAe;AACvC,YAAYC,SAAS,WAAU;AAC/B,SAASC,kBAAkB,EAAEC,qBAAqB,Q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AG2D,IAAI,CAAC3D,GAAG4D,IAAI,CAAC,kCAAkC;;;QAG5E,EAAE5D,GAAG6D,MAAM,CAACX,QAAQ;;AAE5B,EAAElD,GAAG4D,IAAI,CAAC,qBAAqB;;;GAG5B,EAAE5D,GAAGyD,GAAG,CAAC,cAAczD,GAAG2D,IAAI,CAAC,yCAAyC;GACxE,EAAE3D,GAAGyD,GAAG,CAAC,cAAczD,GAAG2D,IAAI,CAAC,mDAAmD;;;;;;;;GAQlF,EAAE3D,GAAG2D,IAAI,CAAC,8BAA8B;;UAEjC,EAAE3D,GAAG2D,IAAI,CAAC,2BAA2B;IAE7C,sCAAsC;IACtCG,QAAQ1D,GAAG,CAACqB;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. 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,U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D,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 +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;
|
|
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,27 +1,20 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { isDebug } from './is-debug.js';
|
|
5
4
|
import * as log from './log.js';
|
|
6
5
|
/**
|
|
7
6
|
* Check if a package is installed in dependencies (not devDependencies)
|
|
8
7
|
*/ export async function checkPackageInstalled(projectPath, packageName) {
|
|
9
8
|
try {
|
|
10
9
|
const pkgJsonPath = path.join(projectPath, 'package.json');
|
|
11
|
-
if
|
|
12
|
-
log.debug(`Checking if ${packageName} is installed in: ${pkgJsonPath}`);
|
|
13
|
-
}
|
|
10
|
+
log.debug(`Checking if ${packageName} is installed in: ${pkgJsonPath}`);
|
|
14
11
|
const pkgJsonContent = await fs.readFile(pkgJsonPath, 'utf-8');
|
|
15
12
|
const pkgJson = JSON.parse(pkgJsonContent);
|
|
16
13
|
const isInstalled = !!pkgJson.dependencies?.[packageName];
|
|
17
|
-
|
|
18
|
-
log.debug(`${packageName} is ${isInstalled ? 'installed' : 'not installed'}`);
|
|
19
|
-
}
|
|
14
|
+
log.debug(`${packageName} is ${isInstalled ? 'installed' : 'not installed'}`);
|
|
20
15
|
return isInstalled;
|
|
21
16
|
} catch (error) {
|
|
22
|
-
|
|
23
|
-
log.debug(`Error checking package installation: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
24
|
-
}
|
|
17
|
+
log.debug(`Error checking package installation: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
25
18
|
return false;
|
|
26
19
|
}
|
|
27
20
|
}
|
|
@@ -38,9 +31,7 @@ import * as log from './log.js';
|
|
|
38
31
|
if (packageManager === 'npm') {
|
|
39
32
|
args[0] = 'install';
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
43
|
-
}
|
|
34
|
+
log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
44
35
|
let stderr = '';
|
|
45
36
|
const child = spawn(command, args, {
|
|
46
37
|
cwd: projectPath,
|
|
@@ -54,23 +45,17 @@ import * as log from './log.js';
|
|
|
54
45
|
});
|
|
55
46
|
}
|
|
56
47
|
child.on('error', (error)=>{
|
|
57
|
-
|
|
58
|
-
log.debug(`Spawn error for ${command}: ${error.message}`);
|
|
59
|
-
}
|
|
48
|
+
log.debug(`Spawn error for ${command}: ${error.message}`);
|
|
60
49
|
reject(new Error(`Failed to spawn ${command}: ${error.message}`));
|
|
61
50
|
});
|
|
62
51
|
child.on('close', (code)=>{
|
|
63
52
|
if (code === 0) {
|
|
64
|
-
|
|
65
|
-
log.debug(`Successfully installed ${packageName}`);
|
|
66
|
-
}
|
|
53
|
+
log.debug(`Successfully installed ${packageName}`);
|
|
67
54
|
resolve();
|
|
68
55
|
} else {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
log.debug(`stderr: ${stderr}`);
|
|
73
|
-
}
|
|
56
|
+
log.debug(`Failed to install ${packageName} (exit code: ${code})`);
|
|
57
|
+
if (stderr) {
|
|
58
|
+
log.debug(`stderr: ${stderr}`);
|
|
74
59
|
}
|
|
75
60
|
reject(new Error(`Failed to install ${packageName}`));
|
|
76
61
|
}
|
|
@@ -91,21 +76,17 @@ import * as log from './log.js';
|
|
|
91
76
|
if (packageManager === 'npm') {
|
|
92
77
|
args[0] = 'uninstall';
|
|
93
78
|
}
|
|
94
|
-
|
|
95
|
-
log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
96
|
-
}
|
|
79
|
+
log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
97
80
|
const child = spawn(command, args, {
|
|
98
81
|
cwd: projectPath,
|
|
99
82
|
shell: true,
|
|
100
83
|
stdio: 'pipe'
|
|
101
84
|
});
|
|
102
85
|
child.on('close', (code)=>{
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
log.debug(`Failed to uninstall ${packageName} (exit code: ${code}), continuing anyway`);
|
|
108
|
-
}
|
|
86
|
+
if (code === 0) {
|
|
87
|
+
log.debug(`Successfully uninstalled ${packageName}`);
|
|
88
|
+
} else {
|
|
89
|
+
log.debug(`Failed to uninstall ${packageName} (exit code: ${code}), continuing anyway`);
|
|
109
90
|
}
|
|
110
91
|
// Always resolve, even on error
|
|
111
92
|
resolve();
|
|
@@ -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
|
|
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,WAAmB,EACnBC,WAAmB;IAEnB,IAAI;QACF,MAAMC,cAAcL,KAAKM,IAAI,CAACH,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,7 @@ export declare function hasRequiredDependencies(projectPath: string): Promise<bo
|
|
|
49
49
|
/**
|
|
50
50
|
* Check if current directory is a project directory
|
|
51
51
|
*
|
|
52
|
-
* A project directory has package.json
|
|
52
|
+
* A project directory has package.json
|
|
53
53
|
*
|
|
54
54
|
* @param projectPath - Path to check (defaults to cwd)
|
|
55
55
|
* @returns True if in project directory
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/utils/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,K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