create-payload-app
Advanced tools
Comparing version 3.0.0-canary.867cc07 to 3.0.0-canary.8789b0b
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 |
@@ -14,17 +14,29 @@ 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) { | ||
@@ -31,0 +43,0 @@ try { |
@@ -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)')); |
@@ -1,4 +0,4 @@ | ||
import swc from '@swc/core'; | ||
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') { | ||
@@ -177,5 +173,5 @@ try { | ||
*/ if (process.env.NODE_ENV === 'test') { | ||
parseOffset = (await swc.parse('')).span.end; | ||
parseOffset = (await parse('')).span.end; | ||
} | ||
const module = await swc.parse(fileContent, { | ||
const module = await parse(fileContent, { | ||
syntax: 'typescript' | ||
@@ -182,0 +178,0 @@ }); |
@@ -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, | ||
@@ -41,0 +42,0 @@ '--use-pnpm': Boolean, |
@@ -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.867cc07", | ||
"version": "3.0.0-canary.8789b0b", | ||
"homepage": "https://payloadcms.com", | ||
@@ -44,7 +44,6 @@ "repository": { | ||
"@sindresorhus/slugify": "^1.1.0", | ||
"@swc/core": "^1.6.13", | ||
"@swc/core": "1.7.10", | ||
"arg": "^5.0.0", | ||
"chalk": "^4.1.0", | ||
"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,3 +71,5 @@ "build": "pnpm pack-template-files && pnpm typecheck && pnpm build:swc", | ||
"clean": "rimraf {dist,*.tsbuildinfo}", | ||
"pack-template-files": "tsx src/scripts/pack-template-files.ts", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"pack-template-files": "node --no-deprecation --import @swc-node/register/esm-register src/scripts/pack-template-files.ts", | ||
"test": "jest", | ||
@@ -72,0 +76,0 @@ "typecheck": "tsc" |
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
233608
4
116
2356
16
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)
+ Added@swc/core@1.7.10(transitive)
+ Added@swc/core-darwin-arm64@1.7.10(transitive)
+ Added@swc/core-darwin-x64@1.7.10(transitive)
+ Added@swc/core-linux-arm-gnueabihf@1.7.10(transitive)
+ Added@swc/core-linux-arm64-gnu@1.7.10(transitive)
+ Added@swc/core-linux-arm64-musl@1.7.10(transitive)
+ Added@swc/core-linux-x64-gnu@1.7.10(transitive)
+ Added@swc/core-linux-x64-musl@1.7.10(transitive)
+ Added@swc/core-win32-arm64-msvc@1.7.10(transitive)
+ Added@swc/core-win32-ia32-msvc@1.7.10(transitive)
+ Added@swc/core-win32-x64-msvc@1.7.10(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
- Removed@swc/core@1.10.4(transitive)
- Removed@swc/core-darwin-arm64@1.10.4(transitive)
- Removed@swc/core-darwin-x64@1.10.4(transitive)
- Removed@swc/core-linux-arm-gnueabihf@1.10.4(transitive)
- Removed@swc/core-linux-arm64-gnu@1.10.4(transitive)
- Removed@swc/core-linux-arm64-musl@1.10.4(transitive)
- Removed@swc/core-linux-x64-gnu@1.10.4(transitive)
- Removed@swc/core-linux-x64-musl@1.10.4(transitive)
- Removed@swc/core-win32-arm64-msvc@1.10.4(transitive)
- Removed@swc/core-win32-ia32-msvc@1.10.4(transitive)
- Removed@swc/core-win32-x64-msvc@1.10.4(transitive)
- Removeddegit@2.8.4(transitive)
Updated@swc/core@1.7.10