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
452
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.0.0-canary.a192632 to 3.0.0-canary.a5aaf21

dist/lib/download-template.d.ts

11

dist/lib/create-project.js
import * as p from '@clack/prompts';
import chalk from 'chalk';
import degit from 'degit';
import execa from 'execa';

@@ -11,2 +10,3 @@ import fse from 'fs-extra';

import { configurePayloadConfig } from './configure-payload-config.js';
import { downloadTemplate } from './download-template.js';
const filename = fileURLToPath(import.meta.url);

@@ -30,2 +30,4 @@ const dirname = path.dirname(filename);

installCmd = 'pnpm install';
} else if (packageManager === 'bun') {
installCmd = 'bun install';
}

@@ -59,4 +61,7 @@ try {

}
const emitter = degit(templateUrl);
await emitter.clone(projectDir);
await downloadTemplate({
name: template.name,
branch: 'beta',
projectDir
});
}

@@ -63,0 +68,0 @@ const spinner = p.spinner();

@@ -13,2 +13,3 @@ import { jest } from '@jest/globals';

beforeAll(()=>{
// eslint-disable-next-line no-console
console.log = jest.fn();

@@ -33,3 +34,3 @@ });

'--db': 'mongodb',
'--local-template': 'blank-3.0',
'--local-template': 'blank',
'--no-deps': true

@@ -56,3 +57,3 @@ };

// Check package name and description
expect(packageJson.name).toEqual(projectName);
expect(packageJson.name).toStrictEqual(projectName);
});

@@ -63,7 +64,7 @@ describe('creates project from template', ()=>{

[
'blank-3.0',
'blank',
'mongodb'
],
[
'blank-3.0',
'blank',
'postgres'

@@ -101,5 +102,2 @@ ]

}))?.[0];
if (!payloadConfigPath) {
throw new Error(`Could not find payload.config.ts inside ${projectDir}`);
}
const content = fse.readFileSync(payloadConfigPath, 'utf-8');

@@ -106,0 +104,0 @@ // Check payload.config.ts

@@ -5,3 +5,3 @@ import type { CliArgs, PackageManager } from '../types.js';

projectDir: string;
}): Promise<PackageManager>;
}): PackageManager;
//# sourceMappingURL=get-package-manager.d.ts.map

@@ -1,4 +0,3 @@

import execa from 'execa';
import fse from 'fs-extra';
export async function getPackageManager(args) {
export function getPackageManager(args) {
const { cliArgs, projectDir } = args;

@@ -14,26 +13,27 @@ try {

detected = 'npm';
} else if (cliArgs?.['--use-bun'] || fse.existsSync(`${projectDir}/bun.lockb`)) {
detected = 'bun';
} else {
// Otherwise check for existing commands
if (await commandExists('pnpm')) {
detected = 'pnpm';
} else if (await commandExists('yarn')) {
detected = 'yarn';
} else {
detected = 'npm';
}
// Otherwise check the execution environment
detected = getEnvironmentPackageManager();
}
return detected;
} catch (error) {
} catch (ignore) {
return 'npm';
}
}
async function commandExists(command) {
try {
await execa.command(`command -v ${command}`);
return true;
} catch {
return false;
function getEnvironmentPackageManager() {
const userAgent = process.env.npm_config_user_agent || '';
if (userAgent.startsWith('yarn')) {
return 'yarn';
}
if (userAgent.startsWith('pnpm')) {
return 'pnpm';
}
if (userAgent.startsWith('bun')) {
return 'bun';
}
return 'npm';
}
//# sourceMappingURL=get-package-manager.js.map

@@ -29,3 +29,3 @@ import * as p from '@clack/prompts';

}
const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
if (!nextConfigType) {

@@ -125,3 +125,5 @@ return {

const logDebug = (message)=>{
if (debug) origDebug(message);
if (debug) {
origDebug(message);
}
};

@@ -134,3 +136,3 @@ if (!fs.existsSync(projectDir)) {

}
const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank-3.0');
const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank');
logDebug(`Using template files from: ${templateFilesPath}`);

@@ -154,3 +156,3 @@ if (!fs.existsSync(templateFilesPath)) {

// This is a little clunky and needs to account for isSrcDir
copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug);
copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath));
// Wrap next.config.js with withPayload

@@ -157,0 +159,0 @@ await wrapNextConfig({

import * as p from '@clack/prompts';
import slugify from '@sindresorhus/slugify';
export async function parseProjectName(args) {
if (args['--name']) return slugify(args['--name']);
if (args._[0]) return slugify(args._[0]);
if (args['--name']) {
return slugify(args['--name']);
}
if (args._[0]) {
return slugify(args._[0]);
}
const projectName = await p.text({
message: 'Project name?',
validate: (value)=>{
if (!value) return 'Please enter a project name.';
if (!value) {
return 'Please enter a project name.';
}
}

@@ -11,0 +17,0 @@ });

@@ -6,3 +6,5 @@ import * as p from '@clack/prompts';

const template = validTemplates.find((t)=>t.name === templateName);
if (!template) throw new Error('Invalid template given');
if (!template) {
throw new Error('Invalid template given');
}
return template;

@@ -9,0 +11,0 @@ }

@@ -22,2 +22,13 @@ const mongodbReplacement = {

};
const vercelPostgresReplacement = {
configReplacement: (envName = 'POSTGRES_URL')=>[
' db: vercelPostgresAdapter({',
' pool: {',
` connectionString: process.env.${envName} || '',`,
' },',
' }),'
],
importReplacement: "import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'",
packageName: '@payloadcms/db-vercel-postgres'
};
const sqliteReplacement = {

@@ -37,3 +48,4 @@ configReplacement: (envName = 'DATABASE_URI')=>[

postgres: postgresReplacement,
sqlite: sqliteReplacement
sqlite: sqliteReplacement,
'vercel-postgres': vercelPostgresReplacement
};

@@ -40,0 +52,0 @@ const vercelBlobStorageReplacement = {

@@ -19,2 +19,7 @@ import * as p from '@clack/prompts';

value: 'sqlite'
},
'vercel-postgres': {
dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',
title: 'Vercel Postgres (beta)',
value: 'vercel-postgres'
}

@@ -38,3 +43,5 @@ };

});
if (p.isCancel(dbType)) process.exit(0);
if (p.isCancel(dbType)) {
process.exit(0);
}
}

@@ -53,3 +60,5 @@ const dbChoice = dbChoiceRecord[dbType];

});
if (p.isCancel(dbUri)) process.exit(0);
if (p.isCancel(dbUri)) {
process.exit(0);
}
}

@@ -56,0 +65,0 @@ return {

@@ -17,3 +17,3 @@ import { error, info } from '../utils/log.js';

description: 'Blank 3.0 Template',
url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta'
url: 'https://github.com/payloadcms/payload/templates/blank#beta'
},

@@ -20,0 +20,0 @@ {

@@ -12,6 +12,8 @@ import execa from 'execa';

export async function updatePayloadInProject(appDetails) {
if (!appDetails.nextConfigPath) return {
message: 'No Next.js config found',
success: false
};
if (!appDetails.nextConfigPath) {
return {
message: 'No Next.js config found',
success: false
};
}
const projectDir = path.dirname(appDetails.nextConfigPath);

@@ -63,3 +65,3 @@ const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));

info(`Updating Payload Next.js files...`);
const templateFilesPath = process.env.JEST_WORKER_ID !== undefined ? path.resolve(dirname, '../../../../templates/blank-3.0') : path.resolve(dirname, '../..', 'dist/template');
const templateFilesPath = process.env.JEST_WORKER_ID !== undefined ? path.resolve(dirname, '../../../../templates/blank') : path.resolve(dirname, '../..', 'dist/template');
const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)');

@@ -66,0 +68,0 @@ copyRecursiveSync(templateSrcDir, path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'));

import { parse } from '@swc/core';
import chalk from 'chalk';
import { Syntax, parseModule } from 'esprima-next';
import { parseModule, Syntax } from 'esprima-next';
import fs from 'fs';

@@ -24,6 +24,2 @@ import { log, warning } from '../utils/log.js';

content = withPayloadStatement[configType] + '\n' + content;
console.log({
configType,
content
});
if (configType === 'cjs' || configType === 'esm') {

@@ -30,0 +26,0 @@ try {

@@ -18,7 +18,9 @@ import fs from 'fs-extra';

fileContents = `# Added by Payload\n` + envFile.split('\n').filter((e)=>e).map((line)=>{
if (line.startsWith('#') || !line.includes('=')) return line;
if (line.startsWith('#') || !line.includes('=')) {
return line;
}
const split = line.split('=');
const key = split[0];
let value = split[1];
if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI') {
if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI' || key === 'POSTGRES_URL') {
value = databaseUri;

@@ -25,0 +27,0 @@ }

@@ -19,3 +19,3 @@ import * as p from '@clack/prompts';

import { error, info } from './utils/log.js';
import { feedbackOutro, helpMessage, moveMessage, successMessage, successfulNextInit } from './utils/messages.js';
import { feedbackOutro, helpMessage, moveMessage, successfulNextInit, successMessage } from './utils/messages.js';
export class Main {

@@ -39,2 +39,3 @@ args;

'--no-deps': Boolean,
'--use-bun': Boolean,
'--use-npm': Boolean,

@@ -99,3 +100,3 @@ '--use-pnpm': Boolean,

const projectDir = nextConfigPath ? path.dirname(nextConfigPath) : path.resolve(process.cwd(), slugify(projectName));
const packageManager = await getPackageManager({
const packageManager = getPackageManager({
cliArgs: this.args,

@@ -102,0 +103,0 @@ projectDir

@@ -10,3 +10,3 @@ import fs from 'fs';

/**
* Copy the necessary template files from `templates/blank-3.0` to `dist/template`
* Copy the necessary template files from `templates/blank` to `dist/template`
*

@@ -17,3 +17,3 @@ * Eventually, this should be replaced with using tar.x to stream from the git repo

const outputPath = path.resolve(dirname, '../../dist/template');
const sourceTemplatePath = path.resolve(root, 'templates/blank-3.0');
const sourceTemplatePath = path.resolve(root, 'templates/blank');
if (!fs.existsSync(sourceTemplatePath)) {

@@ -27,3 +27,3 @@ throw new Error(`Source path does not exist: ${sourceTemplatePath}`);

}
// Copy the src directory from `templates/blank-3.0` to `dist`
// Copy the src directory from `templates/blank` to `dist`
const srcPath = path.resolve(sourceTemplatePath, 'src');

@@ -30,0 +30,0 @@ const distSrcPath = path.resolve(outputPath, 'src');

@@ -18,2 +18,5 @@ // storage-adapter-import-placeholder

user: Users.slug,
importMap: {
baseDir: path.resolve(dirname),
},
},

@@ -20,0 +23,0 @@ collections: [Users, Media],

@@ -18,2 +18,3 @@ import type arg from 'arg';

'--template-branch': StringConstructor;
'--use-bun': BooleanConstructor;
'--use-npm': BooleanConstructor;

@@ -50,3 +51,3 @@ '--use-pnpm': BooleanConstructor;

export type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn';
export type DbType = 'mongodb' | 'postgres' | 'sqlite';
export type DbType = 'mongodb' | 'postgres' | 'sqlite' | 'vercel-postgres';
export type DbDetails = {

@@ -53,0 +54,0 @@ dbUri: string;

@@ -6,3 +6,3 @@ /**

*/
export declare function copyRecursiveSync(src: string, dest: string, debug?: boolean): void;
export declare function copyRecursiveSync(src: string, dest: string): void;
//# sourceMappingURL=copy-recursive-sync.d.ts.map

@@ -7,3 +7,3 @@ import fs from 'fs';

* @internal
*/ export function copyRecursiveSync(src, dest, debug) {
*/ export function copyRecursiveSync(src, dest) {
const exists = fs.existsSync(src);

@@ -10,0 +10,0 @@ const stats = exists && fs.statSync(src);

@@ -35,2 +35,3 @@ /* eslint-disable no-console */ import chalk from 'chalk';

--use-pnpm Use pnpm to install dependencies
--use-bun Use bun to install dependencies (experimental)
--no-deps Do not install any dependencies

@@ -37,0 +38,0 @@ -h Show help

{
"name": "create-payload-app",
"version": "3.0.0-canary.a192632",
"version": "3.0.0-canary.a5aaf21",
"homepage": "https://payloadcms.com",

@@ -48,3 +48,2 @@ "repository": {

"comment-json": "^4.2.3",
"degit": "^2.8.4",
"esprima-next": "^6.0.3",

@@ -55,11 +54,14 @@ "execa": "^5.0.0",

"globby": "11.1.0",
"tar": "^7.4.3",
"terminal-link": "^2.1.1"
},
"devDependencies": {
"@types/degit": "^2.8.3",
"@types/esprima": "^4.0.6",
"@types/fs-extra": "^9.0.12",
"@types/jest": "29.5.12",
"@types/node": "20.12.5"
"@types/node": "22.5.4"
},
"engines": {
"node": "^18.20.2 || >=20.9.0"
},
"scripts": {

@@ -69,2 +71,4 @@ "build": "pnpm pack-template-files && pnpm typecheck && pnpm build:swc",

"clean": "rimraf {dist,*.tsbuildinfo}",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"pack-template-files": "node --no-deprecation --import @swc-node/register/esm-register src/scripts/pack-template-files.ts",

@@ -71,0 +75,0 @@ "test": "jest",

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

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

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

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

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

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