@payloadcms/figma 0.0.1-alpha.6 → 0.0.1-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/control-plane.d.ts +52 -6
- package/dist/api/control-plane.js +174 -72
- package/dist/api/figma-api.d.ts +22 -1
- package/dist/api/figma-api.js +78 -25
- package/dist/auth/callback-server.js +2 -1
- package/dist/auth/credentials.d.ts +21 -0
- package/dist/auth/credentials.js +21 -0
- package/dist/auth/crypto-utils.d.ts +6 -0
- package/dist/auth/crypto-utils.js +16 -14
- package/dist/auth/jwt-validator.d.ts +2 -1
- package/dist/auth/jwt-validator.js +2 -2
- package/dist/auth/oauth-flow.d.ts +17 -3
- package/dist/auth/oauth-flow.js +63 -16
- package/dist/auth/project-token.js +16 -11
- package/dist/auth/refresh.d.ts +2 -1
- package/dist/auth/refresh.js +25 -12
- package/dist/auth/token-store.d.ts +42 -1
- package/dist/auth/token-store.js +118 -14
- package/dist/auth/types.d.ts +17 -4
- package/dist/cli.js +68 -5
- package/dist/commands/build-lambda-zip.d.ts +5 -0
- package/dist/commands/build-lambda-zip.js +19 -0
- package/dist/commands/debug.d.ts +8 -0
- package/dist/commands/debug.js +176 -0
- package/dist/commands/deploy.d.ts +9 -0
- package/dist/commands/deploy.js +178 -151
- package/dist/commands/env.d.ts +13 -0
- package/dist/commands/env.js +88 -0
- package/dist/commands/init.d.ts +3 -5
- package/dist/commands/init.js +165 -148
- package/dist/commands/list-tokens.d.ts +3 -3
- package/dist/commands/list-tokens.js +22 -7
- package/dist/commands/login.d.ts +8 -1
- package/dist/commands/login.js +33 -15
- package/dist/commands/logout.d.ts +5 -4
- package/dist/commands/logout.js +56 -13
- package/dist/commands/upgrade.d.ts +5 -0
- package/dist/commands/upgrade.js +331 -0
- package/dist/config/oauth.d.ts +4 -14
- package/dist/config/oauth.js +18 -40
- package/dist/constants.d.ts +44 -19
- package/dist/constants.js +73 -20
- package/dist/db-content-api/README.md +98 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +3972 -0
- package/dist/db-content-api/generated/content-api-types.js +7 -0
- package/dist/db-content-api/index.d.ts +21 -0
- package/dist/db-content-api/index.js +914 -0
- package/dist/db-content-api/temp-utilities/slug.d.ts +2 -0
- package/dist/db-content-api/temp-utilities/slug.js +3 -0
- package/dist/db-content-api/temp-utilities/sorting.d.ts +3 -0
- package/dist/db-content-api/temp-utilities/sorting.js +39 -0
- package/dist/db-content-api/temp-utilities/types.d.ts +22 -0
- package/dist/db-content-api/temp-utilities/types.js +15 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +39 -0
- package/dist/db-content-api/temp-utilities/unwrapDocument.js +59 -0
- package/dist/db-content-api/utilities/auth.d.ts +30 -0
- package/dist/db-content-api/utilities/auth.js +81 -0
- package/dist/db-content-api/utilities/data/applyDefaults.d.ts +7 -0
- package/dist/db-content-api/utilities/data/applyDefaults.js +75 -0
- package/dist/db-content-api/utilities/data/castFieldValue.d.ts +11 -0
- package/dist/db-content-api/utilities/data/castFieldValue.js +68 -0
- package/dist/db-content-api/utilities/data/index.d.ts +49 -0
- package/dist/db-content-api/utilities/data/index.js +301 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +12 -0
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +54 -0
- package/dist/db-content-api/utilities/data/stripFields.d.ts +48 -0
- package/dist/db-content-api/utilities/data/stripFields.js +195 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.d.ts +23 -0
- package/dist/db-content-api/utilities/data/transformPublishedLocale.js +42 -0
- package/dist/db-content-api/utilities/joins.d.ts +53 -0
- package/dist/db-content-api/utilities/joins.js +139 -0
- package/dist/db-content-api/utilities/locale/index.d.ts +10 -0
- package/dist/db-content-api/utilities/locale/index.js +21 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.d.ts +11 -0
- package/dist/db-content-api/utilities/meta/buildLocalizedPaths.js +74 -0
- package/dist/db-content-api/utilities/meta/buildMeta.d.ts +42 -0
- package/dist/db-content-api/utilities/meta/buildMeta.js +41 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.d.ts +17 -0
- package/dist/db-content-api/utilities/meta/buildPathTypes.js +244 -0
- package/dist/db-content-api/utilities/meta/buildUniquePaths.d.ts +13 -0
- package/dist/db-content-api/utilities/meta/buildUniquePaths.js +62 -0
- package/dist/db-content-api/utilities/meta/normalizeLocaleInWhere.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/normalizeLocaleInWhere.js +102 -0
- package/dist/db-content-api/utilities/where.d.ts +20 -0
- package/dist/db-content-api/utilities/where.js +108 -0
- package/dist/deploy/schedule-extract-plugin.d.ts +11 -0
- package/dist/deploy/schedule-extract-plugin.js +34 -0
- package/dist/endpoints/health.d.ts +3 -0
- package/dist/endpoints/health.js +11 -0
- package/dist/endpoints/schema.d.ts +3 -0
- package/dist/endpoints/schema.js +29 -0
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.js +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/oauth/components/FigmaAvatar/index.d.ts +4 -0
- package/dist/oauth/components/FigmaAvatar/index.js +27 -0
- package/dist/oauth/components/FigmaAvatar/index.scss +12 -0
- package/dist/oauth/components/FigmaAvatarCell/index.d.ts +5 -0
- package/dist/oauth/components/FigmaAvatarCell/index.js +25 -0
- package/dist/oauth/components/FigmaAvatarCell/index.scss +5 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.d.ts +9 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.js +37 -0
- package/dist/oauth/components/FigmaAvatarPlaceholder/index.scss +28 -0
- package/dist/oauth/components/LoginButton/index.js +50 -6
- package/dist/oauth/components/LoginButton/index.scss +50 -3
- package/dist/oauth/components/LogoutButton/index.js +5 -4
- package/dist/oauth/defaults.js +67 -10
- package/dist/oauth/endpoints/getLoginEndpoint.js +77 -24
- package/dist/oauth/endpoints/getLogoutEndpoint.js +7 -4
- package/dist/oauth/index.js +40 -13
- package/dist/oauth/strategy/index.d.ts +0 -2
- package/dist/oauth/strategy/index.js +40 -17
- package/dist/oauth/types.d.ts +6 -6
- package/dist/oauth/utilities/isDuplicateKeyError.d.ts +7 -0
- package/dist/oauth/utilities/isDuplicateKeyError.js +14 -0
- package/dist/oauth/utilities/refreshTokens.js +6 -3
- package/dist/plugin/build-config.d.ts +18 -15
- package/dist/plugin/build-config.js +213 -18
- package/dist/storage-content-api/api-types.d.ts +168 -0
- package/dist/storage-content-api/api-types.js +6 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts +9 -0
- package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +42 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts +13 -0
- package/dist/storage-content-api/client-uploads/generateSignedURL.js +39 -0
- package/dist/storage-content-api/client.d.ts +6 -0
- package/dist/storage-content-api/client.js +36 -0
- package/dist/storage-content-api/generateURL.d.ts +7 -0
- package/dist/storage-content-api/generateURL.js +8 -0
- package/dist/storage-content-api/handleDelete.d.ts +8 -0
- package/dist/storage-content-api/handleDelete.js +17 -0
- package/dist/storage-content-api/handleUpload.d.ts +11 -0
- package/dist/storage-content-api/handleUpload.js +144 -0
- package/dist/storage-content-api/index.d.ts +5 -0
- package/dist/storage-content-api/index.js +31 -0
- package/dist/storage-content-api/staticHandler.d.ts +10 -0
- package/dist/storage-content-api/staticHandler.js +56 -0
- package/dist/storage-content-api/types.d.ts +10 -0
- package/dist/storage-content-api/types.js +3 -0
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +12 -0
- package/dist/storage-content-api/utilities/getSafeFilename.js +61 -0
- package/dist/storage-content-api/utilities/index.d.ts +2 -0
- package/dist/storage-content-api/utilities/index.js +3 -0
- package/dist/templates/.env.example +5 -0
- package/dist/templates/README.md +19 -0
- package/dist/types/config.d.ts +2 -1
- package/dist/types/config.js +0 -2
- package/dist/types.d.ts +8 -1
- package/dist/utils/adapters/nextjs.d.ts +9 -0
- package/dist/utils/adapters/nextjs.js +64 -0
- package/dist/utils/adapters/nitro.d.ts +9 -0
- package/dist/utils/adapters/nitro.js +169 -0
- package/dist/utils/adapters/vite.d.ts +10 -0
- package/dist/utils/adapters/vite.js +33 -0
- package/dist/utils/asset-collection.d.ts +27 -6
- package/dist/utils/asset-collection.js +59 -30
- package/dist/utils/build-detection.d.ts +5 -11
- package/dist/utils/build-detection.js +74 -11
- package/dist/utils/build-lambda-zip.d.ts +14 -0
- package/dist/utils/build-lambda-zip.js +81 -0
- package/dist/utils/cache-bootstrap.d.ts +8 -0
- package/dist/utils/cache-bootstrap.js +18 -0
- package/dist/utils/config.js +1 -1
- package/dist/utils/deploy-adapter.d.ts +40 -0
- package/dist/utils/deploy-adapter.js +58 -0
- package/dist/utils/download-template.js +3 -2
- package/dist/utils/env-management.d.ts +24 -7
- package/dist/utils/env-management.js +119 -64
- package/dist/utils/format-env-suffix.d.ts +12 -0
- package/dist/utils/format-env-suffix.js +13 -0
- package/dist/utils/formatter.js +23 -11
- package/dist/utils/fs-utils.d.ts +6 -0
- package/dist/utils/fs-utils.js +27 -0
- package/dist/utils/handle-upgrade.d.ts +9 -0
- package/dist/utils/handle-upgrade.js +41 -0
- package/dist/utils/lambda-config.d.ts +3 -1
- package/dist/utils/lambda-config.js +75 -78
- package/dist/utils/messages.d.ts +1 -2
- package/dist/utils/messages.js +29 -11
- package/dist/utils/package-manager.d.ts +24 -0
- package/dist/utils/package-manager.js +53 -0
- package/dist/utils/payload-config-ast.d.ts +27 -6
- package/dist/utils/payload-config-ast.js +106 -58
- package/dist/utils/payload-config-finder.d.ts +2 -2
- package/dist/utils/payload-config-finder.js +48 -9
- package/dist/utils/payload-config-modifier.d.ts +1 -1
- package/dist/utils/payload-config-modifier.js +70 -11
- package/dist/utils/payload-package-check.d.ts +12 -1
- package/dist/utils/payload-package-check.js +63 -5
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.js +29 -15
- package/dist/utils/resolve-environment.d.ts +14 -0
- package/dist/utils/resolve-environment.js +31 -0
- package/dist/utils/s3-upload.d.ts +7 -2
- package/dist/utils/s3-upload.js +39 -6
- package/dist/utils/token-display.js +11 -5
- package/dist/utils/typescript-validator.js +4 -6
- package/dist/utils/version-check.d.ts +3 -0
- package/dist/utils/version-check.js +38 -0
- package/package.json +33 -15
- package/dist/api/control-plane.d.ts.map +0 -1
- package/dist/api/control-plane.js.map +0 -1
- package/dist/api/figma-api.d.ts.map +0 -1
- package/dist/api/figma-api.js.map +0 -1
- package/dist/auth/browser.d.ts.map +0 -1
- package/dist/auth/browser.js.map +0 -1
- package/dist/auth/callback-server.d.ts.map +0 -1
- package/dist/auth/callback-server.js.map +0 -1
- package/dist/auth/crypto-utils.d.ts.map +0 -1
- package/dist/auth/crypto-utils.js.map +0 -1
- package/dist/auth/jwt-validator.d.ts.map +0 -1
- package/dist/auth/jwt-validator.js.map +0 -1
- package/dist/auth/oauth-flow.d.ts.map +0 -1
- package/dist/auth/oauth-flow.js.map +0 -1
- package/dist/auth/pkce.d.ts.map +0 -1
- package/dist/auth/pkce.js.map +0 -1
- package/dist/auth/project-token.d.ts.map +0 -1
- package/dist/auth/project-token.js.map +0 -1
- package/dist/auth/refresh.d.ts.map +0 -1
- package/dist/auth/refresh.js.map +0 -1
- package/dist/auth/token-store.d.ts.map +0 -1
- package/dist/auth/token-store.js.map +0 -1
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js.map +0 -1
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/list-tokens.d.ts.map +0 -1
- package/dist/commands/list-tokens.js.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js.map +0 -1
- package/dist/config/oauth.d.ts.map +0 -1
- package/dist/config/oauth.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/exports/client.d.ts.map +0 -1
- package/dist/exports/client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/oauth/components/LoginButton/index.d.ts.map +0 -1
- package/dist/oauth/components/LoginButton/index.js.map +0 -1
- package/dist/oauth/components/LogoutButton/index.d.ts.map +0 -1
- package/dist/oauth/components/LogoutButton/index.js.map +0 -1
- package/dist/oauth/defaults.d.ts.map +0 -1
- package/dist/oauth/defaults.js.map +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +0 -1
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +0 -1
- package/dist/oauth/exports/client.d.ts.map +0 -1
- package/dist/oauth/exports/client.js.map +0 -1
- package/dist/oauth/hooks/afterLogout.d.ts.map +0 -1
- package/dist/oauth/hooks/afterLogout.js.map +0 -1
- package/dist/oauth/hooks/me.d.ts.map +0 -1
- package/dist/oauth/hooks/me.js.map +0 -1
- package/dist/oauth/hooks/refresh.d.ts.map +0 -1
- package/dist/oauth/hooks/refresh.js.map +0 -1
- package/dist/oauth/index.d.ts.map +0 -1
- package/dist/oauth/index.js.map +0 -1
- package/dist/oauth/strategy/index.d.ts.map +0 -1
- package/dist/oauth/strategy/index.js.map +0 -1
- package/dist/oauth/types.d.ts.map +0 -1
- package/dist/oauth/types.js.map +0 -1
- package/dist/oauth/utilities/clearCookie.d.ts.map +0 -1
- package/dist/oauth/utilities/clearCookie.js.map +0 -1
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +0 -1
- package/dist/oauth/utilities/createCookieOptions.js.map +0 -1
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +0 -1
- package/dist/oauth/utilities/createDebugLogger.js.map +0 -1
- package/dist/oauth/utilities/extractOrigin.d.ts.map +0 -1
- package/dist/oauth/utilities/extractOrigin.js.map +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +0 -1
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +0 -1
- package/dist/oauth/utilities/getAdminPath.d.ts +0 -8
- package/dist/oauth/utilities/getAdminPath.d.ts.map +0 -1
- package/dist/oauth/utilities/getAdminPath.js +0 -9
- package/dist/oauth/utilities/getAdminPath.js.map +0 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +0 -1
- package/dist/oauth/utilities/getAuthorizeURL.js.map +0 -1
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +0 -1
- package/dist/oauth/utilities/getCookieExpiration.js.map +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +0 -1
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +0 -1
- package/dist/oauth/utilities/getTokenExp.d.ts.map +0 -1
- package/dist/oauth/utilities/getTokenExp.js.map +0 -1
- package/dist/oauth/utilities/getUsernameField.d.ts.map +0 -1
- package/dist/oauth/utilities/getUsernameField.js.map +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +0 -1
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +0 -1
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +0 -1
- package/dist/oauth/utilities/mergeHeaders.js.map +0 -1
- package/dist/oauth/utilities/refreshTokens.d.ts.map +0 -1
- package/dist/oauth/utilities/refreshTokens.js.map +0 -1
- package/dist/plugin/adapter.d.ts.map +0 -1
- package/dist/plugin/adapter.js.map +0 -1
- package/dist/plugin/build-config.d.ts.map +0 -1
- package/dist/plugin/build-config.js.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/config.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/asset-collection.d.ts.map +0 -1
- package/dist/utils/asset-collection.js.map +0 -1
- package/dist/utils/build-detection.d.ts.map +0 -1
- package/dist/utils/build-detection.js.map +0 -1
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/download-template.d.ts.map +0 -1
- package/dist/utils/download-template.js.map +0 -1
- package/dist/utils/env-management.d.ts.map +0 -1
- package/dist/utils/env-management.js.map +0 -1
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/formatter.d.ts.map +0 -1
- package/dist/utils/formatter.js.map +0 -1
- package/dist/utils/git.d.ts.map +0 -1
- package/dist/utils/git.js.map +0 -1
- package/dist/utils/is-debug.d.ts.map +0 -1
- package/dist/utils/is-debug.js.map +0 -1
- package/dist/utils/lambda-config.d.ts.map +0 -1
- package/dist/utils/lambda-config.js.map +0 -1
- package/dist/utils/log.d.ts.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/messages.d.ts.map +0 -1
- package/dist/utils/messages.js.map +0 -1
- package/dist/utils/package-manager.d.ts.map +0 -1
- package/dist/utils/package-manager.js.map +0 -1
- package/dist/utils/payload-config-ast.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.js.map +0 -1
- package/dist/utils/payload-config-finder.d.ts.map +0 -1
- package/dist/utils/payload-config-finder.js.map +0 -1
- package/dist/utils/payload-config-modifier.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.js.map +0 -1
- package/dist/utils/payload-package-check.d.ts.map +0 -1
- package/dist/utils/payload-package-check.js.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/project.js.map +0 -1
- package/dist/utils/s3-upload.d.ts.map +0 -1
- package/dist/utils/s3-upload.js.map +0 -1
- package/dist/utils/token-display.d.ts.map +0 -1
- package/dist/utils/token-display.js.map +0 -1
- package/dist/utils/typescript-validator.d.ts.map +0 -1
- package/dist/utils/typescript-validator.js.map +0 -1
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
/**
|
|
4
|
-
* Detect
|
|
5
|
-
*
|
|
6
|
-
* Checks for:
|
|
7
|
-
* - .next/standalone/server.js (required for Lambda)
|
|
8
|
-
* - .next/BUILD_ID (Next.js build identifier)
|
|
9
|
-
*
|
|
10
|
-
* @param projectPath - Path to project root
|
|
11
|
-
* @returns Build info if valid build found, null otherwise
|
|
4
|
+
* Detect a valid build across supported frameworks.
|
|
5
|
+
* Tries NextJS, then Nitro, then Vite. Returns the first match.
|
|
12
6
|
*/ export async function detectBuild(projectPath) {
|
|
7
|
+
// Try NextJS first
|
|
8
|
+
const nextjsBuild = await detectNextjsBuild(projectPath);
|
|
9
|
+
if (nextjsBuild) {
|
|
10
|
+
return nextjsBuild;
|
|
11
|
+
}
|
|
12
|
+
// Try Nitro
|
|
13
|
+
const nitroBuild = await detectNitroBuild(projectPath);
|
|
14
|
+
if (nitroBuild) {
|
|
15
|
+
return nitroBuild;
|
|
16
|
+
}
|
|
17
|
+
// Try Vite
|
|
18
|
+
const viteBuild = await detectViteBuild(projectPath);
|
|
19
|
+
if (viteBuild) {
|
|
20
|
+
return viteBuild;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Detect NextJS standalone build (.next/standalone/server.js + .next/BUILD_ID)
|
|
26
|
+
*/ async function detectNextjsBuild(projectPath) {
|
|
13
27
|
try {
|
|
14
|
-
// Check for .next/standalone/server.js
|
|
15
28
|
const serverPath = path.join(projectPath, '.next', 'standalone', 'server.js');
|
|
16
29
|
const serverStat = await fs.stat(serverPath);
|
|
17
|
-
// Check for .next/BUILD_ID
|
|
18
30
|
const buildIdPath = path.join(projectPath, '.next', 'BUILD_ID');
|
|
19
31
|
const buildId = (await fs.readFile(buildIdPath, 'utf-8')).trim();
|
|
20
|
-
// Check for lambda.zip
|
|
21
32
|
const lambdaZipPath = path.join(projectPath, 'lambda.zip');
|
|
22
33
|
let hasLambdaZip = false;
|
|
23
34
|
try {
|
|
@@ -36,6 +47,58 @@ import path from 'path';
|
|
|
36
47
|
return null;
|
|
37
48
|
}
|
|
38
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Detect Nitro build (.output/server/index.mjs)
|
|
52
|
+
* Build ID parsed from .output/nitro.json date field, or mtime of index.mjs
|
|
53
|
+
*/ async function detectNitroBuild(projectPath) {
|
|
54
|
+
try {
|
|
55
|
+
const indexPath = path.join(projectPath, '.output', 'server', 'index.mjs');
|
|
56
|
+
const indexStat = await fs.stat(indexPath);
|
|
57
|
+
let buildId = indexStat.mtime.toISOString();
|
|
58
|
+
try {
|
|
59
|
+
const nitroJsonPath = path.join(projectPath, '.output', 'nitro.json');
|
|
60
|
+
const nitroJson = JSON.parse(await fs.readFile(nitroJsonPath, 'utf-8'));
|
|
61
|
+
if (nitroJson.date) {
|
|
62
|
+
buildId = nitroJson.date;
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
// nitro.json missing or unparseable — fall back to mtime
|
|
66
|
+
}
|
|
67
|
+
const lambdaZipPath = path.join(projectPath, 'lambda.zip');
|
|
68
|
+
let hasLambdaZip = false;
|
|
69
|
+
try {
|
|
70
|
+
await fs.stat(lambdaZipPath);
|
|
71
|
+
hasLambdaZip = true;
|
|
72
|
+
} catch {
|
|
73
|
+
hasLambdaZip = false;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
buildId,
|
|
77
|
+
hasLambdaZip,
|
|
78
|
+
path: '.output',
|
|
79
|
+
timestamp: indexStat.mtime
|
|
80
|
+
};
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Detect Vite build (dist/index.html)
|
|
87
|
+
* Build ID is mtime of index.html as ISO string. No server, so hasLambdaZip is always false.
|
|
88
|
+
*/ async function detectViteBuild(projectPath) {
|
|
89
|
+
try {
|
|
90
|
+
const indexPath = path.join(projectPath, 'dist', 'index.html');
|
|
91
|
+
const indexStat = await fs.stat(indexPath);
|
|
92
|
+
return {
|
|
93
|
+
buildId: indexStat.mtime.toISOString(),
|
|
94
|
+
hasLambdaZip: false,
|
|
95
|
+
path: 'dist',
|
|
96
|
+
timestamp: indexStat.mtime
|
|
97
|
+
};
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
39
102
|
/**
|
|
40
103
|
* Get the build command from package.json
|
|
41
104
|
*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build Lambda deployment zip using pure Node.js
|
|
3
|
+
*
|
|
4
|
+
* Cross-platform replacement for build_for_lambda.sh:
|
|
5
|
+
* 1. Copies .next/static to .next/standalone/.next/static
|
|
6
|
+
* 2. Copies run.sh to .next/standalone/run.sh
|
|
7
|
+
* 3. Copies public/ to .next/standalone/public/ (if exists)
|
|
8
|
+
* 4. Creates lambda.zip from .next/standalone/
|
|
9
|
+
*
|
|
10
|
+
* @param projectPath - Path to project root
|
|
11
|
+
* @throws Error if standalone directory missing or zip creation fails
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildLambdaZip(projectPath: string): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=build-lambda-zip.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import archiver from 'archiver';
|
|
2
|
+
import { createWriteStream } from 'fs';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
/**
|
|
6
|
+
* Build Lambda deployment zip using pure Node.js
|
|
7
|
+
*
|
|
8
|
+
* Cross-platform replacement for build_for_lambda.sh:
|
|
9
|
+
* 1. Copies .next/static to .next/standalone/.next/static
|
|
10
|
+
* 2. Copies run.sh to .next/standalone/run.sh
|
|
11
|
+
* 3. Copies public/ to .next/standalone/public/ (if exists)
|
|
12
|
+
* 4. Creates lambda.zip from .next/standalone/
|
|
13
|
+
*
|
|
14
|
+
* @param projectPath - Path to project root
|
|
15
|
+
* @throws Error if standalone directory missing or zip creation fails
|
|
16
|
+
*/ export async function buildLambdaZip(projectPath) {
|
|
17
|
+
const standalonePath = path.join(projectPath, '.next', 'standalone');
|
|
18
|
+
const staticPath = path.join(projectPath, '.next', 'static');
|
|
19
|
+
const publicPath = path.join(projectPath, 'public');
|
|
20
|
+
const runShPath = path.join(projectPath, 'run.sh');
|
|
21
|
+
const zipPath = path.join(projectPath, 'lambda.zip');
|
|
22
|
+
if (!await isDirectory(standalonePath)) {
|
|
23
|
+
throw new Error('Standalone build not found at .next/standalone. ' + 'Ensure next.config has output: "standalone" and run build first.');
|
|
24
|
+
}
|
|
25
|
+
if (await isDirectory(staticPath)) {
|
|
26
|
+
const destStatic = path.join(standalonePath, '.next', 'static');
|
|
27
|
+
await copyDirectory(staticPath, destStatic);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
await fs.copyFile(runShPath, path.join(standalonePath, 'run.sh'));
|
|
31
|
+
} catch {
|
|
32
|
+
// run.sh may not exist in all setups
|
|
33
|
+
}
|
|
34
|
+
if (await isDirectory(publicPath)) {
|
|
35
|
+
const destPublic = path.join(standalonePath, 'public');
|
|
36
|
+
await copyDirectory(publicPath, destPublic);
|
|
37
|
+
}
|
|
38
|
+
await createZip(standalonePath, zipPath);
|
|
39
|
+
}
|
|
40
|
+
async function isDirectory(dirPath) {
|
|
41
|
+
try {
|
|
42
|
+
const stats = await fs.stat(dirPath);
|
|
43
|
+
return stats.isDirectory();
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function copyDirectory(src, dest) {
|
|
49
|
+
await fs.mkdir(dest, {
|
|
50
|
+
recursive: true
|
|
51
|
+
});
|
|
52
|
+
const entries = await fs.readdir(src, {
|
|
53
|
+
withFileTypes: true
|
|
54
|
+
});
|
|
55
|
+
for (const entry of entries){
|
|
56
|
+
const srcPath = path.join(src, entry.name);
|
|
57
|
+
const destPath = path.join(dest, entry.name);
|
|
58
|
+
if (entry.isDirectory()) {
|
|
59
|
+
await copyDirectory(srcPath, destPath);
|
|
60
|
+
} else {
|
|
61
|
+
await fs.copyFile(srcPath, destPath);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function createZip(sourceDir, zipPath) {
|
|
66
|
+
return new Promise((resolve, reject)=>{
|
|
67
|
+
const output = createWriteStream(zipPath);
|
|
68
|
+
const archive = archiver('zip', {
|
|
69
|
+
zlib: {
|
|
70
|
+
level: 9
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
output.on('close', ()=>resolve());
|
|
74
|
+
archive.on('error', (err)=>reject(err));
|
|
75
|
+
archive.pipe(output);
|
|
76
|
+
archive.directory(sourceDir, false);
|
|
77
|
+
void archive.finalize();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=build-lambda-zip.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BootstrapInfo } from '../api/control-plane.js';
|
|
2
|
+
import type { TokenStore } from '../auth/token-store.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cache bootstrap data for all environments in the local encrypted store.
|
|
5
|
+
* Called from init, env, and build-config to keep the store populated.
|
|
6
|
+
*/
|
|
7
|
+
export declare function cacheAllEnvironments(tokenStore: TokenStore, projectId: string, bootstrapInfo: BootstrapInfo): void;
|
|
8
|
+
//# sourceMappingURL=cache-bootstrap.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as log from './log.js';
|
|
2
|
+
/**
|
|
3
|
+
* Cache bootstrap data for all environments in the local encrypted store.
|
|
4
|
+
* Called from init, env, and build-config to keep the store populated.
|
|
5
|
+
*/ export function cacheAllEnvironments(tokenStore, projectId, bootstrapInfo) {
|
|
6
|
+
const { oauthCredentials } = bootstrapInfo;
|
|
7
|
+
for (const env of bootstrapInfo.environments){
|
|
8
|
+
tokenStore.setBootstrapData(projectId, env.name, {
|
|
9
|
+
contentSystemId: env.contentSystemId,
|
|
10
|
+
oauthClientId: oauthCredentials.oauthClientId,
|
|
11
|
+
oauthClientSecret: oauthCredentials.oauthClientSecret,
|
|
12
|
+
tenantInstanceId: env.tenantInstanceId
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
log.debug(`Cached bootstrap data for environments: ${bootstrapInfo.environments.map((e)=>e.name).join(', ')}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=cache-bootstrap.js.map
|
package/dist/utils/config.js
CHANGED
|
@@ -19,7 +19,7 @@ const GITIGNORE_FILENAME = '.gitignore';
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
// Parse existing entries
|
|
22
|
-
const existingLines = existingContent.split(
|
|
22
|
+
const existingLines = existingContent.split(/\r?\n/).filter((line)=>line.trim());
|
|
23
23
|
const existingSet = new Set(existingLines);
|
|
24
24
|
// Add new entries that don't exist
|
|
25
25
|
const newEntries = entries.filter((entry)=>!existingSet.has(entry));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface PageCollection {
|
|
2
|
+
/** S3 key → relative filesystem path from project root */
|
|
3
|
+
pathMap: Record<string, string>;
|
|
4
|
+
/** Route → S3 upload keys for that route (e.g., { "/products": ["products.html", "products.rsc"] }) */
|
|
5
|
+
routeAssetMap: Record<string, string[]>;
|
|
6
|
+
/** Route paths for the manifest pages array (e.g., ["/products", "/blog"]) */
|
|
7
|
+
routes: string[];
|
|
8
|
+
/** S3 keys to upload (e.g., ["products.html", "products.rsc", "products.meta"]) */
|
|
9
|
+
uploadKeys: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface AssetCollection {
|
|
12
|
+
/** S3 key → relative filesystem path from project root */
|
|
13
|
+
pathMap: Record<string, string>;
|
|
14
|
+
/** Route paths for the manifest assets array (e.g., ["/favicon.ico"]) */
|
|
15
|
+
routes: string[];
|
|
16
|
+
/** S3 keys to upload (same as routes for assets, without leading slash) */
|
|
17
|
+
uploadKeys: string[];
|
|
18
|
+
}
|
|
19
|
+
export type AdapterName = 'nextjs' | 'nitro' | 'vite';
|
|
20
|
+
export interface DeployAdapter {
|
|
21
|
+
collectAssets(projectPath: string): Promise<AssetCollection>;
|
|
22
|
+
collectPages(projectPath: string): Promise<PageCollection>;
|
|
23
|
+
/** SPA fallback path (e.g., "/index.html"). Undefined for SSR/SSG apps. */
|
|
24
|
+
fallback?: string;
|
|
25
|
+
name: AdapterName;
|
|
26
|
+
/** Assembles and zips the server bundle. Returns path to zip, or null if no server (e.g., Vite SPA). */
|
|
27
|
+
prepareLambdaBundle(projectPath: string): Promise<null | string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Auto-detect the framework adapter based on build output.
|
|
31
|
+
*
|
|
32
|
+
* - .next/ exists → nextjs
|
|
33
|
+
* - .output/nitro.json exists → nitro
|
|
34
|
+
* - dist/index.html exists (no .next/, no .output/) → vite
|
|
35
|
+
*
|
|
36
|
+
* @param projectPath - Path to project root
|
|
37
|
+
* @param override - Explicit adapter name from --adapter flag
|
|
38
|
+
*/
|
|
39
|
+
export declare function detectAdapter(projectPath: string, override?: AdapterName): Promise<DeployAdapter>;
|
|
40
|
+
//# sourceMappingURL=deploy-adapter.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Auto-detect the framework adapter based on build output.
|
|
5
|
+
*
|
|
6
|
+
* - .next/ exists → nextjs
|
|
7
|
+
* - .output/nitro.json exists → nitro
|
|
8
|
+
* - dist/index.html exists (no .next/, no .output/) → vite
|
|
9
|
+
*
|
|
10
|
+
* @param projectPath - Path to project root
|
|
11
|
+
* @param override - Explicit adapter name from --adapter flag
|
|
12
|
+
*/ export async function detectAdapter(projectPath, override) {
|
|
13
|
+
if (override) {
|
|
14
|
+
return loadAdapter(override);
|
|
15
|
+
}
|
|
16
|
+
const hasNext = await exists(path.join(projectPath, '.next'));
|
|
17
|
+
const hasNitro = await exists(path.join(projectPath, '.output', 'nitro.json'));
|
|
18
|
+
const hasViteDist = await exists(path.join(projectPath, 'dist', 'index.html'));
|
|
19
|
+
if (hasNext) {
|
|
20
|
+
return loadAdapter('nextjs');
|
|
21
|
+
}
|
|
22
|
+
if (hasNitro) {
|
|
23
|
+
return loadAdapter('nitro');
|
|
24
|
+
}
|
|
25
|
+
if (hasViteDist) {
|
|
26
|
+
return loadAdapter('vite');
|
|
27
|
+
}
|
|
28
|
+
throw new Error('Could not detect framework. Expected .next/ (NextJS), .output/nitro.json (Nitro), or dist/index.html (Vite). ' + 'Use --adapter to specify explicitly.');
|
|
29
|
+
}
|
|
30
|
+
async function loadAdapter(name) {
|
|
31
|
+
switch(name){
|
|
32
|
+
case 'nextjs':
|
|
33
|
+
{
|
|
34
|
+
const mod = await import('./adapters/nextjs.js');
|
|
35
|
+
return mod.nextjsAdapter;
|
|
36
|
+
}
|
|
37
|
+
case 'nitro':
|
|
38
|
+
{
|
|
39
|
+
const mod = await import('./adapters/nitro.js');
|
|
40
|
+
return mod.nitroAdapter;
|
|
41
|
+
}
|
|
42
|
+
case 'vite':
|
|
43
|
+
{
|
|
44
|
+
const mod = await import('./adapters/vite.js');
|
|
45
|
+
return mod.viteAdapter;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function exists(filePath) {
|
|
50
|
+
try {
|
|
51
|
+
await fs.stat(filePath);
|
|
52
|
+
return true;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=deploy-adapter.js.map
|
|
@@ -11,7 +11,8 @@ import { x } from 'tar';
|
|
|
11
11
|
this.name = 'TemplateDownloadError';
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
const BRANCH_OR_TAG = '
|
|
14
|
+
const BRANCH_OR_TAG = 'v3.79.1';
|
|
15
|
+
/** GitHub strips the 'v' prefix in tarball directory names */ const TARBALL_PREFIX = `payload-${BRANCH_OR_TAG.replace(/^v/, '')}`;
|
|
15
16
|
const TEMPLATE_NAME = 'blank';
|
|
16
17
|
const MAX_RETRIES = 3;
|
|
17
18
|
const INITIAL_RETRY_DELAY = 1000 // 1 second
|
|
@@ -43,7 +44,7 @@ const INITIAL_RETRY_DELAY = 1000 // 1 second
|
|
|
43
44
|
* Single attempt to download template (extracted for retry logic)
|
|
44
45
|
*/ async function downloadTemplateAttempt(projectDir) {
|
|
45
46
|
const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${BRANCH_OR_TAG}`;
|
|
46
|
-
const filter =
|
|
47
|
+
const filter = `${TARBALL_PREFIX}/templates/${TEMPLATE_NAME}/`;
|
|
47
48
|
try {
|
|
48
49
|
// Ensure target directory exists
|
|
49
50
|
await fs.mkdir(projectDir, {
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Get an environment variable value from .env file (async)
|
|
3
3
|
*
|
|
4
|
-
* @
|
|
4
|
+
* @param projectPath - Path to project directory
|
|
5
|
+
* @param key - Environment variable name to retrieve
|
|
6
|
+
* @returns The value if found, null otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEnvVar(projectPath: string, key: string): Promise<null | string>;
|
|
9
|
+
/**
|
|
10
|
+
* Get an environment variable value from .env file (sync)
|
|
11
|
+
*
|
|
12
|
+
* @param projectPath - Path to project directory
|
|
13
|
+
* @param key - Environment variable name to retrieve
|
|
14
|
+
* @returns The value if found, null otherwise
|
|
5
15
|
*/
|
|
6
|
-
export declare function
|
|
16
|
+
export declare function getEnvVarSync(projectPath: string, key: string): null | string;
|
|
7
17
|
/**
|
|
8
|
-
*
|
|
18
|
+
* Add or update an environment variable in .env file
|
|
9
19
|
*
|
|
10
|
-
*
|
|
20
|
+
* @param projectPath - Path to project directory
|
|
21
|
+
* @param key - Environment variable name
|
|
22
|
+
* @param value - Environment variable value
|
|
23
|
+
*/
|
|
24
|
+
export declare function addOrUpdateEnvVar(projectPath: string, key: string, value: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Remove an environment variable from .env file
|
|
11
27
|
*
|
|
12
28
|
* @param projectPath - Path to project directory
|
|
13
|
-
* @
|
|
29
|
+
* @param key - Environment variable name to remove
|
|
30
|
+
* @returns true if key was found and removed, false otherwise
|
|
14
31
|
*/
|
|
15
|
-
export declare function
|
|
32
|
+
export declare function removeEnvVar(projectPath: string, key: string): Promise<boolean>;
|
|
16
33
|
//# sourceMappingURL=env-management.d.ts.map
|
|
@@ -1,97 +1,152 @@
|
|
|
1
|
-
import { randomBytes } from 'crypto';
|
|
2
1
|
import fs from 'fs/promises';
|
|
2
|
+
import fsSync from 'node:fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
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 = [];
|
|
5
|
+
* Parse .env file contents and extract value for a key
|
|
6
|
+
*/ function parseEnvValue(contents, key) {
|
|
7
|
+
const lines = contents.split(/\r?\n/);
|
|
21
8
|
for (const line of lines){
|
|
22
9
|
// Skip empty lines and comments
|
|
23
10
|
if (!line.trim() || line.trim().startsWith('#')) {
|
|
24
|
-
processedLines.push(line);
|
|
25
11
|
continue;
|
|
26
12
|
}
|
|
27
13
|
// Skip lines without =
|
|
28
14
|
if (!line.includes('=')) {
|
|
29
|
-
processedLines.push(line);
|
|
30
15
|
continue;
|
|
31
16
|
}
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
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);
|
|
17
|
+
const equalsIndex = line.indexOf('=');
|
|
18
|
+
const lineKey = line.substring(0, equalsIndex).trim();
|
|
19
|
+
if (lineKey === key) {
|
|
20
|
+
return line.substring(equalsIndex + 1);
|
|
44
21
|
}
|
|
45
22
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get an environment variable value from .env file (async)
|
|
27
|
+
*
|
|
28
|
+
* @param projectPath - Path to project directory
|
|
29
|
+
* @param key - Environment variable name to retrieve
|
|
30
|
+
* @returns The value if found, null otherwise
|
|
31
|
+
*/ export async function getEnvVar(projectPath, key) {
|
|
32
|
+
const envPath = path.join(projectPath, '.env');
|
|
33
|
+
try {
|
|
34
|
+
const contents = await fs.readFile(envPath, 'utf-8');
|
|
35
|
+
return parseEnvValue(contents, key);
|
|
36
|
+
} catch {
|
|
37
|
+
// File doesn't exist or can't be read
|
|
38
|
+
return null;
|
|
49
39
|
}
|
|
50
|
-
return processedLines.join('\n');
|
|
51
40
|
}
|
|
52
41
|
/**
|
|
53
|
-
*
|
|
42
|
+
* Get an environment variable value from .env file (sync)
|
|
54
43
|
*
|
|
55
|
-
*
|
|
44
|
+
* @param projectPath - Path to project directory
|
|
45
|
+
* @param key - Environment variable name to retrieve
|
|
46
|
+
* @returns The value if found, null otherwise
|
|
47
|
+
*/ export function getEnvVarSync(projectPath, key) {
|
|
48
|
+
const envPath = path.join(projectPath, '.env');
|
|
49
|
+
try {
|
|
50
|
+
const contents = fsSync.readFileSync(envPath, 'utf-8');
|
|
51
|
+
return parseEnvValue(contents, key);
|
|
52
|
+
} catch {
|
|
53
|
+
// File doesn't exist or can't be read
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Add or update an environment variable in .env file
|
|
56
59
|
*
|
|
57
60
|
* @param projectPath - Path to project directory
|
|
58
|
-
* @
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const envExamplePath = path.join(projectPath, '.env.example');
|
|
61
|
+
* @param key - Environment variable name
|
|
62
|
+
* @param value - Environment variable value
|
|
63
|
+
*/ export async function addOrUpdateEnvVar(projectPath, key, value) {
|
|
62
64
|
const envPath = path.join(projectPath, '.env');
|
|
63
65
|
try {
|
|
64
|
-
|
|
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
|
|
66
|
+
let contents = '';
|
|
73
67
|
let envExists = false;
|
|
68
|
+
// Try to read existing .env file
|
|
74
69
|
try {
|
|
75
|
-
await fs.
|
|
70
|
+
contents = await fs.readFile(envPath, 'utf-8');
|
|
76
71
|
envExists = true;
|
|
77
72
|
} catch {
|
|
78
|
-
// .env doesn't exist
|
|
73
|
+
// .env doesn't exist, will create it
|
|
79
74
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
const lines = contents.split(/\r?\n/);
|
|
76
|
+
const seenKeys = new Set();
|
|
77
|
+
const processedLines = [];
|
|
78
|
+
let keyUpdated = false;
|
|
79
|
+
for (const line of lines){
|
|
80
|
+
// Skip empty lines at start if file didn't exist
|
|
81
|
+
if (!envExists && !line.trim()) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// Preserve empty lines and comments
|
|
85
|
+
if (!line.trim() || line.trim().startsWith('#')) {
|
|
86
|
+
processedLines.push(line);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
// Skip lines without =
|
|
90
|
+
if (!line.includes('=')) {
|
|
91
|
+
processedLines.push(line);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const [lineKey] = line.split('=');
|
|
95
|
+
const trimmedKey = lineKey.trim();
|
|
96
|
+
// Skip duplicate keys (keep first occurrence)
|
|
97
|
+
if (seenKeys.has(trimmedKey)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
seenKeys.add(trimmedKey);
|
|
101
|
+
// Update or keep the line
|
|
102
|
+
if (trimmedKey === key) {
|
|
103
|
+
processedLines.push(`${key}=${value}`);
|
|
104
|
+
keyUpdated = true;
|
|
105
|
+
} else {
|
|
106
|
+
processedLines.push(line);
|
|
90
107
|
}
|
|
91
108
|
}
|
|
92
|
-
|
|
109
|
+
// Add key if not present
|
|
110
|
+
if (!keyUpdated) {
|
|
111
|
+
processedLines.push(`${key}=${value}`);
|
|
112
|
+
}
|
|
113
|
+
await fs.writeFile(envPath, processedLines.join('\n'), 'utf-8');
|
|
93
114
|
} catch (error) {
|
|
94
|
-
throw new Error(`Failed to
|
|
115
|
+
throw new Error(`Failed to update .env file: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove an environment variable from .env file
|
|
120
|
+
*
|
|
121
|
+
* @param projectPath - Path to project directory
|
|
122
|
+
* @param key - Environment variable name to remove
|
|
123
|
+
* @returns true if key was found and removed, false otherwise
|
|
124
|
+
*/ export async function removeEnvVar(projectPath, key) {
|
|
125
|
+
const envPath = path.join(projectPath, '.env');
|
|
126
|
+
try {
|
|
127
|
+
const contents = await fs.readFile(envPath, 'utf-8');
|
|
128
|
+
const lines = contents.split(/\r?\n/);
|
|
129
|
+
const filteredLines = [];
|
|
130
|
+
let found = false;
|
|
131
|
+
for (const line of lines){
|
|
132
|
+
if (line.trim() && !line.trim().startsWith('#') && line.includes('=')) {
|
|
133
|
+
const equalsIndex = line.indexOf('=');
|
|
134
|
+
const lineKey = line.substring(0, equalsIndex).trim();
|
|
135
|
+
if (lineKey === key) {
|
|
136
|
+
found = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
filteredLines.push(line);
|
|
141
|
+
}
|
|
142
|
+
if (found) {
|
|
143
|
+
// Collapse consecutive blank lines and trim leading/trailing blank lines
|
|
144
|
+
const collapsed = filteredLines.join('\n').replace(/\n{3,}/g, '\n\n').replace(/^\n+/, '');
|
|
145
|
+
await fs.writeFile(envPath, collapsed, 'utf-8');
|
|
146
|
+
}
|
|
147
|
+
return found;
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
95
150
|
}
|
|
96
151
|
}
|
|
97
152
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Environment } from '../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Format environment suffix for user-facing messages.
|
|
4
|
+
* Returns empty string for production (default), suffix for other environments.
|
|
5
|
+
*
|
|
6
|
+
* @param env - The environment
|
|
7
|
+
* @param prefix - Prefix before environment name (default: ' to ')
|
|
8
|
+
* @param suffix - Suffix after environment name (default: '')
|
|
9
|
+
* @returns Formatted string or empty string for production
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatEnvSuffix(env: Environment, prefix?: string, suffix?: string): string;
|
|
12
|
+
//# sourceMappingURL=format-env-suffix.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format environment suffix for user-facing messages.
|
|
3
|
+
* Returns empty string for production (default), suffix for other environments.
|
|
4
|
+
*
|
|
5
|
+
* @param env - The environment
|
|
6
|
+
* @param prefix - Prefix before environment name (default: ' to ')
|
|
7
|
+
* @param suffix - Suffix after environment name (default: '')
|
|
8
|
+
* @returns Formatted string or empty string for production
|
|
9
|
+
*/ export function formatEnvSuffix(env, prefix = ' to ', suffix = '') {
|
|
10
|
+
return env !== 'production' ? `${prefix}${env}${suffix}` : '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=format-env-suffix.js.map
|