create-payload-app
Advanced tools
Comparing version 3.0.0-canary.d894ac7 to 3.0.0-canary.dc8b1fe
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 | ||
}); | ||
} | ||
@@ -77,3 +82,3 @@ const spinner = p.spinner(); | ||
// Remove yarn.lock file. This is only desired in Payload Cloud. | ||
const lockPath = path.resolve(projectDir, 'yarn.lock'); | ||
const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml'); | ||
if (fse.existsSync(lockPath)) { | ||
@@ -80,0 +85,0 @@ await fse.remove(lockPath); |
@@ -13,2 +13,3 @@ import { jest } from '@jest/globals'; | ||
beforeAll(()=>{ | ||
// eslint-disable-next-line no-console | ||
console.log = jest.fn(); | ||
@@ -55,3 +56,3 @@ }); | ||
// Check package name and description | ||
expect(packageJson.name).toEqual(projectName); | ||
expect(packageJson.name).toStrictEqual(projectName); | ||
}); | ||
@@ -99,5 +100,2 @@ describe('creates project from template', ()=>{ | ||
}))?.[0]; | ||
if (!payloadConfigPath) { | ||
throw new Error(`Could not find payload.config.ts inside ${projectDir}`); | ||
} | ||
const content = fse.readFileSync(payloadConfigPath, 'utf-8'); | ||
@@ -104,0 +102,0 @@ // Check payload.config.ts |
@@ -14,20 +14,32 @@ import execa from 'execa'; | ||
detected = 'npm'; | ||
} else if (cliArgs?.['--use-bun'] || fse.existsSync(`${projectDir}/bun.lockb`)) { | ||
detected = 'bun'; | ||
} else if (await commandExists('pnpm')) { | ||
// Prefer pnpm if it's installed | ||
detected = 'pnpm'; | ||
} 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'; | ||
} | ||
} | ||
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'; | ||
} | ||
async function commandExists(command) { | ||
try { | ||
await execa.command(`command -v ${command}`); | ||
await execa.command(process.platform === 'win32' ? `where ${command}` : `command -v ${command}`); | ||
return true; | ||
@@ -34,0 +46,0 @@ } catch { |
@@ -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); | ||
} | ||
}; | ||
@@ -153,3 +155,3 @@ if (!fs.existsSync(projectDir)) { | ||
// 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 | ||
@@ -170,3 +172,3 @@ await wrapNextConfig({ | ||
'@payloadcms/richtext-lexical', | ||
'@payloadcms/plugin-cloud' | ||
'@payloadcms/payload-cloud' | ||
].map((pkg)=>`${pkg}@beta`); | ||
@@ -173,0 +175,0 @@ packagesToInstall.push(`@payloadcms/db-${dbType}@beta`); |
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 | ||
}; | ||
@@ -57,4 +69,4 @@ const vercelBlobStorageReplacement = { | ||
], | ||
importReplacement: "import { payloadCloudPlugin } from '@payloadcms/plugin-cloud'", | ||
packageName: '@payloadcms/plugin-cloud' | ||
importReplacement: "import { payloadCloudPlugin } from '@payloadcms/payload-cloud'", | ||
packageName: '@payloadcms/payload-cloud' | ||
}; | ||
@@ -61,0 +73,0 @@ // Removes placeholders |
@@ -11,3 +11,3 @@ import * as p from '@clack/prompts'; | ||
dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/', | ||
title: 'PostgreSQL (beta)', | ||
title: 'PostgreSQL', | ||
value: 'postgres' | ||
@@ -20,2 +20,7 @@ }, | ||
value: 'sqlite' | ||
}, | ||
'vercel-postgres': { | ||
dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/', | ||
title: 'Vercel Postgres (beta)', | ||
value: 'vercel-postgres' | ||
} | ||
@@ -39,3 +44,5 @@ }; | ||
}); | ||
if (p.isCancel(dbType)) process.exit(0); | ||
if (p.isCancel(dbType)) { | ||
process.exit(0); | ||
} | ||
} | ||
@@ -54,3 +61,5 @@ const dbChoice = dbChoiceRecord[dbType]; | ||
}); | ||
if (p.isCancel(dbUri)) process.exit(0); | ||
if (p.isCancel(dbUri)) { | ||
process.exit(0); | ||
} | ||
} | ||
@@ -57,0 +66,0 @@ return { |
import { error, info } from '../utils/log.js'; | ||
import { PACKAGE_VERSION } from './constants.js'; | ||
export function validateTemplate(templateName) { | ||
@@ -17,3 +18,3 @@ const validTemplates = getValidTemplates(); | ||
description: 'Blank 3.0 Template', | ||
url: 'https://github.com/payloadcms/payload/templates/blank#beta' | ||
url: `https://github.com/payloadcms/payload/templates/blank#v${PACKAGE_VERSION}` | ||
}, | ||
@@ -24,3 +25,3 @@ { | ||
description: 'Website Template', | ||
url: 'https://github.com/payloadcms/payload/templates/website#beta' | ||
url: `https://github.com/payloadcms/payload/templates/website#v${PACKAGE_VERSION}` | ||
} | ||
@@ -27,0 +28,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); | ||
@@ -18,0 +20,0 @@ const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json')); |
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 { |
@@ -1,5 +0,6 @@ | ||
import type { CliArgs, ProjectTemplate } from '../types.js'; | ||
import type { CliArgs, DbType, ProjectTemplate } from '../types.js'; | ||
/** Parse and swap .env.example values and write .env */ | ||
export declare function writeEnvFile(args: { | ||
cliArgs: CliArgs; | ||
databaseType?: DbType; | ||
databaseUri: string; | ||
@@ -6,0 +7,0 @@ payloadSecret: string; |
@@ -5,3 +5,3 @@ import fs from 'fs-extra'; | ||
/** Parse and swap .env.example values and write .env */ export async function writeEnvFile(args) { | ||
const { cliArgs, databaseUri, payloadSecret, projectDir, template } = args; | ||
const { cliArgs, databaseType, databaseUri, payloadSecret, projectDir, template } = args; | ||
if (cliArgs['--dry-run']) { | ||
@@ -19,7 +19,12 @@ debug(`DRY RUN: .env file created`); | ||
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 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') { | ||
if (databaseType === 'vercel-postgres') { | ||
key = 'POSTGRES_URL'; | ||
} | ||
value = databaseUri; | ||
@@ -26,0 +31,0 @@ } |
@@ -8,2 +8,3 @@ import * as p from '@clack/prompts'; | ||
import { configurePayloadConfig } from './lib/configure-payload-config.js'; | ||
import { PACKAGE_VERSION } from './lib/constants.js'; | ||
import { createProject } from './lib/create-project.js'; | ||
@@ -19,4 +20,4 @@ import { generateSecret } from './lib/generate-secret.js'; | ||
import { writeEnvFile } from './lib/write-env-file.js'; | ||
import { error, info } from './utils/log.js'; | ||
import { feedbackOutro, helpMessage, moveMessage, successMessage, successfulNextInit } from './utils/messages.js'; | ||
import { debug, error, info } from './utils/log.js'; | ||
import { feedbackOutro, helpMessage, moveMessage, successfulNextInit, successMessage } from './utils/messages.js'; | ||
export class Main { | ||
@@ -40,2 +41,3 @@ args; | ||
'--no-deps': Boolean, | ||
'--use-bun': Boolean, | ||
'--use-npm': Boolean, | ||
@@ -65,2 +67,3 @@ '--use-pnpm': Boolean, | ||
} | ||
const debugFlag = this.args['--debug']; | ||
// eslint-disable-next-line no-console | ||
@@ -144,2 +147,3 @@ console.log('\n'); | ||
cliArgs: this.args, | ||
databaseType: dbDetails.type, | ||
databaseUri: dbDetails.dbUri, | ||
@@ -162,2 +166,5 @@ payloadSecret: generateSecret(), | ||
} | ||
if (debugFlag) { | ||
debug(`Using templates from git tag: ${PACKAGE_VERSION}`); | ||
} | ||
const validTemplates = getValidTemplates(); | ||
@@ -185,2 +192,3 @@ const template = await parseTemplate(this.args, validTemplates); | ||
cliArgs: this.args, | ||
databaseType: dbDetails.type, | ||
databaseUri: dbDetails.dbUri, | ||
@@ -187,0 +195,0 @@ payloadSecret, |
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY it because it could be re-written at any time. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes' | ||
import '@payloadcms/next/css' | ||
import { | ||
REST_DELETE, | ||
REST_GET, | ||
REST_OPTIONS, | ||
REST_PATCH, | ||
REST_POST, | ||
REST_PUT, | ||
} from '@payloadcms/next/routes' | ||
@@ -10,2 +18,3 @@ export const GET = REST_GET(config) | ||
export const PATCH = REST_PATCH(config) | ||
export const PUT = REST_PUT(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY it because it could be re-written at any time. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import '@payloadcms/next/css' | ||
import { GRAPHQL_PLAYGROUND_GET } from '@payloadcms/next/routes' | ||
export const GET = GRAPHQL_PLAYGROUND_GET(config) |
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */ | ||
/* DO NOT MODIFY it because it could be re-written at any time. */ | ||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */ | ||
import config from '@payload-config' | ||
import { GRAPHQL_POST } from '@payloadcms/next/routes' | ||
import { GRAPHQL_POST, REST_OPTIONS } from '@payloadcms/next/routes' | ||
export const POST = GRAPHQL_POST(config) | ||
export const OPTIONS = REST_OPTIONS(config) |
@@ -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.d894ac7", | ||
"version": "3.0.0-canary.dc8b1fe", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237297
4
120
2396
17
2
+ Addedtar@^7.4.3
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@isaacs/fs-minipass@4.0.1(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@6.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedchownr@3.0.0(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedminizlib@3.0.1(transitive)
+ Addedmkdirp@3.0.1(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedrimraf@5.0.10(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedtar@7.4.3(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
+ Addedyallist@5.0.0(transitive)
- Removeddegit@^2.8.4
- Removeddegit@2.8.4(transitive)