create-payload-app 3.0.0-canary.f83d96a → 3.0.0-canary.fb04843

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/dist/lib/constants.d.ts +2 -0
  2. package/dist/lib/constants.d.ts.map +1 -0
  3. package/dist/lib/constants.js +9 -0
  4. package/dist/lib/constants.js.map +1 -0
  5. package/dist/lib/create-project.d.ts.map +1 -1
  6. package/dist/lib/create-project.js +10 -7
  7. package/dist/lib/create-project.js.map +1 -1
  8. package/dist/lib/create-project.spec.js +22 -23
  9. package/dist/lib/create-project.spec.js.map +1 -1
  10. package/dist/lib/download-template.d.ts +7 -0
  11. package/dist/lib/download-template.d.ts.map +1 -0
  12. package/dist/lib/download-template.js +28 -0
  13. package/dist/lib/download-template.js.map +1 -0
  14. package/dist/lib/get-package-manager.js +26 -5
  15. package/dist/lib/get-package-manager.js.map +1 -1
  16. package/dist/lib/init-next.d.ts +7 -7
  17. package/dist/lib/init-next.d.ts.map +1 -1
  18. package/dist/lib/init-next.js +54 -12
  19. package/dist/lib/init-next.js.map +1 -1
  20. package/dist/lib/install-packages.js +12 -12
  21. package/dist/lib/install-packages.js.map +1 -1
  22. package/dist/lib/parse-project-name.d.ts.map +1 -1
  23. package/dist/lib/parse-project-name.js +9 -3
  24. package/dist/lib/parse-project-name.js.map +1 -1
  25. package/dist/lib/parse-template.d.ts.map +1 -1
  26. package/dist/lib/parse-template.js +3 -1
  27. package/dist/lib/parse-template.js.map +1 -1
  28. package/dist/lib/replacements.d.ts.map +1 -1
  29. package/dist/lib/replacements.js +27 -3
  30. package/dist/lib/replacements.js.map +1 -1
  31. package/dist/lib/select-db.d.ts.map +1 -1
  32. package/dist/lib/select-db.js +23 -14
  33. package/dist/lib/select-db.js.map +1 -1
  34. package/dist/lib/templates.d.ts.map +1 -1
  35. package/dist/lib/templates.js +9 -1
  36. package/dist/lib/templates.js.map +1 -1
  37. package/dist/lib/update-payload-in-project.d.ts.map +1 -1
  38. package/dist/lib/update-payload-in-project.js +7 -5
  39. package/dist/lib/update-payload-in-project.js.map +1 -1
  40. package/dist/lib/wrap-next-config.d.ts +5 -5
  41. package/dist/lib/wrap-next-config.d.ts.map +1 -1
  42. package/dist/lib/wrap-next-config.js +119 -59
  43. package/dist/lib/wrap-next-config.js.map +1 -1
  44. package/dist/lib/wrap-next-config.spec.js +84 -34
  45. package/dist/lib/wrap-next-config.spec.js.map +1 -1
  46. package/dist/lib/write-env-file.d.ts +2 -1
  47. package/dist/lib/write-env-file.d.ts.map +1 -1
  48. package/dist/lib/write-env-file.js +31 -26
  49. package/dist/lib/write-env-file.js.map +1 -1
  50. package/dist/main.d.ts.map +1 -1
  51. package/dist/main.js +27 -14
  52. package/dist/main.js.map +1 -1
  53. package/dist/scripts/pack-template-files.js +3 -3
  54. package/dist/scripts/pack-template-files.js.map +1 -1
  55. package/dist/template/src/app/(payload)/admin/[[...segments]]/not-found.tsx +8 -6
  56. package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +8 -6
  57. package/dist/template/src/app/(payload)/admin/importMap.js +1 -0
  58. package/dist/template/src/app/(payload)/api/[...slug]/route.ts +11 -2
  59. package/dist/template/src/app/(payload)/api/graphql/route.ts +4 -2
  60. package/dist/template/src/app/(payload)/api/graphql-playground/route.ts +2 -1
  61. package/dist/template/src/app/(payload)/layout.tsx +19 -4
  62. package/dist/template/src/payload-types.ts +127 -0
  63. package/dist/template/src/payload.config.ts +3 -0
  64. package/dist/types.d.ts +5 -2
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/types.js.map +1 -1
  67. package/dist/utils/copy-recursive-sync.d.ts +1 -1
  68. package/dist/utils/copy-recursive-sync.d.ts.map +1 -1
  69. package/dist/utils/copy-recursive-sync.js +4 -1
  70. package/dist/utils/copy-recursive-sync.js.map +1 -1
  71. package/dist/utils/log.d.ts.map +1 -1
  72. package/dist/utils/log.js +1 -1
  73. package/dist/utils/log.js.map +1 -1
  74. package/dist/utils/messages.d.ts.map +1 -1
  75. package/dist/utils/messages.js +1 -0
  76. package/dist/utils/messages.js.map +1 -1
  77. package/license.md +22 -0
  78. package/package.json +18 -6
@@ -0,0 +1,2 @@
1
+ export declare const PACKAGE_VERSION: any;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,eAAe,KAAsB,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import path from 'path';
4
+ const filename = fileURLToPath(import.meta.url);
5
+ const dirname = path.dirname(filename);
6
+ const packageJson = JSON.parse(readFileSync(path.resolve(dirname, '../../package.json'), 'utf-8'));
7
+ export const PACKAGE_VERSION = packageJson.version;
8
+
9
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/constants.ts"],"sourcesContent":["import { readFileSync } from 'fs'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nconst packageJson = JSON.parse(readFileSync(path.resolve(dirname, '../../package.json'), 'utf-8'))\nexport const PACKAGE_VERSION = packageJson.version\n"],"names":["readFileSync","fileURLToPath","path","filename","url","dirname","packageJson","JSON","parse","resolve","PACKAGE_VERSION","version"],"mappings":"AAAA,SAASA,YAAY,QAAQ,KAAI;AACjC,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAE7B,MAAMG,cAAcC,KAAKC,KAAK,CAACR,aAAaE,KAAKO,OAAO,CAACJ,SAAS,uBAAuB;AACzF,OAAO,MAAMK,kBAAkBJ,YAAYK,OAAO,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../src/lib/create-project.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA4CtF,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,eAAe,CAAA;CAC1B,GAAG,OAAO,CAAC,IAAI,CAAC,CA4DhB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhB"}
1
+ {"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../src/lib/create-project.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA+CtF,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,eAAe,CAAA;CAC1B,GAAG,OAAO,CAAC,IAAI,CAAC,CA8DhB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhB"}
@@ -1,6 +1,5 @@
1
1
  import * as p from '@clack/prompts';
2
2
  import chalk from 'chalk';
3
- import degit from 'degit';
4
3
  import execa from 'execa';
5
4
  import fse from 'fs-extra';
6
5
  import { fileURLToPath } from 'node:url';
@@ -8,6 +7,7 @@ import path from 'path';
8
7
  import { tryInitRepoAndCommit } from '../utils/git.js';
9
8
  import { debug, error, info, warning } from '../utils/log.js';
10
9
  import { configurePayloadConfig } from './configure-payload-config.js';
10
+ import { downloadTemplate } from './download-template.js';
11
11
  const filename = fileURLToPath(import.meta.url);
12
12
  const dirname = path.dirname(filename);
13
13
  async function createOrFindProjectDir(projectDir) {
@@ -26,6 +26,8 @@ async function installDeps(args) {
26
26
  installCmd = 'yarn';
27
27
  } else if (packageManager === 'pnpm') {
28
28
  installCmd = 'pnpm install';
29
+ } else if (packageManager === 'bun') {
30
+ installCmd = 'bun install';
29
31
  }
30
32
  try {
31
33
  await execa.command(installCmd, {
@@ -49,13 +51,14 @@ export async function createProject(args) {
49
51
  const localTemplate = path.resolve(dirname, '../../../../templates/', cliArgs['--local-template']);
50
52
  await fse.copy(localTemplate, projectDir);
51
53
  } else if ('url' in template) {
52
- let templateUrl = template.url;
53
54
  if (cliArgs['--template-branch']) {
54
- templateUrl = `${template.url}#${cliArgs['--template-branch']}`;
55
- debug(`Using template url: ${templateUrl}`);
55
+ template.url = `${template.url.split('#')?.[0]}#${cliArgs['--template-branch']}`;
56
56
  }
57
- const emitter = degit(templateUrl);
58
- await emitter.clone(projectDir);
57
+ await downloadTemplate({
58
+ debug: cliArgs['--debug'],
59
+ projectDir,
60
+ template
61
+ });
59
62
  }
60
63
  const spinner = p.spinner();
61
64
  spinner.start('Checking latest Payload version...');
@@ -71,7 +74,7 @@ export async function createProject(args) {
71
74
  }
72
75
  });
73
76
  // Remove yarn.lock file. This is only desired in Payload Cloud.
74
- const lockPath = path.resolve(projectDir, 'yarn.lock');
77
+ const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml');
75
78
  if (fse.existsSync(lockPath)) {
76
79
  await fse.remove(lockPath);
77
80
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport chalk from 'chalk'\nimport degit from 'degit'\nimport execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nimport type { CliArgs, DbDetails, PackageManager, ProjectTemplate } from '../types.js'\n\nimport { tryInitRepoAndCommit } from '../utils/git.js'\nimport { debug, error, info, warning } from '../utils/log.js'\nimport { configurePayloadConfig } from './configure-payload-config.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nasync function createOrFindProjectDir(projectDir: string): Promise<void> {\n const pathExists = await fse.pathExists(projectDir)\n if (!pathExists) {\n await fse.mkdir(projectDir)\n }\n}\n\nasync function installDeps(args: {\n cliArgs: CliArgs\n packageManager: PackageManager\n projectDir: string\n}): Promise<boolean> {\n const { cliArgs, packageManager, projectDir } = args\n if (cliArgs['--no-deps']) {\n return true\n }\n let installCmd = 'npm install --legacy-peer-deps'\n\n if (packageManager === 'yarn') {\n installCmd = 'yarn'\n } else if (packageManager === 'pnpm') {\n installCmd = 'pnpm install'\n }\n\n try {\n await execa.command(installCmd, {\n cwd: path.resolve(projectDir),\n })\n return true\n } catch (err: unknown) {\n error(`Error installing dependencies${err instanceof Error ? `: ${err.message}` : ''}.`)\n return false\n }\n}\n\nexport async function createProject(args: {\n cliArgs: CliArgs\n dbDetails?: DbDetails\n packageManager: PackageManager\n projectDir: string\n projectName: string\n template: ProjectTemplate\n}): Promise<void> {\n const { cliArgs, dbDetails, packageManager, projectDir, projectName, template } = args\n\n if (cliArgs['--dry-run']) {\n debug(`Dry run: Creating project in ${chalk.green(projectDir)}`)\n return\n }\n\n await createOrFindProjectDir(projectDir)\n\n if (cliArgs['--local-template']) {\n // Copy template from local path. For development purposes.\n const localTemplate = path.resolve(\n dirname,\n '../../../../templates/',\n cliArgs['--local-template'],\n )\n await fse.copy(localTemplate, projectDir)\n } else if ('url' in template) {\n let templateUrl = template.url\n if (cliArgs['--template-branch']) {\n templateUrl = `${template.url}#${cliArgs['--template-branch']}`\n debug(`Using template url: ${templateUrl}`)\n }\n const emitter = degit(templateUrl)\n await emitter.clone(projectDir)\n }\n\n const spinner = p.spinner()\n spinner.start('Checking latest Payload version...')\n\n await updatePackageJSON({ projectDir, projectName })\n spinner.message('Configuring Payload...')\n await configurePayloadConfig({\n dbType: dbDetails?.type,\n projectDirOrConfigPath: { projectDir },\n })\n\n // Remove yarn.lock file. This is only desired in Payload Cloud.\n const lockPath = path.resolve(projectDir, 'yarn.lock')\n if (fse.existsSync(lockPath)) {\n await fse.remove(lockPath)\n }\n\n if (!cliArgs['--no-deps']) {\n info(`Using ${packageManager}.\\n`)\n spinner.message('Installing dependencies...')\n const result = await installDeps({ cliArgs, packageManager, projectDir })\n if (result) {\n spinner.stop('Successfully installed Payload and dependencies')\n } else {\n spinner.stop('Error installing dependencies', 1)\n }\n } else {\n spinner.stop('Dependency installation skipped')\n }\n\n if (!cliArgs['--no-git']) {\n tryInitRepoAndCommit({ cwd: projectDir })\n }\n}\n\nexport async function updatePackageJSON(args: {\n projectDir: string\n projectName: string\n}): Promise<void> {\n const { projectDir, projectName } = args\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n try {\n const packageObj = await fse.readJson(packageJsonPath)\n packageObj.name = projectName\n await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })\n } catch (err: unknown) {\n warning(`Unable to update name in package.json. ${err instanceof Error ? err.message : ''}`)\n }\n}\n"],"names":["p","chalk","degit","execa","fse","fileURLToPath","path","tryInitRepoAndCommit","debug","error","info","warning","configurePayloadConfig","filename","url","dirname","createOrFindProjectDir","projectDir","pathExists","mkdir","installDeps","args","cliArgs","packageManager","installCmd","command","cwd","resolve","err","Error","message","createProject","dbDetails","projectName","template","green","localTemplate","copy","templateUrl","emitter","clone","spinner","start","updatePackageJSON","dbType","type","projectDirOrConfigPath","lockPath","existsSync","remove","result","stop","packageJsonPath","packageObj","readJson","name","writeJson","spaces"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,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,CAAC,iCAAiC;QAChD;IACF,OAAO;QACLV,QAAQU,IAAI,CAAC;IACf;IAEA,IAAI,CAAC7B,OAAO,CAAC,WAAW,EAAE;QACxBf,qBAAqB;YAAEmB,KAAKT;QAAW;IACzC;AACF;AAEA,OAAO,eAAe0B,kBAAkBtB,IAGvC;IACC,MAAM,EAAEJ,UAAU,EAAEgB,WAAW,EAAE,GAAGZ;IACpC,MAAM+B,kBAAkB9C,KAAKqB,OAAO,CAACV,YAAY;IACjD,IAAI;QACF,MAAMoC,aAAa,MAAMjD,IAAIkD,QAAQ,CAACF;QACtCC,WAAWE,IAAI,GAAGtB;QAClB,MAAM7B,IAAIoD,SAAS,CAACJ,iBAAiBC,YAAY;YAAEI,QAAQ;QAAE;IAC/D,EAAE,OAAO7B,KAAc;QACrBjB,QAAQ,CAAC,uCAAuC,EAAEiB,eAAeC,QAAQD,IAAIE,OAAO,GAAG,GAAG,CAAC;IAC7F;AACF"}
1
+ {"version":3,"sources":["../../src/lib/create-project.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport chalk from 'chalk'\nimport execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nimport type { CliArgs, DbDetails, PackageManager, ProjectTemplate } from '../types.js'\n\nimport { tryInitRepoAndCommit } from '../utils/git.js'\nimport { debug, error, info, warning } from '../utils/log.js'\nimport { configurePayloadConfig } from './configure-payload-config.js'\nimport { downloadTemplate } from './download-template.js'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nasync function createOrFindProjectDir(projectDir: string): Promise<void> {\n const pathExists = await fse.pathExists(projectDir)\n if (!pathExists) {\n await fse.mkdir(projectDir)\n }\n}\n\nasync function installDeps(args: {\n cliArgs: CliArgs\n packageManager: PackageManager\n projectDir: string\n}): Promise<boolean> {\n const { cliArgs, packageManager, projectDir } = args\n if (cliArgs['--no-deps']) {\n return true\n }\n let installCmd = 'npm install --legacy-peer-deps'\n\n if (packageManager === 'yarn') {\n installCmd = 'yarn'\n } else if (packageManager === 'pnpm') {\n installCmd = 'pnpm install'\n } else if (packageManager === 'bun') {\n installCmd = 'bun install'\n }\n\n try {\n await execa.command(installCmd, {\n cwd: path.resolve(projectDir),\n })\n return true\n } catch (err: unknown) {\n error(`Error installing dependencies${err instanceof Error ? `: ${err.message}` : ''}.`)\n return false\n }\n}\n\nexport async function createProject(args: {\n cliArgs: CliArgs\n dbDetails?: DbDetails\n packageManager: PackageManager\n projectDir: string\n projectName: string\n template: ProjectTemplate\n}): Promise<void> {\n const { cliArgs, dbDetails, packageManager, projectDir, projectName, template } = args\n\n if (cliArgs['--dry-run']) {\n debug(`Dry run: Creating project in ${chalk.green(projectDir)}`)\n return\n }\n\n await createOrFindProjectDir(projectDir)\n\n if (cliArgs['--local-template']) {\n // Copy template from local path. For development purposes.\n const localTemplate = path.resolve(\n dirname,\n '../../../../templates/',\n cliArgs['--local-template'],\n )\n await fse.copy(localTemplate, projectDir)\n } else if ('url' in template) {\n if (cliArgs['--template-branch']) {\n template.url = `${template.url.split('#')?.[0]}#${cliArgs['--template-branch']}`\n }\n\n await downloadTemplate({\n debug: cliArgs['--debug'],\n projectDir,\n template,\n })\n }\n\n const spinner = p.spinner()\n spinner.start('Checking latest Payload version...')\n\n await updatePackageJSON({ projectDir, projectName })\n spinner.message('Configuring Payload...')\n await configurePayloadConfig({\n dbType: dbDetails?.type,\n projectDirOrConfigPath: { projectDir },\n })\n\n // Remove yarn.lock file. This is only desired in Payload Cloud.\n const lockPath = path.resolve(projectDir, 'pnpm-lock.yaml')\n if (fse.existsSync(lockPath)) {\n await fse.remove(lockPath)\n }\n\n if (!cliArgs['--no-deps']) {\n info(`Using ${packageManager}.\\n`)\n spinner.message('Installing dependencies...')\n const result = await installDeps({ cliArgs, packageManager, projectDir })\n if (result) {\n spinner.stop('Successfully installed Payload and dependencies')\n } else {\n spinner.stop('Error installing dependencies', 1)\n }\n } else {\n spinner.stop('Dependency installation skipped')\n }\n\n if (!cliArgs['--no-git']) {\n tryInitRepoAndCommit({ cwd: projectDir })\n }\n}\n\nexport async function updatePackageJSON(args: {\n projectDir: string\n projectName: string\n}): Promise<void> {\n const { projectDir, projectName } = args\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n try {\n const packageObj = await fse.readJson(packageJsonPath)\n packageObj.name = projectName\n await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })\n } catch (err: unknown) {\n warning(`Unable to update name in package.json. ${err instanceof Error ? err.message : ''}`)\n }\n}\n"],"names":["p","chalk","execa","fse","fileURLToPath","path","tryInitRepoAndCommit","debug","error","info","warning","configurePayloadConfig","downloadTemplate","filename","url","dirname","createOrFindProjectDir","projectDir","pathExists","mkdir","installDeps","args","cliArgs","packageManager","installCmd","command","cwd","resolve","err","Error","message","createProject","dbDetails","projectName","template","green","localTemplate","copy","split","spinner","start","updatePackageJSON","dbType","type","projectDirOrConfigPath","lockPath","existsSync","remove","result","stop","packageJsonPath","packageObj","readJson","name","writeJson","spaces"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,WAAW,QAAO;AACzB,OAAOC,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAIvB,SAASC,oBAAoB,QAAQ,kBAAiB;AACtD,SAASC,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,sBAAsB,QAAQ,gCAA+B;AACtE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,MAAMC,WAAWT,cAAc,YAAYU,GAAG;AAC9C,MAAMC,UAAUV,KAAKU,OAAO,CAACF;AAE7B,eAAeG,uBAAuBC,UAAkB;IACtD,MAAMC,aAAa,MAAMf,IAAIe,UAAU,CAACD;IACxC,IAAI,CAACC,YAAY;QACf,MAAMf,IAAIgB,KAAK,CAACF;IAClB;AACF;AAEA,eAAeG,YAAYC,IA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C,QAAQD,IAAIE,OAAO,GAAG,GAAG,CAAC;IAC7F;AACF"}
@@ -1,17 +1,20 @@
1
+ import { jest } from '@jest/globals';
2
+ import fs from 'fs';
1
3
  import fse from 'fs-extra';
4
+ import globby from 'globby';
5
+ import * as os from 'node:os';
2
6
  import path from 'path';
3
7
  import { createProject } from './create-project.js';
4
8
  import { dbReplacements } from './replacements.js';
5
9
  import { getValidTemplates } from './templates.js';
6
- import globby from 'globby';
7
- import { jest } from '@jest/globals';
8
- import tempDirectory from 'temp-dir';
9
10
  describe('createProject', ()=>{
10
11
  let projectDir;
11
12
  beforeAll(()=>{
13
+ // eslint-disable-next-line no-console
12
14
  console.log = jest.fn();
13
15
  });
14
16
  beforeEach(()=>{
17
+ const tempDirectory = fs.realpathSync(os.tmpdir());
15
18
  projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`;
16
19
  });
17
20
  afterEach(()=>{
@@ -22,13 +25,12 @@ describe('createProject', ()=>{
22
25
  }
23
26
  });
24
27
  describe('#createProject', ()=>{
25
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
28
  const args = {
27
29
  _: [
28
30
  'project-name'
29
31
  ],
30
32
  '--db': 'mongodb',
31
- '--local-template': 'blank-3.0',
33
+ '--local-template': 'blank',
32
34
  '--no-deps': true
33
35
  };
34
36
  const packageManager = 'yarn';
@@ -37,30 +39,30 @@ describe('createProject', ()=>{
37
39
  const template = {
38
40
  name: 'plugin',
39
41
  type: 'plugin',
40
- url: 'https://github.com/payloadcms/payload-plugin-template',
41
- description: 'Template for creating a Payload plugin'
42
+ description: 'Template for creating a Payload plugin',
43
+ url: 'https://github.com/payloadcms/payload-plugin-template'
42
44
  };
43
45
  await createProject({
44
46
  cliArgs: args,
45
- projectName,
47
+ packageManager,
46
48
  projectDir,
47
- template,
48
- packageManager
49
+ projectName,
50
+ template
49
51
  });
50
52
  const packageJsonPath = path.resolve(projectDir, 'package.json');
51
53
  const packageJson = fse.readJsonSync(packageJsonPath);
52
54
  // Check package name and description
53
- expect(packageJson.name).toEqual(projectName);
55
+ expect(packageJson.name).toStrictEqual(projectName);
54
56
  });
55
57
  describe('creates project from template', ()=>{
56
58
  const templates = getValidTemplates();
57
59
  it.each([
58
60
  [
59
- 'blank-3.0',
61
+ 'blank',
60
62
  'mongodb'
61
63
  ],
62
64
  [
63
- 'blank-3.0',
65
+ 'blank',
64
66
  'postgres'
65
67
  ]
66
68
  ])('update config and deps: %s, %s', async (templateName, db)=>{
@@ -73,14 +75,14 @@ describe('createProject', ()=>{
73
75
  };
74
76
  await createProject({
75
77
  cliArgs,
76
- projectName,
77
- projectDir,
78
- template: template,
79
- packageManager,
80
78
  dbDetails: {
81
- dbUri: `${db}://localhost:27017/create-project-test`,
82
- type: db
83
- }
79
+ type: db,
80
+ dbUri: `${db}://localhost:27017/create-project-test`
81
+ },
82
+ packageManager,
83
+ projectDir,
84
+ projectName,
85
+ template: template
84
86
  });
85
87
  const dbReplacement = dbReplacements[db];
86
88
  const packageJsonPath = path.resolve(projectDir, 'package.json');
@@ -93,9 +95,6 @@ describe('createProject', ()=>{
93
95
  absolute: true,
94
96
  cwd: projectDir
95
97
  }))?.[0];
96
- if (!payloadConfigPath) {
97
- throw new Error(`Could not find payload.config.ts inside ${projectDir}`);
98
- }
99
98
  const content = fse.readFileSync(payloadConfigPath, 'utf-8');
100
99
  // Check payload.config.ts
101
100
  expect(content).not.toContain('// database-adapter-import');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport path from 'path'\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\nimport { createProject } from './create-project.js'\nimport { dbReplacements } from './replacements.js'\nimport { getValidTemplates } from './templates.js'\nimport globby from 'globby'\nimport { jest } from '@jest/globals'\n\nimport tempDirectory from 'temp-dir'\n\ndescribe('createProject', () => {\n let projectDir: string\n beforeAll(() => {\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`\n })\n\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n const args = {\n _: ['project-name'],\n '--db': 'mongodb',\n '--local-template': 'blank-3.0',\n '--no-deps': true,\n } as CliArgs\n const packageManager = 'yarn'\n\n it('creates plugin template', async () => {\n const projectName = 'plugin'\n const template: ProjectTemplate = {\n name: 'plugin',\n type: 'plugin',\n url: 'https://github.com/payloadcms/payload-plugin-template',\n description: 'Template for creating a Payload plugin',\n }\n await createProject({\n cliArgs: args,\n projectName,\n projectDir,\n template,\n packageManager,\n })\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Check package name and description\n expect(packageJson.name).toEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank-3.0', 'mongodb'],\n ['blank-3.0', 'postgres'],\n\n // TODO: Re-enable these once 3.0 is stable and templates updated\n // ['website', 'mongodb'],\n // ['website', 'postgres'],\n // ['ecommerce', 'mongodb'],\n // ['ecommerce', 'postgres'],\n ])('update config and deps: %s, %s', async (templateName, db) => {\n const projectName = 'starter-project'\n\n const template = templates.find((t) => t.name === templateName)\n\n const cliArgs = {\n ...args,\n '--db': db,\n '--local-template': templateName,\n } as CliArgs\n\n await createProject({\n cliArgs,\n projectName,\n projectDir,\n template: template as ProjectTemplate,\n packageManager,\n dbDetails: {\n dbUri: `${db}://localhost:27017/create-project-test`,\n type: db as DbType,\n },\n })\n\n const dbReplacement = dbReplacements[db as DbType]\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Verify git was initialized\n expect(fse.existsSync(path.resolve(projectDir, '.git'))).toBe(true)\n\n // Should only have one db adapter\n expect(\n Object.keys(packageJson.dependencies).filter((n) => n.startsWith('@payloadcms/db-')),\n ).toHaveLength(1)\n\n const payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: projectDir,\n })\n )?.[0]\n\n if (!payloadConfigPath) {\n throw new Error(`Could not find payload.config.ts inside ${projectDir}`)\n }\n\n const content = fse.readFileSync(payloadConfigPath, 'utf-8')\n\n // Check payload.config.ts\n expect(content).not.toContain('// database-adapter-import')\n expect(content).toContain(dbReplacement.importReplacement)\n\n expect(content).not.toContain('// database-adapter-config-start')\n expect(content).not.toContain('// database-adapter-config-end')\n expect(content).toContain(dbReplacement.configReplacement().join('\\n'))\n })\n })\n })\n})\n"],"names":["fse","path","createProject","dbReplacements","getValidTemplates","globby","jest","tempDirectory","describe","projectDir","beforeAll","console","log","fn","beforeEach","Math","random","toString","substring","afterEach","existsSync","rmSync","recursive","args","_","packageManager","it","projectName","template","name","type","url","description","cliArgs","packageJsonPath","resolve","packageJson","readJsonSync","expect","toEqual","templates","each","templateName","db","find","t","dbDetails","dbUri","dbReplacement","toBe","Object","keys","dependencies","filter","n","startsWith","toHaveLength","payloadConfigPath","absolute","cwd","Error","content","readFileSync","not","toContain","importReplacement","configReplacement","join"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,UAAU,OAAM;AAEvB,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,cAAc,QAAQ,oBAAmB;AAClD,SAASC,iBAAiB,QAAQ,iBAAgB;AAClD,OAAOC,YAAY,SAAQ;AAC3B,SAASC,IAAI,QAAQ,gBAAe;AAEpC,OAAOC,mBAAmB,WAAU;AAEpCC,SAAS,iBAAiB;IACxB,IAAIC;IACJC,UAAU;QACRC,QAAQC,GAAG,GAAGN,KAAKO,EAAE;IACvB;IAEAC,WAAW;QACTL,aAAa,CAAC,EAAEF,cAAc,CAAC,EAAEQ,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG,CAAC;IAC5E;IAEAC,UAAU;QACR,IAAInB,IAAIo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AACH;gBAErC,6BAA6B;gBAC7BI,OAAOtC,IAAIoB,UAAU,CAACnB,KAAKkC,OAAO,CAAC1B,YAAY,UAAUwC,IAAI,CAAC;gBAE9D,kCAAkC;gBAClCX,OACEY,OAAOC,IAAI,CAACf,YAAYgB,YAAY,EAAEC,MAAM,CAAC,CAACC,IAAMA,EAAEC,UAAU,CAAC,qBACjEC,YAAY,CAAC;gBAEf,MAAMC,oBACJ,CAAA,MAAMpD,OAAO,wBAAwB;oBACnCqD,UAAU;oBACVC,KAAKlD;gBACP,EAAC,GACA,CAAC,EAAE;gBAEN,IAAI,CAACgD,mBAAmB;oBACtB,MAAM,IAAIG,MAAM,CAAC,wCAAwC,EAAEnD,WAAW,CAAC;gBACzE;gBAEA,MAAMoD,UAAU7D,IAAI8D,YAAY,CAACL,mBAAmB;gBAEpD,0BAA0B;gBAC1BnB,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASG,SAAS,CAAChB,cAAciB,iBAAiB;gBAEzD3B,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9B1B,OAAOuB,SAASG,SAAS,CAAChB,cAAckB,iBAAiB,GAAGC,IAAI,CAAC;YACnE;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/lib/create-project.spec.ts"],"sourcesContent":["import { jest } from '@jest/globals'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport * as os from 'node:os'\nimport path from 'path'\n\nimport type { CliArgs, DbType, ProjectTemplate } from '../types.js'\n\nimport { createProject } from './create-project.js'\nimport { dbReplacements } from './replacements.js'\nimport { getValidTemplates } from './templates.js'\n\ndescribe('createProject', () => {\n let projectDir: string\n beforeAll(() => {\n // eslint-disable-next-line no-console\n console.log = jest.fn()\n })\n\n beforeEach(() => {\n const tempDirectory = fs.realpathSync(os.tmpdir())\n projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`\n })\n\n afterEach(() => {\n if (fse.existsSync(projectDir)) {\n fse.rmSync(projectDir, { recursive: true })\n }\n })\n\n describe('#createProject', () => {\n const args = {\n _: ['project-name'],\n '--db': 'mongodb',\n '--local-template': 'blank',\n '--no-deps': true,\n } as CliArgs\n const packageManager = 'yarn'\n\n it('creates plugin template', async () => {\n const projectName = 'plugin'\n const template: ProjectTemplate = {\n name: 'plugin',\n type: 'plugin',\n description: 'Template for creating a Payload plugin',\n url: 'https://github.com/payloadcms/payload-plugin-template',\n }\n await createProject({\n cliArgs: args,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Check package name and description\n expect(packageJson.name).toStrictEqual(projectName)\n })\n\n describe('creates project from template', () => {\n const templates = getValidTemplates()\n\n it.each([\n ['blank', 'mongodb'],\n ['blank', 'postgres'],\n\n // TODO: Re-enable these once 3.0 is stable and templates updated\n // ['website', 'mongodb'],\n // ['website', 'postgres'],\n // ['ecommerce', 'mongodb'],\n // ['ecommerce', 'postgres'],\n ])('update config and deps: %s, %s', async (templateName, db) => {\n const projectName = 'starter-project'\n\n const template = templates.find((t) => t.name === templateName)\n\n const cliArgs = {\n ...args,\n '--db': db,\n '--local-template': templateName,\n } as CliArgs\n\n await createProject({\n cliArgs,\n dbDetails: {\n type: db as DbType,\n dbUri: `${db}://localhost:27017/create-project-test`,\n },\n packageManager,\n projectDir,\n projectName,\n template: template as ProjectTemplate,\n })\n\n const dbReplacement = dbReplacements[db as DbType]\n\n const packageJsonPath = path.resolve(projectDir, 'package.json')\n const packageJson = fse.readJsonSync(packageJsonPath)\n\n // Verify git was initialized\n expect(fse.existsSync(path.resolve(projectDir, '.git'))).toBe(true)\n\n // Should only have one db adapter\n expect(\n Object.keys(packageJson.dependencies).filter((n) => n.startsWith('@payloadcms/db-')),\n ).toHaveLength(1)\n\n const payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: projectDir,\n })\n )?.[0]\n\n const content = fse.readFileSync(payloadConfigPath, 'utf-8')\n\n // Check payload.config.ts\n expect(content).not.toContain('// database-adapter-import')\n expect(content).toContain(dbReplacement.importReplacement)\n\n expect(content).not.toContain('// database-adapter-config-start')\n expect(content).not.toContain('// database-adapter-config-end')\n expect(content).toContain(dbReplacement.configReplacement().join('\\n'))\n })\n })\n })\n})\n"],"names":["jest","fs","fse","globby","os","path","createProject","dbReplacements","getValidTemplates","describe","projectDir","beforeAll","console","log","fn","beforeEach","tempDirectory","realpathSync","tmpdir","Math","random","toString","substring","afterEach","existsSync","rmSync","recursive","args","_","packageManager","it","projectName","template","name","type","description","url","cliArgs","packageJsonPath","resolve","packageJson","readJsonSync","expect","toStrictEqual","templates","each","templateName","db","find","t","dbDetails","dbUri","dbReplacement","toBe","Object","keys","dependencies","filter","n","startsWith","toHaveLength","payloadConfigPath","absolute","cwd","content","readFileSync","not","toContain","importReplacement","configReplacement","join"],"mappings":"AAAA,SAASA,IAAI,QAAQ,gBAAe;AACpC,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,YAAYC,QAAQ,UAAS;AAC7B,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,sBAAqB;AACnD,SAASC,cAAc,QAAQ,oBAAmB;AAClD,SAASC,iBAAiB,QAAQ,iBAAgB;AAElDC,SAAS,iBAAiB;IACxB,IAAIC;IACJC,UAAU;QACR,sCAAsC;QACtCC,QAAQC,GAAG,GAAGb,KAAKc,EAAE;IACvB;IAEAC,WAAW;QACT,MAAMC,gBAAgBf,GAAGgB,YAAY,CAACb,GAAGc,MAAM;QAC/CR,aAAa,CAAC,EAAEM,cAAc,CAAC,EAAEG,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,SAAS,CAAC,GAAG,CAAC;IAC5E;IAEAC,UAAU;QACR,IAAIrB,IAAIsB,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6B;gBAC7BI,OAAOxC,IAAIsB,UAAU,CAACnB,KAAKkC,OAAO,CAAC7B,YAAY,UAAU2C,IAAI,CAAC;gBAE9D,kCAAkC;gBAClCX,OACEY,OAAOC,IAAI,CAACf,YAAYgB,YAAY,EAAEC,MAAM,CAAC,CAACC,IAAMA,EAAEC,UAAU,CAAC,qBACjEC,YAAY,CAAC;gBAEf,MAAMC,oBACJ,CAAA,MAAM1D,OAAO,wBAAwB;oBACnC2D,UAAU;oBACVC,KAAKrD;gBACP,EAAC,GACA,CAAC,EAAE;gBAEN,MAAMsD,UAAU9D,IAAI+D,YAAY,CAACJ,mBAAmB;gBAEpD,0BAA0B;gBAC1BnB,OAAOsB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9BzB,OAAOsB,SAASG,SAAS,CAACf,cAAcgB,iBAAiB;gBAEzD1B,OAAOsB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9BzB,OAAOsB,SAASE,GAAG,CAACC,SAAS,CAAC;gBAC9BzB,OAAOsB,SAASG,SAAS,CAACf,cAAciB,iBAAiB,GAAGC,IAAI,CAAC;YACnE;QACF;IACF;AACF"}
@@ -0,0 +1,7 @@
1
+ import type { ProjectTemplate } from '../types.js';
2
+ export declare function downloadTemplate({ debug, projectDir, template, }: {
3
+ debug?: boolean;
4
+ projectDir: string;
5
+ template: ProjectTemplate;
6
+ }): Promise<void>;
7
+ //# sourceMappingURL=download-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-template.d.ts","sourceRoot":"","sources":["../../src/lib/download-template.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,wBAAsB,gBAAgB,CAAC,EACrC,KAAK,EACL,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,eAAe,CAAA;CAC1B,iBAmBA"}
@@ -0,0 +1,28 @@
1
+ import { Readable } from 'node:stream';
2
+ import { pipeline } from 'node:stream/promises';
3
+ import { x } from 'tar';
4
+ import { debug as debugLog } from '../utils/log.js';
5
+ export async function downloadTemplate({ debug, projectDir, template }) {
6
+ const branchOrTag = template.url.split('#')?.[1] || 'beta';
7
+ const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branchOrTag}`;
8
+ const filter = `payload-${branchOrTag.replace(/^v/, '')}/templates/${template.name}/`;
9
+ if (debug) {
10
+ debugLog(`Using template url: ${template.url}`);
11
+ debugLog(`Codeload url: ${url}`);
12
+ debugLog(`Filter: ${filter}`);
13
+ }
14
+ await pipeline(await downloadTarStream(url), x({
15
+ cwd: projectDir,
16
+ filter: (p)=>p.includes(filter),
17
+ strip: 2 + template.name.split('/').length
18
+ }));
19
+ }
20
+ async function downloadTarStream(url) {
21
+ const res = await fetch(url);
22
+ if (!res.body) {
23
+ throw new Error(`Failed to download: ${url}`);
24
+ }
25
+ return Readable.from(res.body);
26
+ }
27
+
28
+ //# sourceMappingURL=download-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/download-template.ts"],"sourcesContent":["import { Readable } from 'node:stream'\nimport { pipeline } from 'node:stream/promises'\nimport { x } from 'tar'\n\nimport type { ProjectTemplate } from '../types.js'\n\nimport { debug as debugLog } from '../utils/log.js'\n\nexport async function downloadTemplate({\n debug,\n projectDir,\n template,\n}: {\n debug?: boolean\n projectDir: string\n template: ProjectTemplate\n}) {\n const branchOrTag = template.url.split('#')?.[1] || 'beta'\n const url = `https://codeload.github.com/payloadcms/payload/tar.gz/${branchOrTag}`\n const filter = `payload-${branchOrTag.replace(/^v/, '')}/templates/${template.name}/`\n\n if (debug) {\n debugLog(`Using template url: ${template.url}`)\n debugLog(`Codeload url: ${url}`)\n debugLog(`Filter: ${filter}`)\n }\n\n await pipeline(\n await downloadTarStream(url),\n x({\n cwd: projectDir,\n filter: (p) => p.includes(filter),\n strip: 2 + template.name.split('/').length,\n }),\n )\n}\n\nasync function downloadTarStream(url: string) {\n const res = await fetch(url)\n\n if (!res.body) {\n throw new Error(`Failed to download: ${url}`)\n }\n\n return Readable.from(res.body as unknown as NodeJS.ReadableStream)\n}\n"],"names":["Readable","pipeline","x","debug","debugLog","downloadTemplate","projectDir","template","branchOrTag","url","split","filter","replace","name","downloadTarStream","cwd","p","includes","strip","length","res","fetch","body","Error","from"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAa;AACtC,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,CAAC,QAAQ,MAAK;AAIvB,SAASC,SAASC,QAAQ,QAAQ,kBAAiB;AAEnD,OAAO,eAAeC,iBAAiB,EACrCF,KAAK,EACLG,UAAU,EACVC,QAAQ,EAKT;IACC,MAAMC,cAAcD,SAASE,GAAG,CAACC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI;IACpD,MAAMD,MAAM,CAAC,sDAAsD,EAAED,YAAY,CAAC;IAClF,MAAMG,SAAS,CAAC,QAAQ,EAAEH,YAAYI,OAAO,CAAC,MAAM,IAAI,WAAW,EAAEL,SAASM,IAAI,CAAC,CAAC,CAAC;IAErF,IAAIV,OAAO;QACTC,SAAS,CAAC,oBAAoB,EAAEG,SAASE,GAAG,CAAC,CAAC;QAC9CL,SAAS,CAAC,cAAc,EAAEK,IAAI,CAAC;QAC/BL,SAAS,CAAC,QAAQ,EAAEO,OAAO,CAAC;IAC9B;IAEA,MAAMV,SACJ,MAAMa,kBAAkBL,MACxBP,EAAE;QACAa,KAAKT;QACLK,QAAQ,CAACK,IAAMA,EAAEC,QAAQ,CAACN;QAC1BO,OAAO,IAAIX,SAASM,IAAI,CAACH,KAAK,CAAC,KAAKS,MAAM;IAC5C;AAEJ;AAEA,eAAeL,kBAAkBL,GAAW;IAC1C,MAAMW,MAAM,MAAMC,MAAMZ;IAExB,IAAI,CAACW,IAAIE,IAAI,EAAE;QACb,MAAM,IAAIC,MAAM,CAAC,oBAAoB,EAAEd,IAAI,CAAC;IAC9C;IAEA,OAAOT,SAASwB,IAAI,CAACJ,IAAIE,IAAI;AAC/B"}
@@ -3,23 +3,44 @@ import fse from 'fs-extra';
3
3
  export async function getPackageManager(args) {
4
4
  const { cliArgs, projectDir } = args;
5
5
  try {
6
- // Check for yarn.lock, package-lock.json, or pnpm-lock.yaml
6
+ // Check for flag or lockfile
7
7
  let detected = 'npm';
8
- if (cliArgs?.['--use-pnpm'] || fse.existsSync(`${projectDir}/pnpm-lock.yaml`) || await commandExists('pnpm')) {
8
+ if (cliArgs?.['--use-pnpm'] || fse.existsSync(`${projectDir}/pnpm-lock.yaml`)) {
9
9
  detected = 'pnpm';
10
- } else if (cliArgs?.['--use-yarn'] || fse.existsSync(`${projectDir}/yarn.lock`) || await commandExists('yarn')) {
10
+ } else if (cliArgs?.['--use-yarn'] || fse.existsSync(`${projectDir}/yarn.lock`)) {
11
11
  detected = 'yarn';
12
12
  } else if (cliArgs?.['--use-npm'] || fse.existsSync(`${projectDir}/package-lock.json`)) {
13
13
  detected = 'npm';
14
+ } else if (cliArgs?.['--use-bun'] || fse.existsSync(`${projectDir}/bun.lockb`)) {
15
+ detected = 'bun';
16
+ } else if (await commandExists('pnpm')) {
17
+ // Prefer pnpm if it's installed
18
+ detected = 'pnpm';
19
+ } else {
20
+ // Otherwise check the execution environment
21
+ detected = getEnvironmentPackageManager();
14
22
  }
15
23
  return detected;
16
- } catch (error) {
24
+ } catch (ignore) {
17
25
  return 'npm';
18
26
  }
19
27
  }
28
+ function getEnvironmentPackageManager() {
29
+ const userAgent = process.env.npm_config_user_agent || '';
30
+ if (userAgent.startsWith('yarn')) {
31
+ return 'yarn';
32
+ }
33
+ if (userAgent.startsWith('pnpm')) {
34
+ return 'pnpm';
35
+ }
36
+ if (userAgent.startsWith('bun')) {
37
+ return 'bun';
38
+ }
39
+ return 'npm';
40
+ }
20
41
  async function commandExists(command) {
21
42
  try {
22
- await execa.command(`command -v ${command}`);
43
+ await execa.command(process.platform === 'win32' ? `where ${command}` : `command -v ${command}`);
23
44
  return true;
24
45
  } catch {
25
46
  return false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/get-package-manager.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\n\nimport type { CliArgs, PackageManager } from '../types.js'\n\nexport async function getPackageManager(args: {\n cliArgs?: CliArgs\n projectDir: string\n}): Promise<PackageManager> {\n const { cliArgs, projectDir } = args\n\n try {\n // Check for yarn.lock, package-lock.json, or pnpm-lock.yaml\n let detected: PackageManager = 'npm'\n if (\n cliArgs?.['--use-pnpm'] ||\n fse.existsSync(`${projectDir}/pnpm-lock.yaml`) ||\n (await commandExists('pnpm'))\n ) {\n detected = 'pnpm'\n } else if (\n cliArgs?.['--use-yarn'] ||\n fse.existsSync(`${projectDir}/yarn.lock`) ||\n (await commandExists('yarn'))\n ) {\n detected = 'yarn'\n } else if (cliArgs?.['--use-npm'] || fse.existsSync(`${projectDir}/package-lock.json`)) {\n detected = 'npm'\n }\n\n return detected\n } catch (error) {\n return 'npm'\n }\n}\n\nasync function commandExists(command: string): Promise<boolean> {\n try {\n await execa.command(`command -v ${command}`)\n return true\n } catch {\n return false\n }\n}\n"],"names":["execa","fse","getPackageManager","args","cliArgs","projectDir","detected","existsSync","commandExists","error","command"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAI1B,OAAO,eAAeC,kBAAkBC,IAGvC;IACC,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGF;IAEhC,IAAI;QACF,4DAA4D;QAC5D,IAAIG,WAA2B;QAC/B,IACEF,SAAS,CAAC,aAAa,IACvBH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,eAAe,CAAC,KAC5C,MAAMG,cAAc,SACrB;YACAF,WAAW;QACb,OAAO,IACLF,SAAS,CAAC,aAAa,IACvBH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,UAAU,CAAC,KACvC,MAAMG,cAAc,SACrB;YACAF,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,YAAY,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,kBAAkB,CAAC,GAAG;YACtFC,WAAW;QACb;QAEA,OAAOA;IACT,EAAE,OAAOG,OAAO;QACd,OAAO;IACT;AACF;AAEA,eAAeD,cAAcE,OAAe;IAC1C,IAAI;QACF,MAAMV,MAAMU,OAAO,CAAC,CAAC,WAAW,EAAEA,QAAQ,CAAC;QAC3C,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/lib/get-package-manager.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\n\nimport type { CliArgs, PackageManager } from '../types.js'\n\nexport async function getPackageManager(args: {\n cliArgs?: CliArgs\n projectDir: string\n}): Promise<PackageManager> {\n const { cliArgs, projectDir } = args\n\n try {\n // Check for flag or lockfile\n let detected: PackageManager = 'npm'\n if (cliArgs?.['--use-pnpm'] || fse.existsSync(`${projectDir}/pnpm-lock.yaml`)) {\n detected = 'pnpm'\n } else if (cliArgs?.['--use-yarn'] || fse.existsSync(`${projectDir}/yarn.lock`)) {\n detected = 'yarn'\n } else if (cliArgs?.['--use-npm'] || fse.existsSync(`${projectDir}/package-lock.json`)) {\n detected = 'npm'\n } else if (cliArgs?.['--use-bun'] || fse.existsSync(`${projectDir}/bun.lockb`)) {\n detected = 'bun'\n } else if (await commandExists('pnpm')) {\n // Prefer pnpm if it's installed\n detected = 'pnpm'\n } else {\n // Otherwise check the execution environment\n detected = getEnvironmentPackageManager()\n }\n\n return detected\n } catch (ignore) {\n return 'npm'\n }\n}\n\nfunction getEnvironmentPackageManager(): PackageManager {\n const userAgent = process.env.npm_config_user_agent || ''\n\n if (userAgent.startsWith('yarn')) {\n return 'yarn'\n }\n\n if (userAgent.startsWith('pnpm')) {\n return 'pnpm'\n }\n\n if (userAgent.startsWith('bun')) {\n return 'bun'\n }\n\n return 'npm'\n}\n\nasync function commandExists(command: string): Promise<boolean> {\n try {\n await execa.command(process.platform === 'win32' ? `where ${command}` : `command -v ${command}`)\n return true\n } catch {\n return false\n }\n}\n"],"names":["execa","fse","getPackageManager","args","cliArgs","projectDir","detected","existsSync","commandExists","getEnvironmentPackageManager","ignore","userAgent","process","env","npm_config_user_agent","startsWith","command","platform"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAI1B,OAAO,eAAeC,kBAAkBC,IAGvC;IACC,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGF;IAEhC,IAAI;QACF,6BAA6B;QAC7B,IAAIG,WAA2B;QAC/B,IAAIF,SAAS,CAAC,aAAa,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,eAAe,CAAC,GAAG;YAC7EC,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,aAAa,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,UAAU,CAAC,GAAG;YAC/EC,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,YAAY,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,kBAAkB,CAAC,GAAG;YACtFC,WAAW;QACb,OAAO,IAAIF,SAAS,CAAC,YAAY,IAAIH,IAAIM,UAAU,CAAC,CAAC,EAAEF,WAAW,UAAU,CAAC,GAAG;YAC9EC,WAAW;QACb,OAAO,IAAI,MAAME,cAAc,SAAS;YACtC,gCAAgC;YAChCF,WAAW;QACb,OAAO;YACL,4CAA4C;YAC5CA,WAAWG;QACb;QAEA,OAAOH;IACT,EAAE,OAAOI,QAAQ;QACf,OAAO;IACT;AACF;AAEA,SAASD;IACP,MAAME,YAAYC,QAAQC,GAAG,CAACC,qBAAqB,IAAI;IAEvD,IAAIH,UAAUI,UAAU,CAAC,SAAS;QAChC,OAAO;IACT;IAEA,IAAIJ,UAAUI,UAAU,CAAC,SAAS;QAChC,OAAO;IACT;IAEA,IAAIJ,UAAUI,UAAU,CAAC,QAAQ;QAC/B,OAAO;IACT;IAEA,OAAO;AACT;AAEA,eAAeP,cAAcQ,OAAe;IAC1C,IAAI;QACF,MAAMhB,MAAMgB,OAAO,CAACJ,QAAQK,QAAQ,KAAK,UAAU,CAAC,MAAM,EAAED,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAEA,QAAQ,CAAC;QAC/F,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
@@ -1,21 +1,21 @@
1
1
  import type { CliArgs, DbType, NextAppDetails, PackageManager } from '../types.js';
2
- type InitNextArgs = Pick<CliArgs, '--debug'> & {
2
+ type InitNextArgs = {
3
3
  dbType: DbType;
4
4
  nextAppDetails?: NextAppDetails;
5
5
  packageManager: PackageManager;
6
6
  projectDir: string;
7
7
  useDistFiles?: boolean;
8
- };
8
+ } & Pick<CliArgs, '--debug'>;
9
9
  type InitNextResult = {
10
- isSrcDir: boolean;
11
- nextAppDir: string;
12
- payloadConfigPath: string;
13
- success: true;
14
- } | {
15
10
  isSrcDir: boolean;
16
11
  nextAppDir?: string;
17
12
  reason: string;
18
13
  success: false;
14
+ } | {
15
+ isSrcDir: boolean;
16
+ nextAppDir: string;
17
+ payloadConfigPath: string;
18
+ success: true;
19
19
  };
20
20
  export declare function initNext(args: InitNextArgs): Promise<InitNextResult>;
21
21
  export declare function getNextAppDetails(projectDir: string): Promise<NextAppDetails>;
@@ -1 +1 @@
1
- {"version":3,"file":"init-next.d.ts","sourceRoot":"","sources":["../../src/lib/init-next.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAkB,cAAc,EAAE,MAAM,aAAa,CAAA;AAclG,KAAK,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;I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B,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAgE1E;AAqID,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA2FnF"}
@@ -26,7 +26,7 @@ export async function initNext(args) {
26
26
  });
27
27
  nextAppDetails.nextAppDir = createdAppDir;
28
28
  }
29
- const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
29
+ const { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigType } = nextAppDetails;
30
30
  if (!nextConfigType) {
31
31
  return {
32
32
  isSrcDir,
@@ -50,7 +50,7 @@ export async function initNext(args) {
50
50
  }
51
51
  const installSpinner = p.spinner();
52
52
  installSpinner.start('Installing Payload and dependencies...');
53
- const configurationResult = installAndConfigurePayload({
53
+ const configurationResult = await installAndConfigurePayload({
54
54
  ...args,
55
55
  nextAppDetails,
56
56
  nextConfigType,
@@ -112,7 +112,7 @@ async function addPayloadConfigToTsConfig(projectDir, isSrcDir) {
112
112
  });
113
113
  }
114
114
  }
115
- function installAndConfigurePayload(args) {
115
+ async function installAndConfigurePayload(args) {
116
116
  const { '--debug': debug, nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {}, nextConfigType, projectDir, useDistFiles } = args;
117
117
  if (!nextAppDir || !nextConfigPath) {
118
118
  return {
@@ -121,7 +121,9 @@ function installAndConfigurePayload(args) {
121
121
  };
122
122
  }
123
123
  const logDebug = (message)=>{
124
- if (debug) origDebug(message);
124
+ if (debug) {
125
+ origDebug(message);
126
+ }
125
127
  };
126
128
  if (!fs.existsSync(projectDir)) {
127
129
  return {
@@ -129,7 +131,7 @@ function installAndConfigurePayload(args) {
129
131
  success: false
130
132
  };
131
133
  }
132
- const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank-3.0');
134
+ const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank');
133
135
  logDebug(`Using template files from: ${templateFilesPath}`);
134
136
  if (!fs.existsSync(templateFilesPath)) {
135
137
  return {
@@ -148,9 +150,9 @@ function installAndConfigurePayload(args) {
148
150
  logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`);
149
151
  logDebug(`isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`);
150
152
  // This is a little clunky and needs to account for isSrcDir
151
- copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug);
153
+ copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath));
152
154
  // Wrap next.config.js with withPayload
153
- wrapNextConfig({
155
+ await wrapNextConfig({
154
156
  nextConfigPath,
155
157
  nextConfigType
156
158
  });
@@ -164,7 +166,7 @@ async function installDeps(projectDir, packageManager, dbType) {
164
166
  'payload',
165
167
  '@payloadcms/next',
166
168
  '@payloadcms/richtext-lexical',
167
- '@payloadcms/plugin-cloud'
169
+ '@payloadcms/payload-cloud'
168
170
  ].map((pkg)=>`${pkg}@beta`);
169
171
  packagesToInstall.push(`@payloadcms/db-${dbType}@beta`);
170
172
  // Match graphql version of @payloadcms/next
@@ -177,7 +179,8 @@ async function installDeps(projectDir, packageManager, dbType) {
177
179
  }
178
180
  export async function getNextAppDetails(projectDir) {
179
181
  const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'));
180
- const nextConfigPath = (await globby('next.config.*js', {
182
+ // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs
183
+ const nextConfigPath = (await globby('next.config.(\\w)?(t|j)s', {
181
184
  absolute: true,
182
185
  cwd: projectDir
183
186
  }))?.[0];
@@ -185,16 +188,50 @@ export async function getNextAppDetails(projectDir) {
185
188
  return {
186
189
  hasTopLevelLayout: false,
187
190
  isSrcDir,
188
- nextConfigPath: undefined
191
+ isSupportedNextVersion: false,
192
+ nextConfigPath: undefined,
193
+ nextVersion: null
189
194
  };
190
195
  }
191
196
  const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));
197
+ // Check if Next.js version is new enough
198
+ let nextVersion = null;
199
+ if (packageObj.dependencies?.next) {
200
+ nextVersion = packageObj.dependencies.next;
201
+ // Match versions using regex matching groups
202
+ const versionMatch = /(?<major>\d+)/.exec(nextVersion);
203
+ if (!versionMatch) {
204
+ p.log.warn(`Could not determine Next.js version from ${nextVersion}`);
205
+ return {
206
+ hasTopLevelLayout: false,
207
+ isSrcDir,
208
+ isSupportedNextVersion: false,
209
+ nextConfigPath,
210
+ nextVersion
211
+ };
212
+ }
213
+ const { major } = versionMatch.groups;
214
+ const majorVersion = parseInt(major);
215
+ if (majorVersion < 15) {
216
+ return {
217
+ hasTopLevelLayout: false,
218
+ isSrcDir,
219
+ isSupportedNextVersion: false,
220
+ nextConfigPath,
221
+ nextVersion
222
+ };
223
+ }
224
+ }
225
+ const isSupportedNextVersion = true;
226
+ // Check if Payload already installed
192
227
  if (packageObj.dependencies?.payload) {
193
228
  return {
194
229
  hasTopLevelLayout: false,
195
230
  isPayloadInstalled: true,
196
231
  isSrcDir,
197
- nextConfigPath
232
+ isSupportedNextVersion,
233
+ nextConfigPath,
234
+ nextVersion
198
235
  };
199
236
  }
200
237
  let nextAppDir = (await globby([
@@ -218,13 +255,18 @@ export async function getNextAppDetails(projectDir) {
218
255
  return {
219
256
  hasTopLevelLayout,
220
257
  isSrcDir,
258
+ isSupportedNextVersion,
221
259
  nextAppDir,
222
260
  nextConfigPath,
223
- nextConfigType: configType
261
+ nextConfigType: configType,
262
+ nextVersion
224
263
  };
225
264
  }
226
265
  function getProjectType(args) {
227
266
  const { nextConfigPath, packageObj } = args;
267
+ if (nextConfigPath.endsWith('.ts')) {
268
+ return 'ts';
269
+ }
228
270
  if (nextConfigPath.endsWith('.mjs')) {
229
271
  return 'esm';
230
272
  }