@payloadcms/figma 0.0.1-alpha.42 → 0.0.1-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/dist/api/control-plane.d.ts +1 -22
  2. package/dist/api/control-plane.d.ts.map +1 -1
  3. package/dist/api/control-plane.js +22 -55
  4. package/dist/api/control-plane.js.map +1 -1
  5. package/dist/api/figma-api.d.ts.map +1 -1
  6. package/dist/api/figma-api.js +21 -45
  7. package/dist/api/figma-api.js.map +1 -1
  8. package/dist/auth/callback-server.d.ts.map +1 -1
  9. package/dist/auth/callback-server.js +1 -2
  10. package/dist/auth/callback-server.js.map +1 -1
  11. package/dist/auth/crypto-utils.d.ts.map +1 -1
  12. package/dist/auth/crypto-utils.js +5 -5
  13. package/dist/auth/crypto-utils.js.map +1 -1
  14. package/dist/auth/jwt-validator.d.ts +1 -2
  15. package/dist/auth/jwt-validator.d.ts.map +1 -1
  16. package/dist/auth/jwt-validator.js +2 -2
  17. package/dist/auth/jwt-validator.js.map +1 -1
  18. package/dist/auth/oauth-flow.d.ts +1 -1
  19. package/dist/auth/oauth-flow.d.ts.map +1 -1
  20. package/dist/auth/oauth-flow.js +11 -15
  21. package/dist/auth/oauth-flow.js.map +1 -1
  22. package/dist/auth/project-token.d.ts.map +1 -1
  23. package/dist/auth/project-token.js +4 -9
  24. package/dist/auth/project-token.js.map +1 -1
  25. package/dist/auth/refresh.d.ts +1 -2
  26. package/dist/auth/refresh.d.ts.map +1 -1
  27. package/dist/auth/refresh.js +12 -25
  28. package/dist/auth/refresh.js.map +1 -1
  29. package/dist/auth/token-store.d.ts +0 -12
  30. package/dist/auth/token-store.d.ts.map +1 -1
  31. package/dist/auth/token-store.js +5 -28
  32. package/dist/auth/token-store.js.map +1 -1
  33. package/dist/auth/types.d.ts +4 -7
  34. package/dist/auth/types.d.ts.map +1 -1
  35. package/dist/auth/types.js.map +1 -1
  36. package/dist/cli.d.ts.map +1 -1
  37. package/dist/cli.js +6 -39
  38. package/dist/cli.js.map +1 -1
  39. package/dist/commands/deploy.d.ts +0 -4
  40. package/dist/commands/deploy.d.ts.map +1 -1
  41. package/dist/commands/deploy.js +129 -72
  42. package/dist/commands/deploy.js.map +1 -1
  43. package/dist/commands/init.d.ts +5 -1
  44. package/dist/commands/init.d.ts.map +1 -1
  45. package/dist/commands/init.js +85 -105
  46. package/dist/commands/init.js.map +1 -1
  47. package/dist/commands/list-tokens.d.ts +3 -3
  48. package/dist/commands/list-tokens.d.ts.map +1 -1
  49. package/dist/commands/list-tokens.js +7 -22
  50. package/dist/commands/list-tokens.js.map +1 -1
  51. package/dist/commands/login.d.ts +1 -8
  52. package/dist/commands/login.d.ts.map +1 -1
  53. package/dist/commands/login.js +12 -30
  54. package/dist/commands/login.js.map +1 -1
  55. package/dist/commands/logout.d.ts +4 -5
  56. package/dist/commands/logout.d.ts.map +1 -1
  57. package/dist/commands/logout.js +13 -56
  58. package/dist/commands/logout.js.map +1 -1
  59. package/dist/config/oauth.d.ts +14 -4
  60. package/dist/config/oauth.d.ts.map +1 -1
  61. package/dist/config/oauth.js +40 -19
  62. package/dist/config/oauth.js.map +1 -1
  63. package/dist/constants.d.ts +18 -26
  64. package/dist/constants.d.ts.map +1 -1
  65. package/dist/constants.js +20 -34
  66. package/dist/constants.js.map +1 -1
  67. package/dist/exports/client.d.ts +0 -1
  68. package/dist/exports/client.d.ts.map +1 -1
  69. package/dist/exports/client.js +0 -1
  70. package/dist/exports/client.js.map +1 -1
  71. package/dist/index.d.ts +1 -2
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +1 -3
  74. package/dist/index.js.map +1 -1
  75. package/dist/oauth/components/LoginButton/index.d.ts.map +1 -1
  76. package/dist/oauth/components/LoginButton/index.js +6 -50
  77. package/dist/oauth/components/LoginButton/index.js.map +1 -1
  78. package/dist/oauth/components/LoginButton/index.scss +3 -50
  79. package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -1
  80. package/dist/oauth/components/LogoutButton/index.js +4 -5
  81. package/dist/oauth/components/LogoutButton/index.js.map +1 -1
  82. package/dist/oauth/defaults.d.ts.map +1 -1
  83. package/dist/oauth/defaults.js +5 -29
  84. package/dist/oauth/defaults.js.map +1 -1
  85. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
  86. package/dist/oauth/endpoints/getLoginEndpoint.js +11 -21
  87. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
  88. package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -1
  89. package/dist/oauth/endpoints/getLogoutEndpoint.js +4 -7
  90. package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -1
  91. package/dist/oauth/index.d.ts.map +1 -1
  92. package/dist/oauth/index.js +13 -40
  93. package/dist/oauth/index.js.map +1 -1
  94. package/dist/oauth/strategy/index.d.ts +2 -0
  95. package/dist/oauth/strategy/index.d.ts.map +1 -1
  96. package/dist/oauth/strategy/index.js +15 -38
  97. package/dist/oauth/strategy/index.js.map +1 -1
  98. package/dist/oauth/types.d.ts +6 -6
  99. package/dist/oauth/types.d.ts.map +1 -1
  100. package/dist/oauth/types.js.map +1 -1
  101. package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -1
  102. package/dist/oauth/utilities/createCookieOptions.js.map +1 -1
  103. package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
  104. package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
  105. package/dist/oauth/utilities/getAdminPath.js +9 -0
  106. package/dist/oauth/utilities/getAdminPath.js.map +1 -0
  107. package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -1
  108. package/dist/oauth/utilities/refreshTokens.js +1 -1
  109. package/dist/oauth/utilities/refreshTokens.js.map +1 -1
  110. package/dist/plugin/build-config.d.ts +4 -21
  111. package/dist/plugin/build-config.d.ts.map +1 -1
  112. package/dist/plugin/build-config.js +7 -113
  113. package/dist/plugin/build-config.js.map +1 -1
  114. package/dist/types.d.ts +0 -1
  115. package/dist/types.d.ts.map +1 -1
  116. package/dist/types.js.map +1 -1
  117. package/dist/utils/asset-collection.d.ts +6 -3
  118. package/dist/utils/asset-collection.d.ts.map +1 -1
  119. package/dist/utils/asset-collection.js +34 -10
  120. package/dist/utils/asset-collection.js.map +1 -1
  121. package/dist/utils/config.js +1 -1
  122. package/dist/utils/config.js.map +1 -1
  123. package/dist/utils/env-management.d.ts +8 -9
  124. package/dist/utils/env-management.d.ts.map +1 -1
  125. package/dist/utils/env-management.js +74 -73
  126. package/dist/utils/env-management.js.map +1 -1
  127. package/dist/utils/formatter.d.ts.map +1 -1
  128. package/dist/utils/formatter.js +5 -3
  129. package/dist/utils/formatter.js.map +1 -1
  130. package/dist/utils/lambda-config.d.ts +1 -3
  131. package/dist/utils/lambda-config.d.ts.map +1 -1
  132. package/dist/utils/lambda-config.js +32 -38
  133. package/dist/utils/lambda-config.js.map +1 -1
  134. package/dist/utils/messages.js +8 -8
  135. package/dist/utils/messages.js.map +1 -1
  136. package/dist/utils/payload-config-ast.d.ts +3 -22
  137. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  138. package/dist/utils/payload-config-ast.js +31 -89
  139. package/dist/utils/payload-config-ast.js.map +1 -1
  140. package/dist/utils/payload-config-finder.d.ts +2 -2
  141. package/dist/utils/payload-config-finder.d.ts.map +1 -1
  142. package/dist/utils/payload-config-finder.js +9 -48
  143. package/dist/utils/payload-config-finder.js.map +1 -1
  144. package/dist/utils/payload-config-modifier.d.ts.map +1 -1
  145. package/dist/utils/payload-config-modifier.js +6 -54
  146. package/dist/utils/payload-config-modifier.js.map +1 -1
  147. package/dist/utils/payload-package-check.d.ts +1 -12
  148. package/dist/utils/payload-package-check.d.ts.map +1 -1
  149. package/dist/utils/payload-package-check.js +5 -63
  150. package/dist/utils/payload-package-check.js.map +1 -1
  151. package/dist/utils/project.d.ts.map +1 -1
  152. package/dist/utils/project.js +5 -8
  153. package/dist/utils/project.js.map +1 -1
  154. package/dist/utils/s3-upload.d.ts +1 -0
  155. package/dist/utils/s3-upload.d.ts.map +1 -1
  156. package/dist/utils/s3-upload.js +3 -10
  157. package/dist/utils/s3-upload.js.map +1 -1
  158. package/dist/utils/token-display.d.ts.map +1 -1
  159. package/dist/utils/token-display.js +5 -11
  160. package/dist/utils/token-display.js.map +1 -1
  161. package/dist/utils/typescript-validator.d.ts.map +1 -1
  162. package/dist/utils/typescript-validator.js +6 -4
  163. package/dist/utils/typescript-validator.js.map +1 -1
  164. package/package.json +9 -27
  165. package/dist/commands/build-lambda-zip.d.ts +0 -5
  166. package/dist/commands/build-lambda-zip.d.ts.map +0 -1
  167. package/dist/commands/build-lambda-zip.js +0 -19
  168. package/dist/commands/build-lambda-zip.js.map +0 -1
  169. package/dist/db-content-api/README.md +0 -98
  170. package/dist/db-content-api/generated/content-api-types.d.ts +0 -3914
  171. package/dist/db-content-api/generated/content-api-types.d.ts.map +0 -1
  172. package/dist/db-content-api/generated/content-api-types.js +0 -7
  173. package/dist/db-content-api/generated/content-api-types.js.map +0 -1
  174. package/dist/db-content-api/index.d.ts +0 -18
  175. package/dist/db-content-api/index.d.ts.map +0 -1
  176. package/dist/db-content-api/index.js +0 -586
  177. package/dist/db-content-api/index.js.map +0 -1
  178. package/dist/db-content-api/temp-utilities/slug.d.ts +0 -2
  179. package/dist/db-content-api/temp-utilities/slug.d.ts.map +0 -1
  180. package/dist/db-content-api/temp-utilities/slug.js +0 -3
  181. package/dist/db-content-api/temp-utilities/slug.js.map +0 -1
  182. package/dist/db-content-api/temp-utilities/sorting.d.ts +0 -3
  183. package/dist/db-content-api/temp-utilities/sorting.d.ts.map +0 -1
  184. package/dist/db-content-api/temp-utilities/sorting.js +0 -32
  185. package/dist/db-content-api/temp-utilities/sorting.js.map +0 -1
  186. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +0 -34
  187. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts.map +0 -1
  188. package/dist/db-content-api/temp-utilities/unwrapDocument.js +0 -53
  189. package/dist/db-content-api/temp-utilities/unwrapDocument.js.map +0 -1
  190. package/dist/db-content-api/utilities/auth.d.ts +0 -30
  191. package/dist/db-content-api/utilities/auth.d.ts.map +0 -1
  192. package/dist/db-content-api/utilities/auth.js +0 -81
  193. package/dist/db-content-api/utilities/auth.js.map +0 -1
  194. package/dist/db-content-api/utilities/buildPathTypes.d.ts +0 -12
  195. package/dist/db-content-api/utilities/buildPathTypes.d.ts.map +0 -1
  196. package/dist/db-content-api/utilities/buildPathTypes.js +0 -157
  197. package/dist/db-content-api/utilities/buildPathTypes.js.map +0 -1
  198. package/dist/db-content-api/utilities/data/applyDefaults.d.ts +0 -7
  199. package/dist/db-content-api/utilities/data/applyDefaults.d.ts.map +0 -1
  200. package/dist/db-content-api/utilities/data/applyDefaults.js +0 -59
  201. package/dist/db-content-api/utilities/data/applyDefaults.js.map +0 -1
  202. package/dist/db-content-api/utilities/data/castFieldValue.d.ts +0 -11
  203. package/dist/db-content-api/utilities/data/castFieldValue.d.ts.map +0 -1
  204. package/dist/db-content-api/utilities/data/castFieldValue.js +0 -66
  205. package/dist/db-content-api/utilities/data/castFieldValue.js.map +0 -1
  206. package/dist/db-content-api/utilities/data/index.d.ts +0 -32
  207. package/dist/db-content-api/utilities/data/index.d.ts.map +0 -1
  208. package/dist/db-content-api/utilities/data/index.js +0 -190
  209. package/dist/db-content-api/utilities/data/index.js.map +0 -1
  210. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +0 -12
  211. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts.map +0 -1
  212. package/dist/db-content-api/utilities/data/removeVirtualFields.js +0 -54
  213. package/dist/db-content-api/utilities/data/removeVirtualFields.js.map +0 -1
  214. package/dist/db-content-api/utilities/data/stripFields.d.ts +0 -48
  215. package/dist/db-content-api/utilities/data/stripFields.d.ts.map +0 -1
  216. package/dist/db-content-api/utilities/data/stripFields.js +0 -195
  217. package/dist/db-content-api/utilities/data/stripFields.js.map +0 -1
  218. package/dist/db-content-api/utilities/joins.d.ts +0 -55
  219. package/dist/db-content-api/utilities/joins.d.ts.map +0 -1
  220. package/dist/db-content-api/utilities/joins.js +0 -136
  221. package/dist/db-content-api/utilities/joins.js.map +0 -1
  222. package/dist/db-content-api/utilities/where.d.ts +0 -12
  223. package/dist/db-content-api/utilities/where.d.ts.map +0 -1
  224. package/dist/db-content-api/utilities/where.js +0 -121
  225. package/dist/db-content-api/utilities/where.js.map +0 -1
  226. package/dist/endpoints/health.d.ts +0 -3
  227. package/dist/endpoints/health.d.ts.map +0 -1
  228. package/dist/endpoints/health.js +0 -11
  229. package/dist/endpoints/health.js.map +0 -1
  230. package/dist/oauth/utilities/isDuplicateKeyError.d.ts +0 -7
  231. package/dist/oauth/utilities/isDuplicateKeyError.d.ts.map +0 -1
  232. package/dist/oauth/utilities/isDuplicateKeyError.js +0 -14
  233. package/dist/oauth/utilities/isDuplicateKeyError.js.map +0 -1
  234. package/dist/storage-content-api/api-types.d.ts +0 -168
  235. package/dist/storage-content-api/api-types.d.ts.map +0 -1
  236. package/dist/storage-content-api/api-types.js +0 -6
  237. package/dist/storage-content-api/api-types.js.map +0 -1
  238. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts +0 -9
  239. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts.map +0 -1
  240. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +0 -42
  241. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js.map +0 -1
  242. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts +0 -13
  243. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts.map +0 -1
  244. package/dist/storage-content-api/client-uploads/generateSignedURL.js +0 -32
  245. package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +0 -1
  246. package/dist/storage-content-api/client.d.ts +0 -6
  247. package/dist/storage-content-api/client.d.ts.map +0 -1
  248. package/dist/storage-content-api/client.js +0 -36
  249. package/dist/storage-content-api/client.js.map +0 -1
  250. package/dist/storage-content-api/generateURL.d.ts +0 -7
  251. package/dist/storage-content-api/generateURL.d.ts.map +0 -1
  252. package/dist/storage-content-api/generateURL.js +0 -8
  253. package/dist/storage-content-api/generateURL.js.map +0 -1
  254. package/dist/storage-content-api/handleDelete.d.ts +0 -8
  255. package/dist/storage-content-api/handleDelete.d.ts.map +0 -1
  256. package/dist/storage-content-api/handleDelete.js +0 -17
  257. package/dist/storage-content-api/handleDelete.js.map +0 -1
  258. package/dist/storage-content-api/handleUpload.d.ts +0 -11
  259. package/dist/storage-content-api/handleUpload.d.ts.map +0 -1
  260. package/dist/storage-content-api/handleUpload.js +0 -144
  261. package/dist/storage-content-api/handleUpload.js.map +0 -1
  262. package/dist/storage-content-api/index.d.ts +0 -5
  263. package/dist/storage-content-api/index.d.ts.map +0 -1
  264. package/dist/storage-content-api/index.js +0 -31
  265. package/dist/storage-content-api/index.js.map +0 -1
  266. package/dist/storage-content-api/staticHandler.d.ts +0 -10
  267. package/dist/storage-content-api/staticHandler.d.ts.map +0 -1
  268. package/dist/storage-content-api/staticHandler.js +0 -56
  269. package/dist/storage-content-api/staticHandler.js.map +0 -1
  270. package/dist/storage-content-api/types.d.ts +0 -10
  271. package/dist/storage-content-api/types.d.ts.map +0 -1
  272. package/dist/storage-content-api/types.js +0 -3
  273. package/dist/storage-content-api/types.js.map +0 -1
  274. package/dist/templates/README.md +0 -19
  275. package/dist/utils/build-lambda-zip.d.ts +0 -14
  276. package/dist/utils/build-lambda-zip.d.ts.map +0 -1
  277. package/dist/utils/build-lambda-zip.js +0 -81
  278. package/dist/utils/build-lambda-zip.js.map +0 -1
  279. package/dist/utils/format-env-suffix.d.ts +0 -12
  280. package/dist/utils/format-env-suffix.d.ts.map +0 -1
  281. package/dist/utils/format-env-suffix.js +0 -13
  282. package/dist/utils/format-env-suffix.js.map +0 -1
  283. package/dist/utils/version-check.d.ts +0 -3
  284. package/dist/utils/version-check.d.ts.map +0 -1
  285. package/dist/utils/version-check.js +0 -38
  286. package/dist/utils/version-check.js.map +0 -1
@@ -1,96 +1,97 @@
1
+ import { randomBytes } from 'crypto';
1
2
  import fs from 'fs/promises';
2
3
  import path from 'path';
3
4
  /**
4
- * Get an environment variable value from .env file
5
+ * Generate a cryptographically secure secret for PAYLOAD_SECRET
5
6
  *
6
- * @param projectPath - Path to project directory
7
- * @param key - Environment variable name to retrieve
8
- * @returns The value if found, null otherwise
9
- */ export async function getEnvVar(projectPath, key) {
10
- const envPath = path.join(projectPath, '.env');
11
- try {
12
- const contents = await fs.readFile(envPath, 'utf-8');
13
- const lines = contents.split(/\r?\n/);
14
- for (const line of lines){
15
- // Skip empty lines and comments
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
- }
7
+ * @returns 24-character hexadecimal string
8
+ */ export function generateSecret() {
9
+ return randomBytes(32).toString('hex').slice(0, 24);
10
+ }
11
+ /**
12
+ * Sanitize and process environment file contents
13
+ *
14
+ * @param contents - Raw .env file contents
15
+ * @param payloadSecret - Secret to use for PAYLOAD_SECRET
16
+ * @returns Processed .env contents
17
+ */ function sanitizeEnv(contents, payloadSecret) {
18
+ const lines = contents.split('\n');
19
+ const seenKeys = new Set();
20
+ const processedLines = [];
21
+ for (const line of lines){
22
+ // Skip empty lines and comments
23
+ if (!line.trim() || line.trim().startsWith('#')) {
24
+ processedLines.push(line);
25
+ continue;
26
+ }
27
+ // Skip lines without =
28
+ if (!line.includes('=')) {
29
+ processedLines.push(line);
30
+ continue;
31
+ }
32
+ const [key] = line.split('=');
33
+ const trimmedKey = key.trim();
34
+ // Skip duplicate keys
35
+ if (seenKeys.has(trimmedKey)) {
36
+ continue;
28
37
  }
29
- return null;
30
- } catch {
31
- // File doesn't exist or can't be read
32
- return null;
38
+ seenKeys.add(trimmedKey);
39
+ // Replace PAYLOAD_SECRET with actual value
40
+ if (trimmedKey === 'PAYLOAD_SECRET' || trimmedKey === 'PAYLOAD_SECRET_KEY') {
41
+ processedLines.push(`PAYLOAD_SECRET=${payloadSecret}`);
42
+ } else {
43
+ processedLines.push(line);
44
+ }
45
+ }
46
+ // Add PAYLOAD_SECRET if not present
47
+ if (!seenKeys.has('PAYLOAD_SECRET') && !seenKeys.has('PAYLOAD_SECRET_KEY')) {
48
+ processedLines.push(`PAYLOAD_SECRET=${payloadSecret}`);
33
49
  }
50
+ return processedLines.join('\n');
34
51
  }
35
52
  /**
36
- * Add or update an environment variable in .env file
53
+ * Manage environment files for a new project
54
+ *
55
+ * Creates .env from .env.example (if exists) and populates PAYLOAD_SECRET
37
56
  *
38
57
  * @param projectPath - Path to project directory
39
- * @param key - Environment variable name
40
- * @param value - Environment variable value
41
- */ export async function addOrUpdateEnvVar(projectPath, key, value) {
58
+ * @returns The generated payload secret
59
+ */ export async function manageEnvFiles(projectPath) {
60
+ const payloadSecret = generateSecret();
61
+ const envExamplePath = path.join(projectPath, '.env.example');
42
62
  const envPath = path.join(projectPath, '.env');
43
63
  try {
44
- let contents = '';
64
+ // Check if .env.example exists
65
+ let envExampleContents = '';
66
+ try {
67
+ envExampleContents = await fs.readFile(envExamplePath, 'utf-8');
68
+ } catch {
69
+ // No .env.example, create minimal .env
70
+ envExampleContents = '';
71
+ }
72
+ // Check if .env already exists
45
73
  let envExists = false;
46
- // Try to read existing .env file
47
74
  try {
48
- contents = await fs.readFile(envPath, 'utf-8');
75
+ await fs.access(envPath);
49
76
  envExists = true;
50
77
  } catch {
51
- // .env doesn't exist, will create it
78
+ // .env doesn't exist
52
79
  }
53
- const lines = contents.split(/\r?\n/);
54
- const seenKeys = new Set();
55
- const processedLines = [];
56
- let keyUpdated = false;
57
- for (const line of lines){
58
- // Skip empty lines at start if file didn't exist
59
- if (!envExists && !line.trim()) {
60
- continue;
80
+ if (!envExists) {
81
+ // Create .env from .env.example
82
+ const sanitized = sanitizeEnv(envExampleContents, payloadSecret);
83
+ await fs.writeFile(envPath, sanitized, 'utf-8');
84
+ } else {
85
+ // Update existing .env if it doesn't have PAYLOAD_SECRET
86
+ const existingContents = await fs.readFile(envPath, 'utf-8');
87
+ if (!existingContents.includes('PAYLOAD_SECRET=') && !existingContents.includes('PAYLOAD_SECRET_KEY=')) {
88
+ const sanitized = sanitizeEnv(existingContents, payloadSecret);
89
+ await fs.writeFile(envPath, sanitized, 'utf-8');
61
90
  }
62
- // Preserve empty lines and comments
63
- if (!line.trim() || line.trim().startsWith('#')) {
64
- processedLines.push(line);
65
- continue;
66
- }
67
- // Skip lines without =
68
- if (!line.includes('=')) {
69
- processedLines.push(line);
70
- continue;
71
- }
72
- const [lineKey] = line.split('=');
73
- const trimmedKey = lineKey.trim();
74
- // Skip duplicate keys (keep first occurrence)
75
- if (seenKeys.has(trimmedKey)) {
76
- continue;
77
- }
78
- seenKeys.add(trimmedKey);
79
- // Update or keep the line
80
- if (trimmedKey === key) {
81
- processedLines.push(`${key}=${value}`);
82
- keyUpdated = true;
83
- } else {
84
- processedLines.push(line);
85
- }
86
- }
87
- // Add key if not present
88
- if (!keyUpdated) {
89
- processedLines.push(`${key}=${value}`);
90
91
  }
91
- await fs.writeFile(envPath, processedLines.join('\n'), 'utf-8');
92
+ return payloadSecret;
92
93
  } catch (error) {
93
- throw new Error(`Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`);
94
+ throw new Error(`Failed to manage environment files: ${error instanceof Error ? error.message : 'Unknown error'}`);
94
95
  }
95
96
  }
96
97
 
@@ -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(/\\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,CAACH,cAAc;YACtC;QACF;QAEA,OAAO;IACT,EAAE,OAAM;QACN,sCAAsC;QACtC,OAAO;IACT;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeI,kBACpBhB,WAAmB,EACnBC,GAAW,EACXgB,KAAa;IAEb,MAAMf,UAAUJ,KAAKK,IAAI,CAACH,aAAa;IAEvC,IAAI;QACF,IAAII,WAAW;QACf,IAAIc,YAAY;QAEhB,iCAAiC;QACjC,IAAI;YACFd,WAAW,MAAMP,GAAGQ,QAAQ,CAACH,SAAS;YACtCgB,YAAY;QACd,EAAE,OAAM;QACN,qCAAqC;QACvC;QAEA,MAAMZ,QAAQF,SAASG,KAAK,CAAC;QAC7B,MAAMY,WAAW,IAAIC;QACrB,MAAMC,iBAA2B,EAAE;QACnC,IAAIC,aAAa;QAEjB,KAAK,MAAMd,QAAQF,MAAO;YACxB,iDAAiD;YACjD,IAAI,CAACY,aAAa,CAACV,KAAKC,IAAI,IAAI;gBAC9B;YACF;YAEA,oCAAoC;YACpC,IAAI,CAACD,KAAKC,IAAI,MAAMD,KAAKC,IAAI,GAAGC,UAAU,CAAC,MAAM;gBAC/CW,eAAeE,IAAI,CAACf;gBACpB;YACF;YAEA,uBAAuB;YACvB,IAAI,CAACA,KAAKG,QAAQ,CAAC,MAAM;gBACvBU,eAAeE,IAAI,CAACf;gBACpB;YACF;YAEA,MAAM,CAACM,QAAQ,GAAGN,KAAKD,KAAK,CAAC;YAC7B,MAAMiB,aAAaV,QAAQL,IAAI;YAE/B,8CAA8C;YAC9C,IAAIU,SAASM,GAAG,CAACD,aAAa;gBAC5B;YACF;YACAL,SAASO,GAAG,CAACF;YAEb,0BAA0B;YAC1B,IAAIA,eAAevB,KAAK;gBACtBoB,eAAeE,IAAI,CAAC,GAAGtB,IAAI,CAAC,EAAEgB,OAAO;gBACrCK,aAAa;YACf,OAAO;gBACLD,eAAeE,IAAI,CAACf;YACtB;QACF;QAEA,yBAAyB;QACzB,IAAI,CAACc,YAAY;YACfD,eAAeE,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
+ {"version":3,"sources":["../../src/utils/env-management.ts"],"sourcesContent":["import { randomBytes } from 'crypto'\nimport fs from 'fs/promises'\nimport path from 'path'\n\n/**\n * Generate a cryptographically secure secret for PAYLOAD_SECRET\n *\n * @returns 24-character hexadecimal string\n */\nexport function generateSecret(): string {\n return randomBytes(32).toString('hex').slice(0, 24)\n}\n\n/**\n * Sanitize and process environment file contents\n *\n * @param contents - Raw .env file contents\n * @param payloadSecret - Secret to use for PAYLOAD_SECRET\n * @returns Processed .env contents\n */\nfunction sanitizeEnv(contents: string, payloadSecret: string): string {\n const lines = contents.split('\\n')\n const seenKeys = new Set<string>()\n const processedLines: string[] = []\n\n for (const line of lines) {\n // Skip 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 [key] = line.split('=')\n const trimmedKey = key.trim()\n\n // Skip duplicate keys\n if (seenKeys.has(trimmedKey)) {\n continue\n }\n seenKeys.add(trimmedKey)\n\n // Replace PAYLOAD_SECRET with actual value\n if (trimmedKey === 'PAYLOAD_SECRET' || trimmedKey === 'PAYLOAD_SECRET_KEY') {\n processedLines.push(`PAYLOAD_SECRET=${payloadSecret}`)\n } else {\n processedLines.push(line)\n }\n }\n\n // Add PAYLOAD_SECRET if not present\n if (!seenKeys.has('PAYLOAD_SECRET') && !seenKeys.has('PAYLOAD_SECRET_KEY')) {\n processedLines.push(`PAYLOAD_SECRET=${payloadSecret}`)\n }\n\n return processedLines.join('\\n')\n}\n\n/**\n * Manage environment files for a new project\n *\n * Creates .env from .env.example (if exists) and populates PAYLOAD_SECRET\n *\n * @param projectPath - Path to project directory\n * @returns The generated payload secret\n */\nexport async function manageEnvFiles(projectPath: string): Promise<string> {\n const payloadSecret = generateSecret()\n const envExamplePath = path.join(projectPath, '.env.example')\n const envPath = path.join(projectPath, '.env')\n\n try {\n // Check if .env.example exists\n let envExampleContents = ''\n try {\n envExampleContents = await fs.readFile(envExamplePath, 'utf-8')\n } catch {\n // No .env.example, create minimal .env\n envExampleContents = ''\n }\n\n // Check if .env already exists\n let envExists = false\n try {\n await fs.access(envPath)\n envExists = true\n } catch {\n // .env doesn't exist\n }\n\n if (!envExists) {\n // Create .env from .env.example\n const sanitized = sanitizeEnv(envExampleContents, payloadSecret)\n await fs.writeFile(envPath, sanitized, 'utf-8')\n } else {\n // Update existing .env if it doesn't have PAYLOAD_SECRET\n const existingContents = await fs.readFile(envPath, 'utf-8')\n if (\n !existingContents.includes('PAYLOAD_SECRET=') &&\n !existingContents.includes('PAYLOAD_SECRET_KEY=')\n ) {\n const sanitized = sanitizeEnv(existingContents, payloadSecret)\n await fs.writeFile(envPath, sanitized, 'utf-8')\n }\n }\n\n return payloadSecret\n } catch (error) {\n throw new Error(\n `Failed to manage environment files: ${error instanceof Error ? error.message : 'Unknown error'}`,\n )\n }\n}\n"],"names":["randomBytes","fs","path","generateSecret","toString","slice","sanitizeEnv","contents","payloadSecret","lines","split","seenKeys","Set","processedLines","line","trim","startsWith","push","includes","key","trimmedKey","has","add","join","manageEnvFiles","projectPath","envExamplePath","envPath","envExampleContents","readFile","envExists","access","sanitized","writeFile","existingContents","error","Error","message"],"mappings":"AAAA,SAASA,WAAW,QAAQ,SAAQ;AACpC,OAAOC,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB;;;;CAIC,GACD,OAAO,SAASC;IACd,OAAOH,YAAY,IAAII,QAAQ,CAAC,OAAOC,KAAK,CAAC,GAAG;AAClD;AAEA;;;;;;CAMC,GACD,SAASC,YAAYC,QAAgB,EAAEC,aAAqB;IAC1D,MAAMC,QAAQF,SAASG,KAAK,CAAC;IAC7B,MAAMC,WAAW,IAAIC;IACrB,MAAMC,iBAA2B,EAAE;IAEnC,KAAK,MAAMC,QAAQL,MAAO;QACxB,gCAAgC;QAChC,IAAI,CAACK,KAAKC,IAAI,MAAMD,KAAKC,IAAI,GAAGC,UAAU,CAAC,MAAM;YAC/CH,eAAeI,IAAI,CAACH;YACpB;QACF;QAEA,uBAAuB;QACvB,IAAI,CAACA,KAAKI,QAAQ,CAAC,MAAM;YACvBL,eAAeI,IAAI,CAACH;YACpB;QACF;QAEA,M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AAC,sBAC3B,CAACgB,iBAAiBhB,QAAQ,CAAC,wBAC3B;gBACA,MAAMc,YAAY1B,YAAY4B,kBAAkB1B;gBAChD,MAAMP,GAAGgC,SAAS,CAACN,SAASK,WAAW;YACzC;QACF;QAEA,OAAOxB;IACT,EAAE,OAAO2B,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,oCAAoC,EAAED,iBAAiBC,QAAQD,MAAME,OAAO,GAAG,iBAAiB;IAErG;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,CAgCvB"}
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,CAmCvB"}
@@ -1,4 +1,4 @@
1
- import spawn from 'cross-spawn';
1
+ import { spawn } from 'child_process';
2
2
  import path from 'path';
3
3
  /**
4
4
  * Format file with Prettier
@@ -6,13 +6,15 @@ 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(packageManager, [
9
+ const args = [
10
10
  'exec',
11
11
  'prettier',
12
12
  '--write',
13
13
  filePath
14
- ], {
14
+ ];
15
+ const child = spawn(packageManager, args, {
15
16
  cwd: path.dirname(filePath),
17
+ shell: true,
16
18
  stdio: 'pipe'
17
19
  });
18
20
  child.on('close', (code)=>{
@@ -1 +1 @@
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
+ {"version":3,"sources":["../../src/utils/formatter.ts"],"sourcesContent":["import { spawn } from 'child_process'\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 args = ['exec', 'prettier', '--write', filePath]\n\n const child = spawn(packageManager, args, {\n cwd: path.dirname(filePath),\n shell: true,\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","args","child","cwd","dirname","shell","stdio","on","code","success","warning"],"mappings":"AAAA,SAASA,KAAK,QAAQ,gBAAe;AACrC,OAAOC,UAAU,OAAM;AASvB;;;CAGC,GACD,OAAO,eAAeC,WACpBC,QAAgB,EAChBC,cAA8B;IAE9B,OAAO,IAAIC,QAAQ,CAACC;QAClB,IAAI;YACF,MAAMC,OAAO;gBAAC;gBAAQ;gBAAY;gBAAWJ;aAAS;YAEtD,MAAMK,QAAQR,MAAMI,gBAAgBG,MAAM;gBACxCE,KAAKR,KAAKS,OAAO,CAACP;gBAClBQ,OAAO;gBACPC,OAAO;YACT;YAEAJ,MAAMK,EAAE,CAAC,SAAS,CAACC;gBACjB,IAAIA,SAAS,GAAG;oBACdR,QAAQ;wBAAES,SAAS;oBAAK;gBAC1B,OAAO;oBACLT,QAAQ;wBACNS,SAAS;wBACTC,SAAS;oBACX;gBACF;YACF;YAEAR,MAAMK,EAAE,CAAC,SAAS;gBAChBP,QAAQ;oBACNS,SAAS;oBACTC,SAAS;gBACX;YACF;QACF,EAAE,OAAM;YACNV,QAAQ;gBACNS,SAAS;gBACTC,SAAS;YACX;QACF;IACF;AACF"}
@@ -1,9 +1,7 @@
1
- import type { PackageManager } from './package-manager.js';
2
1
  /**
3
2
  * Apply Lambda-specific modifications to a Payload project
4
3
  *
5
4
  * @param projectPath - Path to project directory
6
- * @param packageManager - Package manager to use in scripts (defaults to 'pnpm')
7
5
  */
8
- export declare function applyLambdaModifications(projectPath: string, packageManager?: PackageManager): Promise<void>;
6
+ export declare function applyLambdaModifications(projectPath: string): Promise<void>;
9
7
  //# 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":"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"}
1
+ {"version":3,"file":"lambda-config.d.ts","sourceRoot":"","sources":["../../src/utils/lambda-config.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCjF"}
@@ -7,19 +7,30 @@ 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
+ cd .next/standalone
15
+ zip -r --symlinks lambda.zip .
16
+ mv lambda.zip ../..
17
+ `;
10
18
  /**
11
19
  * Apply Lambda-specific modifications to a Payload project
12
20
  *
13
21
  * @param projectPath - Path to project directory
14
- * @param packageManager - Package manager to use in scripts (defaults to 'pnpm')
15
- */ export async function applyLambdaModifications(projectPath, packageManager = 'pnpm') {
22
+ */ export async function applyLambdaModifications(projectPath) {
16
23
  // 1. Create run.sh
17
24
  const runShPath = path.join(projectPath, 'run.sh');
18
25
  await fs.writeFile(runShPath, RUN_SH_CONTENT, 'utf-8');
19
- await fs.chmod(runShPath, 0o755);
20
- // 2. Modify next config to add standalone output and eslint ignore
21
- await addNextConfigProperties(projectPath);
22
- // 3. Create/update .npmrc
26
+ await fs.chmod(runShPath, 0o755); // rwxr-xr-x
27
+ // 2. Create build_for_lambda.sh
28
+ const buildShPath = path.join(projectPath, 'build_for_lambda.sh');
29
+ await fs.writeFile(buildShPath, BUILD_FOR_LAMBDA_SH_CONTENT, 'utf-8');
30
+ await fs.chmod(buildShPath, 0o755);
31
+ // 3. Modify next config to add standalone output
32
+ await addStandaloneToNextConfig(projectPath);
33
+ // 4. Create/update .npmrc
23
34
  const npmrcPath = path.join(projectPath, '.npmrc');
24
35
  let npmrcContent = '';
25
36
  try {
@@ -32,8 +43,8 @@ NODE_ENV=production exec node server.js
32
43
  npmrcContent += 'node-linker=hoisted\n';
33
44
  await fs.writeFile(npmrcPath, npmrcContent, 'utf-8');
34
45
  }
35
- // 4. Add lambda:buildzip script to package.json
36
- await addLambdaBuildScript(projectPath, packageManager);
46
+ // 5. Add lambda:buildzip script to package.json
47
+ await addLambdaBuildScript(projectPath);
37
48
  }
38
49
  /**
39
50
  * Find the Next.js config file (next.config.js or next.config.mjs)
@@ -56,18 +67,13 @@ NODE_ENV=production exec node server.js
56
67
  throw new Error('Could not find next.config.js or next.config.mjs');
57
68
  }
58
69
  /**
59
- * Add required Next.js config properties using AST parsing
60
- * - output: 'standalone' (for Lambda deployment)
61
- * - eslint: { ignoreDuringBuilds: true } (allow builds with lint errors)
62
- */ async function addNextConfigProperties(projectPath) {
70
+ * Add standalone output to Next.js config using AST parsing
71
+ */ async function addStandaloneToNextConfig(projectPath) {
63
72
  const nextConfigPath = await findNextConfigPath(projectPath);
64
73
  const content = await fs.readFile(nextConfigPath, 'utf-8');
65
- // Check which properties already exist
66
- const hasOutput = content.includes('output:');
67
- const hasEslint = content.includes('eslint:');
68
- // Early exit if both already configured
69
- if (hasOutput && hasEslint) {
70
- return;
74
+ // Check if output already configured (quick check before parsing)
75
+ if (content.includes('output:')) {
76
+ return; // Already configured
71
77
  }
72
78
  const ast = parseModule(content, {
73
79
  loc: true
@@ -108,42 +114,30 @@ NODE_ENV=production exec node server.js
108
114
  throw new Error(`Could not find Next.js config object in ${path.basename(nextConfigPath)}. ` + `Expected either 'export default { ... }' or 'export default wrapper(configVar, ...)'`);
109
115
  }
110
116
  const { loc } = targetObjectExpression;
111
- const lines = content.split(/\r?\n/);
112
- // Build insertion string based on what's missing
113
- const parts = [];
114
- if (!hasOutput) {
115
- parts.push("output: 'standalone',");
116
- }
117
- if (!hasEslint) {
118
- parts.push(`eslint: {
119
- ignoreDuringBuilds: true,
120
- },`);
121
- }
122
- const insertString = '\n ' + parts.join('\n ');
123
- // Insert after opening brace
117
+ const lines = content.split('\n');
118
+ // Insert output: 'standalone' as first property
124
119
  const insertLine = loc.start.line - 1;
125
- const insertColumn = loc.start.column + 1;
120
+ const insertColumn = loc.start.column + 1 // After opening brace
121
+ ;
122
+ // Find the content of the line with the opening brace
126
123
  const targetLine = lines[insertLine];
127
124
  if (!targetLine) {
128
125
  throw new Error(`Could not find target line in ${path.basename(nextConfigPath)}`);
129
126
  }
130
- lines[insertLine] = targetLine.slice(0, insertColumn) + insertString + targetLine.slice(insertColumn);
127
+ lines[insertLine] = targetLine.slice(0, insertColumn) + "\n output: 'standalone'," + targetLine.slice(insertColumn);
131
128
  const modifiedContent = lines.join('\n');
132
129
  await fs.writeFile(nextConfigPath, modifiedContent, 'utf-8');
133
130
  }
134
131
  /**
135
132
  * Add lambda:buildzip script to package.json
136
- */ async function addLambdaBuildScript(projectPath, packageManager) {
133
+ */ async function addLambdaBuildScript(projectPath) {
137
134
  const packageJsonPath = path.join(projectPath, 'package.json');
138
135
  const content = await fs.readFile(packageJsonPath, 'utf-8');
139
136
  const packageJson = JSON.parse(content);
140
137
  if (!packageJson.scripts) {
141
138
  packageJson.scripts = {};
142
139
  }
143
- // Use package manager's run and exec commands
144
- const runCmd = packageManager === 'npm' ? 'npm run' : packageManager;
145
- const execCmd = packageManager === 'npm' ? 'npx' : `${packageManager} exec`;
146
- packageJson.scripts['lambda:buildzip'] = `${runCmd} build && ${execCmd} payloadcms-figma build-lambda-zip`;
140
+ packageJson.scripts['lambda:buildzip'] = 'npm run build && ./build_for_lambda.sh';
147
141
  await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8');
148
142
  }
149
143
 
@@ -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\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 and eslint ignore\n await addNextConfigProperties(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 required Next.js config properties using AST parsing\n * - output: 'standalone' (for Lambda deployment)\n * - eslint: { ignoreDuringBuilds: true } (allow builds with lint errors)\n */\nasync function addNextConfigProperties(projectPath: string): Promise<void> {\n const nextConfigPath = await findNextConfigPath(projectPath)\n const content = await fs.readFile(nextConfigPath, 'utf-8')\n\n // Check which properties already exist\n const hasOutput = content.includes('output:')\n const hasEslint = content.includes('eslint:')\n\n // Early exit if both already configured\n if (hasOutput && hasEslint) {\n return\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 // Build insertion string based on what's missing\n const parts: string[] = []\n if (!hasOutput) {\n parts.push(\"output: 'standalone',\")\n }\n if (!hasEslint) {\n parts.push(`eslint: {\n ignoreDuringBuilds: true,\n },`)\n }\n\n const insertString = '\\n ' + parts.join('\\n ')\n\n // Insert after opening brace\n const insertLine = loc.start.line - 1\n const insertColumn = loc.start.column + 1\n\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) + insertString + 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","addNextConfigProperties","npmrcPath","npmrcContent","readFile","includes","endsWith","addLambdaBuildScript","findNextConfigPath","configFiles","configFile","configPath","access","Error","nextConfigPath","content","hasOutput","hasEslint","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","parts","push","insertString","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,mEAAmE;IACnE,MAAMI,wBAAwBN;IAE9B,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;I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AAkBZ,MAAM9C,IAAI,CAAC;IACnC,MAAMP,GAAGQ,SAAS,CAACe,gBAAgB0C,iBAAiB;AACtD;AAwCA;;CAEC,GACD,eAAejD,qBACbZ,WAAmB,EACnBC,cAA8B;IAE9B,MAAM6D,kBAAkBjE,KAAKM,IAAI,CAACH,aAAa;IAC/C,MAAMoB,UAAU,MAAMxB,GAAGa,QAAQ,CAACqD,iBAAiB;IACnD,MAAMC,cAAcC,KAAKC,KAAK,CAAC7C;IAE/B,IAAI,CAAC2C,YAAYG,OAAO,EAAE;QACxBH,YAAYG,OAAO,GAAG,CAAC;IACzB;IAEA,8CAA8C;IAC9C,MAAMC,SAASlE,mBAAmB,QAAQ,YAAYA;IACtD,MAAMmE,UAAUnE,mBAAmB,QAAQ,QAAQ,GAAGA,eAAe,KAAK,CAAC;IAE3E8D,YAAYG,OAAO,CAAC,kBAAkB,GACpC,GAAGC,OAAO,UAAU,EAAEC,QAAQ,kCAAkC,CAAC;IAEnE,MAAMxE,GAAGQ,SAAS,CAAC0D,iBAAiBE,KAAKK,SAAS,CAACN,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\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\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,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C,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"}
@@ -15,30 +15,30 @@ 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
19
18
 
20
19
  ${pc.bold('OPTIONS')}
21
20
 
22
21
  ${pc.dim('-h, --help Show help')}
23
- ${pc.dim('-v, --version Show CLI version')}
24
22
  ${pc.dim('--debug Enable debug logging')}
25
23
 
26
24
  ${pc.bold('AUTHENTICATION')}
27
25
 
28
26
  ${pc.cyan('@payloadcms/figma login')} Authenticate with Figma
29
- ${pc.cyan('@payloadcms/figma logout')} Clear tokens for current environment
27
+ ${pc.cyan('@payloadcms/figma logout')} Clear all tokens (with confirmation)
30
28
  ${pc.cyan('@payloadcms/figma list-tokens')} Display stored OAuth and project tokens
31
29
 
32
30
  ${pc.bold('INIT COMMAND')}
33
31
 
34
- ${pc.cyan('@payloadcms/figma init --id <content-system-id>')} Initialize project with Content System ID
35
- ${pc.cyan('@payloadcms/figma init --force')} Force reconfiguration of existing project
32
+ ${pc.cyan('@payloadcms/figma init --id <cms-id>')} Initialize project with CMS ID
33
+ ${pc.cyan('@payloadcms/figma init')} Initialize (prompts for CMS ID)
34
+ ${pc.cyan('@payloadcms/figma init --name my-cms')} Specify project name for new projects
35
+ ${pc.cyan('@payloadcms/figma init --force')} Force reconfiguration of existing project
36
+ ${pc.cyan('@payloadcms/figma init --skip-auth')} Skip authentication (testing only)
36
37
 
37
38
  ${pc.bold('DEPLOY COMMAND')}
38
39
 
39
- ${pc.cyan('@payloadcms/figma deploy')} Deploy your project to Figma
40
- ${pc.dim('--yes, -y')} Skip confirmation prompts
41
- ${pc.dim('--skip-build')} Skip building and use existing build
40
+ ${pc.cyan('@payloadcms/figma deploy')} Deploy your project to Figma
41
+ ${pc.dim('--yes, -y')} Skip confirmation prompts
42
42
 
43
43
  ${pc.bold('DOCUMENTATION')}
44
44
 
@@ -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 ${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('-v, --version Show CLI version')}\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 tokens for current environment\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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C,CAAC,CAAC;AAC3I"}
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 <cms-id>')} Initialize project with CMS ID\n ${pc.cyan('@payloadcms/figma init')} Initialize (prompts for CMS ID)\n ${pc.cyan('@payloadcms/figma init --name my-cms')} Specify project name for new projects\n ${pc.cyan('@payloadcms/figma init --force')} Force reconfiguration of existing project\n ${pc.cyan('@payloadcms/figma init --skip-auth')} Skip authentication (testing only)\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\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,SAA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mBC,IAAY,EAAEC,GAAW;IACnD,OAAOX,aAAaU,MAAMC,KAAK;QAC7BC,UAAU,CAACF,MAAMC,MAAQ,GAAGD,KAAK,EAAE,EAAEC,KAAK;IAC5C;AACF;AAEA,OAAO,SAASE,eAAeC,UAAkB,EAAEC,cAA8B;IAC/E,MAAMC,eAAelB,KAAKmB,QAAQ,CAACC,QAAQC,GAAG,IAAIL;IAClD,OAAO,CAAC;AACV,EAAEb,OAAO,uBAAuB;;SAEvB,EAAEe,aAAa;IACpB,EAAED,mBAAmB,QAAQ,YAAYA,eAAe;;AAE5D,EAAEd,OAAO,kBAAkB;;IAEvB,EAAEQ,mBACF,mBACA,+DACA;IACA,EAAEA,mBAAmB,iBAAiB,sDAAsD;;AAEhG,CAAC;AACD;AAEA,OAAO,SAASW;IACd,OAAO,CAAC,EAAE,EAAEX,mBACV,mBACA,+DACA;EACF,EAAEA,mBAAmB,iBAAiB,sDAAsD;AAC9F,CAAC;AACD;AAEA,OAAO,SAASY,YAAYC,IAAgD;IAC1E,MAAMC,iBAAiBzB,KAAKmB,QAAQ,CAACC,QAAQC,GAAG,IAAIG,KAAKE,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,39 +1,19 @@
1
1
  import type { SourceFile } from 'ts-morph';
2
- /**
3
- * Result of detecting what changes are needed in a payload config file
4
- */
5
2
  export type DetectionResult = {
6
- /** Database adapter configuration if present */
7
3
  dbProperty?: {
8
- /** Name of the adapter function (e.g., 'mongooseAdapter', 'postgresAdapter') */
9
4
  adapter: string;
10
- /** NPM package the adapter is imported from (e.g., '@payloadcms/db-mongodb') */
11
5
  importSource: string;
12
6
  };
13
- /** Editor configuration if present */
14
7
  editorProperty?: {
15
- /** NPM package the editor is imported from (e.g., '@payloadcms/richtext-lexical') */
16
8
  importSource: string;
17
- /** Whether this is a default editor with no custom configuration */
18
9
  isDefault: boolean;
19
10
  };
20
- /** Whether the config already has a `figma` property */
21
11
  figmaObjectExists: boolean;
22
- /** Whether buildConfig/buildFigmaConfig uses an import alias (e.g., 'buildConfig as createConfig') */
23
12
  hasAlias: boolean;
24
- /** Whether a buildConfig or buildFigmaConfig call was found (undefined if not checked) */
25
13
  hasBuildConfig?: boolean;
26
- /** Whether there are other imports from 'payload' besides buildConfig (e.g., types) */
27
14
  hasOtherPayloadImports: boolean;
28
- /** Whether the import needs to be changed from 'payload' to '@payloadcms/figma' */
29
15
  needsImportChange: boolean;
30
- /** Whether a `secret` property exists in the config */
31
16
  secretProperty?: boolean;
32
- /** Sharp configuration if present */
33
- sharpProperty?: {
34
- /** NPM package sharp is imported from (always 'sharp') */
35
- importSource: string;
36
- };
37
17
  };
38
18
  /**
39
19
  * Detect what changes are needed in the payload config file
@@ -49,8 +29,9 @@ export type ASTModificationResult = {
49
29
  */
50
30
  export declare function applyModifications(sourceFile: SourceFile, detection: DetectionResult): ASTModificationResult;
51
31
  export type FigmaPropertyConfig = {
52
- contentSystemId: string;
53
- useContentSystem?: boolean;
32
+ region: string;
33
+ tenantId: string;
34
+ useContentSystem: boolean;
54
35
  };
55
36
  /**
56
37
  * Add figma property to buildConfig if it doesn't exist
@@ -1 +1 @@
1
- {"version":3,"file":"payload-config-ast.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAM1C;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,gDAA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