@payloadcms/figma 0.0.1-alpha.33 → 0.0.1-alpha.35
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/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +6 -5
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +14 -9
- package/dist/auth/refresh.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +19 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/build-lambda-zip.d.ts +5 -0
- package/dist/commands/build-lambda-zip.d.ts.map +1 -0
- package/dist/commands/build-lambda-zip.js +19 -0
- package/dist/commands/build-lambda-zip.js.map +1 -0
- package/dist/commands/deploy.js +3 -3
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +3 -1
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +8 -5
- package/dist/commands/login.js.map +1 -1
- package/dist/config/oauth.d.ts +3 -17
- package/dist/config/oauth.d.ts.map +1 -1
- package/dist/config/oauth.js +18 -34
- package/dist/config/oauth.js.map +1 -1
- package/dist/constants.d.ts +7 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -5
- package/dist/constants.js.map +1 -1
- package/dist/db-content-api/README.md +0 -10
- package/dist/db-content-api/generated/content-api-types.d.ts +171 -25
- 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.map +1 -1
- package/dist/db-content-api/index.js +7 -8
- package/dist/db-content-api/index.js.map +1 -1
- package/dist/db-content-api/temp-utilities/sorting.d.ts +2 -6
- package/dist/db-content-api/temp-utilities/sorting.d.ts.map +1 -1
- package/dist/db-content-api/temp-utilities/sorting.js +2 -41
- package/dist/db-content-api/temp-utilities/sorting.js.map +1 -1
- package/dist/db-content-api/utilities/data/index.d.ts +2 -0
- package/dist/db-content-api/utilities/data/index.d.ts.map +1 -1
- package/dist/db-content-api/utilities/data/index.js +7 -0
- package/dist/db-content-api/utilities/data/index.js.map +1 -1
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +12 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts.map +1 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +54 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js.map +1 -0
- package/dist/db-content-api/utilities/joins.d.ts +4 -4
- package/dist/db-content-api/utilities/joins.d.ts.map +1 -1
- package/dist/db-content-api/utilities/joins.js +12 -6
- package/dist/db-content-api/utilities/joins.js.map +1 -1
- package/dist/oauth/strategy/index.d.ts.map +1 -1
- package/dist/oauth/strategy/index.js +33 -12
- package/dist/oauth/strategy/index.js.map +1 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +7 -0
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/asset-collection.d.ts +3 -6
- package/dist/utils/asset-collection.d.ts.map +1 -1
- package/dist/utils/asset-collection.js +10 -34
- package/dist/utils/asset-collection.js.map +1 -1
- package/dist/utils/build-lambda-zip.d.ts +14 -0
- package/dist/utils/build-lambda-zip.d.ts.map +1 -0
- package/dist/utils/build-lambda-zip.js +81 -0
- package/dist/utils/build-lambda-zip.js.map +1 -0
- package/dist/utils/config.js +1 -1
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/env-management.js +2 -2
- package/dist/utils/env-management.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +7 -3
- package/dist/utils/formatter.js.map +1 -1
- package/dist/utils/lambda-config.d.ts +3 -1
- package/dist/utils/lambda-config.d.ts.map +1 -1
- package/dist/utils/lambda-config.js +13 -22
- package/dist/utils/lambda-config.js.map +1 -1
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +2 -0
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +7 -4
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts +7 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +29 -15
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +4 -3
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/typescript-validator.d.ts.map +1 -1
- package/dist/utils/typescript-validator.js +7 -4
- package/dist/utils/typescript-validator.js.map +1 -1
- package/package.json +18 -1
package/dist/utils/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/config.ts"],"sourcesContent":["/**\n * Configuration file management utilities\n */\n\nimport fs from 'fs/promises'\nimport path from 'path'\n\nconst GITIGNORE_FILENAME = '.gitignore'\n\n/**\n * Ensure .gitignore exists and optionally add entries\n *\n * @param projectPath - Path to project directory\n * @param entries - Optional entries to add to .gitignore\n */\nexport async function ensureGitignore(projectPath: string, entries: string[] = []): Promise<void> {\n const gitignorePath = path.join(projectPath, GITIGNORE_FILENAME)\n\n let existingContent = ''\n try {\n existingContent = await fs.readFile(gitignorePath, 'utf-8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw new Error(`Failed to read ${GITIGNORE_FILENAME}: ${(error as Error).message}`)\n }\n }\n\n // Parse existing entries\n const existingLines = existingContent.split(
|
|
1
|
+
{"version":3,"sources":["../../src/utils/config.ts"],"sourcesContent":["/**\n * Configuration file management utilities\n */\n\nimport fs from 'fs/promises'\nimport path from 'path'\n\nconst GITIGNORE_FILENAME = '.gitignore'\n\n/**\n * Ensure .gitignore exists and optionally add entries\n *\n * @param projectPath - Path to project directory\n * @param entries - Optional entries to add to .gitignore\n */\nexport async function ensureGitignore(projectPath: string, entries: string[] = []): Promise<void> {\n const gitignorePath = path.join(projectPath, GITIGNORE_FILENAME)\n\n let existingContent = ''\n try {\n existingContent = await fs.readFile(gitignorePath, 'utf-8')\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n throw new Error(`Failed to read ${GITIGNORE_FILENAME}: ${(error as Error).message}`)\n }\n }\n\n // Parse existing entries\n const existingLines = existingContent.split(/\\r?\\n/).filter((line) => line.trim())\n const existingSet = new Set(existingLines)\n\n // Add new entries that don't exist\n const newEntries = entries.filter((entry) => !existingSet.has(entry))\n\n if (newEntries.length > 0) {\n const newContent = existingContent\n ? `${existingContent.trimEnd()}\\n\\n# Figma CMS\\n${newEntries.join('\\n')}\\n`\n : `# Figma CMS\\n${newEntries.join('\\n')}\\n`\n\n await fs.writeFile(gitignorePath, newContent, 'utf-8')\n }\n}\n"],"names":["fs","path","GITIGNORE_FILENAME","ensureGitignore","projectPath","entries","gitignorePath","join","existingContent","readFile","error","code","Error","message","existingLines","split","filter","line","trim","existingSet","Set","newEntries","entry","has","length","newContent","trimEnd","writeFile"],"mappings":"AAAA;;CAEC,GAED,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB,MAAMC,qBAAqB;AAE3B;;;;;CAKC,GACD,OAAO,eAAeC,gBAAgBC,WAAmB,EAAEC,UAAoB,EAAE;IAC/E,MAAMC,gBAAgBL,KAAKM,IAAI,CAACH,aAAaF;IAE7C,IAAIM,kBAAkB;IACtB,IAAI;QACFA,kBAAkB,MAAMR,GAAGS,QAAQ,CAACH,eAAe;IACrD,EAAE,OAAOI,OAAO;QACd,IAAI,AAACA,MAAgCC,IAAI,KAAK,UAAU;YACtD,MAAM,IAAIC,MAAM,CAAC,eAAe,EAAEV,mBAAmB,EAAE,EAAE,AAACQ,MAAgBG,OAAO,EAAE;QACrF;IACF;IAEA,yBAAyB;IACzB,MAAMC,gBAAgBN,gBAAgBO,KAAK,CAAC,SAASC,MAAM,CAAC,CAACC,OAASA,KAAKC,IAAI;IAC/E,MAAMC,cAAc,IAAIC,IAAIN;IAE5B,mCAAmC;IACnC,MAAMO,aAAahB,QAAQW,MAAM,CAAC,CAACM,QAAU,CAACH,YAAYI,GAAG,CAACD;IAE9D,IAAID,WAAWG,MAAM,GAAG,GAAG;QACzB,MAAMC,aAAajB,kBACf,GAAGA,gBAAgBkB,OAAO,GAAG,iBAAiB,EAAEL,WAAWd,IAAI,CAAC,MAAM,EAAE,CAAC,GACzE,CAAC,aAAa,EAAEc,WAAWd,IAAI,CAAC,MAAM,EAAE,CAAC;QAE7C,MAAMP,GAAG2B,SAAS,CAACrB,eAAemB,YAAY;IAChD;AACF"}
|
|
@@ -10,7 +10,7 @@ import path from 'path';
|
|
|
10
10
|
const envPath = path.join(projectPath, '.env');
|
|
11
11
|
try {
|
|
12
12
|
const contents = await fs.readFile(envPath, 'utf-8');
|
|
13
|
-
const lines = contents.split(
|
|
13
|
+
const lines = contents.split(/\r?\n/);
|
|
14
14
|
for (const line of lines){
|
|
15
15
|
// Skip empty lines and comments
|
|
16
16
|
if (!line.trim() || line.trim().startsWith('#')) {
|
|
@@ -50,7 +50,7 @@ import path from 'path';
|
|
|
50
50
|
} catch {
|
|
51
51
|
// .env doesn't exist, will create it
|
|
52
52
|
}
|
|
53
|
-
const lines = contents.split(
|
|
53
|
+
const lines = contents.split(/\r?\n/);
|
|
54
54
|
const seenKeys = new Set();
|
|
55
55
|
const processedLines = [];
|
|
56
56
|
let keyUpdated = false;
|
|
@@ -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 const lines = contents.split(
|
|
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 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 } 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","path","getEnvVar","projectPath","key","envPath","join","contents","readFile","lines","split","line","trim","startsWith","includes","equalsIndex","indexOf","lineKey","substring","addOrUpdateEnvVar","value","envExists","seenKeys","Set","processedLines","keyUpdated","push","trimmedKey","has","add","writeFile","error","Error","message"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB;;;;;;CAMC,GACD,OAAO,eAAeC,UAAUC,WAAmB,EAAEC,GAAW;IAC9D,MAAMC,UAAUJ,KAAKK,IAAI,CAACH,aAAa;IAEvC,IAAI;QACF,MAAMI,WAAW,MAAMP,GAAGQ,QAAQ,CAACH,SAAS;QAC5C,MAAMI,QAAQF,SAASG,KAAK,CAAC;QAE7B,KAAK,MAAMC,QAAQF,MAAO;YACxB,gCAAgC;YAChC,IAAI,CAACE,KAAKC,IAAI,MAAMD,KAAKC,IAAI,GAAGC,UAAU,CAAC,MAAM;gBAC/C;YACF;YAEA,uBAAuB;YACvB,IAAI,CAACF,KAAKG,QAAQ,CAAC,MAAM;gBACvB;YACF;YAEA,MAAMC,cAAcJ,KAAKK,OAAO,CAAC;YACjC,MAAMC,UAAUN,KAAKO,SAAS,CAAC,GAAGH,aAAaH,IAAI;YAEnD,IAAIK,YAAYb,KAAK;gBACnB,OAAOO,KAAKO,SAAS,CAAC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AAeE,IAAI,CAAC,GAAGtB,IAAI,CAAC,EAAEgB,OAAO;QACvC;QAEA,MAAMpB,GAAG8B,SAAS,CAACzB,SAASmB,eAAelB,IAAI,CAAC,OAAO;IACzD,EAAE,OAAOyB,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,4BAA4B,EAAED,iBAAiBC,QAAQD,MAAME,OAAO,GAAG,iBAAiB;IAE7F;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/utils/formatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/utils/formatter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,YAAY,CAAC,CAgCvB"}
|
package/dist/utils/formatter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import spawn from 'cross-spawn';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
/**
|
|
4
4
|
* Format file with Prettier
|
|
@@ -6,9 +6,13 @@ import path from 'path';
|
|
|
6
6
|
*/ export async function formatFile(filePath, packageManager) {
|
|
7
7
|
return new Promise((resolve)=>{
|
|
8
8
|
try {
|
|
9
|
-
const child = spawn(
|
|
9
|
+
const child = spawn(packageManager, [
|
|
10
|
+
'exec',
|
|
11
|
+
'prettier',
|
|
12
|
+
'--write',
|
|
13
|
+
filePath
|
|
14
|
+
], {
|
|
10
15
|
cwd: path.dirname(filePath),
|
|
11
|
-
shell: true,
|
|
12
16
|
stdio: 'pipe'
|
|
13
17
|
});
|
|
14
18
|
child.on('close', (code)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/formatter.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/utils/formatter.ts"],"sourcesContent":["import spawn from 'cross-spawn'\nimport path from 'path'\n\nimport type { PackageManager } from './package-manager.js'\n\nexport type FormatResult = {\n success: boolean\n warning?: string\n}\n\n/**\n * Format file with Prettier\n * Returns warning if formatting fails but does not throw\n */\nexport async function formatFile(\n filePath: string,\n packageManager: PackageManager,\n): Promise<FormatResult> {\n return new Promise((resolve) => {\n try {\n const child = spawn(packageManager, ['exec', 'prettier', '--write', filePath], {\n cwd: path.dirname(filePath),\n stdio: 'pipe',\n })\n\n child.on('close', (code) => {\n if (code === 0) {\n resolve({ success: true })\n } else {\n resolve({\n success: false,\n warning: 'Could not format file with Prettier',\n })\n }\n })\n\n child.on('error', () => {\n resolve({\n success: false,\n warning: 'Could not format file with Prettier',\n })\n })\n } catch {\n resolve({\n success: false,\n warning: 'Could not format file with Prettier',\n })\n }\n })\n}\n"],"names":["spawn","path","formatFile","filePath","packageManager","Promise","resolve","child","cwd","dirname","stdio","on","code","success","warning"],"mappings":"AAAA,OAAOA,WAAW,cAAa;AAC/B,OAAOC,UAAU,OAAM;AASvB;;;CAGC,GACD,OAAO,eAAeC,WACpBC,QAAgB,EAChBC,cAA8B;IAE9B,OAAO,IAAIC,QAAQ,CAACC;QAClB,IAAI;YACF,MAAMC,QAAQP,MAAMI,gBAAgB;gBAAC;gBAAQ;gBAAY;gBAAWD;aAAS,EAAE;gBAC7EK,KAAKP,KAAKQ,OAAO,CAACN;gBAClBO,OAAO;YACT;YAEAH,MAAMI,EAAE,CAAC,SAAS,CAACC;gBACjB,IAAIA,SAAS,GAAG;oBACdN,QAAQ;wBAAEO,SAAS;oBAAK;gBAC1B,OAAO;oBACLP,QAAQ;wBACNO,SAAS;wBACTC,SAAS;oBACX;gBACF;YACF;YAEAP,MAAMI,EAAE,CAAC,SAAS;gBAChBL,QAAQ;oBACNO,SAAS;oBACTC,SAAS;gBACX;YACF;QACF,EAAE,OAAM;YACNR,QAAQ;gBACNO,SAAS;gBACTC,SAAS;YACX;QACF;IACF;AACF"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { PackageManager } from './package-manager.js';
|
|
1
2
|
/**
|
|
2
3
|
* Apply Lambda-specific modifications to a Payload project
|
|
3
4
|
*
|
|
4
5
|
* @param projectPath - Path to project directory
|
|
6
|
+
* @param packageManager - Package manager to use in scripts (defaults to 'pnpm')
|
|
5
7
|
*/
|
|
6
|
-
export declare function applyLambdaModifications(projectPath: string): Promise<void>;
|
|
8
|
+
export declare function applyLambdaModifications(projectPath: string, packageManager?: PackageManager): Promise<void>;
|
|
7
9
|
//# sourceMappingURL=lambda-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-config.d.ts","sourceRoot":"","sources":["../../src/utils/lambda-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lambda-config.d.ts","sourceRoot":"","sources":["../../src/utils/lambda-config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAS1D;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,cAAuB,GACtC,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|
|
@@ -7,31 +7,19 @@ const RUN_SH_CONTENT = `#!/bin/bash -x
|
|
|
7
7
|
|
|
8
8
|
NODE_ENV=production exec node server.js
|
|
9
9
|
`;
|
|
10
|
-
const BUILD_FOR_LAMBDA_SH_CONTENT = `#!/bin/bash
|
|
11
|
-
|
|
12
|
-
cp -r .next/static .next/standalone/.next/static
|
|
13
|
-
cp run.sh .next/standalone/run.sh
|
|
14
|
-
[ -d public ] && cp -r public .next/standalone/public
|
|
15
|
-
cd .next/standalone
|
|
16
|
-
zip -r --symlinks lambda.zip .
|
|
17
|
-
mv lambda.zip ../..
|
|
18
|
-
`;
|
|
19
10
|
/**
|
|
20
11
|
* Apply Lambda-specific modifications to a Payload project
|
|
21
12
|
*
|
|
22
13
|
* @param projectPath - Path to project directory
|
|
23
|
-
|
|
14
|
+
* @param packageManager - Package manager to use in scripts (defaults to 'pnpm')
|
|
15
|
+
*/ export async function applyLambdaModifications(projectPath, packageManager = 'pnpm') {
|
|
24
16
|
// 1. Create run.sh
|
|
25
17
|
const runShPath = path.join(projectPath, 'run.sh');
|
|
26
18
|
await fs.writeFile(runShPath, RUN_SH_CONTENT, 'utf-8');
|
|
27
|
-
await fs.chmod(runShPath, 0o755);
|
|
28
|
-
// 2.
|
|
29
|
-
const buildShPath = path.join(projectPath, 'build_for_lambda.sh');
|
|
30
|
-
await fs.writeFile(buildShPath, BUILD_FOR_LAMBDA_SH_CONTENT, 'utf-8');
|
|
31
|
-
await fs.chmod(buildShPath, 0o755);
|
|
32
|
-
// 3. Modify next config to add standalone output
|
|
19
|
+
await fs.chmod(runShPath, 0o755);
|
|
20
|
+
// 2. Modify next config to add standalone output
|
|
33
21
|
await addStandaloneToNextConfig(projectPath);
|
|
34
|
-
//
|
|
22
|
+
// 3. Create/update .npmrc
|
|
35
23
|
const npmrcPath = path.join(projectPath, '.npmrc');
|
|
36
24
|
let npmrcContent = '';
|
|
37
25
|
try {
|
|
@@ -44,8 +32,8 @@ mv lambda.zip ../..
|
|
|
44
32
|
npmrcContent += 'node-linker=hoisted\n';
|
|
45
33
|
await fs.writeFile(npmrcPath, npmrcContent, 'utf-8');
|
|
46
34
|
}
|
|
47
|
-
//
|
|
48
|
-
await addLambdaBuildScript(projectPath);
|
|
35
|
+
// 4. Add lambda:buildzip script to package.json
|
|
36
|
+
await addLambdaBuildScript(projectPath, packageManager);
|
|
49
37
|
}
|
|
50
38
|
/**
|
|
51
39
|
* Find the Next.js config file (next.config.js or next.config.mjs)
|
|
@@ -115,7 +103,7 @@ mv lambda.zip ../..
|
|
|
115
103
|
throw new Error(`Could not find Next.js config object in ${path.basename(nextConfigPath)}. ` + `Expected either 'export default { ... }' or 'export default wrapper(configVar, ...)'`);
|
|
116
104
|
}
|
|
117
105
|
const { loc } = targetObjectExpression;
|
|
118
|
-
const lines = content.split(
|
|
106
|
+
const lines = content.split(/\r?\n/);
|
|
119
107
|
// Insert output: 'standalone' as first property
|
|
120
108
|
const insertLine = loc.start.line - 1;
|
|
121
109
|
const insertColumn = loc.start.column + 1 // After opening brace
|
|
@@ -131,14 +119,17 @@ mv lambda.zip ../..
|
|
|
131
119
|
}
|
|
132
120
|
/**
|
|
133
121
|
* Add lambda:buildzip script to package.json
|
|
134
|
-
*/ async function addLambdaBuildScript(projectPath) {
|
|
122
|
+
*/ async function addLambdaBuildScript(projectPath, packageManager) {
|
|
135
123
|
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
136
124
|
const content = await fs.readFile(packageJsonPath, 'utf-8');
|
|
137
125
|
const packageJson = JSON.parse(content);
|
|
138
126
|
if (!packageJson.scripts) {
|
|
139
127
|
packageJson.scripts = {};
|
|
140
128
|
}
|
|
141
|
-
|
|
129
|
+
// Use package manager's run and exec commands
|
|
130
|
+
const runCmd = packageManager === 'npm' ? 'npm run' : packageManager;
|
|
131
|
+
const execCmd = packageManager === 'npm' ? 'npx' : `${packageManager} exec`;
|
|
132
|
+
packageJson.scripts['lambda:buildzip'] = `${runCmd} build && ${execCmd} payloadcms-figma build-lambda-zip`;
|
|
142
133
|
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
|
|
143
134
|
}
|
|
144
135
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/lambda-config.ts"],"sourcesContent":["import { parseModule, Syntax } from 'esprima-next'\nimport fs from 'fs/promises'\nimport path from 'path'\n\nconst RUN_SH_CONTENT = `#!/bin/bash -x\n\n[ ! -d '/tmp/cache' ] && mkdir -p /tmp/cache\n\nNODE_ENV=production exec node server.js\n`\n\nconst BUILD_FOR_LAMBDA_SH_CONTENT = `#!/bin/bash\n\ncp -r .next/static .next/standalone/.next/static\ncp run.sh .next/standalone/run.sh\n[ -d public ] && cp -r public .next/standalone/public\ncd .next/standalone\nzip -r --symlinks lambda.zip .\nmv lambda.zip ../..\n`\n\n/**\n * Apply Lambda-specific modifications to a Payload project\n *\n * @param projectPath - Path to project directory\n */\nexport async function applyLambdaModifications(projectPath: string): Promise<void> {\n // 1. Create run.sh\n const runShPath = path.join(projectPath, 'run.sh')\n await fs.writeFile(runShPath, RUN_SH_CONTENT, 'utf-8')\n await fs.chmod(runShPath, 0o755) // rwxr-xr-x\n\n // 2. Create build_for_lambda.sh\n const buildShPath = path.join(projectPath, 'build_for_lambda.sh')\n await fs.writeFile(buildShPath, BUILD_FOR_LAMBDA_SH_CONTENT, 'utf-8')\n await fs.chmod(buildShPath, 0o755)\n\n // 3. Modify next config to add standalone output\n await addStandaloneToNextConfig(projectPath)\n\n // 4. Create/update .npmrc\n const npmrcPath = path.join(projectPath, '.npmrc')\n let npmrcContent = ''\n\n try {\n npmrcContent = await fs.readFile(npmrcPath, 'utf-8')\n } catch {\n // File doesn't exist, start fresh\n }\n\n if (!npmrcContent.includes('node-linker=hoisted')) {\n npmrcContent += npmrcContent && !npmrcContent.endsWith('\\n') ? '\\n' : ''\n npmrcContent += 'node-linker=hoisted\\n'\n await fs.writeFile(npmrcPath, npmrcContent, 'utf-8')\n }\n\n // 5. Add lambda:buildzip script to package.json\n await addLambdaBuildScript(projectPath)\n}\n\n/**\n * Find the Next.js config file (next.config.js or next.config.mjs)\n *\n * @todo Support TypeScript config files in future\n */\nasync function findNextConfigPath(projectPath: string): Promise<string> {\n const configFiles = ['next.config.js', 'next.config.mjs']\n\n for (const configFile of configFiles) {\n const configPath = path.join(projectPath, configFile)\n try {\n await fs.access(configPath)\n return configPath\n } catch {\n // File doesn't exist, try next one\n }\n }\n\n throw new Error('Could not find next.config.js or next.config.mjs')\n}\n\n/**\n * Add standalone output to Next.js config using AST parsing\n */\nasync function addStandaloneToNextConfig(projectPath: string): Promise<void> {\n const nextConfigPath = await findNextConfigPath(projectPath)\n const content = await fs.readFile(nextConfigPath, 'utf-8')\n\n // Check if output already configured (quick check before parsing)\n if (content.includes('output:')) {\n return // Already configured\n }\n\n const ast = parseModule(content, { loc: true })\n\n // Find export default declaration\n const exportDefaultDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportDefaultDeclaration,\n ) as ExportDefaultDeclaration | undefined\n\n if (!exportDefaultDeclaration?.declaration?.loc) {\n throw new Error(`Could not find export default declaration in ${path.basename(nextConfigPath)}`)\n }\n\n // Find the object expression to modify\n let targetObjectExpression: ObjectExpressionNode | undefined\n\n if (exportDefaultDeclaration.declaration.type === 'ObjectExpression') {\n // Direct export: export default { ... }\n targetObjectExpression = exportDefaultDeclaration.declaration as ObjectExpressionNode\n } else if (exportDefaultDeclaration.declaration.type === 'CallExpression') {\n // Wrapped export: export default withPayload(nextConfig, ...)\n const callExpr = exportDefaultDeclaration.declaration as CallExpressionNode\n const firstArg = callExpr.arguments?.[0]\n\n if (firstArg?.type === 'Identifier') {\n // Find the variable declaration for this identifier\n const configVarName = (firstArg as IdentifierNode).name\n const varDeclaration = ast.body.find((node) => {\n if (node.type === Syntax.VariableDeclaration) {\n const varNode = node as VariableDeclarationNode\n return varNode.declarations?.some(\n (decl) =>\n decl.id?.type === 'Identifier' &&\n (decl.id as IdentifierNode).name === configVarName &&\n decl.init?.type === 'ObjectExpression',\n )\n }\n return false\n }) as undefined | VariableDeclarationNode\n\n if (varDeclaration) {\n const declarator = varDeclaration.declarations?.find(\n (decl) =>\n decl.id?.type === 'Identifier' && (decl.id as IdentifierNode).name === configVarName,\n )\n if (declarator?.init?.type === 'ObjectExpression') {\n targetObjectExpression = declarator.init as ObjectExpressionNode\n }\n }\n }\n }\n\n if (!targetObjectExpression?.loc) {\n throw new Error(\n `Could not find Next.js config object in ${path.basename(nextConfigPath)}. ` +\n `Expected either 'export default { ... }' or 'export default wrapper(configVar, ...)'`,\n )\n }\n\n const { loc } = targetObjectExpression\n const lines = content.split('\\n')\n\n // Insert output: 'standalone' as first property\n const insertLine = loc.start.line - 1\n const insertColumn = loc.start.column + 1 // After opening brace\n\n // Find the content of the line with the opening brace\n const targetLine = lines[insertLine]\n if (!targetLine) {\n throw new Error(`Could not find target line in ${path.basename(nextConfigPath)}`)\n }\n\n lines[insertLine] =\n targetLine.slice(0, insertColumn) + \"\\n output: 'standalone',\" + targetLine.slice(insertColumn)\n\n const modifiedContent = lines.join('\\n')\n await fs.writeFile(nextConfigPath, modifiedContent, 'utf-8')\n}\n\ntype ExportDefaultDeclaration = {\n declaration: {\n arguments?: unknown[]\n loc: {\n end: { column: number; line: number }\n start: { column: number; line: number }\n }\n type: string\n }\n type: string\n}\n\ntype ObjectExpressionNode = {\n loc: {\n end: { column: number; line: number }\n start: { column: number; line: number }\n }\n type: 'ObjectExpression'\n}\n\ntype IdentifierNode = {\n name: string\n type: 'Identifier'\n}\n\ntype CallExpressionNode = {\n arguments?: Array<{ type: string }>\n type: 'CallExpression'\n}\n\ntype VariableDeclarationNode = {\n declarations?: Array<{\n id?: { name?: string; type: string }\n init?: { loc?: ObjectExpressionNode['loc']; type: string }\n }>\n type: 'VariableDeclaration'\n}\n\n/**\n * Add lambda:buildzip script to package.json\n */\nasync function addLambdaBuildScript(projectPath: string): Promise<void> {\n const packageJsonPath = path.join(projectPath, 'package.json')\n const content = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(content)\n\n if (!packageJson.scripts) {\n packageJson.scripts = {}\n }\n\n packageJson.scripts['lambda:buildzip'] = 'npm run build && ./build_for_lambda.sh'\n\n await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\\n', 'utf-8')\n}\n"],"names":["parseModule","Syntax","fs","path","RUN_SH_CONTENT","BUILD_FOR_LAMBDA_SH_CONTENT","applyLambdaModifications","projectPath","runShPath","join","writeFile","chmod","buildShPath","addStandaloneToNextConfig","npmrcPath","npmrcContent","readFile","includes","endsWith","addLambdaBuildScript","findNextConfigPath","configFiles","configFile","configPath","access","Error","nextConfigPath","content","ast","loc","exportDefaultDeclaration","body","find","p","type","ExportDefaultDeclaration","declaration","basename","targetObjectExpression","callExpr","firstArg","arguments","configVarName","name","varDeclaration","node","VariableDeclaration","varNode","declarations","some","decl","id","init","declarator","lines","split","insertLine","start","line","insertColumn","column","targetLine","slice","modifiedContent","packageJsonPath","packageJson","JSON","parse","scripts","stringify"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ,eAAc;AAClD,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB,MAAMC,iBAAiB,CAAC;;;;;AAKxB,CAAC;AAED,MAAMC,8BAA8B,CAAC;;;;;;;;AAQrC,CAAC;AAED;;;;CAIC,GACD,OAAO,eAAeC,yBAAyBC,WAAmB;IAChE,mBAAmB;IACnB,MAAMC,YAAYL,KAAKM,IAAI,CAACF,aAAa;IACzC,MAAML,GAAGQ,SAAS,CAACF,WAAWJ,gBAAgB;IAC9C,MAAMF,GAAGS,KAAK,CAACH,WAAW,QAAO,YAAY;IAE7C,gCAAgC;IAChC,MAAMI,cAAcT,KAAKM,IAAI,CAACF,aAAa;IAC3C,MAAML,GAAGQ,SAAS,CAACE,aAAaP,6BAA6B;IAC7D,MAAMH,GAAGS,KAAK,CAACC,aAAa;IAE5B,iDAAiD;IACjD,MAAMC,0BAA0BN;IAEhC,0BAA0B;IA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MAAMC,aAAa3B,IAAI4B,KAAK,CAACC,IAAI,GAAG;IACpC,MAAMC,eAAe9B,IAAI4B,KAAK,CAACG,MAAM,GAAG,EAAE,sBAAsB;;IAEhE,sDAAsD;IACtD,MAAMC,aAAaP,KAAK,CAACE,WAAW;IACpC,IAAI,CAACK,YAAY;QACf,MAAM,IAAIpC,MAAM,CAAC,8BAA8B,EAAEtB,KAAKkC,QAAQ,CAACX,iBAAiB;IAClF;IAEA4B,KAAK,CAACE,WAAW,GACfK,WAAWC,KAAK,CAAC,GAAGH,gBAAgB,8BAA8BE,WAAWC,KAAK,CAACH;IAErF,MAAMI,kBAAkBT,MAAM7C,IAAI,CAAC;IACnC,MAAMP,GAAGQ,SAAS,CAACgB,gBAAgBqC,iBAAiB;AACtD;AAwCA;;CAEC,GACD,eAAe5C,qBAAqBZ,WAAmB;IACrD,MAAMyD,kBAAkB7D,KAAKM,IAAI,CAACF,aAAa;IAC/C,MAAMoB,UAAU,MAAMzB,GAAGc,QAAQ,CAACgD,iBAAiB;IACnD,MAAMC,cAAcC,KAAKC,KAAK,CAACxC;IAE/B,IAAI,CAACsC,YAAYG,OAAO,EAAE;QACxBH,YAAYG,OAAO,GAAG,CAAC;IACzB;IAEAH,YAAYG,OAAO,CAAC,kBAAkB,GAAG;IAEzC,MAAMlE,GAAGQ,SAAS,CAACsD,iBAAiBE,KAAKG,SAAS,CAACJ,aAAa,MAAM,KAAK,MAAM;AACnF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/lambda-config.ts"],"sourcesContent":["import { parseModule, Syntax } from 'esprima-next'\nimport fs from 'fs/promises'\nimport path from 'path'\n\nimport type { PackageManager } from './package-manager.js'\n\nconst RUN_SH_CONTENT = `#!/bin/bash -x\n\n[ ! -d '/tmp/cache' ] && mkdir -p /tmp/cache\n\nNODE_ENV=production exec node server.js\n`\n\n/**\n * Apply Lambda-specific modifications to a Payload project\n *\n * @param projectPath - Path to project directory\n * @param packageManager - Package manager to use in scripts (defaults to 'pnpm')\n */\nexport async function applyLambdaModifications(\n projectPath: string,\n packageManager: PackageManager = 'pnpm',\n): Promise<void> {\n // 1. Create run.sh\n const runShPath = path.join(projectPath, 'run.sh')\n await fs.writeFile(runShPath, RUN_SH_CONTENT, 'utf-8')\n await fs.chmod(runShPath, 0o755)\n\n // 2. Modify next config to add standalone output\n await addStandaloneToNextConfig(projectPath)\n\n // 3. Create/update .npmrc\n const npmrcPath = path.join(projectPath, '.npmrc')\n let npmrcContent = ''\n\n try {\n npmrcContent = await fs.readFile(npmrcPath, 'utf-8')\n } catch {\n // File doesn't exist, start fresh\n }\n\n if (!npmrcContent.includes('node-linker=hoisted')) {\n npmrcContent += npmrcContent && !npmrcContent.endsWith('\\n') ? '\\n' : ''\n npmrcContent += 'node-linker=hoisted\\n'\n await fs.writeFile(npmrcPath, npmrcContent, 'utf-8')\n }\n\n // 4. Add lambda:buildzip script to package.json\n await addLambdaBuildScript(projectPath, packageManager)\n}\n\n/**\n * Find the Next.js config file (next.config.js or next.config.mjs)\n *\n * @todo Support TypeScript config files in future\n */\nasync function findNextConfigPath(projectPath: string): Promise<string> {\n const configFiles = ['next.config.js', 'next.config.mjs']\n\n for (const configFile of configFiles) {\n const configPath = path.join(projectPath, configFile)\n try {\n await fs.access(configPath)\n return configPath\n } catch {\n // File doesn't exist, try next one\n }\n }\n\n throw new Error('Could not find next.config.js or next.config.mjs')\n}\n\n/**\n * Add standalone output to Next.js config using AST parsing\n */\nasync function addStandaloneToNextConfig(projectPath: string): Promise<void> {\n const nextConfigPath = await findNextConfigPath(projectPath)\n const content = await fs.readFile(nextConfigPath, 'utf-8')\n\n // Check if output already configured (quick check before parsing)\n if (content.includes('output:')) {\n return // Already configured\n }\n\n const ast = parseModule(content, { loc: true })\n\n // Find export default declaration\n const exportDefaultDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportDefaultDeclaration,\n ) as ExportDefaultDeclaration | undefined\n\n if (!exportDefaultDeclaration?.declaration?.loc) {\n throw new Error(`Could not find export default declaration in ${path.basename(nextConfigPath)}`)\n }\n\n // Find the object expression to modify\n let targetObjectExpression: ObjectExpressionNode | undefined\n\n if (exportDefaultDeclaration.declaration.type === 'ObjectExpression') {\n // Direct export: export default { ... }\n targetObjectExpression = exportDefaultDeclaration.declaration as ObjectExpressionNode\n } else if (exportDefaultDeclaration.declaration.type === 'CallExpression') {\n // Wrapped export: export default withPayload(nextConfig, ...)\n const callExpr = exportDefaultDeclaration.declaration as CallExpressionNode\n const firstArg = callExpr.arguments?.[0]\n\n if (firstArg?.type === 'Identifier') {\n // Find the variable declaration for this identifier\n const configVarName = (firstArg as IdentifierNode).name\n const varDeclaration = ast.body.find((node) => {\n if (node.type === Syntax.VariableDeclaration) {\n const varNode = node as VariableDeclarationNode\n return varNode.declarations?.some(\n (decl) =>\n decl.id?.type === 'Identifier' &&\n (decl.id as IdentifierNode).name === configVarName &&\n decl.init?.type === 'ObjectExpression',\n )\n }\n return false\n }) as undefined | VariableDeclarationNode\n\n if (varDeclaration) {\n const declarator = varDeclaration.declarations?.find(\n (decl) =>\n decl.id?.type === 'Identifier' && (decl.id as IdentifierNode).name === configVarName,\n )\n if (declarator?.init?.type === 'ObjectExpression') {\n targetObjectExpression = declarator.init as ObjectExpressionNode\n }\n }\n }\n }\n\n if (!targetObjectExpression?.loc) {\n throw new Error(\n `Could not find Next.js config object in ${path.basename(nextConfigPath)}. ` +\n `Expected either 'export default { ... }' or 'export default wrapper(configVar, ...)'`,\n )\n }\n\n const { loc } = targetObjectExpression\n const lines = content.split(/\\r?\\n/)\n\n // Insert output: 'standalone' as first property\n const insertLine = loc.start.line - 1\n const insertColumn = loc.start.column + 1 // After opening brace\n\n // Find the content of the line with the opening brace\n const targetLine = lines[insertLine]\n if (!targetLine) {\n throw new Error(`Could not find target line in ${path.basename(nextConfigPath)}`)\n }\n\n lines[insertLine] =\n targetLine.slice(0, insertColumn) + \"\\n output: 'standalone',\" + targetLine.slice(insertColumn)\n\n const modifiedContent = lines.join('\\n')\n await fs.writeFile(nextConfigPath, modifiedContent, 'utf-8')\n}\n\ntype ExportDefaultDeclaration = {\n declaration: {\n arguments?: unknown[]\n loc: {\n end: { column: number; line: number }\n start: { column: number; line: number }\n }\n type: string\n }\n type: string\n}\n\ntype ObjectExpressionNode = {\n loc: {\n end: { column: number; line: number }\n start: { column: number; line: number }\n }\n type: 'ObjectExpression'\n}\n\ntype IdentifierNode = {\n name: string\n type: 'Identifier'\n}\n\ntype CallExpressionNode = {\n arguments?: Array<{ type: string }>\n type: 'CallExpression'\n}\n\ntype VariableDeclarationNode = {\n declarations?: Array<{\n id?: { name?: string; type: string }\n init?: { loc?: ObjectExpressionNode['loc']; type: string }\n }>\n type: 'VariableDeclaration'\n}\n\n/**\n * Add lambda:buildzip script to package.json\n */\nasync function addLambdaBuildScript(\n projectPath: string,\n packageManager: PackageManager,\n): Promise<void> {\n const packageJsonPath = path.join(projectPath, 'package.json')\n const content = await fs.readFile(packageJsonPath, 'utf-8')\n const packageJson = JSON.parse(content)\n\n if (!packageJson.scripts) {\n packageJson.scripts = {}\n }\n\n // Use package manager's run and exec commands\n const runCmd = packageManager === 'npm' ? 'npm run' : packageManager\n const execCmd = packageManager === 'npm' ? 'npx' : `${packageManager} exec`\n\n packageJson.scripts['lambda:buildzip'] =\n `${runCmd} build && ${execCmd} payloadcms-figma build-lambda-zip`\n\n await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\\n', 'utf-8')\n}\n"],"names":["parseModule","Syntax","fs","path","RUN_SH_CONTENT","applyLambdaModifications","projectPath","packageManager","runShPath","join","writeFile","chmod","addStandaloneToNextConfig","npmrcPath","npmrcContent","readFile","includes","endsWith","addLambdaBuildScript","findNextConfigPath","configFiles","configFile","configPath","access","Error","nextConfigPath","content","ast","loc","exportDefaultDeclaration","body","find","p","type","ExportDefaultDeclaration","declaration","basename","targetObjectExpression","callExpr","firstArg","arguments","configVarName","name","varDeclaration","node","VariableDeclaration","varNode","declarations","some","decl","id","init","declarator","lines","split","insertLine","start","line","insertColumn","column","targetLine","slice","modifiedContent","packageJsonPath","packageJson","JSON","parse","scripts","runCmd","execCmd","stringify"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ,eAAc;AAClD,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAIvB,MAAMC,iBAAiB,CAAC;;;;;AAKxB,CAAC;AAED;;;;;CAKC,GACD,OAAO,eAAeC,yBACpBC,WAAmB,EACnBC,iBAAiC,MAAM;IAEvC,mBAAmB;IACnB,MAAMC,YAAYL,KAAKM,IAAI,CAACH,aAAa;IACzC,MAAMJ,GAAGQ,SAAS,CAACF,WAAWJ,gBAAgB;IAC9C,MAAMF,GAAGS,KAAK,CAACH,WAAW;IAE1B,iDAAiD;IACjD,MAAMI,0BAA0BN;IAEhC,0BAA0B;IAC1B,MAAMO,YAAYV,KAAKM,IAAI,CAACH,aAAa;IACzC,IAAIQ,eAAe;IAEnB,IAAI;QACFA,eAAe,MAAMZ,GAAGa,QAAQ,CAACF,WAAW;IAC9C,EAAE,OAAM;IACN,kCAAkC;IACpC;IAEA,IAAI,CAACC,aAAaE,QAAQ,CAAC,wBAAwB;QACjDF,gBAAgBA,gBAAgB,CAACA,aAAaG,QAAQ,CAAC,QAAQ,OAAO;QACtEH,gBAAgB;QAChB,MAAMZ,GAAGQ,SAAS,CAACG,WAAWC,cAAc;IAC9C;IAEA,gDAAgD;IAChD,MAAMI,qBAAqBZ,aAAaC;AAC1C;AAEA;;;;CAIC,GACD,eAAeY,mBAAmBb,WAAmB;IACnD,MAAMc,cAAc;QAAC;QAAkB;KAAkB;IAEzD,KAAK,MAAMC,cAAcD,YAAa;QACpC,MAAME,aAAanB,KAAKM,IAAI,CAACH,aAAae;QAC1C,IAAI;YACF,MAAMnB,GAAGqB,MAAM,CAACD;YAChB,OAAOA;QACT,EAAE,OAAM;QACN,mCAAmC;QACrC;IACF;IAEA,MAAM,IAAIE,MAAM;AAClB;AAEA;;CAEC,GACD,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ACsC,YAAYG,OAAO,EAAE;QACxBH,YAAYG,OAAO,GAAG,CAAC;IACzB;IAEA,8CAA8C;IAC9C,MAAMC,SAAS7D,mBAAmB,QAAQ,YAAYA;IACtD,MAAM8D,UAAU9D,mBAAmB,QAAQ,QAAQ,GAAGA,eAAe,KAAK,CAAC;IAE3EyD,YAAYG,OAAO,CAAC,kBAAkB,GACpC,GAAGC,OAAO,UAAU,EAAEC,QAAQ,kCAAkC,CAAC;IAEnE,MAAMnE,GAAGQ,SAAS,CAACqD,iBAAiBE,KAAKK,SAAS,CAACN,aAAa,MAAM,KAAK,MAAM;AACnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/utils/messages.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,wBAAgB,WAAW,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/utils/messages.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,wBAAgB,WAAW,IAAI,IAAI,CA2ClC;AASD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,MAAM,CAiBzF;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAO3C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAgBpF;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
|
package/dist/utils/messages.js
CHANGED
|
@@ -15,11 +15,13 @@ export function helpMessage() {
|
|
|
15
15
|
${pc.cyan('list-tokens')} Show stored token information
|
|
16
16
|
${pc.cyan('init')} Initialize a Figma CMS project
|
|
17
17
|
${pc.cyan('deploy')} Deploy your project to Figma
|
|
18
|
+
${pc.cyan('build-lambda-zip')} Build Lambda deployment zip
|
|
18
19
|
|
|
19
20
|
${pc.bold('OPTIONS')}
|
|
20
21
|
|
|
21
22
|
${pc.dim('-h, --help Show help')}
|
|
22
23
|
${pc.dim('--debug Enable debug logging')}
|
|
24
|
+
${pc.dim('--env <env> Set environment: prod or staging (default: staging)')}
|
|
23
25
|
|
|
24
26
|
${pc.bold('AUTHENTICATION')}
|
|
25
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/messages.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport path from 'path'\nimport pc from 'picocolors'\nimport terminalLink from 'terminal-link'\n\nimport type { PackageManager } from '../types.js'\n\nconst header = (message: string): string => pc.bold(message)\n\nexport function helpMessage(): void {\n console.log(`\n ${pc.bold('USAGE')}\n\n ${pc.dim('@payloadcms/figma <command> [options]')}\n\n ${pc.bold('COMMANDS')}\n\n ${pc.cyan('login')} Authenticate with Figma OAuth2\n ${pc.cyan('logout')} Clear all stored tokens\n ${pc.cyan('list-tokens')} Show stored token information\n ${pc.cyan('init')} Initialize a Figma CMS project\n ${pc.cyan('deploy')} Deploy your project to Figma\n\n ${pc.bold('OPTIONS')}\n\n ${pc.dim('-h, --help Show help')}\n ${pc.dim('--debug Enable debug logging')}\n\n ${pc.bold('AUTHENTICATION')}\n\n ${pc.cyan('@payloadcms/figma login')} Authenticate with Figma\n ${pc.cyan('@payloadcms/figma logout')} Clear all tokens (with confirmation)\n ${pc.cyan('@payloadcms/figma list-tokens')} Display stored OAuth and project tokens\n\n ${pc.bold('INIT COMMAND')}\n\n ${pc.cyan('@payloadcms/figma init --id <content-system-id>')} Initialize project with Content System ID\n ${pc.cyan('@payloadcms/figma init --force')} Force reconfiguration of existing project\n\n ${pc.bold('DEPLOY COMMAND')}\n\n ${pc.cyan('@payloadcms/figma deploy')} Deploy your project to Figma\n ${pc.dim('--yes, -y')} Skip confirmation prompts\n ${pc.dim('--skip-build')} Skip building and use existing build\n\n ${pc.bold('DOCUMENTATION')}\n\n ${createTerminalLink('Getting Started', 'https://payloadcms.com/docs/getting-started/what-is-payload')}\n ${createTerminalLink('Figma CMS Docs', 'https://www.figma.com/developers/api')}\n`)\n}\n\n// Create terminalLink with fallback for unsupported terminals\nfunction createTerminalLink(text: string, url: string) {\n return terminalLink(text, url, {\n fallback: (text, url) => `${text}: ${url}`,\n })\n}\n\nexport function successMessage(projectDir: string, packageManager: PackageManager): string {\n const relativePath = path.relative(process.cwd(), projectDir)\n return `\n${header('Launch Application:')}\n\n - cd ./${relativePath}\n - ${packageManager === 'npm' ? 'npm run' : packageManager} dev or follow directions in README.md\n\n${header('Documentation:')}\n\n - ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n - ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n\n`\n}\n\nexport function successfulNextInit(): string {\n return `- ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n- ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n`\n}\n\nexport function moveMessage(args: { nextAppDir: string; projectDir: string }): string {\n const relativeAppDir = path.relative(process.cwd(), args.nextAppDir)\n return `\n${header('Next Steps:')}\n\nPayload does not support a top-level layout.tsx file in the app directory.\n\n${pc.bold('To continue:')}\n\n- Create a new directory in ./${relativeAppDir} such as ./${relativeAppDir}/${pc.bold('(app)')}\n- Move all files from ./${relativeAppDir} into that directory\n\nIt is recommended to do this from your IDE if your app has existing file references.\n\nOnce moved, rerun the @payloadcms/figma command again.\n`\n}\n\nexport function feedbackOutro(): string {\n return `${pc.bgCyan(pc.black(' Have feedback? '))} Visit us on ${createTerminalLink('GitHub', 'https://github.com/payloadcms/payload')}.`\n}\n"],"names":["path","pc","terminalLink","header","message","bold","helpMessage","console","log","dim","cyan","createTerminalLink","text","url","fallback","successMessage","projectDir","packageManager","relativePath","relative","process","cwd","successfulNextInit","moveMessage","args","relativeAppDir","nextAppDir","feedbackOutro","bgCyan","black"],"mappings":"AAAA,6BAA6B,GAC7B,OAAOA,UAAU,OAAM;AACvB,OAAOC,QAAQ,aAAY;AAC3B,OAAOC,kBAAkB,gBAAe;AAIxC,MAAMC,SAAS,CAACC,UAA4BH,GAAGI,IAAI,CAACD;AAEpD,OAAO,SAASE;IACdC,QAAQC,GAAG,CAAC,CAAC;EACb,EAAEP,GAAGI,IAAI,CAAC,SAAS;;MAEf,EAAEJ,GAAGQ,GAAG,CAAC,yCAAyC;;EAEtD,EAAER,GAAGI,IAAI,CAAC,YAAY;;MAElB,EAAEJ,GAAGS,IAAI,CAAC,SAAS;MACnB,EAAET,GAAGS,IAAI,CAAC,UAAU;MACpB,EAAET,GAAGS,IAAI,CAAC,eAAe;MACzB,EAAET,GAAGS,IAAI,CAAC,QAAQ;MAClB,EAAET,GAAGS,IAAI,CAAC,UAAU;;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/messages.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport path from 'path'\nimport pc from 'picocolors'\nimport terminalLink from 'terminal-link'\n\nimport type { PackageManager } from '../types.js'\n\nconst header = (message: string): string => pc.bold(message)\n\nexport function helpMessage(): void {\n console.log(`\n ${pc.bold('USAGE')}\n\n ${pc.dim('@payloadcms/figma <command> [options]')}\n\n ${pc.bold('COMMANDS')}\n\n ${pc.cyan('login')} Authenticate with Figma OAuth2\n ${pc.cyan('logout')} Clear all stored tokens\n ${pc.cyan('list-tokens')} Show stored token information\n ${pc.cyan('init')} Initialize a Figma CMS project\n ${pc.cyan('deploy')} Deploy your project to Figma\n ${pc.cyan('build-lambda-zip')} Build Lambda deployment zip\n\n ${pc.bold('OPTIONS')}\n\n ${pc.dim('-h, --help Show help')}\n ${pc.dim('--debug Enable debug logging')}\n ${pc.dim('--env <env> Set environment: prod or staging (default: staging)')}\n\n ${pc.bold('AUTHENTICATION')}\n\n ${pc.cyan('@payloadcms/figma login')} Authenticate with Figma\n ${pc.cyan('@payloadcms/figma logout')} Clear all tokens (with confirmation)\n ${pc.cyan('@payloadcms/figma list-tokens')} Display stored OAuth and project tokens\n\n ${pc.bold('INIT COMMAND')}\n\n ${pc.cyan('@payloadcms/figma init --id <content-system-id>')} Initialize project with Content System ID\n ${pc.cyan('@payloadcms/figma init --force')} Force reconfiguration of existing project\n\n ${pc.bold('DEPLOY COMMAND')}\n\n ${pc.cyan('@payloadcms/figma deploy')} Deploy your project to Figma\n ${pc.dim('--yes, -y')} Skip confirmation prompts\n ${pc.dim('--skip-build')} Skip building and use existing build\n\n ${pc.bold('DOCUMENTATION')}\n\n ${createTerminalLink('Getting Started', 'https://payloadcms.com/docs/getting-started/what-is-payload')}\n ${createTerminalLink('Figma CMS Docs', 'https://www.figma.com/developers/api')}\n`)\n}\n\n// Create terminalLink with fallback for unsupported terminals\nfunction createTerminalLink(text: string, url: string) {\n return terminalLink(text, url, {\n fallback: (text, url) => `${text}: ${url}`,\n })\n}\n\nexport function successMessage(projectDir: string, packageManager: PackageManager): string {\n const relativePath = path.relative(process.cwd(), projectDir)\n return `\n${header('Launch Application:')}\n\n - cd ./${relativePath}\n - ${packageManager === 'npm' ? 'npm run' : packageManager} dev or follow directions in README.md\n\n${header('Documentation:')}\n\n - ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n - ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n\n`\n}\n\nexport function successfulNextInit(): string {\n return `- ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n- ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n`\n}\n\nexport function moveMessage(args: { nextAppDir: string; projectDir: string }): string {\n const relativeAppDir = path.relative(process.cwd(), args.nextAppDir)\n return `\n${header('Next Steps:')}\n\nPayload does not support a top-level layout.tsx file in the app directory.\n\n${pc.bold('To continue:')}\n\n- Create a new directory in ./${relativeAppDir} such as ./${relativeAppDir}/${pc.bold('(app)')}\n- Move all files from ./${relativeAppDir} into that directory\n\nIt is recommended to do this from your IDE if your app has existing file references.\n\nOnce moved, rerun the @payloadcms/figma command again.\n`\n}\n\nexport function feedbackOutro(): string {\n return `${pc.bgCyan(pc.black(' Have feedback? '))} Visit us on ${createTerminalLink('GitHub', 'https://github.com/payloadcms/payload')}.`\n}\n"],"names":["path","pc","terminalLink","header","message","bold","helpMessage","console","log","dim","cyan","createTerminalLink","text","url","fallback","successMessage","projectDir","packageManager","relativePath","relative","process","cwd","successfulNextInit","moveMessage","args","relativeAppDir","nextAppDir","feedbackOutro","bgCyan","black"],"mappings":"AAAA,6BAA6B,GAC7B,OAAOA,UAAU,OAAM;AACvB,OAAOC,QAAQ,aAAY;AAC3B,OAAOC,kBAAkB,gBAAe;AAIxC,MAAMC,SAAS,CAACC,UAA4BH,GAAGI,IAAI,CAACD;AAEpD,OAAO,SAASE;IACdC,QAAQC,GAAG,CAAC,CAAC;EACb,EAAEP,GAAGI,IAAI,CAAC,SAAS;;MAEf,EAAEJ,GAAGQ,GAAG,CAAC,yCAAyC;;EAEtD,EAAER,GAAGI,IAAI,CAAC,YAAY;;MAElB,EAAEJ,GAAGS,IAAI,CAAC,SAAS;MACnB,EAAET,GAAGS,IAAI,CAAC,UAAU;MACpB,EAAET,GAAGS,IAAI,CAAC,eAAe;MACzB,EAAET,GAAGS,IAAI,CAAC,QAAQ;MAClB,EAAET,GAAGS,IAAI,CAAC,UAAU;MACpB,EAAET,GAAGS,IAAI,CAAC,oBAAoB;;EAElC,EAAET,GAAGI,IAAI,CAAC,WAAW;;MAEjB,EAAEJ,GAAGQ,GAAG,CAAC,iCAAiC;MAC1C,EAAER,GAAGQ,GAAG,CAAC,4CAA4C;MACrD,EAAER,GAAGQ,GAAG,CAAC,2EAA2E;;EAExF,EAAER,GAAGI,IAAI,CAAC,kBAAkB;;MAExB,EAAEJ,GAAGS,IAAI,CAAC,2BAA2B;MACrC,EAAET,G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E,UAAU;IACnE,OAAO,CAAC;AACV,EAAEvB,OAAO,eAAe;;;;AAIxB,EAAEF,GAAGI,IAAI,CAAC,gBAAgB;;8BAEI,EAAEoB,eAAe,WAAW,EAAEA,eAAe,CAAC,EAAExB,GAAGI,IAAI,CAAC,SAAS;wBACvE,EAAEoB,eAAe;;;;;AAKzC,CAAC;AACD;AAEA,OAAO,SAASE;IACd,OAAO,GAAG1B,GAAG2B,MAAM,CAAC3B,GAAG4B,KAAK,CAAC,qBAAqB,aAAa,EAAElB,mBAAmB,UAAU,yCAAyC,CAAC,CAAC;AAC3I"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;AAUhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,mBAAmB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAkQ7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwC9D"}
|
|
@@ -4,7 +4,7 @@ import { formatFile } from './formatter.js';
|
|
|
4
4
|
import * as log from './log.js';
|
|
5
5
|
import { addFigmaProperty, applyModifications, detectRequiredChanges } from './payload-config-ast.js';
|
|
6
6
|
import { findPayloadConfig } from './payload-config-finder.js';
|
|
7
|
-
import { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js';
|
|
7
|
+
import { checkPackageInstalled, getPayloadVersion, installPackage, uninstallPackage } from './payload-package-check.js';
|
|
8
8
|
import { runTypeScriptCheck } from './typescript-validator.js';
|
|
9
9
|
/**
|
|
10
10
|
* Main orchestrator for payload config modification
|
|
@@ -27,6 +27,9 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
log.debug(`Found config file: ${configPath}`);
|
|
30
|
+
// Get payload version to pin @payloadcms/* dependencies
|
|
31
|
+
const payloadVersion = await getPayloadVersion(projectPath);
|
|
32
|
+
log.debug(`Detected payload version: ${payloadVersion || 'unknown'}`);
|
|
30
33
|
// 2. Check/install @payloadcms/figma package
|
|
31
34
|
const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma');
|
|
32
35
|
if (!isInstalled) {
|
|
@@ -128,7 +131,7 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
128
131
|
if (!hasLexical) {
|
|
129
132
|
log.debug('@payloadcms/richtext-lexical not found, installing...');
|
|
130
133
|
try {
|
|
131
|
-
await installPackage(projectPath, '@payloadcms/richtext-lexical', packageManager);
|
|
134
|
+
await installPackage(projectPath, '@payloadcms/richtext-lexical', packageManager, payloadVersion);
|
|
132
135
|
changes.push('Installed @payloadcms/richtext-lexical (default editor)');
|
|
133
136
|
log.debug('Successfully installed @payloadcms/richtext-lexical');
|
|
134
137
|
} catch (error) {
|
|
@@ -146,7 +149,7 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
146
149
|
if (!hasCloudStorage) {
|
|
147
150
|
log.debug('@payloadcms/plugin-cloud-storage not found, installing...');
|
|
148
151
|
try {
|
|
149
|
-
await installPackage(projectPath, '@payloadcms/plugin-cloud-storage', packageManager);
|
|
152
|
+
await installPackage(projectPath, '@payloadcms/plugin-cloud-storage', packageManager, payloadVersion);
|
|
150
153
|
changes.push('Installed @payloadcms/plugin-cloud-storage');
|
|
151
154
|
log.debug('Successfully installed @payloadcms/plugin-cloud-storage');
|
|
152
155
|
} catch (error) {
|
|
@@ -211,7 +214,7 @@ import { runTypeScriptCheck } from './typescript-validator.js';
|
|
|
211
214
|
*/ export function displayManualInstructions(reason) {
|
|
212
215
|
const leftLineWrap = (message)=>{
|
|
213
216
|
// Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line
|
|
214
|
-
return message.split(
|
|
217
|
+
return message.split(/\r?\n/).map((line, index, arr)=>{
|
|
215
218
|
if (index === 0) {
|
|
216
219
|
return `${pc.dim('┌ ')}${line}`;
|
|
217
220
|
} else if (index === arr.length - 1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/payload-config-modifier.ts"],"sourcesContent":["import pc from 'picocolors'\nimport { Project } from 'ts-morph'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport { formatFile } from './formatter.js'\nimport * as log from './log.js'\nimport {\n addFigmaProperty,\n applyModifications,\n detectRequiredChanges,\n type FigmaPropertyConfig,\n} from './payload-config-ast.js'\nimport { findPayloadConfig } from './payload-config-finder.js'\nimport { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js'\nimport { runTypeScriptCheck } from './typescript-validator.js'\n\nexport type ModificationResult = {\n changes: string[]\n error?: string\n modified: boolean\n success: boolean\n warnings?: string[]\n}\n\n/**\n * Main orchestrator for payload config modification\n * Checks package, detects needed changes, applies modifications\n */\nexport async function ensurePayloadFigmaConfig(\n projectPath: string,\n packageManager: PackageManager,\n figmaConfig?: FigmaPropertyConfig,\n): Promise<ModificationResult> {\n const changes: string[] = []\n const warnings: string[] = []\n let modified = false\n\n try {\n log.debug(`Starting payload config modification for: ${projectPath}`)\n\n // 1. Find config file\n const configPath = await findPayloadConfig(projectPath)\n if (!configPath) {\n log.debug(`Config file not found in: ${projectPath}`)\n return {\n changes: [],\n error: 'payload.config.ts not found in project',\n modified: false,\n success: false,\n }\n }\n\n log.debug(`Found config file: ${configPath}`)\n\n // 2. Check/install @payloadcms/figma package\n const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma')\n if (!isInstalled) {\n log.debug('@payloadcms/figma not installed, attempting installation...')\n try {\n await installPackage(projectPath, '@payloadcms/figma', packageManager)\n changes.push('Installed @payloadcms/figma')\n modified = true\n log.debug('@payloadcms/figma installed successfully')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n return {\n changes: [],\n error: 'Failed to install @payloadcms/figma',\n modified: false,\n success: false,\n }\n }\n } else {\n log.debug('@payloadcms/figma already installed')\n }\n\n // 3. Parse config with ts-morph\n log.debug('Parsing config file with ts-morph...')\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n })\n const sourceFile = project.addSourceFileAtPath(configPath)\n\n // 4. Detect required changes\n log.debug('Detecting required changes...')\n const detection = detectRequiredChanges(sourceFile)\n\n log.debug(\n `Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, hasBuildConfig=${detection.hasBuildConfig}`,\n )\n\n // Handle failure modes\n if (detection.hasAlias) {\n log.debug('Config uses import alias (e.g., buildConfig as X)')\n return {\n changes,\n error: 'Config uses import alias - manual modification required',\n modified,\n success: false,\n }\n }\n\n if (detection.hasBuildConfig === false) {\n log.debug('No buildConfig call found in config file')\n return {\n changes,\n error: 'Config structure not recognized (no buildConfig call found)',\n modified,\n success: false,\n }\n }\n\n // 5. Apply modifications\n log.debug('Applying modifications...')\n const modResult = applyModifications(sourceFile, detection)\n if (modResult.modified) {\n changes.push(...modResult.changes)\n modified = true\n\n log.debug(`Applied ${modResult.changes.length} modifications`)\n }\n\n // 6. Add figma property if config provided and doesn't exist\n if (figmaConfig && !detection.figmaObjectExists) {\n log.debug('Adding figma property to buildConfig...')\n const figmaResult = addFigmaProperty(sourceFile, figmaConfig)\n if (figmaResult.modified) {\n changes.push(...figmaResult.changes)\n modified = true\n log.debug(`Added figma property`)\n } else {\n log.debug('Figma property not added (may already exist)')\n }\n } else if (detection.figmaObjectExists) {\n log.debug('Figma property already exists, skipping')\n }\n\n // Save file if any modifications were made\n if (modified) {\n await sourceFile.save()\n log.debug('Config file saved')\n\n // 7. Handle package management\n const packagesToUninstall: string[] = []\n\n // Uninstall db adapter (buildFigmaConfig provides its own)\n if (detection.dbProperty) {\n packagesToUninstall.push(detection.dbProperty.importSource)\n }\n\n // Uninstall sharp (Figma infrastructure handles image processing)\n if (detection.sharpProperty) {\n packagesToUninstall.push('sharp')\n }\n\n // Ensure lexical is installed if user doesn't have a custom editor\n // (buildFigmaConfig uses lexicalEditor() as default)\n if (!detection.editorProperty) {\n log.debug(\n 'No editor property detected - will ensure lexical is installed for default editor',\n )\n } else if (detection.editorProperty.isDefault) {\n log.debug('Default lexicalEditor() detected - will ensure lexical is installed')\n } else {\n log.debug(\n `Custom editor detected (${detection.editorProperty.importSource}) - skipping lexical installation`,\n )\n }\n\n if (!detection.editorProperty || detection.editorProperty.isDefault) {\n log.debug('Checking if @payloadcms/richtext-lexical is installed...')\n const hasLexical = await checkPackageInstalled(projectPath, '@payloadcms/richtext-lexical')\n if (!hasLexical) {\n log.debug('@payloadcms/richtext-lexical not found, installing...')\n try {\n await installPackage(projectPath, '@payloadcms/richtext-lexical', packageManager)\n changes.push('Installed @payloadcms/richtext-lexical (default editor)')\n log.debug('Successfully installed @payloadcms/richtext-lexical')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/richtext-lexical: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on install error - user can install manually if needed\n warnings.push(\n 'Could not install @payloadcms/richtext-lexical - you may need to install it manually',\n )\n }\n } else {\n log.debug('@payloadcms/richtext-lexical already installed, skipping')\n }\n }\n\n // Ensure cloud-storage is installed (required peer dependency for buildFigmaConfig)\n log.debug('Checking if @payloadcms/plugin-cloud-storage is installed...')\n const hasCloudStorage = await checkPackageInstalled(\n projectPath,\n '@payloadcms/plugin-cloud-storage',\n )\n if (!hasCloudStorage) {\n log.debug('@payloadcms/plugin-cloud-storage not found, installing...')\n try {\n await installPackage(projectPath, '@payloadcms/plugin-cloud-storage', packageManager)\n changes.push('Installed @payloadcms/plugin-cloud-storage')\n log.debug('Successfully installed @payloadcms/plugin-cloud-storage')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/plugin-cloud-storage: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n warnings.push(\n 'Could not install @payloadcms/plugin-cloud-storage - you may need to install it manually',\n )\n }\n } else {\n log.debug('@payloadcms/plugin-cloud-storage already installed, skipping')\n }\n\n if (packagesToUninstall.length > 0) {\n log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`)\n }\n\n for (const pkg of packagesToUninstall) {\n try {\n await uninstallPackage(projectPath, pkg, packageManager)\n changes.push(`Uninstalled ${pkg}`)\n log.debug(`Uninstalled ${pkg}`)\n } catch (error) {\n log.debug(\n `Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on uninstall errors - orphaned package is better than broken config\n }\n }\n\n // 8. Format file\n log.debug('Formatting config file...')\n const formatResult = await formatFile(configPath, packageManager)\n if (!formatResult.success && formatResult.warning) {\n warnings.push(formatResult.warning)\n log.debug(`Formatting warning: ${formatResult.warning}`)\n }\n\n // 9. Run TypeScript validation\n log.debug('Running TypeScript validation...')\n const tsResult = await runTypeScriptCheck(projectPath, packageManager)\n if (!tsResult.success && tsResult.errors.length > 0) {\n warnings.push(\"TypeScript validation found issues - run 'pnpm build' for details\")\n log.debug(`TypeScript validation found ${tsResult.errors.length} issues`)\n }\n } else {\n log.debug('No modifications needed - config already correct')\n }\n\n log.debug('Payload config modification completed successfully')\n\n return {\n changes,\n modified,\n success: true,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n log.debug(\n `Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n if (error instanceof Error && error.stack) {\n log.debug(`Stack trace: ${error.stack}`)\n }\n return {\n changes,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n modified,\n success: false,\n }\n }\n}\n\n/**\n * Display manual configuration instructions\n */\nexport function displayManualInstructions(reason: string): void {\n const leftLineWrap = (message: string): string => {\n // Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line\n return message\n .split('\\n')\n .map((line, index, arr) => {\n if (index === 0) {\n return `${pc.dim('┌ ')}${line}`\n } else if (index === arr.length - 1) {\n return `${pc.dim('└ ')}${line}`\n } else {\n return `${pc.dim('│ ')}${line}`\n }\n })\n .join('\\n')\n }\n\n const message = leftLineWrap(`${pc.cyan(pc.bold('Manual Configuration Required'))}\n\nUnable to automatically modify payload.config.ts\nReason: ${pc.yellow(reason)}\n\n${pc.bold('Required changes:')}\n\n1. Replace buildConfig import:\n ${pc.dim('- FROM: ')}${pc.cyan(\"import { buildConfig } from 'payload'\")}\n ${pc.dim('- TO: ')}${pc.cyan(\"import { buildFigmaConfig } from '@payloadcms/figma'\")}\n\n2. Remove these properties from buildConfig():\n • db\n • secret\n • editor (if using default lexicalEditor())\n\n3. Install package:\n ${pc.cyan('pnpm add @payloadcms/figma')}\n\nThen run: ${pc.cyan('npx @payloadcms/figma init')}`)\n\n // eslint-disable-next-line no-console\n console.log(message)\n}\n"],"names":["pc","Project","formatFile","log","addFigmaProperty","applyModifications","detectRequiredChanges","findPayloadConfig","checkPackageInstalled","installPackage","uninstallPackage","runTypeScriptCheck","ensurePayloadFigmaConfig","projectPath","packageManager","figmaConfig","changes","warnings","modified","debug","configPath","error","success","isInstalled","push","Error","message","project","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPath","detection","needsImportChange","hasAlias","hasBuildConfig","modResult","length","figmaObjectExists","figmaResult","save","packagesToUninstall","dbProperty","importSource","sharpProperty","editorProperty","isDefault","hasLexical","hasCloudStorage","pkg","formatResult","warning","tsResult","errors","undefined","stack","displayManualInstructions","reason","leftLineWrap","split","map","line","index","arr","dim","join","cyan","bold","yellow","console"],"mappings":"AAAA,OAAOA,QAAQ,aAAY;AAC3B,SAASC,OAAO,QAAQ,WAAU;AAIlC,SAASC,UAAU,QAAQ,iBAAgB;AAC3C,YAAYC,SAAS,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,qBAAqB,QAEhB,0BAAyB;AAChC,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,qBAAqB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,6BAA4B;AACpG,SAASC,kBAAkB,QAAQ,4BAA2B;AAU9D;;;CAGC,GACD,OAAO,eAAeC,yBACpBC,WAAmB,EACnBC,cAA8B,EAC9BC,WAAiC;IAEjC,MAAMC,UAAoB,EAAE;IAC5B,MAAMC,WAAqB,EAAE;IAC7B,IAAIC,WAAW;IAEf,IAAI;QACFf,IAAIgB,KAAK,CAAC,CAAC,0CAA0C,EAAEN,aAAa;QAEpE,sBAAsB;QACtB,MAAMO,aAAa,MAAMb,kBAAkBM;QAC3C,IAAI,CAACO,YAAY;YACfjB,IAAIgB,KAAK,CAAC,CAAC,0BAA0B,EAAEN,aAAa;YACpD,OAAO;gBACLG,SAAS,EAAE;gBACXK,OAAO;gBACPH,UAAU;gBACVI,SAAS;YACX;QACF;QAEAnB,IAAIgB,KAAK,CAAC,CAAC,mBAAmB,EAAEC,YAAY;QAE5C,6CAA6C;QAC7C,MAAMG,cAAc,MAAMf,sBAAsBK,aAAa;QAC7D,IAAI,CAACU,aAAa;YAChBpB,IAAIgB,KAAK,CAAC;YACV,IAAI;gBACF,MAAMV,eAAeI,aAAa,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A,QACJgC,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,MAAMC,OAAOC;YACjB,IAAID,UAAU,GAAG;gBACf,OAAO,GAAG7D,GAAG+D,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO,IAAIC,UAAUC,IAAI1B,MAAM,GAAG,GAAG;gBACnC,OAAO,GAAGpC,GAAG+D,GAAG,CAAC,SAASH,MAAM;YAClC,OAAO;gBACL,OAAO,GAAG5D,GAAG+D,GAAG,CAAC,SAASH,MAAM;YAClC;QACF,GACCI,IAAI,CAAC;IACV;IAEA,MAAMtC,UAAU+B,aAAa,GAAGzD,GAAGiE,IAAI,CAACjE,GAAGkE,IAAI,CAAC,kCAAkC;;;QAG5E,EAAElE,GAAGmE,MAAM,CAACX,QAAQ;;AAE5B,EAAExD,GAAGkE,IAAI,CAAC,qBAAqB;;;GAG5B,EAAElE,GAAG+D,GAAG,CAAC,cAAc/D,GAAGiE,IAAI,CAAC,yCAAyC;GACxE,EAAEjE,GAAG+D,GAAG,CAAC,cAAc/D,GAAGiE,IAAI,CAAC,wDAAwD;;;;;;;;GAQvF,EAAEjE,GAAGiE,IAAI,CAAC,8BAA8B;;UAEjC,EAAEjE,GAAGiE,IAAI,CAAC,+BAA+B;IAEjD,sCAAsC;IACtCG,QAAQjE,GAAG,CAACuB;AACd"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/payload-config-modifier.ts"],"sourcesContent":["import pc from 'picocolors'\nimport { Project } from 'ts-morph'\n\nimport type { PackageManager } from './package-manager.js'\n\nimport { formatFile } from './formatter.js'\nimport * as log from './log.js'\nimport {\n addFigmaProperty,\n applyModifications,\n detectRequiredChanges,\n type FigmaPropertyConfig,\n} from './payload-config-ast.js'\nimport { findPayloadConfig } from './payload-config-finder.js'\nimport {\n checkPackageInstalled,\n getPayloadVersion,\n installPackage,\n uninstallPackage,\n} from './payload-package-check.js'\nimport { runTypeScriptCheck } from './typescript-validator.js'\n\nexport type ModificationResult = {\n changes: string[]\n error?: string\n modified: boolean\n success: boolean\n warnings?: string[]\n}\n\n/**\n * Main orchestrator for payload config modification\n * Checks package, detects needed changes, applies modifications\n */\nexport async function ensurePayloadFigmaConfig(\n projectPath: string,\n packageManager: PackageManager,\n figmaConfig?: FigmaPropertyConfig,\n): Promise<ModificationResult> {\n const changes: string[] = []\n const warnings: string[] = []\n let modified = false\n\n try {\n log.debug(`Starting payload config modification for: ${projectPath}`)\n\n // 1. Find config file\n const configPath = await findPayloadConfig(projectPath)\n if (!configPath) {\n log.debug(`Config file not found in: ${projectPath}`)\n return {\n changes: [],\n error: 'payload.config.ts not found in project',\n modified: false,\n success: false,\n }\n }\n\n log.debug(`Found config file: ${configPath}`)\n\n // Get payload version to pin @payloadcms/* dependencies\n const payloadVersion = await getPayloadVersion(projectPath)\n log.debug(`Detected payload version: ${payloadVersion || 'unknown'}`)\n\n // 2. Check/install @payloadcms/figma package\n const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma')\n if (!isInstalled) {\n log.debug('@payloadcms/figma not installed, attempting installation...')\n try {\n await installPackage(projectPath, '@payloadcms/figma', packageManager)\n changes.push('Installed @payloadcms/figma')\n modified = true\n log.debug('@payloadcms/figma installed successfully')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/figma: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n return {\n changes: [],\n error: 'Failed to install @payloadcms/figma',\n modified: false,\n success: false,\n }\n }\n } else {\n log.debug('@payloadcms/figma already installed')\n }\n\n // 3. Parse config with ts-morph\n log.debug('Parsing config file with ts-morph...')\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n })\n const sourceFile = project.addSourceFileAtPath(configPath)\n\n // 4. Detect required changes\n log.debug('Detecting required changes...')\n const detection = detectRequiredChanges(sourceFile)\n\n log.debug(\n `Detection results: needsImportChange=${detection.needsImportChange}, hasAlias=${detection.hasAlias}, hasBuildConfig=${detection.hasBuildConfig}`,\n )\n\n // Handle failure modes\n if (detection.hasAlias) {\n log.debug('Config uses import alias (e.g., buildConfig as X)')\n return {\n changes,\n error: 'Config uses import alias - manual modification required',\n modified,\n success: false,\n }\n }\n\n if (detection.hasBuildConfig === false) {\n log.debug('No buildConfig call found in config file')\n return {\n changes,\n error: 'Config structure not recognized (no buildConfig call found)',\n modified,\n success: false,\n }\n }\n\n // 5. Apply modifications\n log.debug('Applying modifications...')\n const modResult = applyModifications(sourceFile, detection)\n if (modResult.modified) {\n changes.push(...modResult.changes)\n modified = true\n\n log.debug(`Applied ${modResult.changes.length} modifications`)\n }\n\n // 6. Add figma property if config provided and doesn't exist\n if (figmaConfig && !detection.figmaObjectExists) {\n log.debug('Adding figma property to buildConfig...')\n const figmaResult = addFigmaProperty(sourceFile, figmaConfig)\n if (figmaResult.modified) {\n changes.push(...figmaResult.changes)\n modified = true\n log.debug(`Added figma property`)\n } else {\n log.debug('Figma property not added (may already exist)')\n }\n } else if (detection.figmaObjectExists) {\n log.debug('Figma property already exists, skipping')\n }\n\n // Save file if any modifications were made\n if (modified) {\n await sourceFile.save()\n log.debug('Config file saved')\n\n // 7. Handle package management\n const packagesToUninstall: string[] = []\n\n // Uninstall db adapter (buildFigmaConfig provides its own)\n if (detection.dbProperty) {\n packagesToUninstall.push(detection.dbProperty.importSource)\n }\n\n // Uninstall sharp (Figma infrastructure handles image processing)\n if (detection.sharpProperty) {\n packagesToUninstall.push('sharp')\n }\n\n // Ensure lexical is installed if user doesn't have a custom editor\n // (buildFigmaConfig uses lexicalEditor() as default)\n if (!detection.editorProperty) {\n log.debug(\n 'No editor property detected - will ensure lexical is installed for default editor',\n )\n } else if (detection.editorProperty.isDefault) {\n log.debug('Default lexicalEditor() detected - will ensure lexical is installed')\n } else {\n log.debug(\n `Custom editor detected (${detection.editorProperty.importSource}) - skipping lexical installation`,\n )\n }\n\n if (!detection.editorProperty || detection.editorProperty.isDefault) {\n log.debug('Checking if @payloadcms/richtext-lexical is installed...')\n const hasLexical = await checkPackageInstalled(projectPath, '@payloadcms/richtext-lexical')\n if (!hasLexical) {\n log.debug('@payloadcms/richtext-lexical not found, installing...')\n try {\n await installPackage(\n projectPath,\n '@payloadcms/richtext-lexical',\n packageManager,\n payloadVersion,\n )\n changes.push('Installed @payloadcms/richtext-lexical (default editor)')\n log.debug('Successfully installed @payloadcms/richtext-lexical')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/richtext-lexical: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on install error - user can install manually if needed\n warnings.push(\n 'Could not install @payloadcms/richtext-lexical - you may need to install it manually',\n )\n }\n } else {\n log.debug('@payloadcms/richtext-lexical already installed, skipping')\n }\n }\n\n // Ensure cloud-storage is installed (required peer dependency for buildFigmaConfig)\n log.debug('Checking if @payloadcms/plugin-cloud-storage is installed...')\n const hasCloudStorage = await checkPackageInstalled(\n projectPath,\n '@payloadcms/plugin-cloud-storage',\n )\n if (!hasCloudStorage) {\n log.debug('@payloadcms/plugin-cloud-storage not found, installing...')\n try {\n await installPackage(\n projectPath,\n '@payloadcms/plugin-cloud-storage',\n packageManager,\n payloadVersion,\n )\n changes.push('Installed @payloadcms/plugin-cloud-storage')\n log.debug('Successfully installed @payloadcms/plugin-cloud-storage')\n } catch (error) {\n log.debug(\n `Failed to install @payloadcms/plugin-cloud-storage: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n warnings.push(\n 'Could not install @payloadcms/plugin-cloud-storage - you may need to install it manually',\n )\n }\n } else {\n log.debug('@payloadcms/plugin-cloud-storage already installed, skipping')\n }\n\n if (packagesToUninstall.length > 0) {\n log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`)\n }\n\n for (const pkg of packagesToUninstall) {\n try {\n await uninstallPackage(projectPath, pkg, packageManager)\n changes.push(`Uninstalled ${pkg}`)\n log.debug(`Uninstalled ${pkg}`)\n } catch (error) {\n log.debug(\n `Failed to uninstall ${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n // Don't fail on uninstall errors - orphaned package is better than broken config\n }\n }\n\n // 8. Format file\n log.debug('Formatting config file...')\n const formatResult = await formatFile(configPath, packageManager)\n if (!formatResult.success && formatResult.warning) {\n warnings.push(formatResult.warning)\n log.debug(`Formatting warning: ${formatResult.warning}`)\n }\n\n // 9. Run TypeScript validation\n log.debug('Running TypeScript validation...')\n const tsResult = await runTypeScriptCheck(projectPath, packageManager)\n if (!tsResult.success && tsResult.errors.length > 0) {\n warnings.push(\"TypeScript validation found issues - run 'pnpm build' for details\")\n log.debug(`TypeScript validation found ${tsResult.errors.length} issues`)\n }\n } else {\n log.debug('No modifications needed - config already correct')\n }\n\n log.debug('Payload config modification completed successfully')\n\n return {\n changes,\n modified,\n success: true,\n warnings: warnings.length > 0 ? warnings : undefined,\n }\n } catch (error) {\n log.debug(\n `Unexpected error in ensurePayloadFigmaConfig: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n if (error instanceof Error && error.stack) {\n log.debug(`Stack trace: ${error.stack}`)\n }\n return {\n changes,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n modified,\n success: false,\n }\n }\n}\n\n/**\n * Display manual configuration instructions\n */\nexport function displayManualInstructions(reason: string): void {\n const leftLineWrap = (message: string): string => {\n // Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line\n return message\n .split(/\\r?\\n/)\n .map((line, index, arr) => {\n if (index === 0) {\n return `${pc.dim('┌ ')}${line}`\n } else if (index === arr.length - 1) {\n return `${pc.dim('└ ')}${line}`\n } else {\n return `${pc.dim('│ ')}${line}`\n }\n })\n .join('\\n')\n }\n\n const message = leftLineWrap(`${pc.cyan(pc.bold('Manual Configuration Required'))}\n\nUnable to automatically modify payload.config.ts\nReason: ${pc.yellow(reason)}\n\n${pc.bold('Required changes:')}\n\n1. Replace buildConfig import:\n ${pc.dim('- FROM: ')}${pc.cyan(\"import { buildConfig } from 'payload'\")}\n ${pc.dim('- TO: ')}${pc.cyan(\"import { buildFigmaConfig } from '@payloadcms/figma'\")}\n\n2. Remove these properties from buildConfig():\n • db\n • secret\n • editor (if using default lexicalEditor())\n\n3. Install package:\n ${pc.cyan('pnpm add @payloadcms/figma')}\n\nThen run: ${pc.cyan('npx @payloadcms/figma init')}`)\n\n // eslint-disable-next-line no-console\n console.log(message)\n}\n"],"names":["pc","Project","formatFile","log","addFigmaProperty","applyModifications","detectRequiredChanges","findPayloadConfig","checkPackageInstalled","getPayloadVersion","installPackage","uninstallPackage","runTypeScriptCheck","ensurePayloadFigmaConfig","projectPath","packageManager","figmaConfig","changes","warnings","modified","debug","configPath","error","success","payloadVersion","isInstalled","push","Error","message","project","skipAddingFilesFromTsConfig","sourceFile","addSourceFileAtPath","detection","needsImportChange","hasAlias","hasBuildConfig","modResult","length","figmaObjectExists","figmaResult","save","packagesToUninstall","dbProperty","importSource","sharpProperty","editorProperty","isDefault","hasLexical","hasCloudStorage","pkg","formatResult","warning","tsResult","errors","undefined","stack","displayManualInstructions","reason","leftLineWrap","split","map","line","index","arr","dim","join","cyan","bold","yellow","console"],"mappings":"AAAA,OAAOA,QAAQ,aAAY;AAC3B,SAASC,OAAO,QAAQ,WAAU;AAIlC,SAASC,UAAU,QAAQ,iBAAgB;AAC3C,YAAYC,SAAS,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,qBAAqB,QAEhB,0BAAyB;AAChC,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SACEC,qBAAqB,EACrBC,iBAAiB,EACjBC,cAAc,EACdC,gBAAgB,QACX,6BAA4B;AACnC,SAASC,kBAAkB,QAAQ,4BAA2B;AAU9D;;;CAGC,GACD,OAAO,eAAeC,yBACpBC,WAAmB,EACnBC,cAA8B,EAC9BC,WAAiC;IAEjC,MAAMC,UAAoB,EAAE;IAC5B,MAAMC,WAAqB,EAAE;IAC7B,IAAIC,WAAW;IAEf,IAAI;QACFhB,IAAIiB,KAAK,CAAC,CAAC,0CAA0C,EAAEN,aAAa;QAEpE,sBAAsB;QACtB,MAAMO,aAAa,MAAMd,kBAAkBO;QAC3C,IAAI,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AC,+BAA+B;IAEjD,sCAAsC;IACtCG,QAAQnE,GAAG,CAACyB;AACd"}
|
|
@@ -3,10 +3,16 @@ import type { PackageManager } from './package-manager.js';
|
|
|
3
3
|
* Check if a package is installed in dependencies (not devDependencies)
|
|
4
4
|
*/
|
|
5
5
|
export declare function checkPackageInstalled(projectPath: string, packageName: string): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* Get the payload version from project's package.json (without range specifiers)
|
|
8
|
+
* Returns the clean version number (e.g., "3.71.1") or undefined if not found
|
|
9
|
+
*/
|
|
10
|
+
export declare function getPayloadVersion(projectPath: string): Promise<string | undefined>;
|
|
6
11
|
/**
|
|
7
12
|
* Install a package as a production dependency
|
|
13
|
+
* @param version - Version to install (without caret). Defaults to 'latest'.
|
|
8
14
|
*/
|
|
9
|
-
export declare function installPackage(projectPath: string, packageName: string, packageManager: PackageManager): Promise<void>;
|
|
15
|
+
export declare function installPackage(projectPath: string, packageName: string, packageManager: PackageManager, version?: string): Promise<void>;
|
|
10
16
|
/**
|
|
11
17
|
* Uninstall a package
|
|
12
18
|
* Does not throw on failure - orphaned package is better than broken config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-package-check.d.ts","sourceRoot":"","sources":["../../src/utils/payload-package-check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAelB;AAED
|
|
1
|
+
{"version":3,"file":"payload-package-check.d.ts","sourceRoot":"","sources":["../../src/utils/payload-package-check.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAelB;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAcxF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,OAAO,GAAE,MAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CA6Cf;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,OAAO,CAAC,CAuClB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import spawn from 'cross-spawn';
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import * as log from './log.js';
|
|
@@ -18,25 +18,43 @@ import * as log from './log.js';
|
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the payload version from project's package.json (without range specifiers)
|
|
23
|
+
* Returns the clean version number (e.g., "3.71.1") or undefined if not found
|
|
24
|
+
*/ export async function getPayloadVersion(projectPath) {
|
|
25
|
+
try {
|
|
26
|
+
const pkgJsonPath = path.join(projectPath, 'package.json');
|
|
27
|
+
const pkgJsonContent = await fs.readFile(pkgJsonPath, 'utf-8');
|
|
28
|
+
const pkgJson = JSON.parse(pkgJsonContent);
|
|
29
|
+
const rawVersion = pkgJson.dependencies?.payload || pkgJson.devDependencies?.payload;
|
|
30
|
+
if (!rawVersion) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
// Strip range specifiers (^, ~, >=, etc.) to get clean version
|
|
34
|
+
return rawVersion.replace(/^[\^~>=<]+/, '');
|
|
35
|
+
} catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
21
39
|
/**
|
|
22
40
|
* Install a package as a production dependency
|
|
23
|
-
|
|
41
|
+
* @param version - Version to install (without caret). Defaults to 'latest'.
|
|
42
|
+
*/ export async function installPackage(projectPath, packageName, packageManager, version = 'latest') {
|
|
24
43
|
return new Promise((resolve, reject)=>{
|
|
25
44
|
const command = packageManager;
|
|
45
|
+
const packageSpec = `${packageName}@${version}`;
|
|
26
46
|
const args = [
|
|
27
47
|
'add',
|
|
28
|
-
|
|
48
|
+
packageSpec
|
|
29
49
|
];
|
|
30
50
|
// npm uses 'install' instead of 'add'
|
|
31
51
|
if (packageManager === 'npm') {
|
|
32
52
|
args[0] = 'install';
|
|
33
53
|
}
|
|
34
|
-
|
|
35
|
-
log.debug(`Running: ${fullCommand} in ${projectPath}`);
|
|
54
|
+
log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
36
55
|
let stderr = '';
|
|
37
|
-
const child = spawn(
|
|
56
|
+
const child = spawn(command, args, {
|
|
38
57
|
cwd: projectPath,
|
|
39
|
-
shell: true,
|
|
40
58
|
stdio: 'pipe'
|
|
41
59
|
});
|
|
42
60
|
// Capture stderr for debug logging
|
|
@@ -77,11 +95,9 @@ import * as log from './log.js';
|
|
|
77
95
|
if (packageManager === 'npm') {
|
|
78
96
|
args[0] = 'uninstall';
|
|
79
97
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const child = spawn(fullCommand, {
|
|
98
|
+
log.debug(`Running: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
99
|
+
const child = spawn(command, args, {
|
|
83
100
|
cwd: projectPath,
|
|
84
|
-
shell: true,
|
|
85
101
|
stdio: 'pipe'
|
|
86
102
|
});
|
|
87
103
|
child.on('close', (code)=>{
|
|
@@ -106,12 +122,10 @@ import * as log from './log.js';
|
|
|
106
122
|
'run',
|
|
107
123
|
scriptName
|
|
108
124
|
];
|
|
109
|
-
|
|
110
|
-
log.debug(`Running script: ${fullCommand} in ${projectPath}`);
|
|
125
|
+
log.debug(`Running script: ${command} ${args.join(' ')} in ${projectPath}`);
|
|
111
126
|
let stderr = '';
|
|
112
|
-
const child = spawn(
|
|
127
|
+
const child = spawn(command, args, {
|
|
113
128
|
cwd: projectPath,
|
|
114
|
-
shell: true,
|
|
115
129
|
stdio: 'pipe'
|
|
116
130
|
});
|
|
117
131
|
if (child.stderr) {
|