create-payload-app 3.0.0-canary.92e4997 → 3.0.0-canary.a0b06af

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/lib/configure-payload-config.d.ts +8 -2
  3. package/dist/lib/configure-payload-config.d.ts.map +1 -1
  4. package/dist/lib/configure-payload-config.js +74 -25
  5. package/dist/lib/configure-payload-config.js.map +1 -1
  6. package/dist/lib/create-project.d.ts.map +1 -1
  7. package/dist/lib/create-project.js +9 -2
  8. package/dist/lib/create-project.js.map +1 -1
  9. package/dist/lib/create-project.spec.js +11 -12
  10. package/dist/lib/create-project.spec.js.map +1 -1
  11. package/dist/lib/generate-secret.js.map +1 -1
  12. package/dist/lib/get-package-manager.d.ts +6 -0
  13. package/dist/lib/get-package-manager.d.ts.map +1 -0
  14. package/dist/lib/get-package-manager.js +29 -0
  15. package/dist/lib/get-package-manager.js.map +1 -0
  16. package/dist/lib/init-next.d.ts +1 -9
  17. package/dist/lib/init-next.d.ts.map +1 -1
  18. package/dist/lib/init-next.js +31 -50
  19. package/dist/lib/init-next.js.map +1 -1
  20. package/dist/lib/install-packages.d.ts +9 -0
  21. package/dist/lib/install-packages.d.ts.map +1 -0
  22. package/dist/lib/install-packages.js +43 -0
  23. package/dist/lib/install-packages.js.map +1 -0
  24. package/dist/lib/parse-project-name.js.map +1 -1
  25. package/dist/lib/parse-template.js.map +1 -1
  26. package/dist/lib/replacements.d.ts +27 -0
  27. package/dist/lib/replacements.d.ts.map +1 -0
  28. package/dist/lib/replacements.js +68 -0
  29. package/dist/lib/replacements.js.map +1 -0
  30. package/dist/lib/select-db.js.map +1 -1
  31. package/dist/lib/templates.js +5 -24
  32. package/dist/lib/templates.js.map +1 -1
  33. package/dist/lib/update-payload-in-project.d.ts +6 -0
  34. package/dist/lib/update-payload-in-project.d.ts.map +1 -0
  35. package/dist/lib/update-payload-in-project.js +71 -0
  36. package/dist/lib/update-payload-in-project.js.map +1 -0
  37. package/dist/lib/wrap-next-config.d.ts.map +1 -1
  38. package/dist/lib/wrap-next-config.js +1 -2
  39. package/dist/lib/wrap-next-config.js.map +1 -1
  40. package/dist/lib/wrap-next-config.spec.js +1 -0
  41. package/dist/lib/wrap-next-config.spec.js.map +1 -1
  42. package/dist/lib/write-env-file.d.ts.map +1 -1
  43. package/dist/lib/write-env-file.js +25 -25
  44. package/dist/lib/write-env-file.js.map +1 -1
  45. package/dist/main.d.ts.map +1 -1
  46. package/dist/main.js +28 -21
  47. package/dist/main.js.map +1 -1
  48. package/dist/scripts/pack-template-files.js.map +1 -1
  49. package/dist/template/src/collections/Media.ts +16 -0
  50. package/dist/template/src/collections/Users.ts +1 -1
  51. package/dist/template/src/payload.config.ts +10 -15
  52. package/dist/types.d.ts +11 -0
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/types.js.map +1 -1
  55. package/dist/utils/copy-recursive-sync.d.ts +2 -0
  56. package/dist/utils/copy-recursive-sync.d.ts.map +1 -1
  57. package/dist/utils/copy-recursive-sync.js +2 -0
  58. package/dist/utils/copy-recursive-sync.js.map +1 -1
  59. package/dist/utils/git.d.ts +4 -0
  60. package/dist/utils/git.d.ts.map +1 -0
  61. package/dist/utils/git.js +46 -0
  62. package/dist/utils/git.js.map +1 -0
  63. package/dist/utils/log.js.map +1 -1
  64. package/dist/utils/messages.d.ts.map +1 -1
  65. package/dist/utils/messages.js.map +1 -1
  66. package/package.json +17 -6
  67. package/dist/lib/packages.d.ts +0 -9
  68. package/dist/lib/packages.d.ts.map +0 -1
  69. package/dist/lib/packages.js +0 -27
  70. package/dist/lib/packages.js.map +0 -1
@@ -1,20 +1,20 @@
1
1
  import * as p from '@clack/prompts';
2
2
  import { parse, stringify } from 'comment-json';
3
- import execa from 'execa';
4
3
  import fs from 'fs';
5
4
  import fse from 'fs-extra';
6
5
  import globby from 'globby';
6
+ import { fileURLToPath } from 'node:url';
7
7
  import path from 'path';
8
8
  import { promisify } from 'util';
9
- const readFile = promisify(fs.readFile);
10
- const writeFile = promisify(fs.writeFile);
11
- const filename = fileURLToPath(import.meta.url);
12
- const dirname = path.dirname(filename);
13
- import { fileURLToPath } from 'node:url';
14
9
  import { copyRecursiveSync } from '../utils/copy-recursive-sync.js';
15
10
  import { debug as origDebug, warning } from '../utils/log.js';
16
11
  import { moveMessage } from '../utils/messages.js';
12
+ import { installPackages } from './install-packages.js';
17
13
  import { wrapNextConfig } from './wrap-next-config.js';
14
+ const readFile = promisify(fs.readFile);
15
+ const writeFile = promisify(fs.writeFile);
16
+ const filename = fileURLToPath(import.meta.url);
17
+ const dirname = path.dirname(filename);
18
18
  export async function initNext(args) {
19
19
  const { dbType: dbType, packageManager, projectDir } = args;
20
20
  const nextAppDetails = args.nextAppDetails || await getNextAppDetails(projectDir);
@@ -26,7 +26,7 @@ export async function initNext(args) {
26
26
  });
27
27
  nextAppDetails.nextAppDir = createdAppDir;
28
28
  }
29
- const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
29
+ const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
30
30
  if (!nextConfigType) {
31
31
  return {
32
32
  isSrcDir,
@@ -163,48 +163,17 @@ async function installDeps(projectDir, packageManager, dbType) {
163
163
  const packagesToInstall = [
164
164
  'payload',
165
165
  '@payloadcms/next',
166
- '@payloadcms/richtext-lexical'
166
+ '@payloadcms/richtext-lexical',
167
+ '@payloadcms/plugin-cloud'
167
168
  ].map((pkg)=>`${pkg}@beta`);
168
169
  packagesToInstall.push(`@payloadcms/db-${dbType}@beta`);
169
- let exitCode = 0;
170
- switch(packageManager){
171
- case 'npm':
172
- {
173
- ({ exitCode } = await execa('npm', [
174
- 'install',
175
- '--save',
176
- ...packagesToInstall
177
- ], {
178
- cwd: projectDir
179
- }));
180
- break;
181
- }
182
- case 'yarn':
183
- case 'pnpm':
184
- {
185
- ({ exitCode } = await execa(packageManager, [
186
- 'add',
187
- ...packagesToInstall
188
- ], {
189
- cwd: projectDir
190
- }));
191
- break;
192
- }
193
- case 'bun':
194
- {
195
- warning('Bun support is untested.');
196
- ({ exitCode } = await execa('bun', [
197
- 'add',
198
- ...packagesToInstall
199
- ], {
200
- cwd: projectDir
201
- }));
202
- break;
203
- }
204
- }
205
- return {
206
- success: exitCode === 0
207
- };
170
+ // Match graphql version of @payloadcms/next
171
+ packagesToInstall.push('graphql@^16.8.1');
172
+ return await installPackages({
173
+ packageManager,
174
+ packagesToInstall,
175
+ projectDir
176
+ });
208
177
  }
209
178
  export async function getNextAppDetails(projectDir) {
210
179
  const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'));
@@ -219,6 +188,15 @@ export async function getNextAppDetails(projectDir) {
219
188
  nextConfigPath: undefined
220
189
  };
221
190
  }
191
+ const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));
192
+ if (packageObj.dependencies?.payload) {
193
+ return {
194
+ hasTopLevelLayout: false,
195
+ isPayloadInstalled: true,
196
+ isSrcDir,
197
+ nextConfigPath
198
+ };
199
+ }
222
200
  let nextAppDir = (await globby([
223
201
  '**/app'
224
202
  ], {
@@ -232,7 +210,10 @@ export async function getNextAppDetails(projectDir) {
232
210
  if (!nextAppDir || nextAppDir.length === 0) {
233
211
  nextAppDir = undefined;
234
212
  }
235
- const configType = await getProjectType(projectDir, nextConfigPath);
213
+ const configType = getProjectType({
214
+ nextConfigPath,
215
+ packageObj
216
+ });
236
217
  const hasTopLevelLayout = nextAppDir ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx')) : false;
237
218
  return {
238
219
  hasTopLevelLayout,
@@ -242,14 +223,14 @@ export async function getNextAppDetails(projectDir) {
242
223
  nextConfigType: configType
243
224
  };
244
225
  }
245
- async function getProjectType(projectDir, nextConfigPath) {
226
+ function getProjectType(args) {
227
+ const { nextConfigPath, packageObj } = args;
246
228
  if (nextConfigPath.endsWith('.mjs')) {
247
229
  return 'esm';
248
230
  }
249
231
  if (nextConfigPath.endsWith('.cjs')) {
250
232
  return 'cjs';
251
233
  }
252
- const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));
253
234
  const packageJsonType = packageObj.type;
254
235
  if (packageJsonType === 'module') {
255
236
  return 'esm';
@@ -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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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vC;IAEJ,OAAO;QAAEM;QAAmBH;QAAUH;QAAY+B;QAAgBxB,gBAAgB0C;IAAW;AAC/F;AAEA,eAAeC,eAAerD,UAAkB,EAAEkC,cAAsB;IACtE,IAAIA,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IACA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IAEA,MAAMgB,aAAa,MAAM1E,IAAI2E,QAAQ,CAACzE,KAAKuB,OAAO,CAACL,YAAY;IAC/D,MAAMwD,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 { fileURLToPath } from 'node:url'\nimport path from 'path'\nimport { promisify } from 'util'\n\nimport type { CliArgs, DbType, NextAppDetails, NextConfigType, 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 { installPackages } from './install-packages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ntype InitNextArgs = Pick<CliArgs, '--debug'> & {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n}\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, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } =\n 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 = [\n 'payload',\n '@payloadcms/next',\n '@payloadcms/richtext-lexical',\n '@payloadcms/plugin-cloud',\n ].map((pkg) => `${pkg}@beta`)\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n // Match graphql version of @payloadcms/next\n packagesToInstall.push('graphql@^16.8.1')\n\n return await installPackages({ packageManager, packagesToInstall, projectDir })\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\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n nextConfigPath: undefined,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n nextConfigPath,\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 = getProjectType({ nextConfigPath, packageObj })\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\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): 'cjs' | 'esm' {\n const { nextConfigPath, packageObj } = args\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\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","fs","fse","globby","fileURLToPath","path","promisify","copyRecursiveSync","debug","origDebug","warning","moveMessage","installPackages","wrapNextConfig","readFile","writeFile","filename","url","dirname","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","isPayloadInstalled","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","absolute","cwd","length","undefined","packageObj","readJson","dependencies","payload","ignore","onlyDirectories","configType","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;QAChC,OAAO;IACT;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
@@ -0,0 +1,9 @@
1
+ import type { PackageManager } from '../types.js';
2
+ export declare function installPackages(args: {
3
+ packageManager: PackageManager;
4
+ packagesToInstall: string[];
5
+ projectDir: string;
6
+ }): Promise<{
7
+ success: boolean;
8
+ }>;
9
+ //# sourceMappingURL=install-packages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-packages.d.ts","sourceRoot":"","sources":["../../src/lib/install-packages.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,cAAc,EAAE,cAAc,CAAA;IAC9B,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,UAAU,EAAE,MAAM,CAAA;CACnB;;GA+BA"}
@@ -0,0 +1,43 @@
1
+ import execa from 'execa';
2
+ import { error, warning } from '../utils/log.js';
3
+ export async function installPackages(args) {
4
+ const { packageManager, packagesToInstall, projectDir } = args;
5
+ let exitCode = 0;
6
+ let stderr = '';
7
+ switch(packageManager){
8
+ case 'npm':
9
+ {
10
+ ({ exitCode, stderr } = await execa('npm', [
11
+ 'install',
12
+ '--save',
13
+ ...packagesToInstall
14
+ ], {
15
+ cwd: projectDir
16
+ }));
17
+ break;
18
+ }
19
+ case 'yarn':
20
+ case 'pnpm':
21
+ case 'bun':
22
+ {
23
+ if (packageManager === 'bun') {
24
+ warning('Bun support is untested.');
25
+ }
26
+ ({ exitCode, stderr } = await execa(packageManager, [
27
+ 'add',
28
+ ...packagesToInstall
29
+ ], {
30
+ cwd: projectDir
31
+ }));
32
+ break;
33
+ }
34
+ }
35
+ if (exitCode !== 0) {
36
+ error(`Unable to install packages. Error: ${stderr}`);
37
+ }
38
+ return {
39
+ success: exitCode === 0
40
+ };
41
+ }
42
+
43
+ //# sourceMappingURL=install-packages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/install-packages.ts"],"sourcesContent":["import execa from 'execa'\n\nimport type { PackageManager } from '../types.js'\n\nimport { error, warning } from '../utils/log.js'\n\nexport async function installPackages(args: {\n packageManager: PackageManager\n packagesToInstall: string[]\n projectDir: string\n}) {\n const { packageManager, packagesToInstall, projectDir } = args\n\n let exitCode = 0\n let stderr = ''\n\n switch (packageManager) {\n case 'npm': {\n ;({ exitCode, stderr } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'yarn':\n case 'pnpm':\n case 'bun': {\n if (packageManager === 'bun') {\n warning('Bun support is untested.')\n }\n ;({ exitCode, stderr } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n }\n\n if (exitCode !== 0) {\n error(`Unable to install packages. Error: ${stderr}`)\n }\n\n return { success: exitCode === 0 }\n}\n"],"names":["execa","error","warning","installPackages","args","packageManager","packagesToInstall","projectDir","exitCode","stderr","cwd","success"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AAIzB,SAASC,KAAK,EAAEC,OAAO,QAAQ,kBAAiB;AAEhD,OAAO,eAAeC,gBAAgBC,IAIrC;IACC,MAAM,EAAEC,cAAc,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAGH;IAE1D,IAAII,WAAW;IACf,IAAIC,SAAS;IAEb,OAAQJ;QACN,KAAK;YAAO;gBACR,CAAA,EAAEG,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMT,MAAM,OAAO;oBAAC;oBAAW;uBAAaM;iBAAkB,EAAE;oBACvFI,KAAKH;gBACP,EAAC;gBACD;YACF;QACA,KAAK;QACL,KAAK;QACL,KAAK;YAAO;gBACV,IAAIF,mBAAmB,OAAO;oBAC5BH,QAAQ;gBACV;gBACE,CAAA,EAAEM,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMT,MAAMK,gBAAgB;oBAAC;uBAAUC;iBAAkB,EAAE;oBAClFI,KAAKH;gBACP,EAAC;gBACD;YACF;IACF;IAEA,IAAIC,aAAa,GAAG;QAClBP,MAAM,CAAC,mCAAmC,EAAEQ,OAAO,CAAC;IACtD;IAEA,OAAO;QAAEE,SAASH,aAAa;IAAE;AACnC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOF,QAAQE,IAAI,CAAC,SAAS;IACjD,IAAIA,KAAKC,CAAC,CAAC,EAAE,EAAE,OAAOH,QAAQE,KAAKC,CAAC,CAAC,EAAE;IAEvC,MAAMC,cAAc,MAAML,EAAEM,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO,OAAO;QACrB;IACF;IACA,IAAIT,EAAEU,QAAQ,CAACL,cAAc;QAC3BM,QAAQC,IAAI,CAAC;IACf;IACA,OAAOX,QAAQI;AACjB"}
1
+ {"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOF,QAAQE,IAAI,CAAC,SAAS;IACjD,IAAIA,KAAKC,CAAC,CAAC,EAAE,EAAE,OAAOH,QAAQE,KAAKC,CAAC,CAAC,EAAE;IAEvC,MAAMC,cAAc,MAAML,EAAEM,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO,OAAO;QACrB;IACF;IACA,IAAIT,EAAEU,QAAQ,CAACL,cAAc;QAC3BM,QAAQC,IAAI,CAAC;IACf;IACA,OAAOX,QAAQI;AACjB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-template.ts"],"sourcesContent":["import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n args: CliArgs,\n validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n if (args['--template']) {\n const templateName = args['--template']\n const template = validTemplates.find((t) => t.name === templateName)\n if (!template) throw new Error('Invalid template given')\n return template\n }\n\n const response = await p.select<{ label: string; value: string }[], string>({\n message: 'Choose project template',\n options: validTemplates.map((p) => {\n return {\n label: p.name,\n value: p.name,\n }\n }),\n })\n if (p.isCancel(response)) {\n process.exit(0)\n }\n\n const template = validTemplates.find((t) => t.name === response)\n\n return template\n}\n"],"names":["p","parseTemplate","args","validTemplates","templateName","template","find","t","name","Error","response","select","message","options","map","label","value","isCancel","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AAInC,OAAO,eAAeC,cACpBC,IAAa,EACbC,cAAiC;IAEjC,IAAID,IAAI,CAAC,aAAa,EAAE;QACtB,MAAME,eAAeF,IAAI,CAAC,aAAa;QACvC,MAAMG,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QACvD,IAAI,CAACC,UAAU,MAAM,IAAII,MAAM;QAC/B,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMV,EAAEW,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASV,eAAeW,GAAG,CAAC,CAACd;YAC3B,OAAO;gBACLe,OAAOf,EAAEQ,IAAI;gBACbQ,OAAOhB,EAAEQ,IAAI;YACf;QACF;IACF;IACA,IAAIR,EAAEiB,QAAQ,CAACP,WAAW;QACxBQ,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMd,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
1
+ {"version":3,"sources":["../../src/lib/parse-template.ts"],"sourcesContent":["import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n args: CliArgs,\n validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n if (args['--template']) {\n const templateName = args['--template']\n const template = validTemplates.find((t) => t.name === templateName)\n if (!template) throw new Error('Invalid template given')\n return template\n }\n\n const response = await p.select<{ label: string; value: string }[], string>({\n message: 'Choose project template',\n options: validTemplates.map((p) => {\n return {\n label: p.name,\n value: p.name,\n }\n }),\n })\n if (p.isCancel(response)) {\n process.exit(0)\n }\n\n const template = validTemplates.find((t) => t.name === response)\n\n return template\n}\n"],"names":["p","parseTemplate","args","validTemplates","templateName","template","find","t","name","Error","response","select","message","options","map","label","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AAInC,OAAO,eAAeC,cACpBC,IAAa,EACbC,cAAiC;IAEjC,IAAID,IAAI,CAAC,aAAa,EAAE;QACtB,MAAME,eAAeF,IAAI,CAAC,aAAa;QACvC,MAAMG,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QACvD,IAAI,CAACC,UAAU,MAAM,IAAII,MAAM;QAC/B,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMV,EAAEW,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASV,eAAeW,GAAG,CAAC,CAACd;YAC3B,OAAO;gBACLe,OAAOf,EAAEQ,IAAI;gBACbQ,OAAOhB,EAAEQ,IAAI;YACf;QACF;IACF;IACA,IAAIR,EAAEiB,QAAQ,CAACP,WAAW;QACxBQ,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMd,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
@@ -0,0 +1,27 @@
1
+ import type { DbType, StorageAdapterType } from '../types.js';
2
+ type DbAdapterReplacement = {
3
+ configReplacement: (envName?: string) => string[];
4
+ importReplacement: string;
5
+ packageName: string;
6
+ };
7
+ export declare const dbReplacements: Record<DbType, DbAdapterReplacement>;
8
+ type StorageAdapterReplacement = {
9
+ configReplacement: string[];
10
+ importReplacement?: string;
11
+ packageName?: string;
12
+ };
13
+ export declare const storageReplacements: Record<StorageAdapterType, StorageAdapterReplacement>;
14
+ /**
15
+ * Generic config replacement
16
+ */
17
+ type ConfigReplacement = {
18
+ configReplacement: {
19
+ match: string;
20
+ replacement: string;
21
+ };
22
+ importReplacement: string;
23
+ packageName: string;
24
+ };
25
+ export declare const configReplacements: Record<string, ConfigReplacement>;
26
+ export {};
27
+ //# sourceMappingURL=replacements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replacements.d.ts","sourceRoot":"","sources":["../../src/lib/replacements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,oBAAoB,GAAG;IAC1B,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;IACjD,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAyBD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAG/D,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AA4BD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,kBAAkB,EAAE,yBAAyB,CAIrF,CAAA;AAED;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,iBAAiB,EAAE;QACjB,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,EAAE,MAAM,CAAA;KACpB,CAAA;IACD,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAUhE,CAAA"}
@@ -0,0 +1,68 @@
1
+ const mongodbReplacement = {
2
+ // Replacement between `// database-adapter-config-start` and `// database-adapter-config-end`
3
+ configReplacement: (envName = 'DATABASE_URI')=>[
4
+ ' db: mongooseAdapter({',
5
+ ` url: process.env.${envName} || '',`,
6
+ ' }),'
7
+ ],
8
+ importReplacement: "import { mongooseAdapter } from '@payloadcms/db-mongodb'",
9
+ packageName: '@payloadcms/db-mongodb'
10
+ };
11
+ const postgresReplacement = {
12
+ configReplacement: (envName = 'DATABASE_URI')=>[
13
+ ' db: postgresAdapter({',
14
+ ' pool: {',
15
+ ` connectionString: process.env.${envName} || '',`,
16
+ ' },',
17
+ ' }),'
18
+ ],
19
+ importReplacement: "import { postgresAdapter } from '@payloadcms/db-postgres'",
20
+ packageName: '@payloadcms/db-postgres'
21
+ };
22
+ export const dbReplacements = {
23
+ mongodb: mongodbReplacement,
24
+ postgres: postgresReplacement
25
+ };
26
+ const vercelBlobStorageReplacement = {
27
+ // Replacement of `// storage-adapter-placeholder`
28
+ configReplacement: [
29
+ ' vercelBlobStorage({',
30
+ ' collections: {',
31
+ ' [Media.slug]: true,',
32
+ ' },',
33
+ " token: process.env.BLOB_READ_WRITE_TOKEN || '',",
34
+ ' }),'
35
+ ],
36
+ importReplacement: "import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'",
37
+ packageName: '@payloadcms/storage-vercel-blob'
38
+ };
39
+ const payloadCloudReplacement = {
40
+ configReplacement: [
41
+ ' payloadCloudPlugin(),'
42
+ ],
43
+ importReplacement: "import { payloadCloudPlugin } from '@payloadcms/plugin-cloud'",
44
+ packageName: '@payloadcms/plugin-cloud'
45
+ };
46
+ // Removes placeholders
47
+ const diskReplacement = {
48
+ configReplacement: [],
49
+ importReplacement: ''
50
+ };
51
+ export const storageReplacements = {
52
+ localDisk: diskReplacement,
53
+ payloadCloud: payloadCloudReplacement,
54
+ vercelBlobStorage: vercelBlobStorageReplacement
55
+ };
56
+ export const configReplacements = {
57
+ sharp: {
58
+ // Replacement of `sharp, // Now optional`
59
+ configReplacement: {
60
+ match: 'sharp,',
61
+ replacement: ' // sharp,'
62
+ },
63
+ importReplacement: "import sharp from 'sharp'",
64
+ packageName: 'sharp'
65
+ }
66
+ };
67
+
68
+ //# sourceMappingURL=replacements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/replacements.ts"],"sourcesContent":["import type { DbType, StorageAdapterType } from '../types.js'\n\ntype DbAdapterReplacement = {\n configReplacement: (envName?: string) => string[]\n importReplacement: string\n packageName: string\n}\n\nconst mongodbReplacement: DbAdapterReplacement = {\n // Replacement between `// database-adapter-config-start` and `// database-adapter-config-end`\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: mongooseAdapter({',\n ` url: process.env.${envName} || '',`,\n ' }),',\n ],\n importReplacement: \"import { mongooseAdapter } from '@payloadcms/db-mongodb'\",\n packageName: '@payloadcms/db-mongodb',\n}\n\nconst postgresReplacement: DbAdapterReplacement = {\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: postgresAdapter({',\n ' pool: {',\n ` connectionString: process.env.${envName} || '',`,\n ' },',\n ' }),',\n ],\n importReplacement: \"import { postgresAdapter } from '@payloadcms/db-postgres'\",\n packageName: '@payloadcms/db-postgres',\n}\n\nexport const dbReplacements: Record<DbType, DbAdapterReplacement> = {\n mongodb: mongodbReplacement,\n postgres: postgresReplacement,\n}\n\ntype StorageAdapterReplacement = {\n configReplacement: string[]\n importReplacement?: string\n packageName?: string\n}\n\nconst vercelBlobStorageReplacement: StorageAdapterReplacement = {\n // Replacement of `// storage-adapter-placeholder`\n configReplacement: [\n ' vercelBlobStorage({',\n ' collections: {',\n ' [Media.slug]: true,',\n ' },',\n \" token: process.env.BLOB_READ_WRITE_TOKEN || '',\",\n ' }),',\n ],\n importReplacement: \"import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'\",\n packageName: '@payloadcms/storage-vercel-blob',\n}\n\nconst payloadCloudReplacement: StorageAdapterReplacement = {\n configReplacement: [' payloadCloudPlugin(),'],\n importReplacement: \"import { payloadCloudPlugin } from '@payloadcms/plugin-cloud'\",\n packageName: '@payloadcms/plugin-cloud',\n}\n\n// Removes placeholders\nconst diskReplacement: StorageAdapterReplacement = {\n configReplacement: [],\n importReplacement: '',\n}\n\nexport const storageReplacements: Record<StorageAdapterType, StorageAdapterReplacement> = {\n localDisk: diskReplacement,\n payloadCloud: payloadCloudReplacement,\n vercelBlobStorage: vercelBlobStorageReplacement,\n}\n\n/**\n * Generic config replacement\n */\ntype ConfigReplacement = {\n configReplacement: {\n match: string\n replacement: string\n }\n importReplacement: string\n packageName: string\n}\n\nexport const configReplacements: Record<string, ConfigReplacement> = {\n sharp: {\n // Replacement of `sharp, // Now optional`\n configReplacement: {\n match: 'sharp,',\n replacement: ' // sharp,',\n },\n importReplacement: \"import sharp from 'sharp'\",\n packageName: 'sharp',\n },\n}\n"],"names":["mongodbReplacement","configReplacement","envName","importReplacement","packageName","postgresReplacement","dbReplacements","mongodb","postgres","vercelBlobStorageReplacement","payloadCloudReplacement","diskReplacement","storageReplacements","localDisk","payloadCloud","vercelBlobStorage","configReplacements","sharp","match","replacement"],"mappings":"AAQA,MAAMA,qBAA2C;IAC/C,8FAA8F;IAC9FC,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA,CAAC,qBAAqB,EAAEA,QAAQ,OAAO,CAAC;YACxC;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMC,sBAA4C;IAChDJ,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA;YACA,CAAC,oCAAoC,EAAEA,QAAQ,OAAO,CAAC;YACvD;YACA;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,OAAO,MAAME,iBAAuD;IAClEC,SAASP;IACTQ,UAAUH;AACZ,EAAC;AAQD,MAAMI,+BAA0D;IAC9D,kDAAkD;IAClDR,mBAAmB;QACjB;QACA;QACA;QACA;QACA;QACA;KACD;IACDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMM,0BAAqD;IACzDT,mBAAmB;QAAC;KAA4B;IAChDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,uBAAuB;AACvB,MAAMO,kBAA6C;IACjDV,mBAAmB,EAAE;IACrBE,mBAAmB;AACrB;AAEA,OAAO,MAAMS,sBAA6E;IACxFC,WAAWF;IACXG,cAAcJ;IACdK,mBAAmBN;AACrB,EAAC;AAcD,OAAO,MAAMO,qBAAwD;IACnEC,OAAO;QACL,0CAA0C;QAC1ChB,mBAAmB;YACjBiB,OAAO;YACPC,aAAa;QACf;QACAhB,mBAAmB;QACnBC,aAAa;IACf;AACF,EAAC"}
@@ -1 +1 @@
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,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"],"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;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SAASV,KAAK;QACpBsB;IACF;AACF;AAEA,SAASE;IACP,OAAO,AAACI,CAAAA,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAAC,IAAI,EAAC,EAAGC,OAAO,CAAC;AACnD"}
@@ -11,35 +11,16 @@ export function validateTemplate(templateName) {
11
11
  export function getValidTemplates() {
12
12
  return [
13
13
  {
14
- name: 'blank-3.0',
14
+ name: 'blank',
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
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
19
  {
39
- name: 'plugin',
40
- type: 'plugin',
41
- description: 'Template for creating a Payload plugin',
42
- url: 'https://github.com/payloadcms/payload-plugin-template#beta'
20
+ name: 'website',
21
+ type: 'starter',
22
+ description: 'Website Template',
23
+ url: 'https://github.com/payloadcms/payload/templates/website#beta'
43
24
  }
44
25
  ];
45
26
  }
@@ -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 {\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"}
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',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',\n },\n {\n name: 'website',\n type: 'starter',\n description: 'Website Template',\n url: 'https://github.com/payloadcms/payload/templates/website#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: '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"],"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;QACA;YACEL,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;KAkCD;AACH"}
@@ -0,0 +1,6 @@
1
+ import type { NextAppDetails } from '../types.js';
2
+ export declare function updatePayloadInProject(appDetails: NextAppDetails): Promise<{
3
+ message: string;
4
+ success: boolean;
5
+ }>;
6
+ //# sourceMappingURL=update-payload-in-project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-payload-in-project.d.ts","sourceRoot":"","sources":["../../src/lib/update-payload-in-project.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOjD,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAuEhD"}
@@ -0,0 +1,71 @@
1
+ import execa from 'execa';
2
+ import fse from 'fs-extra';
3
+ import { fileURLToPath } from 'node:url';
4
+ import path from 'path';
5
+ const filename = fileURLToPath(import.meta.url);
6
+ const dirname = path.dirname(filename);
7
+ import { copyRecursiveSync } from '../utils/copy-recursive-sync.js';
8
+ import { info } from '../utils/log.js';
9
+ import { getPackageManager } from './get-package-manager.js';
10
+ import { installPackages } from './install-packages.js';
11
+ export async function updatePayloadInProject(appDetails) {
12
+ if (!appDetails.nextConfigPath) return {
13
+ message: 'No Next.js config found',
14
+ success: false
15
+ };
16
+ const projectDir = path.dirname(appDetails.nextConfigPath);
17
+ const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));
18
+ if (!packageObj?.dependencies) {
19
+ throw new Error('No package.json found in this project');
20
+ }
21
+ const payloadVersion = packageObj.dependencies?.payload;
22
+ if (!payloadVersion) {
23
+ throw new Error('Payload is not installed in this project');
24
+ }
25
+ const packageManager = await getPackageManager({
26
+ projectDir
27
+ });
28
+ // Fetch latest Payload version from npm
29
+ const { exitCode: getLatestVersionExitCode, stdout: latestPayloadVersion } = await execa('npm', [
30
+ 'show',
31
+ 'payload@beta',
32
+ 'version'
33
+ ]);
34
+ if (getLatestVersionExitCode !== 0) {
35
+ throw new Error('Failed to fetch latest Payload version');
36
+ }
37
+ if (payloadVersion === latestPayloadVersion) {
38
+ return {
39
+ message: `Payload v${payloadVersion} is already up to date.`,
40
+ success: true
41
+ };
42
+ }
43
+ // Update all existing Payload packages
44
+ const payloadPackages = Object.keys(packageObj.dependencies).filter((dep)=>dep.startsWith('@payloadcms/'));
45
+ const packageNames = [
46
+ 'payload',
47
+ ...payloadPackages
48
+ ];
49
+ const packagesToUpdate = packageNames.map((pkg)=>`${pkg}@${latestPayloadVersion}`);
50
+ info(`Using ${packageManager}.\n`);
51
+ info(`Updating ${packagesToUpdate.length} Payload packages to v${latestPayloadVersion}...\n\n${packageNames.map((p)=>` - ${p}`).join('\n')}`);
52
+ const { success: updateSuccess } = await installPackages({
53
+ packageManager,
54
+ packagesToInstall: packagesToUpdate,
55
+ projectDir
56
+ });
57
+ if (!updateSuccess) {
58
+ throw new Error('Failed to update Payload packages');
59
+ }
60
+ info('Payload packages updated successfully.');
61
+ info(`Updating Payload Next.js files...`);
62
+ const templateFilesPath = dirname.endsWith('dist') ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank-3.0');
63
+ const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)');
64
+ copyRecursiveSync(templateSrcDir, path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'));
65
+ return {
66
+ message: 'Payload updated successfully.',
67
+ success: true
68
+ };
69
+ }
70
+
71
+ //# sourceMappingURL=update-payload-in-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/update-payload-in-project.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport type { NextAppDetails } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { info } from '../utils/log.js'\nimport { getPackageManager } from './get-package-manager.js'\nimport { installPackages } from './install-packages.js'\n\nexport async function updatePayloadInProject(\n appDetails: NextAppDetails,\n): Promise<{ message: string; success: boolean }> {\n if (!appDetails.nextConfigPath) return { message: 'No Next.js config found', success: false }\n\n const projectDir = path.dirname(appDetails.nextConfigPath)\n\n const packageObj = (await fse.readJson(path.resolve(projectDir, 'package.json'))) as {\n dependencies?: Record<string, string>\n }\n if (!packageObj?.dependencies) {\n throw new Error('No package.json found in this project')\n }\n\n const payloadVersion = packageObj.dependencies?.payload\n if (!payloadVersion) {\n throw new Error('Payload is not installed in this project')\n }\n\n const packageManager = await getPackageManager({ projectDir })\n\n // Fetch latest Payload version from npm\n const { exitCode: getLatestVersionExitCode, stdout: latestPayloadVersion } = await execa('npm', [\n 'show',\n 'payload@beta',\n 'version',\n ])\n if (getLatestVersionExitCode !== 0) {\n throw new Error('Failed to fetch latest Payload version')\n }\n\n if (payloadVersion === latestPayloadVersion) {\n return { message: `Payload v${payloadVersion} is already up to date.`, success: true }\n }\n\n // Update all existing Payload packages\n const payloadPackages = Object.keys(packageObj.dependencies).filter((dep) =>\n dep.startsWith('@payloadcms/'),\n )\n\n const packageNames = ['payload', ...payloadPackages]\n\n const packagesToUpdate = packageNames.map((pkg) => `${pkg}@${latestPayloadVersion}`)\n\n info(`Using ${packageManager}.\\n`)\n info(\n `Updating ${packagesToUpdate.length} Payload packages to v${latestPayloadVersion}...\\n\\n${packageNames.map((p) => ` - ${p}`).join('\\n')}`,\n )\n\n const { success: updateSuccess } = await installPackages({\n packageManager,\n packagesToInstall: packagesToUpdate,\n projectDir,\n })\n\n if (!updateSuccess) {\n throw new Error('Failed to update Payload packages')\n }\n info('Payload packages updated successfully.')\n\n info(`Updating Payload Next.js files...`)\n const templateFilesPath = dirname.endsWith('dist')\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)')\n\n copyRecursiveSync(\n templateSrcDir,\n path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'),\n )\n\n return { message: 'Payload updated successfully.', success: true }\n}\n"],"names":["execa","fse","fileURLToPath","path","filename","url","dirname","copyRecursiveSync","info","getPackageManager","installPackages","updatePayloadInProject","appDetails","nextConfigPath","message","success","projectDir","packageObj","readJson","resolve","dependencies","Error","payloadVersion","payload","packageManager","exitCode","getLatestVersionExitCode","stdout","latestPayloadVersion","payloadPackages","Object","keys","filter","dep","startsWith","packageNames","packagesToUpdate","map","pkg","length","p","join","updateSuccess","packagesToInstall","templateFilesPath","endsWith","templateSrcDir","isSrcDir"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UA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O,EAAE,OAAO,CAAA;CAAE,CAiGrD"}
1
+ {"version":3,"file":"wrap-next-config.d.ts","sourceRoot":"","sources":["../../src/lib/wrap-next-config.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,oBAAoB;;;CAGhC,CAAA;AAED,KAAK,cAAc,GAAG,KAAK,GAAG,KAAK,CAAA;AAEnC,eAAO,MAAM,cAAc,SAAU;IACnC,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,cAAc,CAAA;CAC/B,SAaA,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,cAAc,GACzB;IAAE,qBAAqB,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAiGrD"}
@@ -1,8 +1,7 @@
1
1
  import chalk from 'chalk';
2
2
  import { Syntax, parseModule } from 'esprima-next';
3
3
  import fs from 'fs';
4
- import { warning } from '../utils/log.js';
5
- import { log } from '../utils/log.js';
4
+ import { log, warning } from '../utils/log.js';
6
5
  export const withPayloadStatement = {
7
6
  cjs: `const { withPayload } = require('@payloadcms/next/withPayload')\n`,
8
7
  esm: `import { withPayload } from '@payloadcms/next/withPayload'\n`