create-payload-app 3.0.0-beta.7 → 3.0.0-canary.92e4997
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/lib/configure-payload-config.d.ts.map +1 -1
- package/dist/lib/configure-payload-config.js +26 -0
- package/dist/lib/configure-payload-config.js.map +1 -1
- package/dist/lib/init-next.d.ts.map +1 -1
- package/dist/lib/init-next.js +3 -1
- package/dist/lib/init-next.js.map +1 -1
- package/dist/lib/select-db.js +1 -1
- package/dist/lib/select-db.js.map +1 -1
- package/dist/lib/templates.js +25 -0
- package/dist/lib/templates.js.map +1 -1
- package/dist/template/src/app/(payload)/admin/[[...segments]]/not-found.tsx +22 -0
- package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +6 -1
- package/dist/template/src/app/(payload)/api/[...slug]/route.ts +2 -1
- package/dist/template/src/payload.config.ts +2 -1
- package/package.json +16 -16
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"configure-payload-config.d.ts","sourceRoot":"","sources":["../../src/lib/configure-payload-config.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"configure-payload-config.d.ts","sourceRoot":"","sources":["../../src/lib/configure-payload-config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAK5C,gEAAgE;AAChE,wBAAsB,sBAAsB,CAAC,IAAI,EAAE;IACjD,SAAS,EAAE,SAAS,GAAG,SAAS,CAAA;IAChC,sBAAsB,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;CAC/E,GAAG,OAAO,CAAC,IAAI,CAAC,CAyFhB"}
|
@@ -1,11 +1,37 @@
|
|
1
1
|
import fse from 'fs-extra';
|
2
2
|
import globby from 'globby';
|
3
|
+
import { fileURLToPath } from 'node:url';
|
4
|
+
import path from 'path';
|
5
|
+
const filename = fileURLToPath(import.meta.url);
|
6
|
+
const dirname = path.dirname(filename);
|
3
7
|
import { warning } from '../utils/log.js';
|
4
8
|
import { dbReplacements } from './packages.js';
|
5
9
|
/** Update payload config with necessary imports and adapters */ export async function configurePayloadConfig(args) {
|
6
10
|
if (!args.dbDetails) {
|
7
11
|
return;
|
8
12
|
}
|
13
|
+
// Update package.json
|
14
|
+
const packageJsonPath = 'projectDir' in args.projectDirOrConfigPath && path.resolve(args.projectDirOrConfigPath.projectDir, 'package.json');
|
15
|
+
if (packageJsonPath && fse.existsSync(packageJsonPath)) {
|
16
|
+
try {
|
17
|
+
const packageObj = await fse.readJson(packageJsonPath);
|
18
|
+
const dbPackage = dbReplacements[args.dbDetails.type];
|
19
|
+
// Delete all other db adapters
|
20
|
+
Object.values(dbReplacements).forEach((p)=>{
|
21
|
+
if (p.packageName !== dbPackage.packageName) {
|
22
|
+
delete packageObj.dependencies[p.packageName];
|
23
|
+
}
|
24
|
+
});
|
25
|
+
// Set version of db adapter to match payload version
|
26
|
+
packageObj.dependencies[dbPackage.packageName] = packageObj.dependencies['payload'];
|
27
|
+
await fse.writeJson(packageJsonPath, packageObj, {
|
28
|
+
spaces: 2
|
29
|
+
});
|
30
|
+
} catch (err) {
|
31
|
+
warning(`Unable to configure Payload in package.json`);
|
32
|
+
warning(err instanceof Error ? err.message : '');
|
33
|
+
}
|
34
|
+
}
|
9
35
|
try {
|
10
36
|
let payloadConfigPath;
|
11
37
|
if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/configure-payload-config.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\n\nimport type { DbDetails } from '../types.js'\n\nimport { warning } from '../utils/log.js'\nimport { dbReplacements } from './packages.js'\n\n/** Update payload config with necessary imports and adapters */\nexport async function configurePayloadConfig(args: {\n dbDetails: DbDetails | undefined\n projectDirOrConfigPath: { payloadConfigPath: string } | { projectDir: string }\n}): Promise<void> {\n if (!args.dbDetails) {\n return\n }\n\n try {\n let payloadConfigPath: string | undefined\n if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {\n payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: args.projectDirOrConfigPath.projectDir,\n })\n )?.[0]\n } else {\n payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath\n }\n\n if (!payloadConfigPath) {\n warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.')\n return\n }\n\n const configContent = fse.readFileSync(payloadConfigPath, 'utf-8')\n const configLines = configContent.split('\\n')\n\n const dbReplacement = dbReplacements[args.dbDetails.type]\n\n let dbConfigStartLineIndex: number | undefined\n let dbConfigEndLineIndex: number | undefined\n\n configLines.forEach((l, i) => {\n if (l.includes('// database-adapter-import')) {\n configLines[i] = dbReplacement.importReplacement\n }\n\n if (l.includes('// database-adapter-config-start')) {\n dbConfigStartLineIndex = i\n }\n if (l.includes('// database-adapter-config-end')) {\n dbConfigEndLineIndex = i\n }\n })\n\n if (!dbConfigStartLineIndex || !dbConfigEndLineIndex) {\n warning('Unable to update payload.config.ts with database adapter import')\n } else {\n // Replaces lines between `// database-adapter-config-start` and `// database-adapter-config-end`\n configLines.splice(\n dbConfigStartLineIndex,\n dbConfigEndLineIndex - dbConfigStartLineIndex + 1,\n ...dbReplacement.configReplacement,\n )\n }\n\n fse.writeFileSync(payloadConfigPath, configLines.join('\\n'))\n } catch (err: unknown) {\n warning(\n `Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`,\n )\n }\n}\n"],"names":["fse","globby","warning","dbReplacements","configurePayloadConfig","args","dbDetails","
|
1
|
+
{"version":3,"sources":["../../src/lib/configure-payload-config.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport type { DbDetails } from '../types.js'\n\nimport { warning } from '../utils/log.js'\nimport { dbReplacements } from './packages.js'\n\n/** Update payload config with necessary imports and adapters */\nexport async function configurePayloadConfig(args: {\n dbDetails: DbDetails | undefined\n projectDirOrConfigPath: { payloadConfigPath: string } | { projectDir: string }\n}): Promise<void> {\n if (!args.dbDetails) {\n return\n }\n\n // Update package.json\n const packageJsonPath =\n 'projectDir' in args.projectDirOrConfigPath &&\n path.resolve(args.projectDirOrConfigPath.projectDir, 'package.json')\n\n if (packageJsonPath && fse.existsSync(packageJsonPath)) {\n try {\n const packageObj = await fse.readJson(packageJsonPath)\n\n const dbPackage = dbReplacements[args.dbDetails.type]\n\n // Delete all other db adapters\n Object.values(dbReplacements).forEach((p) => {\n if (p.packageName !== dbPackage.packageName) {\n delete packageObj.dependencies[p.packageName]\n }\n })\n\n // Set version of db adapter to match payload version\n packageObj.dependencies[dbPackage.packageName] = packageObj.dependencies['payload']\n\n await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })\n } catch (err: unknown) {\n warning(`Unable to configure Payload in package.json`)\n warning(err instanceof Error ? err.message : '')\n }\n }\n\n try {\n let payloadConfigPath: string | undefined\n if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {\n payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: args.projectDirOrConfigPath.projectDir,\n })\n )?.[0]\n } else {\n payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath\n }\n\n if (!payloadConfigPath) {\n warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.')\n return\n }\n\n const configContent = fse.readFileSync(payloadConfigPath, 'utf-8')\n const configLines = configContent.split('\\n')\n\n const dbReplacement = dbReplacements[args.dbDetails.type]\n\n let dbConfigStartLineIndex: number | undefined\n let dbConfigEndLineIndex: number | undefined\n\n configLines.forEach((l, i) => {\n if (l.includes('// database-adapter-import')) {\n configLines[i] = dbReplacement.importReplacement\n }\n\n if (l.includes('// database-adapter-config-start')) {\n dbConfigStartLineIndex = i\n }\n if (l.includes('// database-adapter-config-end')) {\n dbConfigEndLineIndex = i\n }\n })\n\n if (!dbConfigStartLineIndex || !dbConfigEndLineIndex) {\n warning('Unable to update payload.config.ts with database adapter import')\n } else {\n // Replaces lines between `// database-adapter-config-start` and `// database-adapter-config-end`\n configLines.splice(\n dbConfigStartLineIndex,\n dbConfigEndLineIndex - dbConfigStartLineIndex + 1,\n ...dbReplacement.configReplacement,\n )\n }\n\n fse.writeFileSync(payloadConfigPath, configLines.join('\\n'))\n } catch (err: unknown) {\n warning(\n `Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`,\n )\n }\n}\n"],"names":["fse","globby","fileURLToPath","path","filename","url","dirname","warning","dbReplacements","configurePayloadConfig","args","dbDetails","packageJsonPath","projectDirOrConfigPath","resolve","projectDir","existsSync","packageObj","readJson","dbPackage","type","Object","values","forEach","p","packageName","dependencies","writeJson","spaces","err","Error","message","payloadConfigPath","absolute","cwd","configContent","readFileSync","configLines","split","dbReplacement","dbConfigStartLineIndex","dbConfigEndLineIndex","l","i","includes","importReplacement","splice","configReplacement","writeFileSync","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAI7B,SAASG,OAAO,QAAQ,kBAAiB;AACzC,SAASC,cAAc,QAAQ,gBAAe;AAE9C,8DAA8D,GAC9D,OAAO,eAAeC,uBAAuBC,IAG5C;IACC,IAAI,CAACA,KAAKC,SAAS,EAAE;QACnB;IACF;IAEA,sBAAsB;IACtB,MAAMC,kBACJ,gBAAgBF,KAAKG,sBAAsB,IAC3CV,KAAKW,OAAO,CAACJ,KAAKG,sBAAsB,CAACE,UAAU,EAAE;IAEvD,IAAIH,mBAAmBZ,IAAIgB,UAAU,CAACJ,kBAAk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E,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAkCnF"}
|
package/dist/lib/init-next.js
CHANGED
@@ -95,6 +95,8 @@ async function addPayloadConfigToTsConfig(projectDir, isSrcDir) {
|
|
95
95
|
encoding: 'utf8'
|
96
96
|
});
|
97
97
|
const userTsConfig = parse(userTsConfigContent);
|
98
|
+
const hasBaseUrl = userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.';
|
99
|
+
const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './';
|
98
100
|
if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {
|
99
101
|
userTsConfig.compilerOptions = {};
|
100
102
|
}
|
@@ -102,7 +104,7 @@ async function addPayloadConfigToTsConfig(projectDir, isSrcDir) {
|
|
102
104
|
userTsConfig.compilerOptions.paths = {
|
103
105
|
...userTsConfig.compilerOptions.paths || {},
|
104
106
|
'@payload-config': [
|
105
|
-
|
107
|
+
`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`
|
106
108
|
]
|
107
109
|
};
|
108
110
|
await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport path from 'path'\nimport { promisify } from 'util'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport { fileURLToPath } from 'node:url'\n\nimport type { CliArgs, DbType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\ntype InitNextArgs = Pick<CliArgs, '--debug'> & {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n}\n\ntype NextConfigType = 'cjs' | 'esm'\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`./${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nfunction installAndConfigurePayload(\n args: InitNextArgs & {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n },\n):\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false } {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = ['payload', '@payloadcms/next', '@payloadcms/richtext-lexical'].map(\n (pkg) => `${pkg}@beta`,\n )\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n let exitCode = 0\n switch (packageManager) {\n case 'npm': {\n ;({ exitCode } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'yarn':\n case 'pnpm': {\n ;({ exitCode } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'bun': {\n warning('Bun support is untested.')\n ;({ exitCode } = await execa('bun', ['add', ...packagesToInstall], { cwd: projectDir }))\n break\n }\n }\n\n return { success: exitCode === 0 }\n}\n\ntype NextAppDetails = {\n hasTopLevelLayout: boolean\n isSrcDir: boolean\n nextAppDir?: string\n nextConfigPath?: string\n nextConfigType?: NextConfigType\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n const nextConfigPath: string | undefined = (\n await globby('next.config.*js', { absolute: true, cwd: projectDir })\n )?.[0]\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n nextConfigPath: undefined,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = await getProjectType(projectDir, nextConfigPath)\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigPath, nextConfigType: configType }\n}\n\nasync function getProjectType(projectDir: string, nextConfigPath: string): Promise<'cjs' | 'esm'> {\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","execa","fs","fse","globby","path","promisify","readFile","writeFile","filename","fileURLToPath","url","dirname","copyRecursiveSync","debug","origDebug","warning","moveMessage","wrapNextConfig","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","compilerOptions","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","exitCode","cwd","absolute","length","undefined","ignore","onlyDirectories","configType","getProjectType","packageObj","readJson","packageJsonType","type"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAC/C,OAAOC,WAAW,QAAO;AACzB,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAEhC,MAAMC,WAAWD,UAAUJ,GAAGK,QAAQ;AACtC,MAAMC,YAAYF,UAAUJ,GAAGM,SAAS;AAExC,MAAMC,WAAWC,cAAc,YAAYC,GAAG;AAC9C,MAAMC,UAAUP,KAAKO,OAAO,CAACH;AAE7B,SAASC,aAAa,QAAQ,WAAU;AAIxC,SAASG,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,SAASC,SAAS,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,cAAc,QAAQ,wBAAuB;AAqBtD,OAAO,eAAeC,SAASC,IAAkB;IA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CAAA,MAAMtB,OAAO;QAAC;KAAS,EAAE;QACvBgE,UAAU;QACVD,KAAK5C;QACLgD,QAAQ;YAAC;SAAqB;QAC9BC,iBAAiB;IACnB,EAAC,GACA,CAAC,EAAE;IAEN,IAAI,CAAC9C,cAAcA,WAAW2C,MAAM,KAAK,GAAG;QAC1C3C,aAAa4C;IACf;IAEA,MAAMG,aAAa,MAAMC,eAAenD,YAAYgC;IAEpD,MAAMvB,oBAAoBN,aACtBxB,GAAG+C,UAAU,CAAC5C,KAAKuB,OAAO,CAACF,YAAY,iBACvC;IAEJ,OAAO;QAAEM;QAAmBH;QAAUH;QAAY6B;QAAgBtB,gBAAgBwC;IAAW;AAC/F;AAEA,eAAeC,eAAenD,UAAkB,EAAEgC,cAAsB;IACtE,IAAIA,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IACA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IAEA,MAAMgB,aAAa,MAAMxE,IAAIyE,QAAQ,CAACvE,KAAKuB,OAAO,CAACL,YAAY;IAC/D,MAAMsD,kBAAkBF,WAAWG,IAAI;IACvC,IAAID,oBAAoB,UAAU;QAChC,OAAO;IACT;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
|
1
|
+
{"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport path from 'path'\nimport { promisify } from 'util'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport { fileURLToPath } from 'node:url'\n\nimport type { CliArgs, DbType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\ntype InitNextArgs = Pick<CliArgs, '--debug'> & {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n}\n\ntype NextConfigType = 'cjs' | 'esm'\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n\n const hasBaseUrl =\n userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'\n const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'\n\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nfunction installAndConfigurePayload(\n args: InitNextArgs & {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n },\n):\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false } {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = ['payload', '@payloadcms/next', '@payloadcms/richtext-lexical'].map(\n (pkg) => `${pkg}@beta`,\n )\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n let exitCode = 0\n switch (packageManager) {\n case 'npm': {\n ;({ exitCode } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'yarn':\n case 'pnpm': {\n ;({ exitCode } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'bun': {\n warning('Bun support is untested.')\n ;({ exitCode } = await execa('bun', ['add', ...packagesToInstall], { cwd: projectDir }))\n break\n }\n }\n\n return { success: exitCode === 0 }\n}\n\ntype NextAppDetails = {\n hasTopLevelLayout: boolean\n isSrcDir: boolean\n nextAppDir?: string\n nextConfigPath?: string\n nextConfigType?: NextConfigType\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n const nextConfigPath: string | undefined = (\n await globby('next.config.*js', { absolute: true, cwd: projectDir })\n )?.[0]\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n nextConfigPath: undefined,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = await getProjectType(projectDir, nextConfigPath)\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigPath, nextConfigType: configType }\n}\n\nasync function getProjectType(projectDir: string, nextConfigPath: string): Promise<'cjs' | 'esm'> {\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","execa","fs","fse","globby","path","promisify","readFile","writeFile","filename","fileURLToPath","url","dirname","copyRecursiveSync","debug","origDebug","warning","moveMessage","wrapNextConfig","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","hasBaseUrl","compilerOptions","baseUrl","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","exitCode","cwd","absolute","length","undefined","ignore","onlyDirectories","configType","getProjectType","packageObj","readJson","packageJsonType","type"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAC/C,OAAOC,WAAW,QAAO;AACzB,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAEhC,MAAMC,WAAWD,UAAUJ,GAAGK,QAAQ;AACtC,MAAMC,YAAYF,UAAUJ,GAAGM,SAAS;AAExC,MAAMC,WAAWC,cAAc,YAAYC,GAAG;AAC9C,MAAMC,UAAUP,KAAKO,OAAO,CAACH;AAE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db.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs, DbDetails, DbType } from '../types.js'\n\ntype DbChoice = {\n dbConnectionPrefix: `${string}/`\n title: string\n value: DbType\n}\n\nconst dbChoiceRecord: Record<DbType, DbChoice> = {\n mongodb: {\n dbConnectionPrefix: 'mongodb://127.0.0.1/',\n title: 'MongoDB',\n value: 'mongodb',\n },\n postgres: {\n dbConnectionPrefix: 'postgres://127.0.0.1:5432/',\n title: 'PostgreSQL (beta)',\n value: 'postgres',\n },\n}\n\nexport async function selectDb(args: CliArgs, projectName: string): Promise<DbDetails> {\n let dbType: DbType | symbol | undefined = undefined\n if (args['--db']) {\n if (!Object.values(dbChoiceRecord).some((dbChoice) => dbChoice.value === args['--db'])) {\n throw new Error(\n `Invalid database type given. Valid types are: ${Object.values(dbChoiceRecord)\n .map((dbChoice) => dbChoice.value)\n .join(', ')}`,\n )\n }\n dbType = args['--db'] as DbType\n } else {\n dbType = await p.select<{ label: string; value: DbType }[], DbType>({\n initialValue: 'mongodb',\n message: `Select a database`,\n options: [\n { label: 'MongoDB', value: 'mongodb' },\n { label: 'Postgres', value: 'postgres' },\n ],\n })\n if (p.isCancel(dbType)) process.exit(0)\n }\n\n const dbChoice = dbChoiceRecord[dbType]\n\n let dbUri: string | symbol | undefined = undefined\n const initialDbUri = `${dbChoice.dbConnectionPrefix}${\n projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)\n }`\n\n if (args['--db-accept-recommended']) {\n dbUri = initialDbUri\n } else if (args['--db-connection-string']) {\n dbUri = args['--db-connection-string']\n } else {\n dbUri = await p.text({\n initialValue: initialDbUri,\n message: `Enter ${dbChoice.title.split(' ')[0]} connection string`, // strip beta from title\n })\n if (p.isCancel(dbUri)) process.exit(0)\n }\n\n return {\n type: dbChoice.value,\n dbUri,\n }\n}\n\nfunction getRandomDigitSuffix(): string {\n return (Math.random() * Math.pow(10, 6)).toFixed(0)\n}\n"],"names":["p","slugify","dbChoiceRecord","mongodb","dbConnectionPrefix","title","value","postgres","selectDb","args","projectName","dbType","undefined","Object","values","some","dbChoice","Error","map","join","select","initialValue","message","options","label","isCancel","process","exit","dbUri","initialDbUri","getRandomDigitSuffix","text","split","type","Math","random","pow","toFixed"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAU3C,MAAMC,iBAA2C;IAC/CC,SAAS;QACPC,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;IACAC,UAAU;QACRH,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;AACF;AAEA,OAAO,eAAeE,SAASC,IAAa,EAAEC,WAAmB;IAC/D,IAAIC,SAAsCC;IAC1C,IAAIH,IAAI,CAAC,OAAO,EAAE;QAChB,IAAI,CAACI,OAAOC,MAAM,CAACZ,gBAAgBa,IAAI,CAAC,CAACC,WAAaA,SAASV,KAAK,KAAKG,IAAI,CAAC,OAAO,GAAG;YACtF,MAAM,IAAIQ,MACR,CAAC,8CAA8C,EAAEJ,OAAOC,MAAM,CAACZ,gBAC5DgB,GAAG,CAAC,CAACF,WAAaA,SAASV,KAAK,EAChCa,IAAI,CAAC,MAAM,CAAC;QAEnB;QACAR,SAASF,IAAI,CAAC,OAAO;IACvB,OAAO;QACLE,SAAS,MAAMX,EAAEoB,MAAM,CAA6C;YAClEC,cAAc;YACdC,SAAS,CAAC,iBAAiB,CAAC;YAC5BC,SAAS;gBACP;oBAAEC,OAAO;oBAAWlB,OAAO;gBAAU;gBACrC;oBAAEkB,OAAO;oBAAYlB,OAAO;gBAAW;aACxC;QACH;QACA,IAAIN,EAAEyB,QAAQ,CAACd,SAASe,QAAQC,IAAI,CAAC;IACvC;IAEA,MAAMX,WAAWd,cAAc,CAACS,OAAO;IAEvC,IAAIiB,QAAqChB;IACzC,MAAMiB,eAAe,CAAC,EAAEb,SAASZ,kBAAkB,CAAC,EAClDM,gBAAgB,MAAM,CAAC,QAAQ,EAAEoB,uBAAuB,CAAC,GAAG7B,QAAQS,aACrE,CAAC;IAEF,IAAID,IAAI,CAAC,0BAA0B,EAAE;QACnCmB,QAAQC;IACV,OAAO,IAAIpB,IAAI,CAAC,yBAAyB,EAAE;QACzCmB,QAAQnB,IAAI,CAAC,yBAAyB;IACxC,OAAO;QACLmB,QAAQ,MAAM5B,EAAE+B,IAAI,CAAC;YACnBV,cAAcQ;YACdP,SAAS,CAAC,MAAM,EAAEN,SAASX,KAAK,CAAC2B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC;QACpE;QACA,IAAIhC,EAAEyB,QAAQ,CAACG,QAAQF,QAAQC,IAAI,CAAC;IACtC;IAEA,OAAO;QACLM,MAAMjB,SAASV,KAAK;QACpBsB;IACF;AACF;AAEA,SAASE;IACP,OAAO,AAACI,CAAAA,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAAC,IAAI,EAAC,EAAGC,OAAO,CAAC;AACnD"}
|
1
|
+
{"version":3,"sources":["../../src/lib/select-db.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs, DbDetails, DbType } from '../types.js'\n\ntype DbChoice = {\n dbConnectionPrefix: `${string}/`\n title: string\n value: DbType\n}\n\nconst dbChoiceRecord: Record<DbType, DbChoice> = {\n mongodb: {\n dbConnectionPrefix: 'mongodb://127.0.0.1/',\n title: 'MongoDB',\n value: 'mongodb',\n },\n postgres: {\n dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',\n title: 'PostgreSQL (beta)',\n value: 'postgres',\n },\n}\n\nexport async function selectDb(args: CliArgs, projectName: string): Promise<DbDetails> {\n let dbType: DbType | symbol | undefined = undefined\n if (args['--db']) {\n if (!Object.values(dbChoiceRecord).some((dbChoice) => dbChoice.value === args['--db'])) {\n throw new Error(\n `Invalid database type given. Valid types are: ${Object.values(dbChoiceRecord)\n .map((dbChoice) => dbChoice.value)\n .join(', ')}`,\n )\n }\n dbType = args['--db'] as DbType\n } else {\n dbType = await p.select<{ label: string; value: DbType }[], DbType>({\n initialValue: 'mongodb',\n message: `Select a database`,\n options: [\n { label: 'MongoDB', value: 'mongodb' },\n { label: 'Postgres', value: 'postgres' },\n ],\n })\n if (p.isCancel(dbType)) process.exit(0)\n }\n\n const dbChoice = dbChoiceRecord[dbType]\n\n let dbUri: string | symbol | undefined = undefined\n const initialDbUri = `${dbChoice.dbConnectionPrefix}${\n projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)\n }`\n\n if (args['--db-accept-recommended']) {\n dbUri = initialDbUri\n } else if (args['--db-connection-string']) {\n dbUri = args['--db-connection-string']\n } else {\n dbUri = await p.text({\n initialValue: initialDbUri,\n message: `Enter ${dbChoice.title.split(' ')[0]} connection string`, // strip beta from title\n })\n if (p.isCancel(dbUri)) process.exit(0)\n }\n\n return {\n type: dbChoice.value,\n dbUri,\n }\n}\n\nfunction getRandomDigitSuffix(): string {\n return (Math.random() * Math.pow(10, 6)).toFixed(0)\n}\n"],"names":["p","slugify","dbChoiceRecord","mongodb","dbConnectionPrefix","title","value","postgres","selectDb","args","projectName","dbType","undefined","Object","values","some","dbChoice","Error","map","join","select","initialValue","message","options","label","isCancel","process","exit","dbUri","initialDbUri","getRandomDigitSuffix","text","split","type","Math","random","pow","toFixed"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAU3C,MAAMC,iBAA2C;IAC/CC,SAAS;QACPC,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;IACAC,UAAU;QACRH,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;AACF;AAEA,OAAO,eAAeE,SAASC,IAAa,EAAEC,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tC;IAEA,OAAO;QACLM,MAAMjB,SAASV,KAAK;QACpBsB;IACF;AACF;AAEA,SAASE;IACP,OAAO,AAACI,CAAAA,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAAC,IAAI,EAAC,EAAGC,OAAO,CAAC;AACnD"}
|
package/dist/lib/templates.js
CHANGED
@@ -15,6 +15,31 @@ export function getValidTemplates() {
|
|
15
15
|
type: 'starter',
|
16
16
|
description: 'Blank 3.0 Template',
|
17
17
|
url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta'
|
18
|
+
},
|
19
|
+
// Remove these until they have been updated for 3.0
|
20
|
+
// {
|
21
|
+
// name: 'blank',
|
22
|
+
// type: 'starter',
|
23
|
+
// description: 'Blank Template',
|
24
|
+
// url: 'https://github.com/payloadcms/payload/templates/blank',
|
25
|
+
// },
|
26
|
+
// {
|
27
|
+
// name: 'website',
|
28
|
+
// type: 'starter',
|
29
|
+
// description: 'Website Template',
|
30
|
+
// url: 'https://github.com/payloadcms/payload/templates/website',
|
31
|
+
// },
|
32
|
+
// {
|
33
|
+
// name: 'ecommerce',
|
34
|
+
// type: 'starter',
|
35
|
+
// description: 'E-commerce Template',
|
36
|
+
// url: 'https://github.com/payloadcms/payload/templates/ecommerce',
|
37
|
+
// },
|
38
|
+
{
|
39
|
+
name: 'plugin',
|
40
|
+
type: 'plugin',
|
41
|
+
description: 'Template for creating a Payload plugin',
|
42
|
+
url: 'https://github.com/payloadcms/payload-plugin-template#beta'
|
18
43
|
}
|
19
44
|
];
|
20
45
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\n\nexport function validateTemplate(templateName: string): boolean {\n const validTemplates = getValidTemplates()\n if (!validTemplates.map((t) => t.name).includes(templateName)) {\n error(`'${templateName}' is not a valid template.`)\n info(`Valid templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n return false\n }\n return true\n}\n\nexport function getValidTemplates(): ProjectTemplate[] {\n return [\n {\n name: 'blank-3.0',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'website',\n // type: 'starter',\n // description: 'Website Template',\n // url: 'https://github.com/payloadcms/payload/templates/website',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n
|
1
|
+
{"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\n\nexport function validateTemplate(templateName: string): boolean {\n const validTemplates = getValidTemplates()\n if (!validTemplates.map((t) => t.name).includes(templateName)) {\n error(`'${templateName}' is not a valid template.`)\n info(`Valid templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n return false\n }\n return true\n}\n\nexport function getValidTemplates(): ProjectTemplate[] {\n return [\n {\n name: 'blank-3.0',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'website',\n // type: 'starter',\n // description: 'Website Template',\n // url: 'https://github.com/payloadcms/payload/templates/website',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n {\n name: 'plugin',\n type: 'plugin',\n description: 'Template for creating a Payload plugin',\n url: 'https://github.com/payloadcms/payload-plugin-template#beta',\n },\n // {\n // name: 'payload-demo',\n // type: 'starter',\n // description: 'Payload demo site at https://demo.payloadcms.com',\n // url: 'https://github.com/payloadcms/public-demo',\n // },\n // {\n // name: 'payload-website',\n // type: 'starter',\n // description: 'Payload website CMS at https://payloadcms.com',\n // url: 'https://github.com/payloadcms/website-cms',\n // },\n ]\n}\n"],"names":["error","info","validateTemplate","templateName","validTemplates","getValidTemplates","map","t","name","includes","join","type","description","url"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,KAAK,EAAEC,IAAI,QAAQ,kBAAiB;AAE7C,OAAO,SAASC,iBAAiBC,YAAoB;IACnD,MAAMC,iBAAiBC;IACvB,IAAI,CAACD,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,QAAQ,CAACN,eAAe;QAC7DH,MAAM,CAAC,CAAC,EAAEG,aAAa,0BAA0B,CAAC;QAClDF,KAAK,CAAC,iBAAiB,EAAEG,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEE,IAAI,CAAC,MAAM,CAAC;QACvE,OAAO;IACT;IACA,OAAO;AACT;AAEA,OAAO,SAASL;IACd,OAAO;QACL;YACEG,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;QAEA,oDAAoD;QAEpD,IAAI;QACJ,mBAAmB;QACnB,qBAAqB;QACrB,mCAAmC;QACnC,kEAAkE;QAClE,KAAK;QACL,IAAI;QACJ,qBAAqB;QACrB,qBAAqB;QACrB,qCAAqC;QACrC,oEAAoE;QACpE,KAAK;QACL,IAAI;QACJ,uBAAuB;QACvB,qBAAqB;QACrB,wCAAwC;QACxC,sEAAsE;QACtE,KAAK;QACL;YACEL,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;KAaD;AACH"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
2
|
+
import type { Metadata } from 'next'
|
3
|
+
|
4
|
+
import config from '@payload-config'
|
5
|
+
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
6
|
+
import { NotFoundPage, generatePageMetadata } from '@payloadcms/next/views'
|
7
|
+
|
8
|
+
type Args = {
|
9
|
+
params: {
|
10
|
+
segments: string[]
|
11
|
+
}
|
12
|
+
searchParams: {
|
13
|
+
[key: string]: string | string[]
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
|
18
|
+
generatePageMetadata({ config, params, searchParams })
|
19
|
+
|
20
|
+
const NotFound = ({ params, searchParams }: Args) => NotFoundPage({ config, params, searchParams })
|
21
|
+
|
22
|
+
export default NotFound
|
@@ -1,7 +1,9 @@
|
|
1
1
|
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
2
|
+
import type { Metadata } from 'next'
|
3
|
+
|
2
4
|
import config from '@payload-config'
|
3
5
|
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
4
|
-
import { RootPage } from '@payloadcms/next/views'
|
6
|
+
import { RootPage, generatePageMetadata } from '@payloadcms/next/views'
|
5
7
|
|
6
8
|
type Args = {
|
7
9
|
params: {
|
@@ -12,6 +14,9 @@ type Args = {
|
|
12
14
|
}
|
13
15
|
}
|
14
16
|
|
17
|
+
export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
|
18
|
+
generatePageMetadata({ config, params, searchParams })
|
19
|
+
|
15
20
|
const Page = ({ params, searchParams }: Args) => RootPage({ config, params, searchParams })
|
16
21
|
|
17
22
|
export default Page
|
@@ -1,9 +1,10 @@
|
|
1
1
|
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
2
2
|
/* DO NOT MODIFY it because it could be re-written at any time. */
|
3
3
|
import config from '@payload-config'
|
4
|
-
import { REST_DELETE, REST_GET, REST_PATCH, REST_POST } from '@payloadcms/next/routes'
|
4
|
+
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes'
|
5
5
|
|
6
6
|
export const GET = REST_GET(config)
|
7
7
|
export const POST = REST_POST(config)
|
8
8
|
export const DELETE = REST_DELETE(config)
|
9
9
|
export const PATCH = REST_PATCH(config)
|
10
|
+
export const OPTIONS = REST_OPTIONS(config)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import
|
2
2
|
// import { payloadCloud } from '@payloadcms/plugin-cloud'
|
3
|
-
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
3
|
+
import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
4
4
|
import path from 'path'
|
5
5
|
import { buildConfig } from 'payload/config'
|
6
6
|
// import sharp from 'sharp'
|
@@ -27,6 +27,7 @@ export default buildConfig({
|
|
27
27
|
url: process.env.DATABASE_URI || '',
|
28
28
|
}),
|
29
29
|
// database-adapter-config-end
|
30
|
+
|
30
31
|
// Sharp is now an optional dependency -
|
31
32
|
// if you want to resize images, crop, set focal point, etc.
|
32
33
|
// make sure to install it and pass it to the config.
|
package/package.json
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
{
|
2
2
|
"name": "create-payload-app",
|
3
|
-
"version": "3.0.0-
|
4
|
-
"license": "MIT",
|
5
|
-
"type": "module",
|
3
|
+
"version": "3.0.0-canary.92e4997",
|
6
4
|
"homepage": "https://payloadcms.com",
|
7
|
-
"bin": {
|
8
|
-
"create-payload-app": "bin/cli.js"
|
9
|
-
},
|
10
5
|
"repository": {
|
11
6
|
"type": "git",
|
12
7
|
"url": "https://github.com/payloadcms/payload.git",
|
13
8
|
"directory": "packages/create-payload-app"
|
14
9
|
},
|
10
|
+
"license": "MIT",
|
11
|
+
"type": "module",
|
12
|
+
"exports": {
|
13
|
+
"./commands": {
|
14
|
+
"import": "./src/lib/init-next.ts",
|
15
|
+
"require": "./src/lib/init-next.ts",
|
16
|
+
"types": "./src/lib/init-next.ts"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"bin": {
|
20
|
+
"create-payload-app": "bin/cli.js"
|
21
|
+
},
|
15
22
|
"files": [
|
16
23
|
"package.json",
|
17
24
|
"dist",
|
@@ -41,19 +48,12 @@
|
|
41
48
|
"@types/jest": "^27.0.3",
|
42
49
|
"@types/node": "20.12.5"
|
43
50
|
},
|
44
|
-
"exports": {
|
45
|
-
"./commands": {
|
46
|
-
"import": "./src/lib/init-next.ts",
|
47
|
-
"require": "./src/lib/init-next.ts",
|
48
|
-
"types": "./src/lib/init-next.ts"
|
49
|
-
}
|
50
|
-
},
|
51
51
|
"scripts": {
|
52
52
|
"build": "pnpm pack-template-files && pnpm typecheck && pnpm build:swc",
|
53
|
-
"typecheck": "tsc",
|
54
|
-
"pack-template-files": "tsx src/scripts/pack-template-files.ts",
|
55
53
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
56
54
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
57
|
-
"
|
55
|
+
"pack-template-files": "tsx src/scripts/pack-template-files.ts",
|
56
|
+
"test": "jest",
|
57
|
+
"typecheck": "tsc"
|
58
58
|
}
|
59
59
|
}
|