@payloadcms/figma 0.0.1-alpha.21 → 0.0.1-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin/build-config.d.ts +1 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +1 -1
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +15 -0
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +26 -11
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-modifier.js +1 -1
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { figmaContentSystem } from './plugin/adapter.js';
|
|
2
2
|
export type { FigmaContentSystemOptions } from './plugin/adapter.js';
|
|
3
|
-
export {
|
|
3
|
+
export { buildFigmaConfig } from './plugin/build-config.js';
|
|
4
4
|
export type { FigmaConfig } from './plugin/build-config.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAGpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,YAAY,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AAGpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Export database adapter for advanced use cases
|
|
2
2
|
export { figmaContentSystem } from './plugin/adapter.js';
|
|
3
3
|
// Export buildConfig wrapper and its config type
|
|
4
|
-
export {
|
|
4
|
+
export { buildFigmaConfig } from './plugin/build-config.js';
|
|
5
5
|
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Export database adapter for advanced use cases\nexport { figmaContentSystem } from './plugin/adapter.js'\nexport type { FigmaContentSystemOptions } from './plugin/adapter.js'\n\n// Export buildConfig wrapper and its config type\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Export database adapter for advanced use cases\nexport { figmaContentSystem } from './plugin/adapter.js'\nexport type { FigmaContentSystemOptions } from './plugin/adapter.js'\n\n// Export buildConfig wrapper and its config type\nexport { buildFigmaConfig } from './plugin/build-config.js'\nexport type { FigmaConfig } from './plugin/build-config.js'\n"],"names":["figmaContentSystem","buildFigmaConfig"],"mappings":"AAAA,iDAAiD;AACjD,SAASA,kBAAkB,QAAQ,sBAAqB;AAGxD,iDAAiD;AACjD,SAASC,gBAAgB,QAAQ,2BAA0B"}
|
|
@@ -55,5 +55,5 @@ export type FigmaConfig = {
|
|
|
55
55
|
* @param config - Payload configuration (db and secret omitted, editor optional)
|
|
56
56
|
* @returns Promise<SanitizedConfig> - Built Payload configuration
|
|
57
57
|
*/
|
|
58
|
-
export declare function
|
|
58
|
+
export declare function buildFigmaConfig(config: FigmaConfig): Promise<SanitizedConfig>;
|
|
59
59
|
//# sourceMappingURL=build-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-config.d.ts","sourceRoot":"","sources":["../../src/plugin/build-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAWtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;CAC1B,GAAG;IACF,KAAK,EAAE;QACL,eAAe,EAAE,MAAM,CAAA;QACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAC3B,CAAA;CACF,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,GAC1C,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AAE7B;;;;;;;;;GASG;AACH,wBAAsB,
|
|
1
|
+
{"version":3,"file":"build-config.d.ts","sourceRoot":"","sources":["../../src/plugin/build-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAWtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;CAC1B,GAAG;IACF,KAAK,EAAE;QACL,eAAe,EAAE,MAAM,CAAA;QACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAC3B,CAAA;CACF,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ,CAAC,GAC1C,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AAE7B;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAsEpF"}
|
|
@@ -14,7 +14,7 @@ import { oAuth2Plugin } from '../oauth/index.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @param config - Payload configuration (db and secret omitted, editor optional)
|
|
16
16
|
* @returns Promise<SanitizedConfig> - Built Payload configuration
|
|
17
|
-
*/ export async function
|
|
17
|
+
*/ export async function buildFigmaConfig(config) {
|
|
18
18
|
// Validate required environment variable
|
|
19
19
|
if (!config.figma.contentSystemId) {
|
|
20
20
|
throw new Error('FIGMA_CONTENT_SYSTEM_ID is required. ' + 'Ensure your .env file contains: FIGMA_CONTENT_SYSTEM_ID=your-content-system-id');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/build-config.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { lexicalEditor } from '@payloadcms/richtext-lexical'\nimport { buildConfig as payloadBuildConfig } from 'payload'\n\nimport { getValidProjectToken } from '../auth/project-token.js'\nimport { getTokenStore } from '../auth/token-store.js'\nimport { contentAPIAdapter } from '../db-adapter.js'\nimport { health } from '../endpoints/health.js'\nimport { oAuth2Plugin } from '../oauth/index.js'\n\n/**\n * Configuration type for Payload projects on the Figma platform.\n *\n * Differences from standard Payload Config:\n * - `db`: Omitted (auto-injected by Figma platform)\n * - `secret`: Omitted (auto-injected by Figma platform)\n * - `editor`: Optional (defaults to lexicalEditor() if not provided)\n *\n * @example\n * // Minimal config\n * const config: FigmaConfig = {\n * figma: {\n * contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!\n * },\n * collections: [...]\n * }\n *\n * @example\n * // With custom editor\n * const config: FigmaConfig = {\n * figma: {\n * contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!\n * },\n * collections: [...],\n * editor: lexicalEditor({ features: [...] })\n * }\n *\n * @example\n * // Disable Content System (use custom db)\n * const config: FigmaConfig = {\n * figma: {\n * contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n * useContentSystem: false\n * },\n * db: mongooseAdapter({ url: process.env.DATABASE_URI }),\n * collections: [...]\n * }\n */\nexport type FigmaConfig = {\n editor?: Config['editor']\n} & {\n figma: {\n contentSystemId: string\n useContentSystem?: boolean\n }\n} & Omit<Config, 'db' | 'editor' | 'secret'> &\n Partial<Pick<Config, 'db'>>\n\n/**\n * Figma platform wrapper for Payload's buildConfig.\n * Automatically injects:\n * - Figma database adapter\n * - Secret (platform-provided)\n * - Default lexicalEditor (if no custom editor specified)\n *\n * @param config - Payload configuration (db and secret omitted, editor optional)\n * @returns Promise<SanitizedConfig> - Built Payload configuration\n */\nexport async function
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/build-config.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\n\nimport { lexicalEditor } from '@payloadcms/richtext-lexical'\nimport { buildConfig as payloadBuildConfig } from 'payload'\n\nimport { getValidProjectToken } from '../auth/project-token.js'\nimport { getTokenStore } from '../auth/token-store.js'\nimport { contentAPIAdapter } from '../db-adapter.js'\nimport { health } from '../endpoints/health.js'\nimport { oAuth2Plugin } from '../oauth/index.js'\n\n/**\n * Configuration type for Payload projects on the Figma platform.\n *\n * Differences from standard Payload Config:\n * - `db`: Omitted (auto-injected by Figma platform)\n * - `secret`: Omitted (auto-injected by Figma platform)\n * - `editor`: Optional (defaults to lexicalEditor() if not provided)\n *\n * @example\n * // Minimal config\n * const config: FigmaConfig = {\n * figma: {\n * contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!\n * },\n * collections: [...]\n * }\n *\n * @example\n * // With custom editor\n * const config: FigmaConfig = {\n * figma: {\n * contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!\n * },\n * collections: [...],\n * editor: lexicalEditor({ features: [...] })\n * }\n *\n * @example\n * // Disable Content System (use custom db)\n * const config: FigmaConfig = {\n * figma: {\n * contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n * useContentSystem: false\n * },\n * db: mongooseAdapter({ url: process.env.DATABASE_URI }),\n * collections: [...]\n * }\n */\nexport type FigmaConfig = {\n editor?: Config['editor']\n} & {\n figma: {\n contentSystemId: string\n useContentSystem?: boolean\n }\n} & Omit<Config, 'db' | 'editor' | 'secret'> &\n Partial<Pick<Config, 'db'>>\n\n/**\n * Figma platform wrapper for Payload's buildConfig.\n * Automatically injects:\n * - Figma database adapter\n * - Secret (platform-provided)\n * - Default lexicalEditor (if no custom editor specified)\n *\n * @param config - Payload configuration (db and secret omitted, editor optional)\n * @returns Promise<SanitizedConfig> - Built Payload configuration\n */\nexport async function buildFigmaConfig(config: FigmaConfig): Promise<SanitizedConfig> {\n // Validate required environment variable\n if (!config.figma.contentSystemId) {\n throw new Error(\n 'FIGMA_CONTENT_SYSTEM_ID is required. ' +\n 'Ensure your .env file contains: FIGMA_CONTENT_SYSTEM_ID=your-content-system-id',\n )\n }\n\n const contentSystemId = config.figma.contentSystemId\n\n let projectToken = ''\n\n if (!process.env.FIGMA_CONTENT_API_ACCESS_KEY) {\n const tokenStore = getTokenStore()\n const retrievedToken = await getValidProjectToken(tokenStore, contentSystemId)\n if (retrievedToken) {\n projectToken = retrievedToken\n }\n }\n\n // Build complete config with Figma platform defaults\n const configWithFigmaDefaults: Config = {\n ...config,\n custom: {\n figma: config.figma || {},\n },\n // TODO: - cms-tenants-001-staging needs to be dynamic in the future\n db:\n config.figma.useContentSystem !== false\n ? contentAPIAdapter({\n contentApiKey: process.env.FIGMA_CONTENT_API_ACCESS_KEY!,\n contentApiUrl:\n process.env.FIGMA_CONTENT_API_URL ||\n 'https://us-east-1.cms-tenants-001-staging.figmacontentstaging.com',\n contentSystemId: config.figma.contentSystemId,\n projectToken,\n })\n : config.db!,\n editor: config.editor ?? lexicalEditor(),\n endpoints: [...(config.endpoints ?? []), health],\n secret: 'MY_SECRET',\n // Add oauth to plugins if not already present\n plugins: [\n ...(config.plugins ?? []),\n oAuth2Plugin({\n collections: [\n {\n slug: 'users',\n // Use adapter because Figma app doesn't support OIDC scopes\n authorizationURLParams: {\n response_mode: 'query',\n response_type: 'code',\n },\n clientID: process.env.FIGMA_OAUTH_CLIENT_ID!,\n clientSecret: process.env.FIGMA_OAUTH_CLIENT_SECRET,\n identityMetadata: 'https://staging.figma.com/.well-known/openid-configuration',\n scope: ['current_user:read'],\n token: 'id_token', // Adapter creates JWT id_token from Figma user info\n usernameField: 'email',\n },\n ],\n debug: !!process.env.DEBUG,\n disabled: false,\n }),\n ],\n }\n\n // Delegate to Payload's buildConfig\n return await payloadBuildConfig(configWithFigmaDefaults)\n}\n"],"names":["lexicalEditor","buildConfig","payloadBuildConfig","getValidProjectToken","getTokenStore","contentAPIAdapter","health","oAuth2Plugin","buildFigmaConfig","config","figma","contentSystemId","Error","projectToken","process","env","FIGMA_CONTENT_API_ACCESS_KEY","tokenStore","retrievedToken","configWithFigmaDefaults","custom","db","useContentSystem","contentApiKey","contentApiUrl","FIGMA_CONTENT_API_URL","editor","endpoints","secret","plugins","collections","slug","authorizationURLParams","response_mode","response_type","clientID","FIGMA_OAUTH_CLIENT_ID","clientSecret","FIGMA_OAUTH_CLIENT_SECRET","identityMetadata","scope","token","usernameField","debug","DEBUG","disabled"],"mappings":"AAEA,SAASA,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,eAAeC,kBAAkB,QAAQ,UAAS;AAE3D,SAASC,oBAAoB,QAAQ,2BAA0B;AAC/D,SAASC,aAAa,QAAQ,yBAAwB;AACtD,SAASC,iBAAiB,QAAQ,mBAAkB;AACpD,SAASC,MAAM,QAAQ,yBAAwB;AAC/C,SAASC,YAAY,QAAQ,oBAAmB;AAkDhD;;;;;;;;;CASC,GACD,OAAO,eAAeC,iBAAiBC,MAAmB;IACxD,yCAAyC;IACzC,IAAI,CAACA,OAAOC,KAAK,CAACC,eAAe,EAAE;QACjC,MAAM,IAAIC,MACR,0CACE;IAEN;IAEA,MAAMD,kBAAkBF,OAAOC,KAAK,CAACC,eAAe;IAEpD,IAAIE,eAAe;IAEnB,IAAI,CAACC,QAAQC,GAAG,CAACC,4BAA4B,EAAE;QAC7C,MAAMC,aAAab;QACnB,MAAMc,iBAAiB,MAAMf,qBAAqBc,YAAYN;QAC9D,IAAIO,gBAAgB;YAClBL,eAAeK;QACjB;IACF;IAEA,qDAAqD;IACrD,MAAMC,0BAAkC;QACtC,GAAGV,MAAM;QACTW,QAAQ;YACNV,OAAOD,OAAOC,KAAK,IAAI,CAAC;QAC1B;QACA,oEAAoE;QACpEW,IACEZ,OAAOC,KAAK,CAACY,gBAAgB,KAAK,QAC9BjB,kBAAkB;YAChBkB,eAAeT,QAAQC,GAAG,CAACC,4BAA4B;YACvDQ,eACEV,QAAQC,GAAG,CAACU,qBAAqB,IACjC;YACFd,iBAAiBF,OAAOC,KAAK,CAACC,eAAe;YAC7CE;QACF,KACAJ,OAAOY,EAAE;QACfK,QAAQjB,OAAOiB,MAAM,IAAI1B;QACzB2B,WAAW;eAAKlB,OAAOkB,SAAS,IAAI,EAAE;YAAGrB;SAAO;QAChDsB,QAAQ;QACR,8CAA8C;QAC9CC,SAAS;eACHpB,OAAOoB,OAAO,IAAI,EAAE;YACxBtB,aAAa;gBACXuB,aAAa;oBACX;wBACEC,MAAM;wBACN,4DAA4D;wBAC5DC,wBAAwB;4BACtBC,eAAe;4BACfC,eAAe;wBACjB;wBACAC,UAAUrB,QAAQC,GAAG,CAACqB,qBAAqB;wBAC3CC,cAAcvB,QAAQC,GAAG,CAACuB,yBAAyB;wBACnDC,kBAAkB;wBAClBC,OAAO;4BAAC;yBAAoB;wBAC5BC,OAAO;wBACPC,eAAe;oBACjB;iBACD;gBACDC,OAAO,CAAC,CAAC7B,QAAQC,GAAG,CAAC6B,KAAK;gBAC1BC,UAAU;YACZ;SACD;IACH;IAEA,oCAAoC;IACpC,OAAO,MAAM3C,mBAAmBiB;AAClC"}
|
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import type { SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Result of detecting what changes are needed in a payload config file
|
|
4
|
+
*/
|
|
2
5
|
export type DetectionResult = {
|
|
6
|
+
/** Database adapter configuration if present */
|
|
3
7
|
dbProperty?: {
|
|
8
|
+
/** Name of the adapter function (e.g., 'mongooseAdapter', 'postgresAdapter') */
|
|
4
9
|
adapter: string;
|
|
10
|
+
/** NPM package the adapter is imported from (e.g., '@payloadcms/db-mongodb') */
|
|
5
11
|
importSource: string;
|
|
6
12
|
};
|
|
13
|
+
/** Editor configuration if present */
|
|
7
14
|
editorProperty?: {
|
|
15
|
+
/** NPM package the editor is imported from (e.g., '@payloadcms/richtext-lexical') */
|
|
8
16
|
importSource: string;
|
|
17
|
+
/** Whether this is a default editor with no custom configuration */
|
|
9
18
|
isDefault: boolean;
|
|
10
19
|
};
|
|
20
|
+
/** Whether the config already has a `figma` property */
|
|
11
21
|
figmaObjectExists: boolean;
|
|
22
|
+
/** Whether buildConfig/buildFigmaConfig uses an import alias (e.g., 'buildConfig as createConfig') */
|
|
12
23
|
hasAlias: boolean;
|
|
24
|
+
/** Whether a buildConfig or buildFigmaConfig call was found (undefined if not checked) */
|
|
13
25
|
hasBuildConfig?: boolean;
|
|
26
|
+
/** Whether there are other imports from 'payload' besides buildConfig (e.g., types) */
|
|
14
27
|
hasOtherPayloadImports: boolean;
|
|
28
|
+
/** Whether the import needs to be changed from 'payload' to '@payloadcms/figma' */
|
|
15
29
|
needsImportChange: boolean;
|
|
30
|
+
/** Whether a `secret` property exists in the config */
|
|
16
31
|
secretProperty?: boolean;
|
|
17
32
|
};
|
|
18
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-config-ast.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAM1C,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,cAAc,CAAC,EAAE;QACf,YAAY,EAAE,MAAM,CAAA;QACpB,S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AA;IACjB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AA0CD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,eAAe,GACzB,qBAAqB,CAwKvB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,mBAAmB,GAC1B,qBAAqB,CAqDvB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,mBAAmB,GAAG,IAAI,CA4ElF"}
|
|
@@ -20,15 +20,18 @@ import * as log from './log.js';
|
|
|
20
20
|
log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`);
|
|
21
21
|
const moduleSpecifier = payloadImport.getModuleSpecifierValue();
|
|
22
22
|
const namedImports = payloadImport.getNamedImports();
|
|
23
|
-
//
|
|
24
|
-
|
|
23
|
+
// Determine which function name to look for based on the import source
|
|
24
|
+
// - From 'payload': look for buildConfig (needs migration)
|
|
25
|
+
// - From '@payloadcms/figma': look for buildFigmaConfig (already migrated)
|
|
26
|
+
const expectedFunctionName = moduleSpecifier === 'payload' ? 'buildConfig' : 'buildFigmaConfig';
|
|
27
|
+
const buildConfigImport = namedImports.find((ni)=>ni.getName() === expectedFunctionName);
|
|
25
28
|
if (!buildConfigImport) {
|
|
26
29
|
result.hasBuildConfig = false;
|
|
27
30
|
return result;
|
|
28
31
|
}
|
|
29
32
|
// Check for alias and get the actual name used in code
|
|
30
33
|
const aliasNode = buildConfigImport.getAliasNode();
|
|
31
|
-
const buildConfigName = aliasNode ? aliasNode.getText() :
|
|
34
|
+
const buildConfigName = aliasNode ? aliasNode.getText() : expectedFunctionName;
|
|
32
35
|
if (aliasNode) {
|
|
33
36
|
result.hasAlias = true;
|
|
34
37
|
}
|
|
@@ -258,12 +261,24 @@ import * as log from './log.js';
|
|
|
258
261
|
sourceFile.addImportDeclaration({
|
|
259
262
|
moduleSpecifier: '@payloadcms/figma',
|
|
260
263
|
namedImports: [
|
|
261
|
-
'
|
|
264
|
+
'buildFigmaConfig'
|
|
262
265
|
]
|
|
263
266
|
});
|
|
264
267
|
changes.push('Split buildConfig import to @payloadcms/figma');
|
|
265
268
|
} else {
|
|
266
|
-
// Replace entire import
|
|
269
|
+
// Replace entire import: change module specifier and rename all references
|
|
270
|
+
const buildConfigImport = payloadImport.getNamedImports().find((ni)=>ni.getName() === 'buildConfig');
|
|
271
|
+
if (buildConfigImport) {
|
|
272
|
+
// Change the import name
|
|
273
|
+
buildConfigImport.setName('buildFigmaConfig');
|
|
274
|
+
// Find and rename all usages of 'buildConfig' in the file
|
|
275
|
+
const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier);
|
|
276
|
+
identifiers.forEach((identifier)=>{
|
|
277
|
+
if (identifier.getText() === 'buildConfig') {
|
|
278
|
+
identifier.replaceWithText('buildFigmaConfig');
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
267
282
|
payloadImport.setModuleSpecifier('@payloadcms/figma');
|
|
268
283
|
changes.push('Changed buildConfig import to @payloadcms/figma');
|
|
269
284
|
}
|
|
@@ -301,15 +316,15 @@ import * as log from './log.js';
|
|
|
301
316
|
*/ export function addFigmaProperty(sourceFile, config) {
|
|
302
317
|
const changes = [];
|
|
303
318
|
let modified = false;
|
|
304
|
-
// Find
|
|
319
|
+
// Find buildFigmaConfig call (this function is only used with Figma configs)
|
|
305
320
|
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
|
|
306
321
|
const buildConfigCall = callExpressions.find((ce)=>{
|
|
307
322
|
const expr = ce.getExpression();
|
|
308
323
|
const text = expr.getText();
|
|
309
|
-
return text === '
|
|
324
|
+
return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig');
|
|
310
325
|
});
|
|
311
326
|
if (!buildConfigCall) {
|
|
312
|
-
log.debug('No
|
|
327
|
+
log.debug('No buildFigmaConfig call found');
|
|
313
328
|
return {
|
|
314
329
|
changes: [],
|
|
315
330
|
modified: false
|
|
@@ -359,15 +374,15 @@ import * as log from './log.js';
|
|
|
359
374
|
* Read figma configuration from payload.config.ts
|
|
360
375
|
* Returns the figma object if it exists, null otherwise
|
|
361
376
|
*/ export function readFigmaConfig(sourceFile) {
|
|
362
|
-
// Find
|
|
377
|
+
// Find buildFigmaConfig call (this function is only used with Figma configs)
|
|
363
378
|
const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
|
|
364
379
|
const buildConfigCall = callExpressions.find((ce)=>{
|
|
365
380
|
const expr = ce.getExpression();
|
|
366
381
|
const text = expr.getText();
|
|
367
|
-
return text === '
|
|
382
|
+
return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig');
|
|
368
383
|
});
|
|
369
384
|
if (!buildConfigCall) {
|
|
370
|
-
log.debug('No
|
|
385
|
+
log.debug('No buildFigmaConfig call found');
|
|
371
386
|
return null;
|
|
372
387
|
}
|
|
373
388
|
// Get config object argument
|
|
@@ -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 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 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 // 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 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 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","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","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;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,I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ACtE,2CAA2C;YAC3CN,kBAAkB;QACpB,OAAO;YACL,oCAAoC;YACpCA,kBAAkBR,KAAKe,OAAO,CAAC,SAAS;QAC1C;IACF;IAEA,MAAMX,mBAAmBtG,KAAK4G,oBAAoB,CAACG,wBAC/CA,qBAAqBF,cAAc,IAAIlF,cAAc,SACrDuF,UAAU,uCAAuC;;IAErD,IAAI,CAACR,iBAAiB;QACpBxG,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACL0F;QACAJ;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}\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 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: ['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 // 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 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","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;AAkC/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,MAAMC,kBAAkBF,YAAYA,UAAUG,OAAO,KAAKP;IAC1D,IAAII,WAAW;QACbpB,OAAOE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;IAErD,IAAI,CAACR,iBAAiB;QACpB9G,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACLgG;QACAJ;IACF;AACF"}
|
|
@@ -185,7 +185,7 @@ ${pc.bold('Required changes:')}
|
|
|
185
185
|
|
|
186
186
|
1. Replace buildConfig import:
|
|
187
187
|
${pc.dim('- FROM: ')}${pc.cyan("import { buildConfig } from 'payload'")}
|
|
188
|
-
${pc.dim('- TO: ')}${pc.cyan("import {
|
|
188
|
+
${pc.dim('- TO: ')}${pc.cyan("import { buildFigmaConfig } from '@payloadcms/figma'")}
|
|
189
189
|
|
|
190
190
|
2. Remove these properties from buildConfig():
|
|
191
191
|
• 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;AA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AGtD,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. 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 { 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","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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