create-payload-app
Advanced tools
Comparing version 3.0.0-alpha.61 to 3.0.0-alpha.62
@@ -9,2 +9,3 @@ import type { CliArgs, DbType, PackageManager } from '../types.js'; | ||
}; | ||
type NextConfigType = 'cjs' | 'esm'; | ||
type InitNextResult = { | ||
@@ -27,2 +28,3 @@ isSrcDir: boolean; | ||
nextConfigPath?: string; | ||
nextConfigType?: NextConfigType; | ||
}; | ||
@@ -29,0 +31,0 @@ export declare function getNextAppDetails(projectDir: string): Promise<NextAppDetails>; |
@@ -5,2 +5,3 @@ import * as p from '@clack/prompts'; | ||
import fs from 'fs'; | ||
import fse from 'fs-extra'; | ||
import globby from 'globby'; | ||
@@ -21,7 +22,16 @@ import path from 'path'; | ||
const nextAppDetails = args.nextAppDetails || await getNextAppDetails(projectDir); | ||
const { hasTopLevelLayout, isSrcDir, nextAppDir } = nextAppDetails || await getNextAppDetails(projectDir); | ||
if (!nextAppDir) { | ||
if (!nextAppDetails.nextAppDir) { | ||
warning(`Could not find app directory in ${projectDir}, creating...`); | ||
const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app'); | ||
fse.mkdirSync(createdAppDir, { | ||
recursive: true | ||
}); | ||
nextAppDetails.nextAppDir = createdAppDir; | ||
} | ||
const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails; | ||
if (!nextConfigType) { | ||
return { | ||
isSrcDir, | ||
reason: `Could not find app directory in ${projectDir}`, | ||
nextAppDir, | ||
reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`, | ||
success: false | ||
@@ -48,2 +58,3 @@ }; | ||
nextAppDetails, | ||
nextConfigType, | ||
useDistFiles: true | ||
@@ -81,2 +92,7 @@ }); | ||
const tsConfigPath = path.resolve(projectDir, 'tsconfig.json'); | ||
// Check if tsconfig.json exists | ||
if (!fs.existsSync(tsConfigPath)) { | ||
warning(`Could not find tsconfig.json to add @payload-config path.`); | ||
return; | ||
} | ||
const userTsConfigContent = await readFile(tsConfigPath, { | ||
@@ -86,2 +102,4 @@ encoding: 'utf8' | ||
const userTsConfig = parse(userTsConfigContent); | ||
const hasBaseUrl = userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'; | ||
const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'; | ||
if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) { | ||
@@ -94,3 +112,3 @@ userTsConfig.compilerOptions = {}; | ||
'@payload-config': [ | ||
`./${isSrcDir ? 'src/' : ''}payload.config.ts` | ||
`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts` | ||
] | ||
@@ -104,3 +122,3 @@ }; | ||
function installAndConfigurePayload(args) { | ||
const { '--debug': debug, nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {}, projectDir, useDistFiles } = args; | ||
const { '--debug': debug, nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {}, nextConfigType, projectDir, useDistFiles } = args; | ||
if (!nextAppDir || !nextConfigPath) { | ||
@@ -137,2 +155,3 @@ return { | ||
logDebug(`nextConfigPath: ${nextConfigPath}`); | ||
logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`); | ||
logDebug(`isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`); | ||
@@ -143,3 +162,4 @@ // This is a little clunky and needs to account for isSrcDir | ||
wrapNextConfig({ | ||
nextConfigPath | ||
nextConfigPath, | ||
nextConfigType | ||
}); | ||
@@ -156,4 +176,4 @@ return { | ||
'@payloadcms/richtext-lexical' | ||
].map((pkg)=>`${pkg}@alpha`); | ||
packagesToInstall.push(`@payloadcms/db-${dbType}@alpha`); | ||
].map((pkg)=>`${pkg}@beta`); | ||
packagesToInstall.push(`@payloadcms/db-${dbType}@beta`); | ||
let exitCode = 0; | ||
@@ -217,2 +237,5 @@ switch(packageManager){ | ||
cwd: projectDir, | ||
ignore: [ | ||
'**/node_modules/**' | ||
], | ||
onlyDirectories: true | ||
@@ -223,2 +246,3 @@ }))?.[0]; | ||
} | ||
const configType = await getProjectType(projectDir, nextConfigPath); | ||
const hasTopLevelLayout = nextAppDir ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx')) : false; | ||
@@ -229,6 +253,24 @@ return { | ||
nextAppDir, | ||
nextConfigPath | ||
nextConfigPath, | ||
nextConfigType: configType | ||
}; | ||
} | ||
async function getProjectType(projectDir, nextConfigPath) { | ||
if (nextConfigPath.endsWith('.mjs')) { | ||
return 'esm'; | ||
} | ||
if (nextConfigPath.endsWith('.cjs')) { | ||
return 'cjs'; | ||
} | ||
const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json')); | ||
const packageJsonType = packageObj.type; | ||
if (packageJsonType === 'module') { | ||
return 'esm'; | ||
} | ||
if (packageJsonType === 'commonjs') { | ||
return 'cjs'; | ||
} | ||
return 'cjs'; | ||
} | ||
//# sourceMappingURL=init-next.js.map |
@@ -7,3 +7,3 @@ const mongodbReplacement = { | ||
' db: mongooseAdapter({', | ||
' url: process.env.DATABASE_URI,', | ||
" url: process.env.DATABASE_URI || '',", | ||
' }),' | ||
@@ -16,3 +16,3 @@ ] | ||
' pool: {', | ||
' connectionString: process.env.DATABASE_URI,', | ||
" connectionString: process.env.DATABASE_URI || '',", | ||
' },', | ||
@@ -19,0 +19,0 @@ ' }),' |
@@ -10,3 +10,3 @@ import * as p from '@clack/prompts'; | ||
postgres: { | ||
dbConnectionPrefix: 'postgres://127.0.0.1:5432/', | ||
dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/', | ||
title: 'PostgreSQL (beta)', | ||
@@ -13,0 +13,0 @@ value: 'postgres' |
@@ -17,39 +17,28 @@ import { error, info } from '../utils/log.js'; | ||
description: 'Blank 3.0 Template', | ||
url: 'https://github.com/payloadcms/payload/templates/blank-3.0' | ||
url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta' | ||
}, | ||
// Remove these until they have been updated for 3.0 | ||
// { | ||
// name: 'blank', | ||
// type: 'starter', | ||
// description: 'Blank Template', | ||
// url: 'https://github.com/payloadcms/payload/templates/blank', | ||
// }, | ||
// { | ||
// name: 'website', | ||
// type: 'starter', | ||
// description: 'Website Template', | ||
// url: 'https://github.com/payloadcms/payload/templates/website', | ||
// }, | ||
// { | ||
// name: 'ecommerce', | ||
// type: 'starter', | ||
// description: 'E-commerce Template', | ||
// url: 'https://github.com/payloadcms/payload/templates/ecommerce', | ||
// }, | ||
{ | ||
name: 'blank', | ||
type: 'starter', | ||
description: 'Blank Template', | ||
url: 'https://github.com/payloadcms/payload/templates/blank' | ||
}, | ||
{ | ||
name: 'website', | ||
type: 'starter', | ||
description: 'Website Template', | ||
url: 'https://github.com/payloadcms/payload/templates/website' | ||
}, | ||
{ | ||
name: 'ecommerce', | ||
type: 'starter', | ||
description: 'E-commerce Template', | ||
url: 'https://github.com/payloadcms/payload/templates/ecommerce' | ||
}, | ||
{ | ||
name: 'plugin', | ||
type: 'plugin', | ||
description: 'Template for creating a Payload plugin', | ||
url: 'https://github.com/payloadcms/payload-plugin-template' | ||
}, | ||
{ | ||
name: 'payload-demo', | ||
type: 'starter', | ||
description: 'Payload demo site at https://demo.payloadcms.com', | ||
url: 'https://github.com/payloadcms/public-demo' | ||
}, | ||
{ | ||
name: 'payload-website', | ||
type: 'starter', | ||
description: 'Payload website CMS at https://payloadcms.com', | ||
url: 'https://github.com/payloadcms/website-cms' | ||
url: 'https://github.com/payloadcms/payload-plugin-template#beta' | ||
} | ||
@@ -56,0 +45,0 @@ ]; |
@@ -1,4 +0,9 @@ | ||
export declare const withPayloadImportStatement = "import { withPayload } from '@payloadcms/next'\n"; | ||
export declare const withPayloadStatement: { | ||
cjs: string; | ||
esm: string; | ||
}; | ||
type NextConfigType = 'cjs' | 'esm'; | ||
export declare const wrapNextConfig: (args: { | ||
nextConfigPath: string; | ||
nextConfigType: NextConfigType; | ||
}) => void; | ||
@@ -8,6 +13,7 @@ /** | ||
*/ | ||
export declare function parseAndModifyConfigContent(content: string): { | ||
export declare function parseAndModifyConfigContent(content: string, configType: NextConfigType): { | ||
modifiedConfigContent: string; | ||
success: boolean; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=wrap-next-config.d.ts.map |
import chalk from 'chalk'; | ||
import { parseModule } from 'esprima'; | ||
import { Syntax, parseModule } from 'esprima-next'; | ||
import fs from 'fs'; | ||
import { warning } from '../utils/log.js'; | ||
import { log } from '../utils/log.js'; | ||
export const withPayloadImportStatement = `import { withPayload } from '@payloadcms/next'\n`; | ||
export const withPayloadStatement = { | ||
cjs: `const { withPayload } = require('@payloadcms/next/withPayload')\n`, | ||
esm: `import { withPayload } from '@payloadcms/next/withPayload'\n` | ||
}; | ||
export const wrapNextConfig = (args)=>{ | ||
const { nextConfigPath } = args; | ||
const { nextConfigPath, nextConfigType: configType } = args; | ||
const configContent = fs.readFileSync(nextConfigPath, 'utf8'); | ||
const { modifiedConfigContent: newConfig, success } = parseAndModifyConfigContent(configContent); | ||
const { modifiedConfigContent: newConfig, success } = parseAndModifyConfigContent(configContent, configType); | ||
if (!success) { | ||
@@ -18,32 +21,66 @@ return; | ||
* Parses config content with AST and wraps it with withPayload function | ||
*/ export function parseAndModifyConfigContent(content) { | ||
content = withPayloadImportStatement + content; | ||
const ast = parseModule(content, { | ||
loc: true | ||
}); | ||
const exportDefaultDeclaration = ast.body.find((p)=>p.type === 'ExportDefaultDeclaration'); | ||
const exportNamedDeclaration = ast.body.find((p)=>p.type === 'ExportNamedDeclaration'); | ||
if (!exportDefaultDeclaration && !exportNamedDeclaration) { | ||
throw new Error('Could not find ExportDefaultDeclaration in next.config.js'); | ||
*/ export function parseAndModifyConfigContent(content, configType) { | ||
content = withPayloadStatement[configType] + content; | ||
let ast; | ||
try { | ||
ast = parseModule(content, { | ||
loc: true | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
warning(`Unable to parse Next config. Error: ${error.message} `); | ||
warnUserWrapNotSuccessful(configType); | ||
} | ||
return { | ||
modifiedConfigContent: content, | ||
success: false | ||
}; | ||
} | ||
if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) { | ||
const modifiedConfigContent = insertBeforeAndAfter(content, exportDefaultDeclaration.declaration.loc); | ||
if (configType === 'esm') { | ||
const exportDefaultDeclaration = ast.body.find((p)=>p.type === Syntax.ExportDefaultDeclaration); | ||
const exportNamedDeclaration = ast.body.find((p)=>p.type === Syntax.ExportNamedDeclaration); | ||
if (!exportDefaultDeclaration && !exportNamedDeclaration) { | ||
throw new Error('Could not find ExportDefaultDeclaration in next.config.js'); | ||
} | ||
if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) { | ||
const modifiedConfigContent = insertBeforeAndAfter(content, exportDefaultDeclaration.declaration.loc); | ||
return { | ||
modifiedConfigContent, | ||
success: true | ||
}; | ||
} else if (exportNamedDeclaration) { | ||
const exportSpecifier = exportNamedDeclaration.specifiers.find((s)=>s.type === 'ExportSpecifier' && s.exported?.name === 'default' && s.local?.type === 'Identifier' && s.local?.name); | ||
if (exportSpecifier) { | ||
warning('Could not automatically wrap next.config.js with withPayload.'); | ||
warning('Automatic wrapping of named exports as default not supported yet.'); | ||
warnUserWrapNotSuccessful(configType); | ||
return { | ||
modifiedConfigContent: content, | ||
success: false | ||
}; | ||
} | ||
} | ||
warning('Could not automatically wrap Next config with withPayload.'); | ||
warnUserWrapNotSuccessful(configType); | ||
return { | ||
modifiedConfigContent, | ||
success: true | ||
modifiedConfigContent: content, | ||
success: false | ||
}; | ||
} else if (exportNamedDeclaration) { | ||
const exportSpecifier = exportNamedDeclaration.specifiers.find((s)=>s.type === 'ExportSpecifier' && s.exported?.name === 'default' && s.local?.type === 'Identifier' && s.local?.name); | ||
if (exportSpecifier) { | ||
warning('Could not automatically wrap next.config.js with withPayload.'); | ||
warning('Automatic wrapping of named exports as default not supported yet.'); | ||
warnUserWrapNotSuccessful(); | ||
} else if (configType === 'cjs') { | ||
// Find `module.exports = X` | ||
const moduleExports = ast.body.find((p)=>p.type === Syntax.ExpressionStatement && p.expression?.type === Syntax.AssignmentExpression && p.expression.left?.type === Syntax.MemberExpression && p.expression.left.object?.type === Syntax.Identifier && p.expression.left.object.name === 'module' && p.expression.left.property?.type === Syntax.Identifier && p.expression.left.property.name === 'exports'); | ||
if (moduleExports && moduleExports.expression.right?.loc) { | ||
const modifiedConfigContent = insertBeforeAndAfter(content, moduleExports.expression.right.loc); | ||
return { | ||
modifiedConfigContent: content, | ||
success: false | ||
modifiedConfigContent, | ||
success: true | ||
}; | ||
} | ||
return { | ||
modifiedConfigContent: content, | ||
success: false | ||
}; | ||
} | ||
warning('Could not automatically wrap next.config.js with withPayload.'); | ||
warnUserWrapNotSuccessful(); | ||
warning('Could not automatically wrap Next config with withPayload.'); | ||
warnUserWrapNotSuccessful(configType); | ||
return { | ||
@@ -54,3 +91,3 @@ modifiedConfigContent: content, | ||
} | ||
function warnUserWrapNotSuccessful() { | ||
function warnUserWrapNotSuccessful(configType) { | ||
// Output directions for user to update next.config.js | ||
@@ -61,3 +98,3 @@ const withPayloadMessage = ` | ||
import withPayload from '@payloadcms/next/withPayload' | ||
${withPayloadStatement[configType]} | ||
@@ -68,3 +105,3 @@ const nextConfig = { | ||
export default withPayload(nextConfig) | ||
${configType === 'esm' ? 'export default withPayload(nextConfig)' : 'module.exports = withPayload(nextConfig)'} | ||
@@ -71,0 +108,0 @@ `; |
@@ -1,53 +0,116 @@ | ||
import { parseAndModifyConfigContent, withPayloadImportStatement } from './wrap-next-config.js'; | ||
import { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js'; | ||
import * as p from '@clack/prompts'; | ||
const defaultNextConfig = `/** @type {import('next').NextConfig} */ | ||
const esmConfigs = { | ||
defaultNextConfig: `/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
export default nextConfig; | ||
`; | ||
const nextConfigWithFunc = `const nextConfig = { | ||
// Your Next.js config here | ||
} | ||
export default someFunc(nextConfig) | ||
`; | ||
const nextConfigWithFuncMultiline = `const nextConfig = { | ||
// Your Next.js config here | ||
} | ||
`, | ||
nextConfigWithFunc: `const nextConfig = {}; | ||
export default someFunc(nextConfig); | ||
`, | ||
nextConfigWithFuncMultiline: `const nextConfig = {};; | ||
export default someFunc( | ||
nextConfig | ||
) | ||
`; | ||
const nextConfigExportNamedDefault = `const nextConfig = { | ||
// Your Next.js config here | ||
} | ||
const wrapped = someFunc(asdf) | ||
export { wrapped as default } | ||
`; | ||
); | ||
`, | ||
nextConfigExportNamedDefault: `const nextConfig = {}; | ||
const wrapped = someFunc(asdf); | ||
export { wrapped as default }; | ||
`, | ||
nextConfigWithSpread: `const nextConfig = { | ||
...someConfig, | ||
}; | ||
export default nextConfig; | ||
` | ||
}; | ||
const cjsConfigs = { | ||
defaultNextConfig: ` | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
module.exports = nextConfig; | ||
`, | ||
anonConfig: `module.exports = {};`, | ||
nextConfigWithFunc: `const nextConfig = {}; | ||
module.exports = someFunc(nextConfig); | ||
`, | ||
nextConfigWithFuncMultiline: `const nextConfig = {}; | ||
module.exports = someFunc( | ||
nextConfig | ||
); | ||
`, | ||
nextConfigExportNamedDefault: `const nextConfig = {}; | ||
const wrapped = someFunc(asdf); | ||
module.exports = wrapped; | ||
`, | ||
nextConfigWithSpread: `const nextConfig = { ...someConfig }; | ||
module.exports = nextConfig; | ||
` | ||
}; | ||
describe('parseAndInsertWithPayload', ()=>{ | ||
it('should parse the default next config', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(defaultNextConfig); | ||
expect(modifiedConfigContent).toContain(withPayloadImportStatement); | ||
expect(modifiedConfigContent).toContain('withPayload(nextConfig)'); | ||
describe('esm', ()=>{ | ||
const configType = 'esm'; | ||
const importStatement = withPayloadStatement[configType]; | ||
it('should parse the default next config', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.defaultNextConfig, configType); | ||
expect(modifiedConfigContent).toContain(importStatement); | ||
expect(modifiedConfigContent).toContain('withPayload(nextConfig)'); | ||
}); | ||
it('should parse the config with a function', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithFunc, configType); | ||
expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))'); | ||
}); | ||
it('should parse the config with a function on a new line', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithFuncMultiline, configType); | ||
expect(modifiedConfigContent).toContain(importStatement); | ||
expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n nextConfig\n\)\)/); | ||
}); | ||
it('should parse the config with a spread', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithSpread, configType); | ||
expect(modifiedConfigContent).toContain(importStatement); | ||
expect(modifiedConfigContent).toContain('withPayload(nextConfig)'); | ||
}); | ||
// Unsupported: export { wrapped as default } | ||
it('should give warning with a named export as default', ()=>{ | ||
const warnLogSpy = jest.spyOn(p.log, 'warn').mockImplementation(()=>{}); | ||
const { modifiedConfigContent, success } = parseAndModifyConfigContent(esmConfigs.nextConfigExportNamedDefault, configType); | ||
expect(modifiedConfigContent).toContain(importStatement); | ||
expect(success).toBe(false); | ||
expect(warnLogSpy).toHaveBeenCalledWith(expect.stringContaining('Could not automatically wrap')); | ||
}); | ||
}); | ||
it('should parse the config with a function', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(nextConfigWithFunc); | ||
expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))'); | ||
describe('cjs', ()=>{ | ||
const configType = 'cjs'; | ||
const requireStatement = withPayloadStatement[configType]; | ||
it('should parse the default next config', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.defaultNextConfig, configType); | ||
expect(modifiedConfigContent).toContain(requireStatement); | ||
expect(modifiedConfigContent).toContain('withPayload(nextConfig)'); | ||
}); | ||
it('should parse anonymous default config', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.anonConfig, configType); | ||
expect(modifiedConfigContent).toContain(requireStatement); | ||
expect(modifiedConfigContent).toContain('withPayload({})'); | ||
}); | ||
it('should parse the config with a function', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithFunc, configType); | ||
expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))'); | ||
}); | ||
it('should parse the config with a function on a new line', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithFuncMultiline, configType); | ||
expect(modifiedConfigContent).toContain(requireStatement); | ||
expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n nextConfig\n\)\)/); | ||
}); | ||
it('should parse the config with a named export as default', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigExportNamedDefault, configType); | ||
expect(modifiedConfigContent).toContain(requireStatement); | ||
expect(modifiedConfigContent).toContain('withPayload(wrapped)'); | ||
}); | ||
it('should parse the config with a spread', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithSpread, configType); | ||
expect(modifiedConfigContent).toContain(requireStatement); | ||
expect(modifiedConfigContent).toContain('withPayload(nextConfig)'); | ||
}); | ||
}); | ||
it('should parse the config with a function on a new line', ()=>{ | ||
const { modifiedConfigContent } = parseAndModifyConfigContent(nextConfigWithFuncMultiline); | ||
expect(modifiedConfigContent).toContain(withPayloadImportStatement); | ||
expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n nextConfig\n\)\)/); | ||
}); | ||
// Unsupported: export { wrapped as default } | ||
it('should give warning with a named export as default', ()=>{ | ||
const warnLogSpy = jest.spyOn(p.log, 'warn').mockImplementation(()=>{}); | ||
const { modifiedConfigContent, success } = parseAndModifyConfigContent(nextConfigExportNamedDefault); | ||
expect(modifiedConfigContent).toContain(withPayloadImportStatement); | ||
expect(success).toBe(false); | ||
expect(warnLogSpy).toHaveBeenCalledWith(expect.stringContaining('Could not automatically wrap')); | ||
}); | ||
}); | ||
//# sourceMappingURL=wrap-next-config.spec.js.map |
@@ -10,21 +10,28 @@ import fs from 'fs-extra'; | ||
} | ||
const envOutputPath = path.join(projectDir, '.env'); | ||
try { | ||
if (template?.type === 'starter' && fs.existsSync(path.join(projectDir, '.env.example'))) { | ||
// Parse .env file into key/value pairs | ||
const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8'); | ||
const envWithValues = envFile.split('\n').filter((e)=>e).map((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') { | ||
value = databaseUri; | ||
} | ||
if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') { | ||
value = payloadSecret; | ||
} | ||
return `${key}=${value}`; | ||
}); | ||
// Write new .env file | ||
await fs.writeFile(path.join(projectDir, '.env'), envWithValues.join('\n')); | ||
if (fs.existsSync(envOutputPath)) { | ||
if (template?.type === 'starter') { | ||
// Parse .env file into key/value pairs | ||
const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8'); | ||
const envWithValues = envFile.split('\n').filter((e)=>e).map((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') { | ||
value = databaseUri; | ||
} | ||
if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') { | ||
value = payloadSecret; | ||
} | ||
return `${key}=${value}`; | ||
}); | ||
// Write new .env file | ||
await fs.writeFile(envOutputPath, envWithValues.join('\n')); | ||
} else { | ||
const existingEnv = await fs.readFile(envOutputPath, 'utf8'); | ||
const newEnv = existingEnv + `\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`; | ||
await fs.writeFile(envOutputPath, newEnv); | ||
} | ||
} else { | ||
@@ -31,0 +38,0 @@ const content = `DATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}`; |
import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import | ||
// import { payloadCloud } from '@payloadcms/plugin-cloud' | ||
import { lexicalEditor } from '@payloadcms/richtext-lexical' // editor-import | ||
import { lexicalEditor } from '@payloadcms/richtext-lexical' | ||
import path from 'path' | ||
@@ -30,2 +30,3 @@ import { buildConfig } from 'payload/config' | ||
// database-adapter-config-end | ||
// Sharp is now an optional dependency - | ||
@@ -32,0 +33,0 @@ // if you want to resize images, crop, set focal point, etc. |
@@ -15,3 +15,9 @@ /* eslint-disable no-console */ import chalk from 'chalk'; | ||
{dim Inside of an existing Next.js project} | ||
{dim $} {bold npx create-payload-app} | ||
{dim Create a new project from scratch} | ||
{dim $} {bold npx create-payload-app} | ||
{dim $} {bold npx create-payload-app} my-project | ||
@@ -58,3 +64,3 @@ {dim $} {bold npx create-payload-app} -n my-project -t template-name | ||
export function moveMessage(args) { | ||
const relativePath = path.relative(process.cwd(), args.nextAppDir); | ||
const relativeAppDir = path.relative(process.cwd(), args.nextAppDir); | ||
return ` | ||
@@ -67,4 +73,7 @@ ${header('Next Steps:')} | ||
Move all files from ./${relativePath} to a named directory such as ./${relativePath}/${chalk.bold('(app)')} | ||
- Create a new directory in ./${relativeAppDir} such as ./${relativeAppDir}/${chalk.bold('(app)')} | ||
- Move all files from ./${relativeAppDir} into that directory | ||
It is recommended to do this from your IDE if your app has existing file references. | ||
Once moved, rerun the create-payload-app command again. | ||
@@ -71,0 +80,0 @@ `; |
{ | ||
"name": "create-payload-app", | ||
"version": "3.0.0-alpha.61", | ||
"version": "3.0.0-alpha.62", | ||
"license": "MIT", | ||
@@ -29,3 +29,3 @@ "type": "module", | ||
"detect-package-manager": "^3.0.1", | ||
"esprima": "^4.0.1", | ||
"esprima-next": "^6.0.3", | ||
"execa": "^5.0.0", | ||
@@ -32,0 +32,0 @@ "figures": "^6.1.0", |
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
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
170188
1605
10
+ Addedesprima-next@^6.0.3
+ Addedesprima-next@6.0.3(transitive)
- Removedesprima@^4.0.1