@payloadcms/figma 0.0.1-alpha.42 → 0.0.1-alpha.44
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/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -4
- package/dist/constants.js.map +1 -1
- package/dist/db-content-api/generated/content-api-types.d.ts +6 -174
- package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -1
- package/dist/db-content-api/generated/content-api-types.js.map +1 -1
- package/dist/db-content-api/index.d.ts +2 -0
- package/dist/db-content-api/index.d.ts.map +1 -1
- package/dist/db-content-api/index.js +135 -44
- package/dist/db-content-api/index.js.map +1 -1
- package/dist/db-content-api/utilities/data/castFieldValue.d.ts.map +1 -1
- package/dist/db-content-api/utilities/data/castFieldValue.js +4 -1
- package/dist/db-content-api/utilities/data/castFieldValue.js.map +1 -1
- package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
- package/dist/db-content-api/utilities/data/index.js +16 -2
- package/dist/db-content-api/utilities/data/index.js.map +1 -1
- package/dist/db-content-api/utilities/locale/index.d.ts +10 -0
- package/dist/db-content-api/utilities/locale/index.d.ts.map +1 -0
- package/dist/db-content-api/utilities/locale/index.js +21 -0
- package/dist/db-content-api/utilities/locale/index.js.map +1 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +11 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts.map +1 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +55 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js.map +1 -0
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +22 -0
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts.map +1 -0
- package/dist/db-content-api/utilities/meta/buildMeta.js +30 -0
- package/dist/db-content-api/utilities/meta/buildMeta.js.map +1 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +7 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts.map +1 -0
- package/dist/db-content-api/utilities/{buildPathTypes.js → meta/buildPathTypes.js} +3 -9
- package/dist/db-content-api/utilities/meta/buildPathTypes.js.map +1 -0
- package/dist/db-content-api/utilities/meta/index.d.ts +5 -0
- package/dist/db-content-api/utilities/meta/index.d.ts.map +1 -0
- package/dist/db-content-api/utilities/meta/index.js +5 -0
- package/dist/db-content-api/utilities/meta/index.js.map +1 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts.map +1 -1
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +3 -3
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.js.map +1 -1
- package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts.map +1 -1
- package/dist/storage-content-api/client-uploads/generateSignedURL.js +8 -1
- package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +1 -1
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +12 -0
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts.map +1 -0
- package/dist/storage-content-api/utilities/getSafeFilename.js +61 -0
- package/dist/storage-content-api/utilities/getSafeFilename.js.map +1 -0
- package/dist/storage-content-api/utilities/index.d.ts +2 -0
- package/dist/storage-content-api/utilities/index.d.ts.map +1 -0
- package/dist/storage-content-api/utilities/index.js +3 -0
- package/dist/storage-content-api/utilities/index.js.map +1 -0
- package/dist/templates/.env.example +11 -0
- package/dist/utils/env-management.d.ts +9 -1
- package/dist/utils/env-management.d.ts.map +1 -1
- package/dist/utils/env-management.js +39 -17
- package/dist/utils/env-management.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +7 -0
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -0
- package/dist/utils/project.js.map +1 -1
- package/package.json +2 -2
- package/dist/db-content-api/utilities/buildPathTypes.d.ts +0 -12
- package/dist/db-content-api/utilities/buildPathTypes.d.ts.map +0 -1
- package/dist/db-content-api/utilities/buildPathTypes.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/storage-content-api/utilities/getSafeFilename.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nimport sanitize from 'sanitize-filename'\n\n/**\n * Check if a document with the given filename already exists in the database\n * Matches Payload's docWithFilenameExists\n */\nasync function docWithFilenameExists({\n collectionSlug,\n filename,\n prefix,\n req,\n}: {\n collectionSlug: string\n filename: string\n prefix?: string\n req: PayloadRequest\n}): Promise<boolean> {\n const where: Where = {\n filename: {\n equals: filename,\n },\n }\n\n if (prefix) {\n where.prefix = {\n equals: prefix,\n }\n }\n\n const doc = await req.payload.db.findOne({\n collection: collectionSlug,\n req,\n where,\n })\n\n return !!doc\n}\n\n/**\n * Increment filename by adding -1, -2, etc. suffix\n * photo.jpg → photo-1.jpg\n * photo-1.jpg → photo-2.jpg\n * Matches Payload's incrementName\n */\nfunction incrementFilename(name: string): string {\n const extension = name.split('.').pop()\n const baseFilename = sanitize(name.substring(0, name.lastIndexOf('.')) || name)\n\n let incrementedName = baseFilename\n const regex = /(.*)-(\\d+)$/\n const found = baseFilename.match(regex)\n\n if (found === null) {\n incrementedName += '-1'\n } else {\n const matchedName = found[1]\n const matchedNumber = found[2]\n const incremented = Number(matchedNumber) + 1\n incrementedName = `${matchedName}-${incremented}`\n }\n\n return `${incrementedName}.${extension}`\n}\n\n/**\n * Get a safe filename that doesn't collide with existing documents\n * Similar to Payload's getSafeFileName\n */\nexport async function getSafeFilename({\n collectionSlug,\n desiredFilename,\n prefix,\n req,\n}: {\n collectionSlug: string\n desiredFilename: string\n prefix?: string\n req: PayloadRequest\n}): Promise<string> {\n let modifiedFilename = desiredFilename\n\n // Keep incrementing until we find a filename that doesn't exist\n while (\n await docWithFilenameExists({\n collectionSlug,\n filename: modifiedFilename,\n prefix,\n req,\n })\n ) {\n modifiedFilename = incrementFilename(modifiedFilename)\n }\n\n return modifiedFilename\n}\n"],"names":["sanitize","docWithFilenameExists","collectionSlug","filename","prefix","req","where","equals","doc","payload","db","findOne","collection","incrementFilename","name","extension","split","pop","baseFilename","substring","lastIndexOf","incrementedName","regex","found","match","matchedName","matchedNumber","incremented","Number","getSafeFilename","desiredFilename","modifiedFilename"],"mappings":"AAEA,OAAOA,cAAc,oBAAmB;AAExC;;;CAGC,GACD,eAAeC,sBAAsB,EACnCC,cAAc,EACdC,QAAQ,EACRC,MAAM,EACNC,GAAG,EAMJ;IACC,MAAMC,QAAe;QACnBH,UAAU;YACRI,QAAQJ;QACV;IACF;IAEA,IAAIC,QAAQ;QACVE,MAAMF,MAAM,GAAG;YACbG,QAAQH;QACV;IACF;IAEA,MAAMI,MAAM,MAAMH,IAAII,OAAO,CAACC,EAAE,CAACC,OAAO,CAAC;QACvCC,YAAYV;QACZG;QACAC;IACF;IAEA,OAAO,CAAC,CAACE;AACX;AAEA;;;;;CAKC,GACD,SAASK,kBAAkBC,IAAY;IACrC,MAAMC,YAAYD,KAAKE,KAAK,CAAC,KAAKC,GAAG;IACrC,MAAMC,eAAelB,SAASc,KAAKK,SAAS,CAAC,GAAGL,KAAKM,WAAW,CAAC,SAASN;IAE1E,IAAIO,kBAAkBH;IACtB,MAAMI,QAAQ;IACd,MAAMC,QAAQL,aAAaM,KAAK,CAACF;IAEjC,IAAIC,UAAU,MAAM;QAClBF,mBAAmB;IACrB,OAAO;QACL,MAAMI,cAAcF,KAAK,CAAC,EAAE;QAC5B,MAAMG,gBAAgBH,KAAK,CAAC,EAAE;QAC9B,MAAMI,cAAcC,OAAOF,iBAAiB;QAC5CL,kBAAkB,GAAGI,YAAY,CAAC,EAAEE,aAAa;IACnD;IAEA,OAAO,GAAGN,gBAAgB,CAAC,EAAEN,WAAW;AAC1C;AAEA;;;CAGC,GACD,OAAO,eAAec,gBAAgB,EACpC3B,cAAc,EACd4B,eAAe,EACf1B,MAAM,EACNC,GAAG,EAMJ;IACC,IAAI0B,mBAAmBD;IAEvB,gEAAgE;IAChE,MACE,MAAM7B,sBAAsB;QAC1BC;QACAC,UAAU4B;QACV3B;QACAC;IACF,GACA;QACA0B,mBAAmBlB,kBAAkBkB;IACvC;IAEA,OAAOA;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage-content-api/utilities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/storage-content-api/utilities/index.ts"],"sourcesContent":["export { getSafeFilename } from './getSafeFilename.js'\n"],"names":["getSafeFilename"],"mappings":"AAAA,SAASA,eAAe,QAAQ,uBAAsB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Content System ID for Content API access
|
|
2
|
+
FIGMA_CONTENT_SYSTEM_ID=
|
|
3
|
+
|
|
4
|
+
# Tenant ID for deploy operations
|
|
5
|
+
FIGMA_TENANT_ID=
|
|
6
|
+
|
|
7
|
+
# OAuth client ID for admin panel authentication
|
|
8
|
+
FIGMA_OAUTH_CLIENT_ID=
|
|
9
|
+
|
|
10
|
+
# OAuth client secret for admin panel authentication
|
|
11
|
+
FIGMA_OAUTH_CLIENT_SECRET=
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get an environment variable value from .env file
|
|
2
|
+
* Get an environment variable value from .env file (async)
|
|
3
3
|
*
|
|
4
4
|
* @param projectPath - Path to project directory
|
|
5
5
|
* @param key - Environment variable name to retrieve
|
|
6
6
|
* @returns The value if found, null otherwise
|
|
7
7
|
*/
|
|
8
8
|
export declare function getEnvVar(projectPath: string, key: string): Promise<null | string>;
|
|
9
|
+
/**
|
|
10
|
+
* Get an environment variable value from .env file (sync)
|
|
11
|
+
*
|
|
12
|
+
* @param projectPath - Path to project directory
|
|
13
|
+
* @param key - Environment variable name to retrieve
|
|
14
|
+
* @returns The value if found, null otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare function getEnvVarSync(projectPath: string, key: string): null | string;
|
|
9
17
|
/**
|
|
10
18
|
* Add or update an environment variable in .env file
|
|
11
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-management.d.ts","sourceRoot":"","sources":["../../src/utils/env-management.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env-management.d.ts","sourceRoot":"","sources":["../../src/utils/env-management.ts"],"names":[],"mappings":"AAgCA;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAUxF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAU7E;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAmEf"}
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
|
+
import fsSync from 'node:fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Parse .env file contents and extract value for a key
|
|
6
|
+
*/ function parseEnvValue(contents, key) {
|
|
7
|
+
const lines = contents.split(/\r?\n/);
|
|
8
|
+
for (const line of lines){
|
|
9
|
+
// Skip empty lines and comments
|
|
10
|
+
if (!line.trim() || line.trim().startsWith('#')) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
// Skip lines without =
|
|
14
|
+
if (!line.includes('=')) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const equalsIndex = line.indexOf('=');
|
|
18
|
+
const lineKey = line.substring(0, equalsIndex).trim();
|
|
19
|
+
if (lineKey === key) {
|
|
20
|
+
return line.substring(equalsIndex + 1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get an environment variable value from .env file (async)
|
|
5
27
|
*
|
|
6
28
|
* @param projectPath - Path to project directory
|
|
7
29
|
* @param key - Environment variable name to retrieve
|
|
@@ -10,23 +32,23 @@ import path from 'path';
|
|
|
10
32
|
const envPath = path.join(projectPath, '.env');
|
|
11
33
|
try {
|
|
12
34
|
const contents = await fs.readFile(envPath, 'utf-8');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!line.trim() || line.trim().startsWith('#')) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
// Skip lines without =
|
|
20
|
-
if (!line.includes('=')) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const equalsIndex = line.indexOf('=');
|
|
24
|
-
const lineKey = line.substring(0, equalsIndex).trim();
|
|
25
|
-
if (lineKey === key) {
|
|
26
|
-
return line.substring(equalsIndex + 1);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
35
|
+
return parseEnvValue(contents, key);
|
|
36
|
+
} catch {
|
|
37
|
+
// File doesn't exist or can't be read
|
|
29
38
|
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get an environment variable value from .env file (sync)
|
|
43
|
+
*
|
|
44
|
+
* @param projectPath - Path to project directory
|
|
45
|
+
* @param key - Environment variable name to retrieve
|
|
46
|
+
* @returns The value if found, null otherwise
|
|
47
|
+
*/ export function getEnvVarSync(projectPath, key) {
|
|
48
|
+
const envPath = path.join(projectPath, '.env');
|
|
49
|
+
try {
|
|
50
|
+
const contents = fsSync.readFileSync(envPath, 'utf-8');
|
|
51
|
+
return parseEnvValue(contents, key);
|
|
30
52
|
} catch {
|
|
31
53
|
// File doesn't exist or can't be read
|
|
32
54
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/env-management.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\n/**\n * Get an environment variable value from .env file\n *\n * @param projectPath - Path to project directory\n * @param key - Environment variable name to retrieve\n * @returns The value if found, null otherwise\n */\nexport async function getEnvVar(projectPath: string, key: string): Promise<null | string> {\n const envPath = path.join(projectPath, '.env')\n\n try {\n const contents = await fs.readFile(envPath, 'utf-8')\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils/env-management.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport fsSync from 'node:fs'\nimport path from 'path'\n\n/**\n * Parse .env file contents and extract value for a key\n */\nfunction parseEnvValue(contents: string, key: string): null | string {\n const lines = contents.split(/\\r?\\n/)\n\n for (const line of lines) {\n // Skip empty lines and comments\n if (!line.trim() || line.trim().startsWith('#')) {\n continue\n }\n\n // Skip lines without =\n if (!line.includes('=')) {\n continue\n }\n\n const equalsIndex = line.indexOf('=')\n const lineKey = line.substring(0, equalsIndex).trim()\n\n if (lineKey === key) {\n return line.substring(equalsIndex + 1)\n }\n }\n\n return null\n}\n\n/**\n * Get an environment variable value from .env file (async)\n *\n * @param projectPath - Path to project directory\n * @param key - Environment variable name to retrieve\n * @returns The value if found, null otherwise\n */\nexport async function getEnvVar(projectPath: string, key: string): Promise<null | string> {\n const envPath = path.join(projectPath, '.env')\n\n try {\n const contents = await fs.readFile(envPath, 'utf-8')\n return parseEnvValue(contents, key)\n } catch {\n // File doesn't exist or can't be read\n return null\n }\n}\n\n/**\n * Get an environment variable value from .env file (sync)\n *\n * @param projectPath - Path to project directory\n * @param key - Environment variable name to retrieve\n * @returns The value if found, null otherwise\n */\nexport function getEnvVarSync(projectPath: string, key: string): null | string {\n const envPath = path.join(projectPath, '.env')\n\n try {\n const contents = fsSync.readFileSync(envPath, 'utf-8')\n return parseEnvValue(contents, key)\n } catch {\n // File doesn't exist or can't be read\n return null\n }\n}\n\n/**\n * Add or update an environment variable in .env file\n *\n * @param projectPath - Path to project directory\n * @param key - Environment variable name\n * @param value - Environment variable value\n */\nexport async function addOrUpdateEnvVar(\n projectPath: string,\n key: string,\n value: string,\n): Promise<void> {\n const envPath = path.join(projectPath, '.env')\n\n try {\n let contents = ''\n let envExists = false\n\n // Try to read existing .env file\n try {\n contents = await fs.readFile(envPath, 'utf-8')\n envExists = true\n } catch {\n // .env doesn't exist, will create it\n }\n\n const lines = contents.split(/\\r?\\n/)\n const seenKeys = new Set<string>()\n const processedLines: string[] = []\n let keyUpdated = false\n\n for (const line of lines) {\n // Skip empty lines at start if file didn't exist\n if (!envExists && !line.trim()) {\n continue\n }\n\n // Preserve empty lines and comments\n if (!line.trim() || line.trim().startsWith('#')) {\n processedLines.push(line)\n continue\n }\n\n // Skip lines without =\n if (!line.includes('=')) {\n processedLines.push(line)\n continue\n }\n\n const [lineKey] = line.split('=')\n const trimmedKey = lineKey.trim()\n\n // Skip duplicate keys (keep first occurrence)\n if (seenKeys.has(trimmedKey)) {\n continue\n }\n seenKeys.add(trimmedKey)\n\n // Update or keep the line\n if (trimmedKey === key) {\n processedLines.push(`${key}=${value}`)\n keyUpdated = true\n } else {\n processedLines.push(line)\n }\n }\n\n // Add key if not present\n if (!keyUpdated) {\n processedLines.push(`${key}=${value}`)\n }\n\n await fs.writeFile(envPath, processedLines.join('\\n'), 'utf-8')\n } catch (error) {\n throw new Error(\n `Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n}\n"],"names":["fs","fsSync","path","parseEnvValue","contents","key","lines","split","line","trim","startsWith","includes","equalsIndex","indexOf","lineKey","substring","getEnvVar","projectPath","envPath","join","readFile","getEnvVarSync","readFileSync","addOrUpdateEnvVar","value","envExists","seenKeys","Set","processedLines","keyUpdated","push","trimmedKey","has","add","writeFile","error","Error","message"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,YAAY,UAAS;AAC5B,OAAOC,UAAU,OA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|
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;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,gDAAgD;IAChD,UAAU,CAAC,EAAE;QACX,gFAAgF;QAChF,OAAO,EAAE,MAAM,CAAA;QACf,gFAAgF;QAChF,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,sCAAsC;IACtC,cAAc,CAAC,EAAE;QACf,qFAAqF;QACrF,YAAY,EAAE,MAAM,CAAA;QACpB,oEAAoE;QACpE,SAAS,EAAE,OAAO,CAAA;KACnB,CAAA;IACD,wDAAwD;IACxD,iBAAiB,EAAE,OAAO,CAAA;IAC1B,sGAAsG;IACtG,QAAQ,EAAE,OAAO,CAAA;IACjB,0FAA0F;IAC1F,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,uFAAuF;IACvF,sBAAsB,EAAE,OAAO,CAAA;IAC/B,mFAAmF;IACnF,iBAAiB,EAAE,OAAO,CAAA;IAC1B,uDAAuD;IACvD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,qCAAqC;IACrC,aAAa,CAAC,EAAE;QACd,0DAA0D;QAC1D,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;CACF,CAAA;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAoK7E;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AA0CD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,eAAe,GACzB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"payload-config-ast.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-ast.ts"],"names":[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AAU,EAAE,UAAU,EACtB,MAAM,EAAE,mBAAmB,GAC1B,qBAAqB,CAqDvB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,mBAAmB,GAAG,IAAI,CA4ElF"}
|
|
@@ -282,6 +282,13 @@ import * as log from './log.js';
|
|
|
282
282
|
'buildFigmaConfig'
|
|
283
283
|
]
|
|
284
284
|
});
|
|
285
|
+
// Rename all usages of 'buildConfig' to 'buildFigmaConfig'
|
|
286
|
+
const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier);
|
|
287
|
+
identifiers.forEach((identifier)=>{
|
|
288
|
+
if (identifier.getText() === 'buildConfig') {
|
|
289
|
+
identifier.replaceWithText('buildFigmaConfig');
|
|
290
|
+
}
|
|
291
|
+
});
|
|
285
292
|
changes.push('Split buildConfig import to @payloadcms/figma');
|
|
286
293
|
} else {
|
|
287
294
|
// Replace entire import: change module specifier and rename all references
|
|
@@ -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\n/**\n * Result of detecting what changes are needed in a payload config file\n */\nexport type DetectionResult = {\n /** Database adapter configuration if present */\n dbProperty?: {\n /** Name of the adapter function (e.g., 'mongooseAdapter', 'postgresAdapter') */\n adapter: string\n /** NPM package the adapter is imported from (e.g., '@payloadcms/db-mongodb') */\n importSource: string\n }\n /** Editor configuration if present */\n editorProperty?: {\n /** NPM package the editor is imported from (e.g., '@payloadcms/richtext-lexical') */\n importSource: string\n /** Whether this is a default editor with no custom configuration */\n isDefault: boolean\n }\n /** Whether the config already has a `figma` property */\n figmaObjectExists: boolean\n /** Whether buildConfig/buildFigmaConfig uses an import alias (e.g., 'buildConfig as createConfig') */\n hasAlias: boolean\n /** Whether a buildConfig or buildFigmaConfig call was found (undefined if not checked) */\n hasBuildConfig?: boolean\n /** Whether there are other imports from 'payload' besides buildConfig (e.g., types) */\n hasOtherPayloadImports: boolean\n /** Whether the import needs to be changed from 'payload' to '@payloadcms/figma' */\n needsImportChange: boolean\n /** Whether a `secret` property exists in the config */\n secretProperty?: boolean\n /** Sharp configuration if present */\n sharpProperty?: {\n /** NPM package sharp is imported from (always 'sharp') */\n importSource: string\n }\n}\n\n/**\n * Detect what changes are needed in the payload config file\n */\nexport function detectRequiredChanges(sourceFile: SourceFile): DetectionResult {\n const result: DetectionResult = {\n figmaObjectExists: false,\n hasAlias: false,\n hasOtherPayloadImports: false,\n needsImportChange: false,\n }\n\n // Find buildConfig import\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'payload' ||\n imp.getModuleSpecifierValue() === '@payloadcms/figma',\n )\n\n if (!payloadImport) {\n log.debug('No payload or @payloadcms/figma import found')\n result.hasBuildConfig = false\n return result\n }\n\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n\n const moduleSpecifier = payloadImport.getModuleSpecifierValue()\n const namedImports = payloadImport.getNamedImports()\n\n // Determine which function name to look for based on the import source\n // - From 'payload': look for buildConfig (needs migration)\n // - From '@payloadcms/figma': look for buildFigmaConfig (already migrated)\n const expectedFunctionName = moduleSpecifier === 'payload' ? 'buildConfig' : 'buildFigmaConfig'\n\n const buildConfigImport = namedImports.find((ni) => ni.getName() === expectedFunctionName)\n\n if (!buildConfigImport) {\n result.hasBuildConfig = false\n return result\n }\n\n // Check for alias and get the actual name used in code\n const aliasNode = buildConfigImport.getAliasNode()\n const buildConfigName = aliasNode ? aliasNode.getText() : expectedFunctionName\n if (aliasNode) {\n result.hasAlias = true\n }\n\n // Check if import needs change\n if (moduleSpecifier === 'payload') {\n result.needsImportChange = true\n\n // Check if there are other imports from payload\n if (namedImports.length > 1) {\n result.hasOtherPayloadImports = true\n }\n }\n\n // Find buildConfig call in export default\n // First try to find export default with the buildConfig call\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n // Look for buildConfig call in the export default\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n result.hasBuildConfig = false\n return result\n }\n\n // Get config object\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return result\n }\n\n // Check for db property\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n const dbValue = dbProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (dbValue) {\n const adapterName = dbValue.getExpression().getText()\n\n // Find the import source for this adapter\n const adapterImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === adapterName),\n )\n\n if (adapterImport) {\n result.dbProperty = {\n adapter: adapterName,\n importSource: adapterImport.getModuleSpecifierValue(),\n }\n }\n }\n }\n\n // Check for secret property\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n result.secretProperty = true\n }\n\n // Check for editor property\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n const editorValue = editorProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (editorValue) {\n const editorName = editorValue.getExpression().getText()\n\n // Find the import source\n const editorImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === editorName),\n )\n\n if (editorImport && editorName === 'lexicalEditor') {\n // Check if it has arguments\n const args = editorValue.getArguments()\n const isDefault = args.length === 0\n\n result.editorProperty = {\n importSource: editorImport.getModuleSpecifierValue(),\n isDefault,\n }\n }\n }\n }\n\n // Check for sharp property\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n // Find the import source for sharp\n const sharpImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'sharp' ||\n imp.getNamedImports().some((ni) => ni.getName() === 'sharp'),\n )\n\n result.sharpProperty = {\n importSource: sharpImport?.getModuleSpecifierValue() || 'sharp',\n }\n }\n\n // Check for figma property\n const figmaProperty = configArg.getProperty('figma')\n if (figmaProperty) {\n result.figmaObjectExists = true\n }\n\n return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\n}\n\n/**\n * Remove all comments\n * @returns true if any comments were removed\n */\nfunction removeAllComments(sourceFile: SourceFile): boolean {\n const ranges: Array<[number, number]> = []\n\n // Recursively collect comments from node and ALL children (including tokens)\n const collectComments = (node: Node) => {\n node.getLeadingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n node.getTrailingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n\n // Process ALL children including token nodes (commas, braces, etc.)\n node.getChildren().forEach(collectComments)\n }\n\n collectComments(sourceFile)\n\n if (ranges.length === 0) {\n return false\n }\n\n // Remove duplicates and sort in reverse order to avoid position shifts\n const uniqueRanges = Array.from(new Set(ranges.map((r) => JSON.stringify(r)))).map(\n (r) => JSON.parse(r) as [number, number],\n )\n uniqueRanges.sort((a, b) => b[0] - a[0])\n\n // Remove each comment range\n for (const [pos, end] of uniqueRanges) {\n sourceFile.removeText(pos, end)\n }\n\n return true\n}\n\n/**\n * Apply modifications to the source file based on detection result\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function applyModifications(\n sourceFile: SourceFile,\n detection: DetectionResult,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n if (detection.hasBuildConfig === false || detection.hasAlias) {\n log.debug(\n `Skipping modifications: hasBuildConfig=${detection.hasBuildConfig}, hasAlias=${detection.hasAlias}`,\n )\n return { changes: [], modified: false }\n }\n\n // 1. Remove all comments FIRST (before AST modifications that might shift positions)\n const hadComments = removeAllComments(sourceFile)\n if (hadComments) {\n changes.push('Removed comments')\n modified = true\n }\n\n // Find the import declarations\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find((imp) => imp.getModuleSpecifierValue() === 'payload')\n\n // Get the buildConfig name (could be aliased)\n let buildConfigName = 'buildConfig'\n if (payloadImport) {\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n const aliasNode = buildConfigImport.getAliasNode()\n buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n }\n }\n\n // Find buildConfig call in export default (prefer export default)\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n return { changes: [], modified: false }\n }\n\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return { changes: [], modified: false }\n }\n\n // 1. Remove db property\n if (detection.dbProperty) {\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n dbProperty.remove()\n changes.push('Removed db property')\n modified = true\n }\n }\n\n // 2. Remove secret property\n if (detection.secretProperty) {\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n secretProperty.remove()\n changes.push('Removed secret property')\n modified = true\n }\n }\n\n // 3. Remove editor if default\n if (detection.editorProperty?.isDefault) {\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n editorProperty.remove()\n changes.push('Removed default editor property')\n modified = true\n }\n }\n\n // 4. Remove sharp property\n if (detection.sharpProperty) {\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n sharpProperty.remove()\n changes.push('Removed sharp property')\n modified = true\n }\n }\n\n // 5. Update buildConfig import\n if (detection.needsImportChange) {\n if (payloadImport) {\n if (detection.hasOtherPayloadImports) {\n // Remove buildConfig from payload import, add new figma import\n const namedImports = payloadImport.getNamedImports()\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n buildConfigImport.remove()\n\n // If payload import is now empty, remove it\n if (payloadImport.getNamedImports().length === 0) {\n payloadImport.remove()\n }\n }\n\n // Add new import at the top\n sourceFile.addImportDeclaration({\n moduleSpecifier: '@payloadcms/figma',\n namedImports: ['buildFigmaConfig'],\n })\n\n changes.push('Split buildConfig import to @payloadcms/figma')\n } else {\n // Replace entire import: change module specifier and rename all references\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n // Change the import name\n buildConfigImport.setName('buildFigmaConfig')\n\n // Find and rename all usages of 'buildConfig' in the file\n const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)\n identifiers.forEach((identifier) => {\n if (identifier.getText() === 'buildConfig') {\n identifier.replaceWithText('buildFigmaConfig')\n }\n })\n }\n payloadImport.setModuleSpecifier('@payloadcms/figma')\n changes.push('Changed buildConfig import to @payloadcms/figma')\n }\n modified = true\n }\n }\n\n // 6. Remove orphaned imports\n // Re-fetch imports after each removal to avoid stale references\n if (detection.dbProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const dbImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.dbProperty?.importSource,\n )\n if (dbImport) {\n dbImport.remove()\n changes.push(`Removed ${detection.dbProperty.adapter} import`)\n modified = true\n }\n }\n\n if (detection.editorProperty?.isDefault) {\n const currentImports = sourceFile.getImportDeclarations()\n const editorImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.editorProperty?.importSource,\n )\n if (editorImport) {\n editorImport.remove()\n changes.push('Removed lexicalEditor import')\n modified = true\n }\n }\n\n if (detection.sharpProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const sharpImport = currentImports.find((imp) => imp.getModuleSpecifierValue() === 'sharp')\n if (sharpImport) {\n sharpImport.remove()\n changes.push('Removed sharp import')\n modified = true\n }\n }\n\n return { changes, modified }\n}\n\nexport type FigmaPropertyConfig = {\n contentSystemId: string\n useContentSystem?: boolean\n}\n\n/**\n * Add figma property to buildConfig if it doesn't exist\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function addFigmaProperty(\n sourceFile: SourceFile,\n config: FigmaPropertyConfig,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return { changes: [], modified: false }\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return { changes: [], modified: false }\n }\n\n // Check if figma property already exists\n const existingFigmaProperty = configArg.getProperty('figma')\n if (existingFigmaProperty) {\n log.debug('figma property already exists, skipping')\n return { changes: ['Skipped: figma property already exists'], modified: false }\n }\n\n // Add figma property\n // Note: useContentSystem is optional and defaults to true, so we don't generate it during init\n // contentSystemId is stored in .env file and referenced via process.env with non-null assertion\n const figmaObj =\n config.useContentSystem === false\n ? `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n useContentSystem: false,\n }`\n : `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n }`\n\n configArg.addPropertyAssignment({\n name: 'figma',\n initializer: figmaObj,\n })\n\n changes.push(`Added figma property (contentSystemId: ${config.contentSystemId})`)\n modified = true\n\n return { changes, modified }\n}\n\n/**\n * Read figma configuration from payload.config.ts\n * Returns the figma object if it exists, null otherwise\n */\nexport function readFigmaConfig(sourceFile: SourceFile): FigmaPropertyConfig | null {\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return null\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return null\n }\n\n // Find figma property\n const figmaProperty = configArg.getProperty('figma')\n if (!figmaProperty || !Node.isPropertyAssignment(figmaProperty)) {\n log.debug('No figma property found in buildConfig')\n return null\n }\n\n // Get initializer (the object value)\n const initializer = figmaProperty.getInitializer()\n if (!initializer || !Node.isObjectLiteralExpression(initializer)) {\n log.debug('figma property is not an object literal')\n return null\n }\n\n // Extract values\n const contentSystemIdProp = initializer.getProperty('contentSystemId')\n const useContentSystemProp = initializer.getProperty('useContentSystem')\n\n if (!contentSystemIdProp) {\n log.debug('Missing required figma property: contentSystemId')\n return null\n }\n\n // Extract contentSystemId - support both literal strings and env var references\n let contentSystemId: string | undefined\n if (Node.isPropertyAssignment(contentSystemIdProp)) {\n const initializer = contentSystemIdProp.getInitializer()\n const text = initializer?.getText() || ''\n\n // Support both patterns:\n // 1. Literal string: 'cms_abc123' or \"cms_abc123\"\n // 2. Environment variable: process.env.FIGMA_CONTENT_SYSTEM_ID\n if (text.includes('process.env.FIGMA_CONTENT_SYSTEM_ID')) {\n // For env var reference, return a marker that indicates it's from env\n // The actual value will be read at runtime\n contentSystemId = 'process.env.FIGMA_CONTENT_SYSTEM_ID'\n } else {\n // Remove quotes for literal strings\n contentSystemId = text.replace(/['\"]/g, '')\n }\n }\n\n const useContentSystem = Node.isPropertyAssignment(useContentSystemProp)\n ? useContentSystemProp.getInitializer()?.getText() === 'true'\n : undefined // Optional: undefined if not specified\n\n if (!contentSystemId) {\n log.debug('Could not extract contentSystemId value')\n return null\n }\n\n return {\n contentSystemId,\n useContentSystem,\n }\n}\n"],"names":["Node","SyntaxKind","log","detectRequiredChanges","sourceFile","result","figmaObjectExists","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","hasBuildConfig","moduleSpecifier","namedImports","getNamedImports","expectedFunctionName","buildConfigImport","ni","getName","aliasNode","getAliasNode","buildConfigName","getText","length","exportAssignment","getFirstDescendantByKind","ExportAssignment","buildConfigCall","callExpressions","getDescendantsOfKind","CallExpression","ce","expr","getExpression","configArg","getArguments","isObjectLiteralExpression","dbProperty","getProperty","dbValue","getChildrenOfKind","adapterName","adapterImport","some","adapter","importSource","secretProperty","editorProperty","editorValue","editorName","editorImport","args","isDefault","sharpProperty","sharpImport","figmaProperty","removeAllComments","ranges","collectComments","node","getLeadingCommentRanges","forEach","range","push","getPos","getEnd","getTrailingCommentRanges","getChildren","uniqueRanges","Array","from","Set","map","r","JSON","stringify","parse","sort","a","b","pos","end","removeText","applyModifications","detection","changes","modified","hadComments","remove","addImportDeclaration","setName","identifiers","Identifier","identifier","replaceWithText","setModuleSpecifier","currentImports","dbImport","addFigmaProperty","config","text","endsWith","existingFigmaProperty","figmaObj","useContentSystem","addPropertyAssignment","name","initializer","contentSystemId","readFigmaConfig","isPropertyAssignment","getInitializer","contentSystemIdProp","useContentSystemProp","includes","replace","undefined"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAE3C,YAAYC,SAAS,WAAU;AAuC/B;;CAEC,GACD,OAAO,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,CAACE,sBAAsB;QAClD,MAAML,cAAcK,oBAAoBD,cAAc;QACtD,MAAMX,OAAOO,aAAarF,aAAa;QAEvC,yBAAyB;QACzB,kDAAkD;QAClD,+DAA+D;QAC/D,IAAI8E,KAAKc,QAAQ,CAAC,wCAAwC;YACxD,sEAAsE;YACtE,2CAA2C;YAC3CN,kBAAkB;QACpB,OAAO;YACL,oCAAoC;YACpCA,kBAAkBR,KAAKe,OAAO,CAAC,SAAS;QAC1C;IACF;IAEA,MAAMX,mBAAmB9G,KAAKoH,oBAAoB,CAACG,wBAC/CA,qBAAqBF,cAAc,IAAIzF,cAAc,SACrD8F,UAAU,uCAAuC;;IAErD,IAAI,CAACR,iBAAiB;QACpBhH,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACLkG;QACAJ;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/payload-config-ast.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph'\n\nimport { Node, SyntaxKind } from 'ts-morph'\n\nimport * as log from './log.js'\n\n/**\n * Result of detecting what changes are needed in a payload config file\n */\nexport type DetectionResult = {\n /** Database adapter configuration if present */\n dbProperty?: {\n /** Name of the adapter function (e.g., 'mongooseAdapter', 'postgresAdapter') */\n adapter: string\n /** NPM package the adapter is imported from (e.g., '@payloadcms/db-mongodb') */\n importSource: string\n }\n /** Editor configuration if present */\n editorProperty?: {\n /** NPM package the editor is imported from (e.g., '@payloadcms/richtext-lexical') */\n importSource: string\n /** Whether this is a default editor with no custom configuration */\n isDefault: boolean\n }\n /** Whether the config already has a `figma` property */\n figmaObjectExists: boolean\n /** Whether buildConfig/buildFigmaConfig uses an import alias (e.g., 'buildConfig as createConfig') */\n hasAlias: boolean\n /** Whether a buildConfig or buildFigmaConfig call was found (undefined if not checked) */\n hasBuildConfig?: boolean\n /** Whether there are other imports from 'payload' besides buildConfig (e.g., types) */\n hasOtherPayloadImports: boolean\n /** Whether the import needs to be changed from 'payload' to '@payloadcms/figma' */\n needsImportChange: boolean\n /** Whether a `secret` property exists in the config */\n secretProperty?: boolean\n /** Sharp configuration if present */\n sharpProperty?: {\n /** NPM package sharp is imported from (always 'sharp') */\n importSource: string\n }\n}\n\n/**\n * Detect what changes are needed in the payload config file\n */\nexport function detectRequiredChanges(sourceFile: SourceFile): DetectionResult {\n const result: DetectionResult = {\n figmaObjectExists: false,\n hasAlias: false,\n hasOtherPayloadImports: false,\n needsImportChange: false,\n }\n\n // Find buildConfig import\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'payload' ||\n imp.getModuleSpecifierValue() === '@payloadcms/figma',\n )\n\n if (!payloadImport) {\n log.debug('No payload or @payloadcms/figma import found')\n result.hasBuildConfig = false\n return result\n }\n\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n\n const moduleSpecifier = payloadImport.getModuleSpecifierValue()\n const namedImports = payloadImport.getNamedImports()\n\n // Determine which function name to look for based on the import source\n // - From 'payload': look for buildConfig (needs migration)\n // - From '@payloadcms/figma': look for buildFigmaConfig (already migrated)\n const expectedFunctionName = moduleSpecifier === 'payload' ? 'buildConfig' : 'buildFigmaConfig'\n\n const buildConfigImport = namedImports.find((ni) => ni.getName() === expectedFunctionName)\n\n if (!buildConfigImport) {\n result.hasBuildConfig = false\n return result\n }\n\n // Check for alias and get the actual name used in code\n const aliasNode = buildConfigImport.getAliasNode()\n const buildConfigName = aliasNode ? aliasNode.getText() : expectedFunctionName\n if (aliasNode) {\n result.hasAlias = true\n }\n\n // Check if import needs change\n if (moduleSpecifier === 'payload') {\n result.needsImportChange = true\n\n // Check if there are other imports from payload\n if (namedImports.length > 1) {\n result.hasOtherPayloadImports = true\n }\n }\n\n // Find buildConfig call in export default\n // First try to find export default with the buildConfig call\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n // Look for buildConfig call in the export default\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n result.hasBuildConfig = false\n return result\n }\n\n // Get config object\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return result\n }\n\n // Check for db property\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n const dbValue = dbProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (dbValue) {\n const adapterName = dbValue.getExpression().getText()\n\n // Find the import source for this adapter\n const adapterImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === adapterName),\n )\n\n if (adapterImport) {\n result.dbProperty = {\n adapter: adapterName,\n importSource: adapterImport.getModuleSpecifierValue(),\n }\n }\n }\n }\n\n // Check for secret property\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n result.secretProperty = true\n }\n\n // Check for editor property\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n const editorValue = editorProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (editorValue) {\n const editorName = editorValue.getExpression().getText()\n\n // Find the import source\n const editorImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === editorName),\n )\n\n if (editorImport && editorName === 'lexicalEditor') {\n // Check if it has arguments\n const args = editorValue.getArguments()\n const isDefault = args.length === 0\n\n result.editorProperty = {\n importSource: editorImport.getModuleSpecifierValue(),\n isDefault,\n }\n }\n }\n }\n\n // Check for sharp property\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n // Find the import source for sharp\n const sharpImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'sharp' ||\n imp.getNamedImports().some((ni) => ni.getName() === 'sharp'),\n )\n\n result.sharpProperty = {\n importSource: sharpImport?.getModuleSpecifierValue() || 'sharp',\n }\n }\n\n // Check for figma property\n const figmaProperty = configArg.getProperty('figma')\n if (figmaProperty) {\n result.figmaObjectExists = true\n }\n\n return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\n}\n\n/**\n * Remove all comments\n * @returns true if any comments were removed\n */\nfunction removeAllComments(sourceFile: SourceFile): boolean {\n const ranges: Array<[number, number]> = []\n\n // Recursively collect comments from node and ALL children (including tokens)\n const collectComments = (node: Node) => {\n node.getLeadingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n node.getTrailingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n\n // Process ALL children including token nodes (commas, braces, etc.)\n node.getChildren().forEach(collectComments)\n }\n\n collectComments(sourceFile)\n\n if (ranges.length === 0) {\n return false\n }\n\n // Remove duplicates and sort in reverse order to avoid position shifts\n const uniqueRanges = Array.from(new Set(ranges.map((r) => JSON.stringify(r)))).map(\n (r) => JSON.parse(r) as [number, number],\n )\n uniqueRanges.sort((a, b) => b[0] - a[0])\n\n // Remove each comment range\n for (const [pos, end] of uniqueRanges) {\n sourceFile.removeText(pos, end)\n }\n\n return true\n}\n\n/**\n * Apply modifications to the source file based on detection result\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function applyModifications(\n sourceFile: SourceFile,\n detection: DetectionResult,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n if (detection.hasBuildConfig === false || detection.hasAlias) {\n log.debug(\n `Skipping modifications: hasBuildConfig=${detection.hasBuildConfig}, hasAlias=${detection.hasAlias}`,\n )\n return { changes: [], modified: false }\n }\n\n // 1. Remove all comments FIRST (before AST modifications that might shift positions)\n const hadComments = removeAllComments(sourceFile)\n if (hadComments) {\n changes.push('Removed comments')\n modified = true\n }\n\n // Find the import declarations\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find((imp) => imp.getModuleSpecifierValue() === 'payload')\n\n // Get the buildConfig name (could be aliased)\n let buildConfigName = 'buildConfig'\n if (payloadImport) {\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n const aliasNode = buildConfigImport.getAliasNode()\n buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n }\n }\n\n // Find buildConfig call in export default (prefer export default)\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n return { changes: [], modified: false }\n }\n\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return { changes: [], modified: false }\n }\n\n // 1. Remove db property\n if (detection.dbProperty) {\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n dbProperty.remove()\n changes.push('Removed db property')\n modified = true\n }\n }\n\n // 2. Remove secret property\n if (detection.secretProperty) {\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n secretProperty.remove()\n changes.push('Removed secret property')\n modified = true\n }\n }\n\n // 3. Remove editor if default\n if (detection.editorProperty?.isDefault) {\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n editorProperty.remove()\n changes.push('Removed default editor property')\n modified = true\n }\n }\n\n // 4. Remove sharp property\n if (detection.sharpProperty) {\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n sharpProperty.remove()\n changes.push('Removed sharp property')\n modified = true\n }\n }\n\n // 5. Update buildConfig import\n if (detection.needsImportChange) {\n if (payloadImport) {\n if (detection.hasOtherPayloadImports) {\n // Remove buildConfig from payload import, add new figma import\n const namedImports = payloadImport.getNamedImports()\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n buildConfigImport.remove()\n\n // If payload import is now empty, remove it\n if (payloadImport.getNamedImports().length === 0) {\n payloadImport.remove()\n }\n }\n\n // Add new import at the top\n sourceFile.addImportDeclaration({\n moduleSpecifier: '@payloadcms/figma',\n namedImports: ['buildFigmaConfig'],\n })\n\n // Rename all usages of 'buildConfig' to 'buildFigmaConfig'\n const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)\n identifiers.forEach((identifier) => {\n if (identifier.getText() === 'buildConfig') {\n identifier.replaceWithText('buildFigmaConfig')\n }\n })\n\n changes.push('Split buildConfig import to @payloadcms/figma')\n } else {\n // Replace entire import: change module specifier and rename all references\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n // Change the import name\n buildConfigImport.setName('buildFigmaConfig')\n\n // Find and rename all usages of 'buildConfig' in the file\n const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)\n identifiers.forEach((identifier) => {\n if (identifier.getText() === 'buildConfig') {\n identifier.replaceWithText('buildFigmaConfig')\n }\n })\n }\n payloadImport.setModuleSpecifier('@payloadcms/figma')\n changes.push('Changed buildConfig import to @payloadcms/figma')\n }\n modified = true\n }\n }\n\n // 6. Remove orphaned imports\n // Re-fetch imports after each removal to avoid stale references\n if (detection.dbProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const dbImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.dbProperty?.importSource,\n )\n if (dbImport) {\n dbImport.remove()\n changes.push(`Removed ${detection.dbProperty.adapter} import`)\n modified = true\n }\n }\n\n if (detection.editorProperty?.isDefault) {\n const currentImports = sourceFile.getImportDeclarations()\n const editorImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.editorProperty?.importSource,\n )\n if (editorImport) {\n editorImport.remove()\n changes.push('Removed lexicalEditor import')\n modified = true\n }\n }\n\n if (detection.sharpProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const sharpImport = currentImports.find((imp) => imp.getModuleSpecifierValue() === 'sharp')\n if (sharpImport) {\n sharpImport.remove()\n changes.push('Removed sharp import')\n modified = true\n }\n }\n\n return { changes, modified }\n}\n\nexport type FigmaPropertyConfig = {\n contentSystemId: string\n useContentSystem?: boolean\n}\n\n/**\n * Add figma property to buildConfig if it doesn't exist\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function addFigmaProperty(\n sourceFile: SourceFile,\n config: FigmaPropertyConfig,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return { changes: [], modified: false }\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return { changes: [], modified: false }\n }\n\n // Check if figma property already exists\n const existingFigmaProperty = configArg.getProperty('figma')\n if (existingFigmaProperty) {\n log.debug('figma property already exists, skipping')\n return { changes: ['Skipped: figma property already exists'], modified: false }\n }\n\n // Add figma property\n // Note: useContentSystem is optional and defaults to true, so we don't generate it during init\n // contentSystemId is stored in .env file and referenced via process.env with non-null assertion\n const figmaObj =\n config.useContentSystem === false\n ? `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n useContentSystem: false,\n }`\n : `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n }`\n\n configArg.addPropertyAssignment({\n name: 'figma',\n initializer: figmaObj,\n })\n\n changes.push(`Added figma property (contentSystemId: ${config.contentSystemId})`)\n modified = true\n\n return { changes, modified }\n}\n\n/**\n * Read figma configuration from payload.config.ts\n * Returns the figma object if it exists, null otherwise\n */\nexport function readFigmaConfig(sourceFile: SourceFile): FigmaPropertyConfig | null {\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return null\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return null\n }\n\n // Find figma property\n const figmaProperty = configArg.getProperty('figma')\n if (!figmaProperty || !Node.isPropertyAssignment(figmaProperty)) {\n log.debug('No figma property found in buildConfig')\n return null\n }\n\n // Get initializer (the object value)\n const initializer = figmaProperty.getInitializer()\n if (!initializer || !Node.isObjectLiteralExpression(initializer)) {\n log.debug('figma property is not an object literal')\n return null\n }\n\n // Extract values\n const contentSystemIdProp = initializer.getProperty('contentSystemId')\n const useContentSystemProp = initializer.getProperty('useContentSystem')\n\n if (!contentSystemIdProp) {\n log.debug('Missing required figma property: contentSystemId')\n return null\n }\n\n // Extract contentSystemId - support both literal strings and env var references\n let contentSystemId: string | undefined\n if (Node.isPropertyAssignment(contentSystemIdProp)) {\n const initializer = contentSystemIdProp.getInitializer()\n const text = initializer?.getText() || ''\n\n // Support both patterns:\n // 1. Literal string: 'cms_abc123' or \"cms_abc123\"\n // 2. Environment variable: process.env.FIGMA_CONTENT_SYSTEM_ID\n if (text.includes('process.env.FIGMA_CONTENT_SYSTEM_ID')) {\n // For env var reference, return a marker that indicates it's from env\n // The actual value will be read at runtime\n contentSystemId = 'process.env.FIGMA_CONTENT_SYSTEM_ID'\n } else {\n // Remove quotes for literal strings\n contentSystemId = text.replace(/['\"]/g, '')\n }\n }\n\n const useContentSystem = Node.isPropertyAssignment(useContentSystemProp)\n ? useContentSystemProp.getInitializer()?.getText() === 'true'\n : undefined // Optional: undefined if not specified\n\n if (!contentSystemId) {\n log.debug('Could not extract contentSystemId value')\n return null\n }\n\n return {\n contentSystemId,\n useContentSystem,\n }\n}\n"],"names":["Node","SyntaxKind","log","detectRequiredChanges","sourceFile","result","figmaObjectExists","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","hasBuildConfig","moduleSpecifier","namedImports","getNamedImports","expectedFunctionName","buildConfigImport","ni","getName","aliasNode","getAliasNode","buildConfigName","getText","length","exportAssignment","getFirstDescendantByKind","ExportAssignment","buildConfigCall","callExpressions","getDescendantsOfKind","CallExpression","ce","expr","getExpression","configArg","getArguments","isObjectLiteralExpression","dbProperty","getProperty","dbValue","getChildrenOfKind","adapterName","adapterImport","some","adapter","importSource","secretProperty","editorProperty","editorValue","editorName","editorImport","args","isDefault","sharpProperty","sharpImport","figmaProperty","removeAllComments","ranges","collectComments","node","getLeadingCommentRanges","forEach","range","push","getPos","getEnd","getTrailingCommentRanges","getChildren","uniqueRanges","Array","from","Set","map","r","JSON","stringify","parse","sort","a","b","pos","end","removeText","applyModifications","detection","changes","modified","hadComments","remove","addImportDeclaration","identifiers","Identifier","identifier","replaceWithText","setName","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,U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,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/utils/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAOrD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,GAAE,MAAsB,GAClC,OAAO,CAAC,WAAW,CAAC,CAwCtB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAS/D;AAiED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoD7F;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,CAqCf;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAenF;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,GAAE,MAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQhG"}
|
package/dist/utils/project.js
CHANGED
|
@@ -163,6 +163,9 @@ import { applyLambdaModifications } from './lambda-config.js';
|
|
|
163
163
|
let readmeContent = await fs.readFile(readmeTemplatePath, 'utf-8');
|
|
164
164
|
readmeContent = readmeContent.replace(/\{\{PROJECT_NAME\}\}/g, projectName);
|
|
165
165
|
await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent, 'utf-8');
|
|
166
|
+
// Copy .env.example template
|
|
167
|
+
const envExampleTemplatePath = fileURLToPath(new URL('../templates/.env.example', import.meta.url));
|
|
168
|
+
await fs.copyFile(envExampleTemplatePath, path.join(projectPath, '.env.example'));
|
|
166
169
|
}
|
|
167
170
|
/**
|
|
168
171
|
* Initialize git repository after all setup is complete
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/project.ts"],"sourcesContent":["/**\n * Project detection and scaffolding utilities\n */\n\nimport spawn from 'cross-spawn'\nimport fs from 'fs/promises'\nimport path from 'path'\nimport { fileURLToPath } from 'url'\n\nimport type { ProjectInfo } from '../types/config.js'\n\nimport { ensureGitignore } from './config.js'\nimport { downloadTemplateFromGitHub } from './download-template.js'\nimport { tryInitRepoAndCommit } from './git.js'\nimport { applyLambdaModifications } from './lambda-config.js'\n\n/**\n * Detect if current directory has a Payload project\n *\n * @param projectPath - Path to check (defaults to cwd)\n * @returns Project information\n */\nexport async function detectPayloadProject(\n projectPath: string = process.cwd(),\n): Promise<ProjectInfo> {\n const packageJsonPath = path.join(projectPath, 'package.json')\n\n try {\n const content = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(content)\n\n // Check for payload in dependencies or devDependencies\n const payloadVersion = packageJson.dependencies?.payload || packageJson.devDependencies?.payload\n\n // Detect package manager\n let packageManager: 'npm' | 'pnpm' | 'yarn' = 'npm'\n try {\n await fs.access(path.join(projectPath, 'pnpm-lock.yaml'))\n packageManager = 'pnpm'\n } catch {\n try {\n await fs.access(path.join(projectPath, 'yarn.lock'))\n packageManager = 'yarn'\n } catch {\n packageManager = 'npm'\n }\n }\n\n return {\n hasPayload: !!payloadVersion,\n packageManager,\n path: projectPath,\n payloadVersion: payloadVersion || undefined,\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n // No package.json found\n return {\n hasPayload: false,\n path: projectPath,\n }\n }\n throw new Error(`Failed to read package.json: ${(error as Error).message}`)\n }\n}\n\n/**\n * Validate Payload version (must be 3.x)\n *\n * @param version - Version string from package.json\n * @returns True if version is valid\n */\nexport function validatePayloadVersion(version: string): boolean {\n // Extract major version (handle ^3.0.0, ~3.0.0, 3.0.0, etc.)\n const match = version.match(/(\\d+)/)\n if (!match) {\n return false\n }\n\n const majorVersion = parseInt(match[1], 10)\n return majorVersion === 3\n}\n\n/**\n * Fetch the latest version of a package from npm registry\n *\n * @param packageName - Package name to fetch version for\n * @returns Latest version string\n */\nasync function getLatestPackageVersion(packageName: string): Promise<string> {\n const response = await fetch(`https://registry.npmjs.org/-/package/${packageName}/dist-tags`)\n\n if (!response.ok) {\n throw new Error(`Failed to fetch version for ${packageName}: ${response.statusText}`)\n }\n\n const data = (await response.json()) as Record<string, unknown>\n\n if (typeof data.latest !== 'string') {\n throw new Error(`Invalid version data received for ${packageName}`)\n }\n\n return data.latest\n}\n\n/**\n * Replace workspace versions in package.json with actual versions\n *\n * @param packageJson - Package JSON object to update\n * @param latestVersion - Latest Payload version to use\n */\nfunction replaceWorkspaceVersions(\n packageJson: Record<string, unknown>,\n latestVersion: string,\n): void {\n const deps = packageJson.dependencies as Record<string, string> | undefined\n if (!deps) {\n return\n }\n\n for (const [key, value] of Object.entries(deps)) {\n // Replace workspace:* or workspace:^ with actual version\n if (typeof value === 'string' && value.startsWith('workspace:')) {\n deps[key] = latestVersion\n }\n // Ensure all payload packages use the same version\n else if (key === 'payload' || key.startsWith('@payloadcms/')) {\n deps[key] = latestVersion\n }\n }\n\n // Also handle devDependencies if present\n const devDeps = packageJson.devDependencies as Record<string, string> | undefined\n if (!devDeps) {\n return\n }\n\n for (const [key, value] of Object.entries(devDeps)) {\n if (typeof value === 'string' && value.startsWith('workspace:')) {\n devDeps[key] = latestVersion\n } else if (key === 'payload' || key.startsWith('@payloadcms/')) {\n devDeps[key] = latestVersion\n }\n }\n}\n\n/**\n * Scaffold a new Payload project from GitHub template\n *\n * @param projectPath - Path where to create the project\n * @param projectName - Name for the project\n */\nexport async function scaffoldProject(projectPath: string, projectName: string): Promise<void> {\n // Create project directory if it doesn't exist\n await fs.mkdir(projectPath, { recursive: true })\n\n // Download template from GitHub\n await downloadTemplateFromGitHub(projectPath)\n\n // Apply Lambda modifications BEFORE updating package.json\n // This ensures we don't overwrite version replacements\n await applyLambdaModifications(projectPath)\n\n // Get latest Payload version from npm\n const latestVersion = await getLatestPackageVersion('payload')\n\n // Delete any existing lock files from template (they reference workspace:* versions)\n // This ensures pnpm install creates a fresh lock file with actual versions\n const lockFiles = ['pnpm-lock.yaml', 'yarn.lock', 'package-lock.json']\n for (const lockFile of lockFiles) {\n try {\n await fs.unlink(path.join(projectPath, lockFile))\n } catch {\n // File doesn't exist, ignore\n }\n }\n\n // Update package.json: set name, replace workspace versions\n // This must come AFTER applyLambdaModifications to ensure we have final versions\n const packageJsonPath = path.join(projectPath, 'package.json')\n const packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>\n packageJson.name = projectName\n\n // Replace workspace:* versions with actual versions\n replaceWorkspaceVersions(packageJson, latestVersion)\n\n await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\\n', 'utf-8')\n\n // Ensure .gitignore has required entries\n // Note: .env file is created by init command with FIGMA_CONTENT_SYSTEM_ID\n await ensureGitignore(projectPath, ['.env', '.env.local', 'lambda.zip'])\n\n // Replace README with Figma-specific version\n const readmeTemplatePath = fileURLToPath(new URL('../templates/README.md', import.meta.url))\n let readmeContent = await fs.readFile(readmeTemplatePath, 'utf-8')\n readmeContent = readmeContent.replace(/\\{\\{PROJECT_NAME\\}\\}/g, projectName)\n await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent, 'utf-8')\n}\n\n/**\n * Initialize git repository after all setup is complete\n *\n * This should be called AFTER installDependencies so that lock files are included\n *\n * @param projectPath - Path to project directory\n */\nexport function initializeGitRepo(projectPath: string): void {\n tryInitRepoAndCommit(projectPath)\n}\n\n/**\n * Install dependencies using the detected package manager\n *\n * @param projectPath - Path to project\n * @param packageManager - Package manager to use\n * @returns Promise that resolves when installation completes\n */\nexport async function installDependencies(\n projectPath: string,\n packageManager: 'npm' | 'pnpm' | 'yarn' = 'npm',\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(packageManager, ['install'], {\n cwd: projectPath,\n stdio: 'pipe',\n })\n\n let stdout = ''\n let stderr = ''\n\n // Capture stdout\n child.stdout?.on('data', (data) => {\n stdout += data.toString()\n })\n\n // Capture stderr\n child.stderr?.on('data', (data) => {\n stderr += data.toString()\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n resolve()\n } else {\n // Show captured output on error\n const output = [stdout, stderr].filter(Boolean).join('\\n\\n')\n const errorMessage = output\n ? `${packageManager} install failed with code ${code}\\n\\nOutput:\\n${output}`\n : `${packageManager} install failed with code ${code}`\n reject(new Error(errorMessage))\n }\n })\n\n child.on('error', (error) => {\n reject(new Error(`Failed to run ${packageManager} install: ${error.message}`))\n })\n })\n}\n\n/**\n * Check if required dependencies are installed\n *\n * @param projectPath - Path to project\n * @returns True if all required dependencies exist\n */\nexport async function hasRequiredDependencies(projectPath: string): Promise<boolean> {\n const packageJsonPath = path.join(projectPath, 'package.json')\n\n try {\n const content = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(content)\n\n // Check for Payload and Next.js\n const hasPayload = packageJson.dependencies?.payload || packageJson.devDependencies?.payload\n const hasNext = packageJson.dependencies?.next || packageJson.devDependencies?.next\n\n return !!(hasPayload && hasNext)\n } catch {\n return false\n }\n}\n\n/**\n * Check if current directory is a project directory\n *\n * A project directory has package.json\n *\n * @param projectPath - Path to check (defaults to cwd)\n * @returns True if in project directory\n */\nexport async function isInProjectDirectory(projectPath: string = process.cwd()): Promise<boolean> {\n try {\n // Check for package.json\n await fs.access(path.join(projectPath, 'package.json'))\n return true\n } catch {\n return false\n }\n}\n"],"names":["spawn","fs","path","fileURLToPath","ensureGitignore","downloadTemplateFromGitHub","tryInitRepoAndCommit","applyLambdaModifications","detectPayloadProject","projectPath","process","cwd","packageJsonPath","join","content","readFile","packageJson","JSON","parse","payloadVersion","dependencies","payload","devDependencies","packageManager","access","hasPayload","undefined","error","code","Error","message","validatePayloadVersion","version","match","majorVersion","parseInt","getLatestPackageVersion","packageName","response","fetch","ok","statusText","data","json","latest","replaceWorkspaceVersions","latestVersion","deps","key","value","Object","entries","startsWith","devDeps","scaffoldProject","projectName","mkdir","recursive","lockFiles","lockFile","unlink","packageJsonContent","name","writeFile","stringify","readmeTemplatePath","URL","url","readmeContent","replace","initializeGitRepo","installDependencies","Promise","resolve","reject","child","stdio","stdout","stderr","on","toString","output","filter","Boolean","errorMessage","hasRequiredDependencies","hasNext","next","isInProjectDirectory"],"mappings":"AAAA;;CAEC,GAED,OAAOA,WAAW,cAAa;AAC/B,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,aAAa,QAAQ,MAAK;AAInC,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,0BAA0B,QAAQ,yBAAwB;AACnE,SAASC,oBAAoB,QAAQ,WAAU;AAC/C,SAASC,wBAAwB,QAAQ,qBAAoB;AAE7D;;;;;CAKC,GACD,OAAO,eAAeC,qBACpBC,cAAsBC,QAAQC,GAAG,EAAE;IAEnC,MAAMC,kBAAkBV,KAAKW,IAAI,CAACJ,aAAa;IAE/C,IAAI;QACF,MAAMK,UAAU,MAAMb,GAAGc,QAAQ,CAACH,iBAAiB;QACnD,MAAMI,cAAcC,KAAKC,KAAK,CAACJ;QAE/B,uDAAuD;QACvD,MAAMK,iBAAiBH,YAAYI,YAAY,EAAEC,WAAWL,YAAYM,eAAe,EAAED;QAEzF,yBAAyB;QACzB,IAAIE,iBAA0C;QAC9C,IAAI;YACF,MAAMtB,GAAGuB,MAAM,CAACtB,KAAKW,IAAI,CAACJ,aAAa;YACvCc,iBAAiB;QACnB,EAAE,OAAM;YACN,IAAI;gBACF,MAAMtB,GAAGuB,MAAM,CAACtB,KAAKW,IAAI,CAACJ,aAAa;gBACvCc,iBAAiB;YACnB,EAAE,OAAM;g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AC;gBACrD,MAAMuE,eAAeH,SACjB,GAAG1D,eAAe,0BAA0B,EAAEK,KAAK,aAAa,EAAEqD,QAAQ,GAC1E,GAAG1D,eAAe,0BAA0B,EAAEK,MAAM;gBACxD8C,OAAO,IAAI7C,MAAMuD;YACnB;QACF;QAEAT,MAAMI,EAAE,CAAC,SAAS,CAACpD;YACjB+C,OAAO,IAAI7C,MAAM,CAAC,cAAc,EAAEN,eAAe,UAAU,EAAEI,MAAMG,OAAO,EAAE;QAC9E;IACF;AACF;AAEA;;;;;CAKC,GACD,OAAO,eAAeuD,wBAAwB5E,WAAmB;IAC/D,MAAMG,kBAAkBV,KAAKW,IAAI,CAACJ,aAAa;IAE/C,IAAI;QACF,MAAMK,UAAU,MAAMb,GAAGc,QAAQ,CAACH,iBAAiB;QACnD,MAAMI,cAAcC,KAAKC,KAAK,CAACJ;QAE/B,gCAAgC;QAChC,MAAMW,aAAaT,YAAYI,YAAY,EAAEC,WAAWL,YAAYM,eAAe,EAAED;QACrF,MAAMiE,UAAUtE,YAAYI,YAAY,EAAEmE,QAAQvE,YAAYM,eAAe,EAAEiE;QAE/E,OAAO,CAAC,CAAE9D,CAAAA,cAAc6D,OAAM;IAChC,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,eAAeE,qBAAqB/E,cAAsBC,QAAQC,GAAG,EAAE;IAC5E,IAAI;QACF,yBAAyB;QACzB,MAAMV,GAAGuB,MAAM,CAACtB,KAAKW,IAAI,CAACJ,aAAa;QACvC,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/project.ts"],"sourcesContent":["/**\n * Project detection and scaffolding utilities\n */\n\nimport spawn from 'cross-spawn'\nimport fs from 'fs/promises'\nimport path from 'path'\nimport { fileURLToPath } from 'url'\n\nimport type { ProjectInfo } from '../types/config.js'\n\nimport { ensureGitignore } from './config.js'\nimport { downloadTemplateFromGitHub } from './download-template.js'\nimport { tryInitRepoAndCommit } from './git.js'\nimport { applyLambdaModifications } from './lambda-config.js'\n\n/**\n * Detect if current directory has a Payload project\n *\n * @param projectPath - Path to check (defaults to cwd)\n * @returns Project information\n */\nexport async function detectPayloadProject(\n projectPath: string = process.cwd(),\n): Promise<ProjectInfo> {\n const packageJsonPath = path.join(projectPath, 'package.json')\n\n try {\n const content = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(content)\n\n // Check for payload in dependencies or devDependencies\n const payloadVersion = packageJson.dependencies?.payload || packageJson.devDependencies?.payload\n\n // Detect package manager\n let packageManager: 'npm' | 'pnpm' | 'yarn' = 'npm'\n try {\n await fs.access(path.join(projectPath, 'pnpm-lock.yaml'))\n packageManager = 'pnpm'\n } catch {\n try {\n await fs.access(path.join(projectPath, 'yarn.lock'))\n packageManager = 'yarn'\n } catch {\n packageManager = 'npm'\n }\n }\n\n return {\n hasPayload: !!payloadVersion,\n packageManager,\n path: projectPath,\n payloadVersion: payloadVersion || undefined,\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n // No package.json found\n return {\n hasPayload: false,\n path: projectPath,\n }\n }\n throw new Error(`Failed to read package.json: ${(error as Error).message}`)\n }\n}\n\n/**\n * Validate Payload version (must be 3.x)\n *\n * @param version - Version string from package.json\n * @returns True if version is valid\n */\nexport function validatePayloadVersion(version: string): boolean {\n // Extract major version (handle ^3.0.0, ~3.0.0, 3.0.0, etc.)\n const match = version.match(/(\\d+)/)\n if (!match) {\n return false\n }\n\n const majorVersion = parseInt(match[1], 10)\n return majorVersion === 3\n}\n\n/**\n * Fetch the latest version of a package from npm registry\n *\n * @param packageName - Package name to fetch version for\n * @returns Latest version string\n */\nasync function getLatestPackageVersion(packageName: string): Promise<string> {\n const response = await fetch(`https://registry.npmjs.org/-/package/${packageName}/dist-tags`)\n\n if (!response.ok) {\n throw new Error(`Failed to fetch version for ${packageName}: ${response.statusText}`)\n }\n\n const data = (await response.json()) as Record<string, unknown>\n\n if (typeof data.latest !== 'string') {\n throw new Error(`Invalid version data received for ${packageName}`)\n }\n\n return data.latest\n}\n\n/**\n * Replace workspace versions in package.json with actual versions\n *\n * @param packageJson - Package JSON object to update\n * @param latestVersion - Latest Payload version to use\n */\nfunction replaceWorkspaceVersions(\n packageJson: Record<string, unknown>,\n latestVersion: string,\n): void {\n const deps = packageJson.dependencies as Record<string, string> | undefined\n if (!deps) {\n return\n }\n\n for (const [key, value] of Object.entries(deps)) {\n // Replace workspace:* or workspace:^ with actual version\n if (typeof value === 'string' && value.startsWith('workspace:')) {\n deps[key] = latestVersion\n }\n // Ensure all payload packages use the same version\n else if (key === 'payload' || key.startsWith('@payloadcms/')) {\n deps[key] = latestVersion\n }\n }\n\n // Also handle devDependencies if present\n const devDeps = packageJson.devDependencies as Record<string, string> | undefined\n if (!devDeps) {\n return\n }\n\n for (const [key, value] of Object.entries(devDeps)) {\n if (typeof value === 'string' && value.startsWith('workspace:')) {\n devDeps[key] = latestVersion\n } else if (key === 'payload' || key.startsWith('@payloadcms/')) {\n devDeps[key] = latestVersion\n }\n }\n}\n\n/**\n * Scaffold a new Payload project from GitHub template\n *\n * @param projectPath - Path where to create the project\n * @param projectName - Name for the project\n */\nexport async function scaffoldProject(projectPath: string, projectName: string): Promise<void> {\n // Create project directory if it doesn't exist\n await fs.mkdir(projectPath, { recursive: true })\n\n // Download template from GitHub\n await downloadTemplateFromGitHub(projectPath)\n\n // Apply Lambda modifications BEFORE updating package.json\n // This ensures we don't overwrite version replacements\n await applyLambdaModifications(projectPath)\n\n // Get latest Payload version from npm\n const latestVersion = await getLatestPackageVersion('payload')\n\n // Delete any existing lock files from template (they reference workspace:* versions)\n // This ensures pnpm install creates a fresh lock file with actual versions\n const lockFiles = ['pnpm-lock.yaml', 'yarn.lock', 'package-lock.json']\n for (const lockFile of lockFiles) {\n try {\n await fs.unlink(path.join(projectPath, lockFile))\n } catch {\n // File doesn't exist, ignore\n }\n }\n\n // Update package.json: set name, replace workspace versions\n // This must come AFTER applyLambdaModifications to ensure we have final versions\n const packageJsonPath = path.join(projectPath, 'package.json')\n const packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>\n packageJson.name = projectName\n\n // Replace workspace:* versions with actual versions\n replaceWorkspaceVersions(packageJson, latestVersion)\n\n await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\\n', 'utf-8')\n\n // Ensure .gitignore has required entries\n // Note: .env file is created by init command with FIGMA_CONTENT_SYSTEM_ID\n await ensureGitignore(projectPath, ['.env', '.env.local', 'lambda.zip'])\n\n // Replace README with Figma-specific version\n const readmeTemplatePath = fileURLToPath(new URL('../templates/README.md', import.meta.url))\n let readmeContent = await fs.readFile(readmeTemplatePath, 'utf-8')\n readmeContent = readmeContent.replace(/\\{\\{PROJECT_NAME\\}\\}/g, projectName)\n await fs.writeFile(path.join(projectPath, 'README.md'), readmeContent, 'utf-8')\n\n // Copy .env.example template\n const envExampleTemplatePath = fileURLToPath(\n new URL('../templates/.env.example', import.meta.url),\n )\n await fs.copyFile(envExampleTemplatePath, path.join(projectPath, '.env.example'))\n}\n\n/**\n * Initialize git repository after all setup is complete\n *\n * This should be called AFTER installDependencies so that lock files are included\n *\n * @param projectPath - Path to project directory\n */\nexport function initializeGitRepo(projectPath: string): void {\n tryInitRepoAndCommit(projectPath)\n}\n\n/**\n * Install dependencies using the detected package manager\n *\n * @param projectPath - Path to project\n * @param packageManager - Package manager to use\n * @returns Promise that resolves when installation completes\n */\nexport async function installDependencies(\n projectPath: string,\n packageManager: 'npm' | 'pnpm' | 'yarn' = 'npm',\n): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(packageManager, ['install'], {\n cwd: projectPath,\n stdio: 'pipe',\n })\n\n let stdout = ''\n let stderr = ''\n\n // Capture stdout\n child.stdout?.on('data', (data) => {\n stdout += data.toString()\n })\n\n // Capture stderr\n child.stderr?.on('data', (data) => {\n stderr += data.toString()\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n resolve()\n } else {\n // Show captured output on error\n const output = [stdout, stderr].filter(Boolean).join('\\n\\n')\n const errorMessage = output\n ? `${packageManager} install failed with code ${code}\\n\\nOutput:\\n${output}`\n : `${packageManager} install failed with code ${code}`\n reject(new Error(errorMessage))\n }\n })\n\n child.on('error', (error) => {\n reject(new Error(`Failed to run ${packageManager} install: ${error.message}`))\n })\n })\n}\n\n/**\n * Check if required dependencies are installed\n *\n * @param projectPath - Path to project\n * @returns True if all required dependencies exist\n */\nexport async function hasRequiredDependencies(projectPath: string): Promise<boolean> {\n const packageJsonPath = path.join(projectPath, 'package.json')\n\n try {\n const content = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(content)\n\n // Check for Payload and Next.js\n const hasPayload = packageJson.dependencies?.payload || packageJson.devDependencies?.payload\n const hasNext = packageJson.dependencies?.next || packageJson.devDependencies?.next\n\n return !!(hasPayload && hasNext)\n } catch {\n return false\n }\n}\n\n/**\n * Check if current directory is a project directory\n *\n * A project directory has package.json\n *\n * @param projectPath - Path to check (defaults to cwd)\n * @returns True if in project directory\n */\nexport async function isInProjectDirectory(projectPath: string = process.cwd()): Promise<boolean> {\n try {\n // Check for package.json\n await fs.access(path.join(projectPath, 'package.json'))\n return true\n } catch {\n return false\n }\n}\n"],"names":["spawn","fs","path","fileURLToPath","ensureGitignore","downloadTemplateFromGitHub","tryInitRepoAndCommit","applyLambdaModifications","detectPayloadProject","projectPath","process","cwd","packageJsonPath","join","content","readFile","packageJson","JSON","parse","payloadVersion","dependencies","payload","devDependencies","packageManager","access","hasPayload","undefined","error","code","Error","message","validatePayloadVersion","version","match","majorVersion","parseInt","getLatestPackageVersion","packageName","response","fetch","ok","statusText","data","json","latest","replaceWorkspaceVersions","latestVersion","deps","key","value","Object","entries","startsWith","devDeps","scaffoldProject","projectName","mkdir","recursive","lockFiles","lockFile","unlink","packageJsonContent","name","writeFile","stringify","readmeTemplatePath","URL","url","readmeContent","replace","envExampleTemplatePath","copyFile","initializeGitRepo","installDependencies","Promise","resolve","reject","child","stdio","stdout","stderr","on","toString","output","filter","Boolean","errorMessage","hasRequiredDependencies","hasNext","next","isInProjectDirectory"],"mappings":"AAAA;;CAEC,GAED,OAAOA,WAAW,cAAa;AAC/B,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AACvB,SAASC,aAAa,QAAQ,MAAK;AAInC,SAASC,eAAe,QAAQ,cAAa;AAC7C,SAASC,0BAA0B,QAAQ,yBAAwB;AACnE,SAASC,oBAAoB,QAAQ,WAAU;AAC/C,SAASC,wBAAwB,QAAQ,qBAAoB;AAE7D;;;;;CAKC,GACD,OAAO,eAAeC,qBACpBC,cAAsBC,QAAQC,GAAG,EAAE;IAEnC,MAAMC,kBAAkBV,KAAKW,IAAI,CAACJ,aAAa;IAE/C,IAAI;QACF,MAAMK,UAAU,MAAMb,GAAGc,QAAQ,CAACH,iBAAiB;QACnD,MAAMI,cAAcC,KAAKC,KAAK,CAACJ;QAE/B,uDAAuD;QACvD,MAAMK,iBAAiBH,YAAYI,YAAY,EAAEC,WAAWL,YAAYM,eAAe,EAAED;QAEzF,yBAAyB;QACzB,IAAIE,iBAA0C;QAC9C,IAAI;YACF,MAAMtB,GAAGuB,MAAM,CAACtB,KAAKW,IAAI,CAACJ,aAAa;YACvCc,iBAAiB;QACnB,EAAE,OAAM;YACN,IAAI;gBACF,MAAMtB,GAAGuB,MAAM,CAACtB,KAAKW,IAAI,CAACJ,aAAa;gBACvCc,iBAAiB;YACnB,EAAE,OAAM;gBACNA,iBAAiB;YACnB;QACF;QAEA,OAAO;YACLE,YAAY,CAAC,CAACN;YACdI;YACArB,MAAMO;YACNU,gBAAgBA,kBAAkBO;QACpC;IACF,EAAE,OAAOC,OAAO;QACd,IAAI,AAACA,MAAgCC,IAAI,KAAK,UAAU;YACtD,wBAAwB;YACxB,OAAO;gBACLH,YAAY;gBACZvB,MAAMO;YACR;QACF;QACA,MAAM,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GAAG5D,eAAe,0BAA0B,EAAEK,MAAM;gBACxDgD,OAAO,IAAI/C,MAAMyD;YACnB;QACF;QAEAT,MAAMI,EAAE,CAAC,SAAS,CAACtD;YACjBiD,OAAO,IAAI/C,MAAM,CAAC,cAAc,EAAEN,eAAe,UAAU,EAAEI,MAAMG,OAAO,EAAE;QAC9E;IACF;AACF;AAEA;;;;;CAKC,GACD,OAAO,eAAeyD,wBAAwB9E,WAAmB;IAC/D,MAAMG,kBAAkBV,KAAKW,IAAI,CAACJ,aAAa;IAE/C,IAAI;QACF,MAAMK,UAAU,MAAMb,GAAGc,QAAQ,CAACH,iBAAiB;QACnD,MAAMI,cAAcC,KAAKC,KAAK,CAACJ;QAE/B,gCAAgC;QAChC,MAAMW,aAAaT,YAAYI,YAAY,EAAEC,WAAWL,YAAYM,eAAe,EAAED;QACrF,MAAMmE,UAAUxE,YAAYI,YAAY,EAAEqE,QAAQzE,YAAYM,eAAe,EAAEmE;QAE/E,OAAO,CAAC,CAAEhE,CAAAA,cAAc+D,OAAM;IAChC,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,eAAeE,qBAAqBjF,cAAsBC,QAAQC,GAAG,EAAE;IAC5E,IAAI;QACF,yBAAyB;QACzB,MAAMV,GAAGuB,MAAM,CAACtB,KAAKW,IAAI,CAACJ,aAAa;QACvC,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/figma",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.44",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
76
76
|
"build:types": "tsc --project tsconfig.build.json",
|
|
77
77
|
"clean": "rimraf -g \"{dist,*.tsbuildinfo,package}\"",
|
|
78
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,md}\" dist/",
|
|
78
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,md}\" \"src/**/.env.example\" dist/",
|
|
79
79
|
"debug:clear-tokens": "tsx scripts/clear-tokens.ts",
|
|
80
80
|
"debug:expire-token": "tsx scripts/expire-token.ts",
|
|
81
81
|
"debug:get-project-token": "tsx scripts/get-project-token.ts",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Payload, Where } from 'payload';
|
|
2
|
-
/**
|
|
3
|
-
* Builds metadata for Content API request with pathTypes information
|
|
4
|
-
* Returns an object ready to spread into the request body
|
|
5
|
-
* This tells the Content API which paths are arrays/objects for proper query generation
|
|
6
|
-
*/
|
|
7
|
-
export declare function buildPathTypes(payload: Payload, collectionSlug: string, where: undefined | Where): {
|
|
8
|
-
meta?: {
|
|
9
|
-
pathTypes: Record<string, 'array'>;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=buildPathTypes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildPathTypes.d.ts","sourceRoot":"","sources":["../../../src/db-content-api/utilities/buildPathTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AA8JpD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,SAAS,GAAG,KAAK,GACvB;IAAE,IAAI,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAA;CAAE,CA2BnD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/db-content-api/utilities/buildPathTypes.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\n/**\n * Extracts all field paths from a where clause recursively\n */\nfunction extractPathsFromWhere(where: Where, paths: Set<string> = new Set()): Set<string> {\n if (!where || typeof where !== 'object') {\n return paths\n }\n\n // Handle 'and' operator\n if ('and' in where && Array.isArray(where.and)) {\n for (const clause of where.and) {\n extractPathsFromWhere(clause, paths)\n }\n return paths\n }\n\n // Handle 'or' operator\n if ('or' in where && Array.isArray(where.or)) {\n for (const clause of where.or) {\n extractPathsFromWhere(clause, paths)\n }\n return paths\n }\n\n // Handle regular conditions - keys are field paths\n for (const key in where) {\n if (key === 'and' || key === 'or') {\n continue\n }\n\n // Add the path\n paths.add(key)\n\n // Check if the value is a nested where clause (for relationships)\n const value = where[key]\n if (value && typeof value === 'object' && !('equals' in value) && !('in' in value)) {\n // Might be a nested where, recurse\n extractPathsFromWhere(value as Where, paths)\n }\n }\n\n return paths\n}\n\n/**\n * Determines the type of a field based on its configuration\n */\nfunction getFieldType(field: Field): 'array' | null {\n // Array field\n if (field.type === 'array') {\n return 'array'\n }\n\n // Blocks field (array of objects)\n if (field.type === 'blocks') {\n return 'array'\n }\n\n // Relationship field with hasMany (array)\n if (field.type === 'relationship' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Select field with hasMany (array)\n if (field.type === 'select' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Upload field with hasMany (array)\n if (field.type === 'upload' && 'hasMany' in field && field.hasMany) {\n return 'array'\n }\n\n // Objects (group, collapsible, row, tabs) don't need traversal\n return null\n}\n\n/**\n * Finds a field in the collection schema by its path\n * Supports nested paths like \"access.read.users\"\n */\nfunction findFieldByPath(\n payload: Payload,\n collectionSlug: string,\n path: string,\n): Field | undefined {\n const collectionConfig = payload.config.collections.find((c) => c.slug === collectionSlug)\n if (!collectionConfig) {\n return undefined\n }\n\n const pathSegments = path.split('.')\n\n // Walk through the path segments to find the field\n let currentFields = collectionConfig.fields\n let currentField: Field | undefined = undefined\n\n for (let i = 0; i < pathSegments.length; i++) {\n const segment = pathSegments[i]\n\n // First try to find a direct match\n currentField = currentFields.find((f) => 'name' in f && f.name === segment)\n\n // If not found, check if any unnamed container fields (collapsible, row) contain it\n if (!currentField) {\n for (const field of currentFields) {\n if (!('name' in field) || !field.name) {\n // This is an unnamed field, check its contents\n if (\n ('fields' in field && field.type === 'collapsible') ||\n ('fields' in field && field.type === 'row')\n ) {\n currentField = field.fields.find((f) => 'name' in f && f.name === segment)\n if (currentField) {\n break\n }\n } else if ('tabs' in field && field.type === 'tabs') {\n // Check all tabs\n for (const tab of field.tabs) {\n currentField = tab.fields.find((f) => 'name' in f && f.name === segment)\n if (currentField) {\n break\n }\n }\n if (currentField) {\n break\n }\n }\n }\n }\n }\n\n if (!currentField) {\n return undefined\n }\n\n // If we're not at the end, get nested fields\n if (i < pathSegments.length - 1) {\n if (currentField.type === 'group' && 'fields' in currentField) {\n currentFields = currentField.fields\n } else if (currentField.type === 'array' && 'fields' in currentField) {\n currentFields = currentField.fields\n } else if (currentField.type === 'blocks' && 'blocks' in currentField) {\n // For blocks, we can't determine the exact field without knowing the block type\n // Return the blocks field itself\n return currentField\n } else {\n // Field doesn't have nested fields, can't continue\n return undefined\n }\n }\n }\n\n return currentField\n}\n\n/**\n * Builds metadata for Content API request with pathTypes information\n * Returns an object ready to spread into the request body\n * This tells the Content API which paths are arrays/objects for proper query generation\n */\nexport function buildPathTypes(\n payload: Payload,\n collectionSlug: string,\n where: undefined | Where,\n): { meta?: { pathTypes: Record<string, 'array'> } } {\n if (!where) {\n return {}\n }\n\n const pathTypes: Record<string, 'array'> = {}\n const paths = extractPathsFromWhere(where)\n\n for (const path of paths) {\n // For each path, we need to check all segments to see if any intermediate ones are arrays/objects\n const segments = path.split('.')\n\n for (let i = 0; i < segments.length; i++) {\n const partialPath = segments.slice(0, i + 1).join('.')\n const field = findFieldByPath(payload, collectionSlug, partialPath)\n\n if (field) {\n const fieldType = getFieldType(field)\n if (fieldType === 'array') {\n pathTypes[partialPath] = fieldType\n }\n }\n }\n }\n\n // Only include meta if there are pathTypes\n return Object.keys(pathTypes).length > 0 ? { meta: { pathTypes } } : {}\n}\n"],"names":["extractPathsFromWhere","where","paths","Set","Array","isArray","and","clause","or","key","add","value","getFieldType","field","type","hasMany","findFieldByPath","payload","collectionSlug","path","collectionConfig","config","collections","find","c","slug","undefined","pathSegments","split","currentFields","fields","currentField","i","length","segment","f","name","tab","tabs","buildPathTypes","pathTypes","segments","partialPath","slice","join","fieldType","Object","keys","meta"],"mappings":"AAEA;;CAEC,GACD,SAASA,sBAAsBC,KAAY,EAAEC,QAAqB,IAAIC,KAAK;IACzE,IAAI,CAACF,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,wBAAwB;IACxB,IAAI,SAASD,SAASG,MAAMC,OAAO,CAACJ,MAAMK,GAAG,GAAG;QAC9C,KAAK,MAAMC,UAAUN,MAAMK,GAAG,CAAE;YAC9BN,sBAAsBO,QAAQL;QAChC;QACA,OAAOA;IACT;IAEA,uBAAuB;IACvB,IAAI,QAAQD,SAASG,MAAMC,OAAO,CAACJ,MAAMO,EAAE,GAAG;QAC5C,KAAK,MAAMD,UAAUN,MAAMO,EAAE,CAAE;YAC7BR,sBAAsBO,QAAQL;QAChC;QACA,OAAOA;IACT;IAEA,mDAAmD;IACnD,IAAK,MAAMO,OAAOR,MAAO;QACvB,IAAIQ,QAAQ,SAASA,QAAQ,MAAM;YACjC;QACF;QAEA,eAAe;QACfP,MAAMQ,GAAG,CAACD;QAEV,kEAAkE;QAClE,MAAME,QAAQV,KAAK,CAACQ,IAAI;QACxB,IAAIE,SAAS,OAAOA,UAAU,YAAY,CAAE,CAAA,YAAYA,KAAI,KAAM,CAAE,CAAA,QAAQA,KAAI,GAAI;YAClF,mCAAmC;YACnCX,sBAAsBW,OAAgBT;QACxC;IACF;IAEA,OA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