create-payload-app 3.0.0-canary.a78fca3 → 3.0.0-canary.b6520aa
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js.map +1 -1
- package/dist/lib/configure-payload-config.js +1 -1
- package/dist/lib/configure-payload-config.js.map +1 -1
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/create-project.spec.js +17 -16
- package/dist/lib/create-project.spec.js.map +1 -1
- package/dist/lib/generate-secret.js.map +1 -1
- package/dist/lib/get-package-manager.d.ts.map +1 -1
- package/dist/lib/get-package-manager.js +12 -3
- package/dist/lib/get-package-manager.js.map +1 -1
- package/dist/lib/init-next.d.ts +2 -2
- package/dist/lib/init-next.d.ts.map +1 -1
- package/dist/lib/init-next.js +47 -7
- package/dist/lib/init-next.js.map +1 -1
- package/dist/lib/install-packages.js.map +1 -1
- package/dist/lib/parse-project-name.js.map +1 -1
- package/dist/lib/parse-template.js.map +1 -1
- package/dist/lib/replacements.d.ts.map +1 -1
- package/dist/lib/replacements.js +15 -2
- package/dist/lib/replacements.js.map +1 -1
- package/dist/lib/select-db.d.ts.map +1 -1
- package/dist/lib/select-db.js +11 -11
- package/dist/lib/select-db.js.map +1 -1
- package/dist/lib/templates.js +6 -0
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/update-payload-in-project.d.ts.map +1 -1
- package/dist/lib/update-payload-in-project.js +1 -1
- package/dist/lib/update-payload-in-project.js.map +1 -1
- package/dist/lib/wrap-next-config.d.ts +5 -5
- package/dist/lib/wrap-next-config.d.ts.map +1 -1
- package/dist/lib/wrap-next-config.js +122 -58
- package/dist/lib/wrap-next-config.js.map +1 -1
- package/dist/lib/wrap-next-config.spec.js +84 -34
- package/dist/lib/wrap-next-config.spec.js.map +1 -1
- package/dist/lib/write-env-file.d.ts.map +1 -1
- package/dist/lib/write-env-file.js +25 -25
- package/dist/lib/write-env-file.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +6 -1
- package/dist/main.js.map +1 -1
- package/dist/scripts/pack-template-files.js.map +1 -1
- package/dist/template/src/collections/Media.ts +1 -1
- package/dist/template/src/collections/Users.ts +1 -1
- package/dist/template/src/payload.config.ts +1 -1
- package/dist/types.d.ts +4 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/copy-recursive-sync.js.map +1 -1
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/log.d.ts.map +1 -1
- package/dist/utils/log.js +1 -1
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/messages.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Main } from './main.js'\nimport { error } from './utils/log.js'\n\nexport async function main(): Promise<void> {\n try {\n await new Main().init()\n } catch (e) {\n if (e instanceof Error) {\n error(e.message)\n }\n }\n}\n"],"names":["Main","error","main","init","e","Error","message"],"
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Main } from './main.js'\nimport { error } from './utils/log.js'\n\nexport async function main(): Promise<void> {\n try {\n await new Main().init()\n } catch (e) {\n if (e instanceof Error) {\n error(e.message)\n }\n }\n}\n"],"names":["Main","error","main","init","e","Error","message"],"mappings":"AAAA,SAASA,IAAI,QAAQ,YAAW;AAChC,SAASC,KAAK,QAAQ,iBAAgB;AAEtC,OAAO,eAAeC;IACpB,IAAI;QACF,MAAM,IAAIF,OAAOG,IAAI;IACvB,EAAE,OAAOC,GAAG;QACV,IAAIA,aAAaC,OAAO;YACtBJ,MAAMG,EAAEE,OAAO;QACjB;IACF;AACF"}
|
@@ -82,7 +82,7 @@ import { dbReplacements, storageReplacements } from './replacements.js';
|
|
82
82
|
replacement: replacement.configReplacement,
|
83
83
|
startMatch: '// storage-adapter-placeholder'
|
84
84
|
});
|
85
|
-
if (replacement?.importReplacement) {
|
85
|
+
if (replacement?.importReplacement !== undefined) {
|
86
86
|
configLines = replaceInConfigLines({
|
87
87
|
lines: configLines,
|
88
88
|
replacement: [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/configure-payload-config.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\nimport path from 'path'\n\nimport type { DbType, StorageAdapterType } from '../types.js'\n\nimport { warning } from '../utils/log.js'\nimport { dbReplacements, storageReplacements } from './replacements.js'\n\n/** Update payload config with necessary imports and adapters */\nexport async function configurePayloadConfig(args: {\n dbType?: DbType\n envNames?: {\n dbUri: string\n }\n packageJsonName?: string\n projectDirOrConfigPath: { payloadConfigPath: string } | { projectDir: string }\n sharp?: boolean\n storageAdapter?: StorageAdapterType\n}): Promise<void> {\n if (!args.dbType) {\n return\n }\n\n // Update package.json\n const packageJsonPath =\n 'projectDir' in args.projectDirOrConfigPath &&\n path.resolve(args.projectDirOrConfigPath.projectDir, 'package.json')\n\n if (packageJsonPath && fse.existsSync(packageJsonPath)) {\n try {\n const packageObj = await fse.readJson(packageJsonPath)\n\n const dbPackage = dbReplacements[args.dbType]\n\n // Delete all other db adapters\n Object.values(dbReplacements).forEach((p) => {\n if (p.packageName !== dbPackage.packageName) {\n delete packageObj.dependencies[p.packageName]\n }\n })\n\n // Set version of db adapter to match payload version\n packageObj.dependencies[dbPackage.packageName] = packageObj.dependencies['payload']\n\n if (args.storageAdapter) {\n const storagePackage = storageReplacements[args.storageAdapter]\n\n if (storagePackage?.packageName) {\n // Set version of storage adapter to match payload version\n packageObj.dependencies[storagePackage.packageName] = packageObj.dependencies['payload']\n }\n }\n\n // Sharp provided by default, only remove if explicitly set to false\n if (args.sharp === false) {\n delete packageObj.dependencies['sharp']\n }\n\n if (args.packageJsonName) {\n packageObj.name = args.packageJsonName\n }\n\n await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })\n } catch (err: unknown) {\n warning(`Unable to configure Payload in package.json`)\n warning(err instanceof Error ? err.message : '')\n }\n }\n\n try {\n let payloadConfigPath: string | undefined\n if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {\n payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: args.projectDirOrConfigPath.projectDir,\n })\n )?.[0]\n } else {\n payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath\n }\n\n if (!payloadConfigPath) {\n warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.')\n return\n }\n\n const configContent = fse.readFileSync(payloadConfigPath, 'utf-8')\n let configLines = configContent.split('\\n')\n\n // DB Replacement\n const dbReplacement = dbReplacements[args.dbType]\n\n configLines = replaceInConfigLines({\n endMatch: `// database-adapter-config-end`,\n lines: configLines,\n replacement: dbReplacement.configReplacement(args.envNames?.dbUri),\n startMatch: `// database-adapter-config-start`,\n })\n\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [dbReplacement.importReplacement],\n startMatch: '// database-adapter-import',\n })\n\n // Storage Adapter Replacement\n if (args.storageAdapter) {\n const replacement = storageReplacements[args.storageAdapter]\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: replacement.configReplacement,\n startMatch: '// storage-adapter-placeholder',\n })\n\n if (replacement?.importReplacement) {\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [replacement.importReplacement],\n startMatch: '// storage-adapter-import-placeholder',\n })\n }\n }\n\n // Sharp Replacement (provided by default, only remove if explicitly set to false)\n if (args.sharp === false) {\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [],\n startMatch: 'sharp,',\n })\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [],\n startMatch: \"import sharp from 'sharp'\",\n })\n }\n\n fse.writeFileSync(payloadConfigPath, configLines.join('\\n'))\n } catch (err: unknown) {\n warning(\n `Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`,\n )\n }\n}\n\nfunction replaceInConfigLines({\n endMatch,\n lines,\n replacement,\n startMatch,\n}: {\n /** Optional endMatch to replace multiple lines */\n endMatch?: string\n lines: string[]\n replacement: string[]\n startMatch: string\n}) {\n if (!replacement) {\n return lines\n }\n\n const startIndex = lines.findIndex((l) => l.includes(startMatch))\n const endIndex = endMatch ? lines.findIndex((l) => l.includes(endMatch)) : startIndex\n\n if (startIndex === -1 || endIndex === -1) {\n return lines\n }\n\n lines.splice(startIndex, endIndex - startIndex + 1, ...replacement)\n return lines\n}\n"],"names":["fse","globby","path","warning","dbReplacements","storageReplacements","configurePayloadConfig","args","dbType","packageJsonPath","projectDirOrConfigPath","resolve","projectDir","existsSync","packageObj","readJson","dbPackage","Object","values","forEach","p","packageName","dependencies","storageAdapter","storagePackage","sharp","packageJsonName","name","writeJson","spaces","err","Error","message","payloadConfigPath","absolute","cwd","configContent","readFileSync","configLines","split","dbReplacement","replaceInConfigLines","endMatch","lines","replacement","configReplacement","envNames","dbUri","startMatch","importReplacement","writeFileSync","join","startIndex","findIndex","l","includes","endIndex","splice"],"
|
1
|
+
{"version":3,"sources":["../../src/lib/configure-payload-config.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\nimport path from 'path'\n\nimport type { DbType, StorageAdapterType } from '../types.js'\n\nimport { warning } from '../utils/log.js'\nimport { dbReplacements, storageReplacements } from './replacements.js'\n\n/** Update payload config with necessary imports and adapters */\nexport async function configurePayloadConfig(args: {\n dbType?: DbType\n envNames?: {\n dbUri: string\n }\n packageJsonName?: string\n projectDirOrConfigPath: { payloadConfigPath: string } | { projectDir: string }\n sharp?: boolean\n storageAdapter?: StorageAdapterType\n}): Promise<void> {\n if (!args.dbType) {\n return\n }\n\n // Update package.json\n const packageJsonPath =\n 'projectDir' in args.projectDirOrConfigPath &&\n path.resolve(args.projectDirOrConfigPath.projectDir, 'package.json')\n\n if (packageJsonPath && fse.existsSync(packageJsonPath)) {\n try {\n const packageObj = await fse.readJson(packageJsonPath)\n\n const dbPackage = dbReplacements[args.dbType]\n\n // Delete all other db adapters\n Object.values(dbReplacements).forEach((p) => {\n if (p.packageName !== dbPackage.packageName) {\n delete packageObj.dependencies[p.packageName]\n }\n })\n\n // Set version of db adapter to match payload version\n packageObj.dependencies[dbPackage.packageName] = packageObj.dependencies['payload']\n\n if (args.storageAdapter) {\n const storagePackage = storageReplacements[args.storageAdapter]\n\n if (storagePackage?.packageName) {\n // Set version of storage adapter to match payload version\n packageObj.dependencies[storagePackage.packageName] = packageObj.dependencies['payload']\n }\n }\n\n // Sharp provided by default, only remove if explicitly set to false\n if (args.sharp === false) {\n delete packageObj.dependencies['sharp']\n }\n\n if (args.packageJsonName) {\n packageObj.name = args.packageJsonName\n }\n\n await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })\n } catch (err: unknown) {\n warning(`Unable to configure Payload in package.json`)\n warning(err instanceof Error ? err.message : '')\n }\n }\n\n try {\n let payloadConfigPath: string | undefined\n if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {\n payloadConfigPath = (\n await globby('**/payload.config.ts', {\n absolute: true,\n cwd: args.projectDirOrConfigPath.projectDir,\n })\n )?.[0]\n } else {\n payloadConfigPath = args.projectDirOrConfigPath.payloadConfigPath\n }\n\n if (!payloadConfigPath) {\n warning('Unable to update payload.config.ts with plugins. Could not find payload.config.ts.')\n return\n }\n\n const configContent = fse.readFileSync(payloadConfigPath, 'utf-8')\n let configLines = configContent.split('\\n')\n\n // DB Replacement\n const dbReplacement = dbReplacements[args.dbType]\n\n configLines = replaceInConfigLines({\n endMatch: `// database-adapter-config-end`,\n lines: configLines,\n replacement: dbReplacement.configReplacement(args.envNames?.dbUri),\n startMatch: `// database-adapter-config-start`,\n })\n\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [dbReplacement.importReplacement],\n startMatch: '// database-adapter-import',\n })\n\n // Storage Adapter Replacement\n if (args.storageAdapter) {\n const replacement = storageReplacements[args.storageAdapter]\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: replacement.configReplacement,\n startMatch: '// storage-adapter-placeholder',\n })\n\n if (replacement?.importReplacement !== undefined) {\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [replacement.importReplacement],\n startMatch: '// storage-adapter-import-placeholder',\n })\n }\n }\n\n // Sharp Replacement (provided by default, only remove if explicitly set to false)\n if (args.sharp === false) {\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [],\n startMatch: 'sharp,',\n })\n configLines = replaceInConfigLines({\n lines: configLines,\n replacement: [],\n startMatch: \"import sharp from 'sharp'\",\n })\n }\n\n fse.writeFileSync(payloadConfigPath, configLines.join('\\n'))\n } catch (err: unknown) {\n warning(\n `Unable to update payload.config.ts with plugins: ${err instanceof Error ? err.message : ''}`,\n )\n }\n}\n\nfunction replaceInConfigLines({\n endMatch,\n lines,\n replacement,\n startMatch,\n}: {\n /** Optional endMatch to replace multiple lines */\n endMatch?: string\n lines: string[]\n replacement: string[]\n startMatch: string\n}) {\n if (!replacement) {\n return lines\n }\n\n const startIndex = lines.findIndex((l) => l.includes(startMatch))\n const endIndex = endMatch ? lines.findIndex((l) => l.includes(endMatch)) : startIndex\n\n if (startIndex === -1 || endIndex === -1) {\n return lines\n }\n\n lines.splice(startIndex, endIndex - startIndex + 1, ...replacement)\n return lines\n}\n"],"names":["fse","globby","path","warning","dbReplacements","storageReplacements","configurePayloadConfig","args","dbType","packageJsonPath","projectDirOrConfigPath","resolve","projectDir","existsSync","packageObj","readJson","dbPackage","Object","values","forEach","p","packageName","dependencies","storageAdapter","storagePackage","sharp","packageJsonName","name","writeJson","spaces","err","Error","message","payloadConfigPath","absolute","cwd","configContent","readFileSync","configLines","split","dbReplacement","replaceInConfigLines","endMatch","lines","replacement","configReplacement","envNames","dbUri","startMatch","importReplacement","undefined","writeFileSync","join","startIndex","findIndex","l","includes","endIndex","splice"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AAIvB,SAASC,OAAO,QAAQ,kBAAiB;AACzC,SAASC,cAAc,EAAEC,mBAAmB,QAAQ,oBAAmB;AAEvE,8DAA8D,GAC9D,OAAO,eAAeC,uBAAuBC,IAS5C;IACC,IAAI,CAACA,KAAKC,MAAM,EAAE;QACh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YACd;YACAV,cAAcG,qBAAqB;gBACjCE,OAAOL;gBACPM,aAAa,EAAE;gBACfI,YAAY;YACd;QACF;QAEAhD,IAAImD,aAAa,CAAClB,mBAAmBK,YAAYc,IAAI,CAAC;IACxD,EAAE,OAAOtB,KAAc;QACrB3B,QACE,CAAC,iDAAiD,EAAE2B,eAAeC,QAAQD,IAAIE,OAAO,GAAG,GAAG,CAAC;IAEjG;AACF;AAEA,SAASS,qBAAqB,EAC5BC,QAAQ,EACRC,KAAK,EACLC,WAAW,EACXI,UAAU,EAOX;IACC,IAAI,CAACJ,aAAa;QAChB,OAAOD;IACT;IAEA,MAAMU,aAAaV,MAAMW,SAAS,CAAC,CAACC,IAAMA,EAAEC,QAAQ,CAACR;IACrD,MAAMS,WAAWf,WAAWC,MAAMW,SAAS,CAAC,CAACC,IAAMA,EAAEC,QAAQ,CAACd,aAAaW;IAE3E,IAAIA,eAAe,CAAC,KAAKI,aAAa,CAAC,GAAG;QACxC,OAAOd;IACT;IAEAA,MAAMe,MAAM,CAACL,YAAYI,WAAWJ,aAAa,MAAMT;IACvD,OAAOD;AACT"}
|
@@ -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"],"
|
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,WAAW,QAAO;AACzB,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;AAEtE,MAAMC,WAAWR,cAAc,YAAYS,GAAG;AAC9C,MAAMC,UAAUT,KAAKS,OAAO,CAACF;AAE7B,eAAeG,uBAAuBC,UAAkB;IACtD,MAAMC,aAAa,MAAMd,IAAIc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Y;YAAEI,QAAQ;QAAE;IAC/D,EAAE,OAAO7B,KAAc;QACrBjB,QAAQ,CAAC,uCAAuC,EAAEiB,eAAeC,QAAQD,IAAIE,OAAO,GAAG,GAAG,CAAC;IAC7F;AACF"}
|
@@ -1,17 +1,19 @@
|
|
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(()=>{
|
12
13
|
console.log = jest.fn();
|
13
14
|
});
|
14
15
|
beforeEach(()=>{
|
16
|
+
const tempDirectory = fs.realpathSync(os.tmpdir());
|
15
17
|
projectDir = `${tempDirectory}/${Math.random().toString(36).substring(7)}`;
|
16
18
|
});
|
17
19
|
afterEach(()=>{
|
@@ -22,7 +24,6 @@ describe('createProject', ()=>{
|
|
22
24
|
}
|
23
25
|
});
|
24
26
|
describe('#createProject', ()=>{
|
25
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
26
27
|
const args = {
|
27
28
|
_: [
|
28
29
|
'project-name'
|
@@ -37,15 +38,15 @@ describe('createProject', ()=>{
|
|
37
38
|
const template = {
|
38
39
|
name: 'plugin',
|
39
40
|
type: 'plugin',
|
40
|
-
|
41
|
-
|
41
|
+
description: 'Template for creating a Payload plugin',
|
42
|
+
url: 'https://github.com/payloadcms/payload-plugin-template'
|
42
43
|
};
|
43
44
|
await createProject({
|
44
45
|
cliArgs: args,
|
45
|
-
|
46
|
+
packageManager,
|
46
47
|
projectDir,
|
47
|
-
|
48
|
-
|
48
|
+
projectName,
|
49
|
+
template
|
49
50
|
});
|
50
51
|
const packageJsonPath = path.resolve(projectDir, 'package.json');
|
51
52
|
const packageJson = fse.readJsonSync(packageJsonPath);
|
@@ -73,14 +74,14 @@ describe('createProject', ()=>{
|
|
73
74
|
};
|
74
75
|
await createProject({
|
75
76
|
cliArgs,
|
76
|
-
projectName,
|
77
|
-
projectDir,
|
78
|
-
template: template,
|
79
|
-
packageManager,
|
80
77
|
dbDetails: {
|
81
|
-
|
82
|
-
|
83
|
-
}
|
78
|
+
type: db,
|
79
|
+
dbUri: `${db}://localhost:27017/create-project-test`
|
80
|
+
},
|
81
|
+
packageManager,
|
82
|
+
projectDir,
|
83
|
+
projectName,
|
84
|
+
template: template
|
84
85
|
});
|
85
86
|
const dbReplacement = dbReplacements[db];
|
86
87
|
const packageJsonPath = path.resolve(projectDir, 'package.json');
|
@@ -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'\
|
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 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-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 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).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 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 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":["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","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,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;QACRC,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,UAAU,CAACd,aAAa;YAC9BR,IAAIuB,MAAM,CAACf,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KkC,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,IAAI,CAACmD,mBAAmB;oBACtB,MAAM,IAAIG,MAAM,CAAC,wCAAwC,EAAEtD,WAAW,CAAC;gBACzE;gBAEA,MAAMuD,UAAU/D,IAAIgE,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 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/lib/generate-secret.ts"],"sourcesContent":["import { randomBytes } from 'crypto'\n\nexport function generateSecret(): string {\n return randomBytes(32).toString('hex').slice(0, 24)\n}\n"],"names":["randomBytes","generateSecret","toString","slice"],"
|
1
|
+
{"version":3,"sources":["../../src/lib/generate-secret.ts"],"sourcesContent":["import { randomBytes } from 'crypto'\n\nexport function generateSecret(): string {\n return randomBytes(32).toString('hex').slice(0, 24)\n}\n"],"names":["randomBytes","generateSecret","toString","slice"],"mappings":"AAAA,SAASA,WAAW,QAAQ,SAAQ;AAEpC,OAAO,SAASC;IACd,OAAOD,YAAY,IAAIE,QAAQ,CAAC,OAAOC,KAAK,CAAC,GAAG;AAClD"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-package-manager.d.ts","sourceRoot":"","sources":["../../src/lib/get-package-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE1D,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,cAAc,CAAC,
|
1
|
+
{"version":3,"file":"get-package-manager.d.ts","sourceRoot":"","sources":["../../src/lib/get-package-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE1D,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,cAAc,CAAC,CA2B1B"}
|
@@ -3,14 +3,23 @@ import fse from 'fs-extra';
|
|
3
3
|
export async function getPackageManager(args) {
|
4
4
|
const { cliArgs, projectDir } = args;
|
5
5
|
try {
|
6
|
-
// Check for
|
6
|
+
// Check for flag or lockfile
|
7
7
|
let detected = 'npm';
|
8
|
-
if (cliArgs?.['--use-pnpm'] || fse.existsSync(`${projectDir}/pnpm-lock.yaml`)
|
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`)
|
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 {
|
15
|
+
// Otherwise check for existing commands
|
16
|
+
if (await commandExists('pnpm')) {
|
17
|
+
detected = 'pnpm';
|
18
|
+
} else if (await commandExists('yarn')) {
|
19
|
+
detected = 'yarn';
|
20
|
+
} else {
|
21
|
+
detected = 'npm';
|
22
|
+
}
|
14
23
|
}
|
15
24
|
return detected;
|
16
25
|
} catch (error) {
|
@@ -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
|
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 {\n // Otherwise check for existing commands\n if (await commandExists('pnpm')) {\n detected = 'pnpm'\n } else if (await commandExists('yarn')) {\n detected = 'yarn'\n } else {\n detected = 'npm'\n }\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,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;YACL,wCAAwC;YACxC,IAAI,MAAME,cAAc,SAAS;gBAC/BF,WAAW;YACb,OAAO,IAAI,MAAME,cAAc,SAAS;gBACtCF,WAAW;YACb,OAAO;gBACLA,WAAW;YACb;QACF;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"}
|
package/dist/lib/init-next.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import type { CliArgs, DbType, NextAppDetails, PackageManager } from '../types.js';
|
2
|
-
type InitNextArgs =
|
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
10
|
isSrcDir: boolean;
|
11
11
|
nextAppDir: string;
|
@@ -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
|
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;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAE5B,KAAK,cAAc,GACf;IACE,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,IAAI,CAAA;CACd,GACD;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAA;AAE9E,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAiE1E;AAmID,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA2FnF"}
|
package/dist/lib/init-next.js
CHANGED
@@ -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 {
|
@@ -150,7 +150,7 @@ function installAndConfigurePayload(args) {
|
|
150
150
|
// This is a little clunky and needs to account for isSrcDir
|
151
151
|
copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug);
|
152
152
|
// Wrap next.config.js with withPayload
|
153
|
-
wrapNextConfig({
|
153
|
+
await wrapNextConfig({
|
154
154
|
nextConfigPath,
|
155
155
|
nextConfigType
|
156
156
|
});
|
@@ -177,7 +177,8 @@ async function installDeps(projectDir, packageManager, dbType) {
|
|
177
177
|
}
|
178
178
|
export async function getNextAppDetails(projectDir) {
|
179
179
|
const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'));
|
180
|
-
|
180
|
+
// Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs
|
181
|
+
const nextConfigPath = (await globby('next.config.(\\w)?(t|j)s', {
|
181
182
|
absolute: true,
|
182
183
|
cwd: projectDir
|
183
184
|
}))?.[0];
|
@@ -185,16 +186,50 @@ export async function getNextAppDetails(projectDir) {
|
|
185
186
|
return {
|
186
187
|
hasTopLevelLayout: false,
|
187
188
|
isSrcDir,
|
188
|
-
|
189
|
+
isSupportedNextVersion: false,
|
190
|
+
nextConfigPath: undefined,
|
191
|
+
nextVersion: null
|
189
192
|
};
|
190
193
|
}
|
191
194
|
const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));
|
195
|
+
// Check if Next.js version is new enough
|
196
|
+
let nextVersion = null;
|
197
|
+
if (packageObj.dependencies?.next) {
|
198
|
+
nextVersion = packageObj.dependencies.next;
|
199
|
+
// Match versions using regex matching groups
|
200
|
+
const versionMatch = /(?<major>\d+)/.exec(nextVersion);
|
201
|
+
if (!versionMatch) {
|
202
|
+
p.log.warn(`Could not determine Next.js version from ${nextVersion}`);
|
203
|
+
return {
|
204
|
+
hasTopLevelLayout: false,
|
205
|
+
isSrcDir,
|
206
|
+
isSupportedNextVersion: false,
|
207
|
+
nextConfigPath,
|
208
|
+
nextVersion
|
209
|
+
};
|
210
|
+
}
|
211
|
+
const { major } = versionMatch.groups;
|
212
|
+
const majorVersion = parseInt(major);
|
213
|
+
if (majorVersion < 15) {
|
214
|
+
return {
|
215
|
+
hasTopLevelLayout: false,
|
216
|
+
isSrcDir,
|
217
|
+
isSupportedNextVersion: false,
|
218
|
+
nextConfigPath,
|
219
|
+
nextVersion
|
220
|
+
};
|
221
|
+
}
|
222
|
+
}
|
223
|
+
const isSupportedNextVersion = true;
|
224
|
+
// Check if Payload already installed
|
192
225
|
if (packageObj.dependencies?.payload) {
|
193
226
|
return {
|
194
227
|
hasTopLevelLayout: false,
|
195
228
|
isPayloadInstalled: true,
|
196
229
|
isSrcDir,
|
197
|
-
|
230
|
+
isSupportedNextVersion,
|
231
|
+
nextConfigPath,
|
232
|
+
nextVersion
|
198
233
|
};
|
199
234
|
}
|
200
235
|
let nextAppDir = (await globby([
|
@@ -218,13 +253,18 @@ export async function getNextAppDetails(projectDir) {
|
|
218
253
|
return {
|
219
254
|
hasTopLevelLayout,
|
220
255
|
isSrcDir,
|
256
|
+
isSupportedNextVersion,
|
221
257
|
nextAppDir,
|
222
258
|
nextConfigPath,
|
223
|
-
nextConfigType: configType
|
259
|
+
nextConfigType: configType,
|
260
|
+
nextVersion
|
224
261
|
};
|
225
262
|
}
|
226
263
|
function getProjectType(args) {
|
227
264
|
const { nextConfigPath, packageObj } = args;
|
265
|
+
if (nextConfigPath.endsWith('.ts')) {
|
266
|
+
return 'ts';
|
267
|
+
}
|
228
268
|
if (nextConfigPath.endsWith('.mjs')) {
|
229
269
|
return 'esm';
|
230
270
|
}
|
@@ -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 { 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","getProjectType","packageJsonType","type"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAI;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 = {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n} & Pick<CliArgs, '--debug'>\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 = await 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\nasync function installAndConfigurePayload(\n args: {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n } & InitNextArgs,\n): Promise<\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false }\n> {\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 await 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 // Match next.config.js, next.config.ts, next.config.mjs, next.config.cjs\n const nextConfigPath: string | undefined = (\n await globby('next.config.(\\\\w)?(t|j)s', { absolute: true, cwd: projectDir })\n )?.[0]\n\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath: undefined,\n nextVersion: null,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n // Check if Next.js version is new enough\n let nextVersion = null\n if (packageObj.dependencies?.next) {\n nextVersion = packageObj.dependencies.next\n // Match versions using regex matching groups\n const versionMatch = /(?<major>\\d+)/.exec(nextVersion)\n if (!versionMatch) {\n p.log.warn(`Could not determine Next.js version from ${nextVersion}`)\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n\n const { major } = versionMatch.groups as { major: string }\n const majorVersion = parseInt(major)\n if (majorVersion < 15) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n isSupportedNextVersion: false,\n nextConfigPath,\n nextVersion,\n }\n }\n }\n\n const isSupportedNextVersion = true\n\n // Check if Payload already installed\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n isSupportedNextVersion,\n nextConfigPath,\n nextVersion,\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 {\n hasTopLevelLayout,\n isSrcDir,\n isSupportedNextVersion,\n nextAppDir,\n nextConfigPath,\n nextConfigType: configType,\n nextVersion,\n }\n}\n\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): NextConfigType {\n const { nextConfigPath, packageObj } = args\n\n if (nextConfigPath.endsWith('.ts')) {\n return 'ts'\n }\n\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","isSupportedNextVersion","undefined","nextVersion","packageObj","readJson","dependencies","next","versionMatch","exec","major","groups","majorVersion","parseInt","payload","ignore","onlyDirectories","configType","getProjectType","packageJsonType","type"],"mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAE/C,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAIhC,SAASC,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,SAASC,SAAS,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,cAAc,QAAQ,wBAAuB;AAEtD,MAAMC,WAAWR,UAAUL,GAAGa,QAAQ;AACtC,MAAMC,YAAYT,UAAUL,GAAGc,SAAS;AAExC,MAAMC,WAAWZ,cAAc,YAAYa,GAAG;AAC9C,MAAMC,UAAUb,KAAKa,OAAO,CAACF;AAmB7B,OAAO,eAAeG,SAASC,IAAkB;IAC/C,MAAM,EAAEC,QAAQA,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGH;IAEvD,MAAMI,iBAAiBJ,KAAKI,cAAc,IAAK,MAAMC,kBAAkBF;IAEvE,IAAI,CAACC,eAAeE,UAAU,EAAE;QAC9BhB,QAAQ,CAAC,gCAAgC,EAAEa,WAA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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"],"
|
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"],"
|
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"],"
|
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"}
|
@@ -1 +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;
|
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;AAqCD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAI/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"}
|
package/dist/lib/replacements.js
CHANGED
@@ -19,9 +19,21 @@ const postgresReplacement = {
|
|
19
19
|
importReplacement: "import { postgresAdapter } from '@payloadcms/db-postgres'",
|
20
20
|
packageName: '@payloadcms/db-postgres'
|
21
21
|
};
|
22
|
+
const sqliteReplacement = {
|
23
|
+
configReplacement: (envName = 'DATABASE_URI')=>[
|
24
|
+
' db: sqliteAdapter({',
|
25
|
+
' client: {',
|
26
|
+
` url: process.env.${envName} || '',`,
|
27
|
+
' },',
|
28
|
+
' }),'
|
29
|
+
],
|
30
|
+
importReplacement: "import { sqliteAdapter } from '@payloadcms/db-sqlite'",
|
31
|
+
packageName: '@payloadcms/db-sqlite'
|
32
|
+
};
|
22
33
|
export const dbReplacements = {
|
23
34
|
mongodb: mongodbReplacement,
|
24
|
-
postgres: postgresReplacement
|
35
|
+
postgres: postgresReplacement,
|
36
|
+
sqlite: sqliteReplacement
|
25
37
|
};
|
26
38
|
const vercelBlobStorageReplacement = {
|
27
39
|
// Replacement of `// storage-adapter-placeholder`
|
@@ -45,7 +57,8 @@ const payloadCloudReplacement = {
|
|
45
57
|
};
|
46
58
|
// Removes placeholders
|
47
59
|
const diskReplacement = {
|
48
|
-
configReplacement: []
|
60
|
+
configReplacement: [],
|
61
|
+
importReplacement: ''
|
49
62
|
};
|
50
63
|
export const storageReplacements = {
|
51
64
|
localDisk: diskReplacement,
|