Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-payload-app

Package Overview
Dependencies
Maintainers
0
Versions
435
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-payload-app - npm Package Compare versions

Comparing version 3.8.0 to 3.8.1-canary.84084b6

LICENSE.md

54

dist/lib/manage-env-files.js
import fs from 'fs-extra';
import path from 'path';
import { debug, error } from '../utils/log.js';
const updateEnvVariables = (contents, databaseType, databaseUri, payloadSecret)=>{
return contents.split('\n').filter((e)=>e).map((line)=>{
import { dbChoiceRecord } from './select-db.js';
const updateEnvExampleVariables = (contents, databaseType)=>{
return contents.split('\n').map((line)=>{
if (line.startsWith('#') || !line.includes('=')) {
return line;
return line // Preserve comments and unrelated lines
;
}
const [key, ...valueParts] = line.split('=');
let value = valueParts.join('=');
if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI' || key === 'POSTGRES_URL') {
value = databaseUri;
if (databaseType === 'vercel-postgres') {
value = databaseUri;
const [key] = line.split('=');
if (key === 'DATABASE_URI' || key === 'POSTGRES_URL' || key === 'MONGODB_URI') {
const dbChoice = databaseType ? dbChoiceRecord[databaseType] : null;
if (dbChoice) {
const placeholderUri = `${dbChoice.dbConnectionPrefix}your-database-name${dbChoice.dbConnectionSuffix || ''}`;
return databaseType === 'vercel-postgres' ? `POSTGRES_URL=${placeholderUri}` : `DATABASE_URI=${placeholderUri}`;
}
return `DATABASE_URI=your-database-connection-here` // Fallback
;
}
if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') {
value = payloadSecret;
return `PAYLOAD_SECRET=YOUR_SECRET_HERE`;
}
return `${key}=${value}`;
return line;
}).join('\n');
};
const generateEnvContent = (existingEnv, databaseType, databaseUri, payloadSecret)=>{
const dbKey = databaseType === 'vercel-postgres' ? 'POSTGRES_URL' : 'DATABASE_URI';
const envVars = {};
existingEnv.split('\n').filter((line)=>line.includes('=') && !line.startsWith('#')).forEach((line)=>{
const [key, value] = line.split('=');
envVars[key] = value;
});
// Override specific keys
envVars[dbKey] = databaseUri;
envVars['PAYLOAD_SECRET'] = payloadSecret;
// Rebuild content
return Object.entries(envVars).map(([key, value])=>`${key}=${value}`).join('\n');
};
/** Parse and swap .env.example values and write .env */ export async function manageEnvFiles(args) {

@@ -33,2 +50,3 @@ const { cliArgs, databaseType, databaseUri, payloadSecret, projectDir, template } = args;

let updatedExampleContents;
// Update .env.example
if (template?.type === 'starter') {

@@ -40,11 +58,13 @@ if (!fs.existsSync(envExamplePath)) {

const envExampleContents = await fs.readFile(envExamplePath, 'utf8');
updatedExampleContents = updateEnvVariables(envExampleContents, databaseType, databaseUri, payloadSecret);
await fs.writeFile(envExamplePath, updatedExampleContents);
updatedExampleContents = updateEnvExampleVariables(envExampleContents, databaseType);
await fs.writeFile(envExamplePath, updatedExampleContents.trimEnd() + '\n');
debug(`.env.example file successfully updated`);
} else {
updatedExampleContents = `# Added by Payload\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`;
updatedExampleContents = `# Added by Payload\nDATABASE_URI=your-connection-string-here\nPAYLOAD_SECRET=YOUR_SECRET_HERE\n`;
await fs.writeFile(envExamplePath, updatedExampleContents.trimEnd() + '\n');
}
const existingEnvContents = fs.existsSync(envPath) ? await fs.readFile(envPath, 'utf8') : '';
const updatedEnvContents = existingEnvContents ? `${existingEnvContents}\n# Added by Payload\n${updatedExampleContents}` : `# Added by Payload\n${updatedExampleContents}`;
await fs.writeFile(envPath, updatedEnvContents);
// Merge existing variables and create or update .env
const envExampleContents = await fs.readFile(envExamplePath, 'utf8');
const envContent = generateEnvContent(envExampleContents, databaseType, databaseUri, payloadSecret);
await fs.writeFile(envPath, `# Added by Payload\n${envContent.trimEnd()}\n`);
debug(`.env file successfully created or updated`);

@@ -51,0 +71,0 @@ } catch (err) {

@@ -1,3 +0,11 @@

import type { CliArgs, DbDetails } from '../types.js';
import type { CliArgs, DbDetails, DbType } from '../types.js';
type DbChoice = {
dbConnectionPrefix: `${string}/`;
dbConnectionSuffix?: string;
title: string;
value: DbType;
};
export declare const dbChoiceRecord: Record<DbType, DbChoice>;
export declare function selectDb(args: CliArgs, projectName: string): Promise<DbDetails>;
export {};
//# sourceMappingURL=select-db.d.ts.map
import * as p from '@clack/prompts';
import slugify from '@sindresorhus/slugify';
const dbChoiceRecord = {
export const dbChoiceRecord = {
mongodb: {

@@ -5,0 +5,0 @@ dbConnectionPrefix: 'mongodb://127.0.0.1/',

@@ -16,6 +16,9 @@ import fs from 'fs';

fs.readdirSync(src).forEach((childItemName)=>{
if (ignoreRegex && ignoreRegex.some((regex)=>new RegExp(regex).test(childItemName))) {
if (ignoreRegex && ignoreRegex.some((regex)=>{
return new RegExp(regex).test(childItemName);
})) {
console.log(`Ignoring ${childItemName} due to regex: ${ignoreRegex}`);
return;
}
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName), ignoreRegex);
});

@@ -22,0 +25,0 @@ } else {

{
"name": "create-payload-app",
"version": "3.8.0",
"version": "3.8.1-canary.84084b6",
"homepage": "https://payloadcms.com",

@@ -5,0 +5,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc