create-payload-app 3.0.0-canary.8223f17 → 3.0.0-canary.926cbeb

Sign up to get free protection for your applications and to get access to all the features.
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"],"rangeMappings":";;;;;;;;;;","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"}
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"}
@@ -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 !== 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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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;QAChB;IACF;IAEA,sBAAsB;IACtB,MAAMC,kBACJ,gBAAgBF,KAAKG,sBAAsB,IAC3CR,KAAKS,OAAO,CAACJ,KAAKG,sBAAsB,CAACE,UAAU,EAAE;IAEvD,IAAIH,mBAAmBT,IAAIa,UAAU,CAACJ,kBAAkB;QACtD,IAAI;YACF,MAAMK,aAAa,MAAMd,IAAIe,QAAQ,CAACN;YAEtC,MAAMO,YAAYZ,cAAc,CAACG,KAAKC,MAAM,CAAC;YAE7C,+BAA+B;YAC/BS,OAAOC,MAAM,CAACd,gBAAgBe,OAAO,CAAC,CAACC;gBACrC,IAAIA,EAAEC,WAAW,KAAKL,UAAUK,WAAW,EAAE;oBAC3C,OAAOP,WAAWQ,YAAY,CAACF,EAAEC,WAAW,CAAC;gBAC/C;YACF;YAEA,qDAAqD;YACrDP,WAAWQ,YAAY,CAACN,UAAUK,WAAW,CAAC,GAAGP,WAAWQ,YAAY,CAAC,UAAU;YAEnF,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AAG;QACxC,OAAOd;IACT;IAEAA,MAAMe,MAAM,CAACL,YAAYI,WAAWJ,aAAa,MAAMT;IACvD,OAAOD;AACT"}
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;QAChB;IACF;IAEA,sBAAsB;IACtB,MAAMC,kBACJ,gBAAgBF,KAAKG,sBAAsB,IAC3CR,KAAKS,OAAO,CAACJ,KAAKG,sBAAsB,CAACE,UAAU,EAAE;IAEvD,IAAIH,mBAAmBT,IAAIa,UAAU,CAACJ,kBAAkB;QACtD,IAAI;YACF,MAAMK,aAAa,MAAMd,IAAIe,QAAQ,CAACN;YAEtC,MAAMO,YAAYZ,cAAc,CAACG,KAAKC,MAAM,CAAC;YAE7C,+BAA+B;YAC/BS,OAAOC,MAAM,CAACd,gBAAgBe,OAAO,CAAC,CAACC;gBACrC,IAAIA,EAAEC,WAAW,KAAK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AaV,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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,UAAU,CAACD;IACxC,IAAI,CAACC,YAAY;QACf,MAAMd,IAAIe,KAAK,CAACF;IAClB;AACF;AAEA,eAAeG,YAAYC,IAI1B;IACC,MAAM,EAAEC,OAAO,EAAEC,cAAc,EAAEN,UAAU,EAAE,GAAGI;IAChD,IAAIC,OAAO,CAAC,YAAY,EAAE;QACxB,OAAO;IACT;IACA,IAAIE,aAAa;IAEjB,IAAID,mBAAmB,QAAQ;QAC7BC,aAAa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QX,OAAO,CAAC;IAChB,MAAMlB,uBAAuB;QAC3BgC,QAAQZ,WAAWa;QACnBC,wBAAwB;YAAE7B;QAAW;IACvC;IAEA,gEAAgE;IAChE,MAAM8B,WAAWzC,KAAKqB,OAAO,CAACV,YAAY;IAC1C,IAAIb,IAAI4C,UAAU,CAACD,WAAW;QAC5B,MAAM3C,IAAI6C,MAAM,CAACF;IACnB;IAEA,IAAI,CAACzB,OAAO,CAAC,YAAY,EAAE;QACzBZ,KAAK,CAAC,MAAM,EAAEa,eAAe,GAAG,CAAC;QACjCkB,QAAQX,OAAO,CAAC;QAChB,MAAMoB,SAAS,MAAM9B,YAAY;YAAEE;YAASC;YAAgBN;QAAW;QACvE,IAAIiC,QAAQ;YACVT,QAAQU,IAAI,CAAC;QACf,OAAO;YACLV,QAAQU,IAAI,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 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,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AAC7B,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 +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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,IAAIoB,UAAU,CAACX,aAAa;YAC9BT,IAAIqB,MAAM,CAACZ,YAAY;gBAAEa,WAAW;YAAK;QAC3C;IACF;IAEAd,SAAS,kBAAkB;QACzB,yEAAyE;QACzE,MAAMe,OAAO;YACXC,GAAG;gBAAC;aAAe;YACnB,QAAQ;YACR,oBAAoB;YACpB,aAAa;QACf;QACA,MAAMC,iBAA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jEC,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 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,IAAIoB,UAAU,CAACX,aAAa;YAC9BT,IAAIqB,MAAM,CAACZ,YAAY;gBAAEa,WAAW;YAAK;QAC3C;IACF;IAEAd,SAAS,kBAAkB;QACzB,yEAAyE;QACzE,MAAMe,OAAO;YACXC,GAAG;gBAAC;aAAe;YACnB,QAAQ;YACR,oBAAoB;YACpB,aAAa;QACf;QACA,MAAMC,iBAAiB;QAEvBC,GAAG,2BAA2B;YAC5B,MAAMC,cAAc;YACpB,MAAMC,WAA4B;gBACh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CqD,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 +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"],"rangeMappings":";;;","mappings":"AAAA,SAASA,WAAW,QAAQ,SAAQ;AAEpC,OAAO,SAASC;IACd,OAAOD,YAAY,IAAIE,QAAQ,CAAC,OAAOC,KAAK,CAAC,GAAG;AAClD"}
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,"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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","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 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 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,WAAW,aA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,YAAY,iBACvC;IAEJ,OAAO;QAAEM;QAAmBH;QAAUH;QAAYgC;QAAgBxB,gBAAgB6C;IAAW;AAC/F;AAEA,SAASC,eAAe5D,IAGvB;IACC,MAAM,EAAEsC,cAAc,EAAEe,UAAU,EAAE,GAAGrD;IACvC,IAAIsC,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IACA,IAAIJ,eAAeI,QAAQ,CAAC,SAAS;QACnC,OAAO;IACT;IAEA,MAAMmB,kBAAkBR,WAAWS,IAAI;IACvC,IAAID,oBAAoB,UAAU;QAChC,OAAO;IACT;IACA,IAAIA,oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport fse from 'fs-extra'\nimport globby from 'globby'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nimport { promisify } from 'util'\n\nimport type { CliArgs, DbType, NextAppDetails, NextConfigType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { installPackages } from './install-packages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\ntype InitNextArgs = Pick<CliArgs, '--debug'> & {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n}\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDetails.nextAppDir) {\n warning(`Could not find app directory in ${projectDir}, creating...`)\n const createdAppDir = path.resolve(projectDir, nextAppDetails.isSrcDir ? 'src/app' : 'app')\n fse.mkdirSync(createdAppDir, { recursive: true })\n nextAppDetails.nextAppDir = createdAppDir\n }\n\n const { hasTopLevelLayout, isPayloadInstalled, isSrcDir, nextAppDir, nextConfigType } =\n nextAppDetails\n\n if (!nextConfigType) {\n return {\n isSrcDir,\n nextAppDir,\n reason: `Could not determine Next Config type in ${projectDir}. Possibly try renaming next.config.js to next.config.cjs or next.config.mjs.`,\n success: false,\n }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = installAndConfigurePayload({\n ...args,\n nextAppDetails,\n nextConfigType,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n\n // Check if tsconfig.json exists\n if (!fs.existsSync(tsConfigPath)) {\n warning(`Could not find tsconfig.json to add @payload-config path.`)\n return\n }\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n\n const hasBaseUrl =\n userTsConfig?.compilerOptions?.baseUrl && userTsConfig?.compilerOptions?.baseUrl !== '.'\n const baseUrl = hasBaseUrl ? userTsConfig?.compilerOptions?.baseUrl : './'\n\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`${baseUrl}${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nfunction installAndConfigurePayload(\n args: InitNextArgs & {\n nextAppDetails: NextAppDetails\n nextConfigType: NextConfigType\n useDistFiles?: boolean\n },\n):\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false } {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n nextConfigType,\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n logDebug(`payloadConfigPath: ${path.resolve(projectDir, 'payload.config.ts')}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n wrapNextConfig({ nextConfigPath, nextConfigType })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = [\n 'payload',\n '@payloadcms/next',\n '@payloadcms/richtext-lexical',\n '@payloadcms/plugin-cloud',\n ].map((pkg) => `${pkg}@beta`)\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@beta`)\n\n // Match graphql version of @payloadcms/next\n packagesToInstall.push('graphql@^16.8.1')\n\n return await installPackages({ packageManager, packagesToInstall, projectDir })\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n const nextConfigPath: string | undefined = (\n await globby('next.config.*js', { absolute: true, cwd: projectDir })\n )?.[0]\n\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n nextConfigPath: undefined,\n }\n }\n\n const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'))\n if (packageObj.dependencies?.payload) {\n return {\n hasTopLevelLayout: false,\n isPayloadInstalled: true,\n isSrcDir,\n nextConfigPath,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n ignore: ['**/node_modules/**'],\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const configType = getProjectType({ nextConfigPath, packageObj })\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigPath, nextConfigType: configType }\n}\n\nfunction getProjectType(args: {\n nextConfigPath: string\n packageObj: Record<string, unknown>\n}): 'cjs' | 'esm' {\n const { nextConfigPath, packageObj } = args\n if (nextConfigPath.endsWith('.mjs')) {\n return 'esm'\n }\n if (nextConfigPath.endsWith('.cjs')) {\n return 'cjs'\n }\n\n const packageJsonType = packageObj.type\n if (packageJsonType === 'module') {\n return 'esm'\n }\n if (packageJsonType === 'commonjs') {\n return 'cjs'\n }\n\n return 'cjs'\n}\n"],"names":["p","parse","stringify","fs","fse","globby","fileURLToPath","path","promisify","copyRecursiveSync","debug","origDebug","warning","moveMessage","installPackages","wrapNextConfig","readFile","writeFile","filename","url","dirname","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","nextAppDir","createdAppDir","resolve","isSrcDir","mkdirSync","recursive","hasTopLevelLayout","isPayloadInstalled","nextConfigType","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","existsSync","userTsConfigContent","encoding","userTsConfig","hasBaseUrl","compilerOptions","baseUrl","paths","nextConfigPath","logDebug","message","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","absolute","cwd","length","undefined","packageObj","readJson","dependencies","payload","ignore","onlyDirectories","configType","getProjectType","packageJsonType","type"],"mappings":"AAE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oBAAoB,YAAY;QAClC,OAAO;IACT;IAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/install-packages.ts"],"sourcesContent":["import execa from 'execa'\n\nimport type { PackageManager } from '../types.js'\n\nimport { error, warning } from '../utils/log.js'\n\nexport async function installPackages(args: {\n packageManager: PackageManager\n packagesToInstall: string[]\n projectDir: string\n}) {\n const { packageManager, packagesToInstall, projectDir } = args\n\n let exitCode = 0\n let stderr = ''\n\n switch (packageManager) {\n case 'npm': {\n ;({ exitCode, stderr } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'yarn':\n case 'pnpm':\n case 'bun': {\n if (packageManager === 'bun') {\n warning('Bun support is untested.')\n }\n ;({ exitCode, stderr } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n }\n\n if (exitCode !== 0) {\n error(`Unable to install packages. Error: ${stderr}`)\n }\n\n return { success: exitCode === 0 }\n}\n"],"names":["execa","error","warning","installPackages","args","packageManager","packagesToInstall","projectDir","exitCode","stderr","cwd","success"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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
+ {"version":3,"sources":["../../src/lib/install-packages.ts"],"sourcesContent":["import execa from 'execa'\n\nimport type { PackageManager } from '../types.js'\n\nimport { error, warning } from '../utils/log.js'\n\nexport async function installPackages(args: {\n packageManager: PackageManager\n packagesToInstall: string[]\n projectDir: string\n}) {\n const { packageManager, packagesToInstall, projectDir } = args\n\n let exitCode = 0\n let stderr = ''\n\n switch (packageManager) {\n case 'npm': {\n ;({ exitCode, stderr } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'yarn':\n case 'pnpm':\n case 'bun': {\n if (packageManager === 'bun') {\n warning('Bun support is untested.')\n }\n ;({ exitCode, stderr } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n }\n\n if (exitCode !== 0) {\n error(`Unable to install packages. Error: ${stderr}`)\n }\n\n return { success: exitCode === 0 }\n}\n"],"names":["execa","error","warning","installPackages","args","packageManager","packagesToInstall","projectDir","exitCode","stderr","cwd","success"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AAIzB,SAASC,KAAK,EAAEC,OAAO,QAAQ,kBAAiB;AAEhD,OAAO,eAAeC,gBAAgBC,IAIrC;IACC,MAAM,EAAEC,cAAc,EAAEC,iBAAiB,EAAEC,UAAU,EAAE,GAAGH;IAE1D,IAAII,WAAW;IACf,IAAIC,SAAS;IAEb,OAAQJ;QACN,KAAK;YAAO;gBACR,CAAA,EAAEG,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMT,MAAM,OAAO;oBAAC;oBAAW;uBAAaM;iBAAkB,EAAE;oBACvFI,KAAKH;gBACP,EAAC;gBACD;YACF;QACA,KAAK;QACL,KAAK;QACL,KAAK;YAAO;gBACV,IAAIF,mBAAmB,OAAO;oBAC5BH,QAAQ;gBACV;gBACE,CAAA,EAAEM,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAMT,MAAMK,gBAAgB;oBAAC;uBAAUC;iBAAkB,EAAE;oBAClFI,KAAKH;gBACP,EAAC;gBACD;YACF;IACF;IAEA,IAAIC,aAAa,GAAG;QAClBP,MAAM,CAAC,mCAAmC,EAAEQ,OAAO,CAAC;IACtD;IAEA,OAAO;QAAEE,SAASH,aAAa;IAAE;AACnC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOF,QAAQE,IAAI,CAAC,SAAS;IACjD,IAAIA,KAAKC,CAAC,CAAC,EAAE,EAAE,OAAOH,QAAQE,KAAKC,CAAC,CAAC,EAAE;IAEvC,MAAMC,cAAc,MAAML,EAAEM,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO,OAAO;QACrB;IACF;IACA,IAAIT,EAAEU,QAAQ,CAACL,cAAc;QAC3BM,QAAQC,IAAI,CAAC;IACf;IACA,OAAOX,QAAQI;AACjB"}
1
+ {"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOF,QAAQE,IAAI,CAAC,SAAS;IACjD,IAAIA,KAAKC,CAAC,CAAC,EAAE,EAAE,OAAOH,QAAQE,KAAKC,CAAC,CAAC,EAAE;IAEvC,MAAMC,cAAc,MAAML,EAAEM,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO,OAAO;QACrB;IACF;IACA,IAAIT,EAAEU,QAAQ,CAACL,cAAc;QAC3BM,QAAQC,IAAI,CAAC;IACf;IACA,OAAOX,QAAQI;AACjB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-template.ts"],"sourcesContent":["import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n args: CliArgs,\n validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n if (args['--template']) {\n const templateName = args['--template']\n const template = validTemplates.find((t) => t.name === templateName)\n if (!template) throw new Error('Invalid template given')\n return template\n }\n\n const response = await p.select<{ label: string; value: string }[], string>({\n message: 'Choose project template',\n options: validTemplates.map((p) => {\n return {\n label: p.name,\n value: p.name,\n }\n }),\n })\n if (p.isCancel(response)) {\n process.exit(0)\n }\n\n const template = validTemplates.find((t) => t.name === response)\n\n return template\n}\n"],"names":["p","parseTemplate","args","validTemplates","templateName","template","find","t","name","Error","response","select","message","options","map","label","value","isCancel","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AAInC,OAAO,eAAeC,cACpBC,IAAa,EACbC,cAAiC;IAEjC,IAAID,IAAI,CAAC,aAAa,EAAE;QACtB,MAAME,eAAeF,IAAI,CAAC,aAAa;QACvC,MAAMG,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QACvD,IAAI,CAACC,UAAU,MAAM,IAAII,MAAM;QAC/B,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMV,EAAEW,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASV,eAAeW,GAAG,CAAC,CAACd;YAC3B,OAAO;gBACLe,OAAOf,EAAEQ,IAAI;gBACbQ,OAAOhB,EAAEQ,IAAI;YACf;QACF;IACF;IACA,IAAIR,EAAEiB,QAAQ,CAACP,WAAW;QACxBQ,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMd,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
1
+ {"version":3,"sources":["../../src/lib/parse-template.ts"],"sourcesContent":["import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n args: CliArgs,\n validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n if (args['--template']) {\n const templateName = args['--template']\n const template = validTemplates.find((t) => t.name === templateName)\n if (!template) throw new Error('Invalid template given')\n return template\n }\n\n const response = await p.select<{ label: string; value: string }[], string>({\n message: 'Choose project template',\n options: validTemplates.map((p) => {\n return {\n label: p.name,\n value: p.name,\n }\n }),\n })\n if (p.isCancel(response)) {\n process.exit(0)\n }\n\n const template = validTemplates.find((t) => t.name === response)\n\n return template\n}\n"],"names":["p","parseTemplate","args","validTemplates","templateName","template","find","t","name","Error","response","select","message","options","map","label","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AAInC,OAAO,eAAeC,cACpBC,IAAa,EACbC,cAAiC;IAEjC,IAAID,IAAI,CAAC,aAAa,EAAE;QACtB,MAAME,eAAeF,IAAI,CAAC,aAAa;QACvC,MAAMG,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QACvD,IAAI,CAACC,UAAU,MAAM,IAAII,MAAM;QAC/B,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMV,EAAEW,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASV,eAAeW,GAAG,CAAC,CAACd;YAC3B,OAAO;gBACLe,OAAOf,EAAEQ,IAAI;gBACbQ,OAAOhB,EAAEQ,IAAI;YACf;QACF;IACF;IACA,IAAIR,EAAEiB,QAAQ,CAACP,WAAW;QACxBQ,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMd,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/replacements.ts"],"sourcesContent":["import type { DbType, StorageAdapterType } from '../types.js'\n\ntype DbAdapterReplacement = {\n configReplacement: (envName?: string) => string[]\n importReplacement: string\n packageName: string\n}\n\nconst mongodbReplacement: DbAdapterReplacement = {\n // Replacement between `// database-adapter-config-start` and `// database-adapter-config-end`\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: mongooseAdapter({',\n ` url: process.env.${envName} || '',`,\n ' }),',\n ],\n importReplacement: \"import { mongooseAdapter } from '@payloadcms/db-mongodb'\",\n packageName: '@payloadcms/db-mongodb',\n}\n\nconst postgresReplacement: DbAdapterReplacement = {\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: postgresAdapter({',\n ' pool: {',\n ` connectionString: process.env.${envName} || '',`,\n ' },',\n ' }),',\n ],\n importReplacement: \"import { postgresAdapter } from '@payloadcms/db-postgres'\",\n packageName: '@payloadcms/db-postgres',\n}\n\nexport const dbReplacements: Record<DbType, DbAdapterReplacement> = {\n mongodb: mongodbReplacement,\n postgres: postgresReplacement,\n}\n\ntype StorageAdapterReplacement = {\n configReplacement: string[]\n importReplacement?: string\n packageName?: string\n}\n\nconst vercelBlobStorageReplacement: StorageAdapterReplacement = {\n // Replacement of `// storage-adapter-placeholder`\n configReplacement: [\n ' vercelBlobStorage({',\n ' collections: {',\n ' [Media.slug]: true,',\n ' },',\n \" token: process.env.BLOB_READ_WRITE_TOKEN || '',\",\n ' }),',\n ],\n importReplacement: \"import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'\",\n packageName: '@payloadcms/storage-vercel-blob',\n}\n\nconst payloadCloudReplacement: StorageAdapterReplacement = {\n configReplacement: [' payloadCloudPlugin(),'],\n importReplacement: \"import { payloadCloudPlugin } from '@payloadcms/plugin-cloud'\",\n packageName: '@payloadcms/plugin-cloud',\n}\n\n// Removes placeholders\nconst diskReplacement: StorageAdapterReplacement = {\n configReplacement: [],\n importReplacement: '',\n}\n\nexport const storageReplacements: Record<StorageAdapterType, StorageAdapterReplacement> = {\n localDisk: diskReplacement,\n payloadCloud: payloadCloudReplacement,\n vercelBlobStorage: vercelBlobStorageReplacement,\n}\n\n/**\n * Generic config replacement\n */\ntype ConfigReplacement = {\n configReplacement: {\n match: string\n replacement: string\n }\n importReplacement: string\n packageName: string\n}\n\nexport const configReplacements: Record<string, ConfigReplacement> = {\n sharp: {\n // Replacement of `sharp, // Now optional`\n configReplacement: {\n match: 'sharp,',\n replacement: ' // sharp,',\n },\n importReplacement: \"import sharp from 'sharp'\",\n packageName: 'sharp',\n },\n}\n"],"names":["mongodbReplacement","configReplacement","envName","importReplacement","packageName","postgresReplacement","dbReplacements","mongodb","postgres","vercelBlobStorageReplacement","payloadCloudReplacement","diskReplacement","storageReplacements","localDisk","payloadCloud","vercelBlobStorage","configReplacements","sharp","match","replacement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,MAAMA,qBAA2C;IAC/C,8FAA8F;IAC9FC,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA,CAAC,qBAAqB,EAAEA,QAAQ,OAAO,CAAC;YACxC;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMC,sBAA4C;IAChDJ,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA;YACA,CAAC,oCAAoC,EAAEA,QAAQ,OAAO,CAAC;YACvD;YACA;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,OAAO,MAAME,iBAAuD;IAClEC,SAASP;IACTQ,UAAUH;AACZ,EAAC;AAQD,MAAMI,+BAA0D;IAC9D,kDAAkD;IAClDR,mBAAmB;QACjB;QACA;QACA;QACA;QACA;QACA;KACD;IACDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMM,0BAAqD;IACzDT,mBAAmB;QAAC;KAA4B;IAChDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,uBAAuB;AACvB,MAAMO,kBAA6C;IACjDV,mBAAmB,EAAE;IACrBE,mBAAmB;AACrB;AAEA,OAAO,MAAMS,sBAA6E;IACxFC,WAAWF;IACXG,cAAcJ;IACdK,mBAAmBN;AACrB,EAAC;AAcD,OAAO,MAAMO,qBAAwD;IACnEC,OAAO;QACL,0CAA0C;QAC1ChB,mBAAmB;YACjBiB,OAAO;YACPC,aAAa;QACf;QACAhB,mBAAmB;QACnBC,aAAa;IACf;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/lib/replacements.ts"],"sourcesContent":["import type { DbType, StorageAdapterType } from '../types.js'\n\ntype DbAdapterReplacement = {\n configReplacement: (envName?: string) => string[]\n importReplacement: string\n packageName: string\n}\n\nconst mongodbReplacement: DbAdapterReplacement = {\n // Replacement between `// database-adapter-config-start` and `// database-adapter-config-end`\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: mongooseAdapter({',\n ` url: process.env.${envName} || '',`,\n ' }),',\n ],\n importReplacement: \"import { mongooseAdapter } from '@payloadcms/db-mongodb'\",\n packageName: '@payloadcms/db-mongodb',\n}\n\nconst postgresReplacement: DbAdapterReplacement = {\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: postgresAdapter({',\n ' pool: {',\n ` connectionString: process.env.${envName} || '',`,\n ' },',\n ' }),',\n ],\n importReplacement: \"import { postgresAdapter } from '@payloadcms/db-postgres'\",\n packageName: '@payloadcms/db-postgres',\n}\n\nexport const dbReplacements: Record<DbType, DbAdapterReplacement> = {\n mongodb: mongodbReplacement,\n postgres: postgresReplacement,\n}\n\ntype StorageAdapterReplacement = {\n configReplacement: string[]\n importReplacement?: string\n packageName?: string\n}\n\nconst vercelBlobStorageReplacement: StorageAdapterReplacement = {\n // Replacement of `// storage-adapter-placeholder`\n configReplacement: [\n ' vercelBlobStorage({',\n ' collections: {',\n ' [Media.slug]: true,',\n ' },',\n \" token: process.env.BLOB_READ_WRITE_TOKEN || '',\",\n ' }),',\n ],\n importReplacement: \"import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'\",\n packageName: '@payloadcms/storage-vercel-blob',\n}\n\nconst payloadCloudReplacement: StorageAdapterReplacement = {\n configReplacement: [' payloadCloudPlugin(),'],\n importReplacement: \"import { payloadCloudPlugin } from '@payloadcms/plugin-cloud'\",\n packageName: '@payloadcms/plugin-cloud',\n}\n\n// Removes placeholders\nconst diskReplacement: StorageAdapterReplacement = {\n configReplacement: [],\n importReplacement: '',\n}\n\nexport const storageReplacements: Record<StorageAdapterType, StorageAdapterReplacement> = {\n localDisk: diskReplacement,\n payloadCloud: payloadCloudReplacement,\n vercelBlobStorage: vercelBlobStorageReplacement,\n}\n\n/**\n * Generic config replacement\n */\ntype ConfigReplacement = {\n configReplacement: {\n match: string\n replacement: string\n }\n importReplacement: string\n packageName: string\n}\n\nexport const configReplacements: Record<string, ConfigReplacement> = {\n sharp: {\n // Replacement of `sharp, // Now optional`\n configReplacement: {\n match: 'sharp,',\n replacement: ' // sharp,',\n },\n importReplacement: \"import sharp from 'sharp'\",\n packageName: 'sharp',\n },\n}\n"],"names":["mongodbReplacement","configReplacement","envName","importReplacement","packageName","postgresReplacement","dbReplacements","mongodb","postgres","vercelBlobStorageReplacement","payloadCloudReplacement","diskReplacement","storageReplacements","localDisk","payloadCloud","vercelBlobStorage","configReplacements","sharp","match","replacement"],"mappings":"AAQA,MAAMA,qBAA2C;IAC/C,8FAA8F;IAC9FC,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA,CAAC,qBAAqB,EAAEA,QAAQ,OAAO,CAAC;YACxC;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMC,sBAA4C;IAChDJ,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA;YACA,CAAC,oCAAoC,EAAEA,QAAQ,OAAO,CAAC;YACvD;YACA;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,OAAO,MAAME,iBAAuD;IAClEC,SAASP;IACTQ,UAAUH;AACZ,EAAC;AAQD,MAAMI,+BAA0D;IAC9D,kDAAkD;IAClDR,mBAAmB;QACjB;QACA;QACA;QACA;QACA;QACA;KACD;IACDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMM,0BAAqD;IACzDT,mBAAmB;QAAC;KAA4B;IAChDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,uBAAuB;AACvB,MAAMO,kBAA6C;IACjDV,mBAAmB,EAAE;IACrBE,mBAAmB;AACrB;AAEA,OAAO,MAAMS,sBAA6E;IACxFC,WAAWF;IACXG,cAAcJ;IACdK,mBAAmBN;AACrB,EAAC;AAcD,OAAO,MAAMO,qBAAwD;IACnEC,OAAO;QACL,0CAA0C;QAC1ChB,mBAAmB;YACjBiB,OAAO;YACPC,aAAa;QACf;QACAhB,mBAAmB;QACnBC,aAAa;IACf;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/select-db.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs, DbDetails, DbType } from '../types.js'\n\ntype DbChoice = {\n dbConnectionPrefix: `${string}/`\n title: string\n value: DbType\n}\n\nconst dbChoiceRecord: Record<DbType, DbChoice> = {\n mongodb: {\n dbConnectionPrefix: 'mongodb://127.0.0.1/',\n title: 'MongoDB',\n value: 'mongodb',\n },\n postgres: {\n dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',\n title: 'PostgreSQL (beta)',\n value: 'postgres',\n },\n}\n\nexport async function selectDb(args: CliArgs, projectName: string): Promise<DbDetails> {\n let dbType: DbType | symbol | undefined = undefined\n if (args['--db']) {\n if (!Object.values(dbChoiceRecord).some((dbChoice) => dbChoice.value === args['--db'])) {\n throw new Error(\n `Invalid database type given. Valid types are: ${Object.values(dbChoiceRecord)\n .map((dbChoice) => dbChoice.value)\n .join(', ')}`,\n )\n }\n dbType = args['--db'] as DbType\n } else {\n dbType = await p.select<{ label: string; value: DbType }[], DbType>({\n initialValue: 'mongodb',\n message: `Select a database`,\n options: [\n { label: 'MongoDB', value: 'mongodb' },\n { label: 'Postgres', value: 'postgres' },\n ],\n })\n if (p.isCancel(dbType)) process.exit(0)\n }\n\n const dbChoice = dbChoiceRecord[dbType]\n\n let dbUri: string | symbol | undefined = undefined\n const initialDbUri = `${dbChoice.dbConnectionPrefix}${\n projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)\n }`\n\n if (args['--db-accept-recommended']) {\n dbUri = initialDbUri\n } else if (args['--db-connection-string']) {\n dbUri = args['--db-connection-string']\n } else {\n dbUri = await p.text({\n initialValue: initialDbUri,\n message: `Enter ${dbChoice.title.split(' ')[0]} connection string`, // strip beta from title\n })\n if (p.isCancel(dbUri)) process.exit(0)\n }\n\n return {\n type: dbChoice.value,\n dbUri,\n }\n}\n\nfunction getRandomDigitSuffix(): string {\n return (Math.random() * Math.pow(10, 6)).toFixed(0)\n}\n"],"names":["p","slugify","dbChoiceRecord","mongodb","dbConnectionPrefix","title","value","postgres","selectDb","args","projectName","dbType","undefined","Object","values","some","dbChoice","Error","map","join","select","initialValue","message","options","label","isCancel","process","exit","dbUri","initialDbUri","getRandomDigitSuffix","text","split","type","Math","random","pow","toFixed"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAU3C,MAAMC,iBAA2C;IAC/CC,SAAS;QACPC,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;IACAC,UAAU;QACRH,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;AACF;AAEA,OAAO,eAAeE,SAASC,IAAa,EAAEC,WAAmB;IAC/D,IAAIC,SAAsCC;IAC1C,IAAIH,IAAI,CAAC,OAAO,EAAE;QAChB,IAAI,CAACI,OAAOC,MAAM,CAACZ,gBAAgBa,IAAI,CAAC,CAACC,WAAaA,SAASV,KAAK,KAAKG,IAAI,CAAC,OAAO,GAAG;YACtF,MAAM,IAAIQ,MACR,CAAC,8CAA8C,EAAEJ,OAAOC,MAAM,CAACZ,gBAC5DgB,GAAG,CAAC,CAACF,WAAaA,SAASV,KAAK,EAChCa,IAAI,CAAC,MAAM,CAAC;QAEnB;QACAR,SAASF,IAAI,CAAC,OAAO;IACvB,OAAO;QACLE,SAAS,MAAMX,EAAEoB,MAAM,CAA6C;YAClEC,cAAc;YACdC,SAAS,CAAC,iBAAiB,CAAC;YAC5BC,SAAS;gBACP;oBAAEC,OAAO;oBAAWlB,OAAO;gBAAU;gBACrC;oBAAEkB,OAAO;oBAAYlB,OAAO;gBAAW;aACxC;QACH;QACA,IAAIN,EAAEyB,QAAQ,CAACd,SAASe,QAAQC,IAAI,CAAC;IACvC;IAEA,MAAMX,WAAWd,cAAc,CAACS,OAAO;IAEvC,IAAIiB,QAAqChB;IACzC,MAAMiB,eAAe,CAAC,EAAEb,SAASZ,kBAAkB,CAAC,EAClDM,gBAAgB,MAAM,CAAC,QAAQ,EAAEoB,uBAAuB,CAAC,GAAG7B,QAAQS,aACrE,CAAC;IAEF,IAAID,IAAI,CAAC,0BAA0B,EAAE;QACnCmB,QAAQC;IACV,OAAO,IAAIpB,IAAI,CAAC,yBAAyB,EAAE;QACzCmB,QAAQnB,IAAI,CAAC,yBAAyB;IACxC,OAAO;QACLmB,QAAQ,MAAM5B,EAAE+B,IAAI,CAAC;YACnBV,cAAcQ;YACdP,SAAS,CAAC,MAAM,EAAEN,SAASX,KAAK,CAAC2B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC;QACpE;QACA,IAAIhC,EAAEyB,QAAQ,CAACG,QAAQF,QAAQC,IAAI,CAAC;IACtC;IAEA,OAAO;QACLM,MAAMjB,SAASV,KAAK;QACpBsB;IACF;AACF;AAEA,SAASE;IACP,OAAO,AAACI,CAAAA,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAAC,IAAI,EAAC,EAAGC,OAAO,CAAC;AACnD"}
1
+ {"version":3,"sources":["../../src/lib/select-db.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs, DbDetails, DbType } from '../types.js'\n\ntype DbChoice = {\n dbConnectionPrefix: `${string}/`\n title: string\n value: DbType\n}\n\nconst dbChoiceRecord: Record<DbType, DbChoice> = {\n mongodb: {\n dbConnectionPrefix: 'mongodb://127.0.0.1/',\n title: 'MongoDB',\n value: 'mongodb',\n },\n postgres: {\n dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',\n title: 'PostgreSQL (beta)',\n value: 'postgres',\n },\n}\n\nexport async function selectDb(args: CliArgs, projectName: string): Promise<DbDetails> {\n let dbType: DbType | symbol | undefined = undefined\n if (args['--db']) {\n if (!Object.values(dbChoiceRecord).some((dbChoice) => dbChoice.value === args['--db'])) {\n throw new Error(\n `Invalid database type given. Valid types are: ${Object.values(dbChoiceRecord)\n .map((dbChoice) => dbChoice.value)\n .join(', ')}`,\n )\n }\n dbType = args['--db'] as DbType\n } else {\n dbType = await p.select<{ label: string; value: DbType }[], DbType>({\n initialValue: 'mongodb',\n message: `Select a database`,\n options: [\n { label: 'MongoDB', value: 'mongodb' },\n { label: 'Postgres', value: 'postgres' },\n ],\n })\n if (p.isCancel(dbType)) process.exit(0)\n }\n\n const dbChoice = dbChoiceRecord[dbType]\n\n let dbUri: string | symbol | undefined = undefined\n const initialDbUri = `${dbChoice.dbConnectionPrefix}${\n projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)\n }`\n\n if (args['--db-accept-recommended']) {\n dbUri = initialDbUri\n } else if (args['--db-connection-string']) {\n dbUri = args['--db-connection-string']\n } else {\n dbUri = await p.text({\n initialValue: initialDbUri,\n message: `Enter ${dbChoice.title.split(' ')[0]} connection string`, // strip beta from title\n })\n if (p.isCancel(dbUri)) process.exit(0)\n }\n\n return {\n type: dbChoice.value,\n dbUri,\n }\n}\n\nfunction getRandomDigitSuffix(): string {\n return (Math.random() * Math.pow(10, 6)).toFixed(0)\n}\n"],"names":["p","slugify","dbChoiceRecord","mongodb","dbConnectionPrefix","title","value","postgres","selectDb","args","projectName","dbType","undefined","Object","values","some","dbChoice","Error","map","join","select","initialValue","message","options","label","isCancel","process","exit","dbUri","initialDbUri","getRandomDigitSuffix","text","split","type","Math","random","pow","toFixed"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAU3C,MAAMC,iBAA2C;IAC/CC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AM,EAAEN,SAASX,KAAK,CAAC2B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC;QACpE;QACA,IAAIhC,EAAEyB,QAAQ,CAACG,QAAQF,QAAQC,IAAI,CAAC;IACtC;IAEA,OAAO;QACLM,MAAMjB,SAASV,KAAK;QACpBsB;IACF;AACF;AAEA,SAASE;IACP,OAAO,AAACI,CAAAA,KAAKC,MAAM,KAAKD,KAAKE,GAAG,CAAC,IAAI,EAAC,EAAGC,OAAO,CAAC;AACnD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\n\nexport function validateTemplate(templateName: string): boolean {\n const validTemplates = getValidTemplates()\n if (!validTemplates.map((t) => t.name).includes(templateName)) {\n error(`'${templateName}' is not a valid template.`)\n info(`Valid templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n return false\n }\n return true\n}\n\nexport function getValidTemplates(): ProjectTemplate[] {\n return [\n {\n name: 'blank',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'website',\n // type: 'starter',\n // description: 'Website Template',\n // url: 'https://github.com/payloadcms/payload/templates/website',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n // {\n // name: 'plugin',\n // type: 'plugin',\n // description: 'Template for creating a Payload plugin',\n // url: 'https://github.com/payloadcms/payload-plugin-template#beta',\n // },\n // {\n // name: 'payload-demo',\n // type: 'starter',\n // description: 'Payload demo site at https://demo.payloadcms.com',\n // url: 'https://github.com/payloadcms/public-demo',\n // },\n // {\n // name: 'payload-website',\n // type: 'starter',\n // description: 'Payload website CMS at https://payloadcms.com',\n // url: 'https://github.com/payloadcms/website-cms',\n // },\n ]\n}\n"],"names":["error","info","validateTemplate","templateName","validTemplates","getValidTemplates","map","t","name","includes","join","type","description","url"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,KAAK,EAAEC,IAAI,QAAQ,kBAAiB;AAE7C,OAAO,SAASC,iBAAiBC,YAAoB;IACnD,MAAMC,iBAAiBC;IACvB,IAAI,CAACD,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,QAAQ,CAACN,eAAe;QAC7DH,MAAM,CAAC,CAAC,EAAEG,aAAa,0BAA0B,CAAC;QAClDF,KAAK,CAAC,iBAAiB,EAAEG,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEE,IAAI,CAAC,MAAM,CAAC;QACvE,OAAO;IACT;IACA,OAAO;AACT;AAEA,OAAO,SAASL;IACd,OAAO;QACL;YACEG,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;KAwCD;AACH"}
1
+ {"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\n\nexport function validateTemplate(templateName: string): boolean {\n const validTemplates = getValidTemplates()\n if (!validTemplates.map((t) => t.name).includes(templateName)) {\n error(`'${templateName}' is not a valid template.`)\n info(`Valid templates: ${validTemplates.map((t) => t.name).join(', ')}`)\n return false\n }\n return true\n}\n\nexport function getValidTemplates(): ProjectTemplate[] {\n return [\n {\n name: 'blank',\n type: 'starter',\n description: 'Blank 3.0 Template',\n url: 'https://github.com/payloadcms/payload/templates/blank-3.0#beta',\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'website',\n // type: 'starter',\n // description: 'Website Template',\n // url: 'https://github.com/payloadcms/payload/templates/website',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n // {\n // name: 'plugin',\n // type: 'plugin',\n // description: 'Template for creating a Payload plugin',\n // url: 'https://github.com/payloadcms/payload-plugin-template#beta',\n // },\n // {\n // name: 'payload-demo',\n // type: 'starter',\n // description: 'Payload demo site at https://demo.payloadcms.com',\n // url: 'https://github.com/payloadcms/public-demo',\n // },\n // {\n // name: 'payload-website',\n // type: 'starter',\n // description: 'Payload website CMS at https://payloadcms.com',\n // url: 'https://github.com/payloadcms/website-cms',\n // },\n ]\n}\n"],"names":["error","info","validateTemplate","templateName","validTemplates","getValidTemplates","map","t","name","includes","join","type","description","url"],"mappings":"AAEA,SAASA,KAAK,EAAEC,IAAI,QAAQ,kBAAiB;AAE7C,OAAO,SAASC,iBAAiBC,YAAoB;IACnD,MAAMC,iBAAiBC;IACvB,IAAI,CAACD,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,QAAQ,CAACN,eAAe;QAC7DH,MAAM,CAAC,CAAC,EAAEG,aAAa,0BAA0B,CAAC;QAClDF,KAAK,CAAC,iBAAiB,EAAEG,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEE,IAAI,CAAC,MAAM,CAAC;QACvE,OAAO;IACT;IACA,OAAO;AACT;AAEA,OAAO,SAASL;IACd,OAAO;QACL;YACEG,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK;QACP;KAwCD;AACH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/update-payload-in-project.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport type { NextAppDetails } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { info } from '../utils/log.js'\nimport { getPackageManager } from './get-package-manager.js'\nimport { installPackages } from './install-packages.js'\n\nexport async function updatePayloadInProject(\n appDetails: NextAppDetails,\n): Promise<{ message: string; success: boolean }> {\n if (!appDetails.nextConfigPath) return { message: 'No Next.js config found', success: false }\n\n const projectDir = path.dirname(appDetails.nextConfigPath)\n\n const packageObj = (await fse.readJson(path.resolve(projectDir, 'package.json'))) as {\n dependencies?: Record<string, string>\n }\n if (!packageObj?.dependencies) {\n throw new Error('No package.json found in this project')\n }\n\n const payloadVersion = packageObj.dependencies?.payload\n if (!payloadVersion) {\n throw new Error('Payload is not installed in this project')\n }\n\n const packageManager = await getPackageManager({ projectDir })\n\n // Fetch latest Payload version from npm\n const { exitCode: getLatestVersionExitCode, stdout: latestPayloadVersion } = await execa('npm', [\n 'show',\n 'payload@beta',\n 'version',\n ])\n if (getLatestVersionExitCode !== 0) {\n throw new Error('Failed to fetch latest Payload version')\n }\n\n if (payloadVersion === latestPayloadVersion) {\n return { message: `Payload v${payloadVersion} is already up to date.`, success: true }\n }\n\n // Update all existing Payload packages\n const payloadPackages = Object.keys(packageObj.dependencies).filter((dep) =>\n dep.startsWith('@payloadcms/'),\n )\n\n const packageNames = ['payload', ...payloadPackages]\n\n const packagesToUpdate = packageNames.map((pkg) => `${pkg}@${latestPayloadVersion}`)\n\n info(`Using ${packageManager}.\\n`)\n info(\n `Updating ${packagesToUpdate.length} Payload packages to v${latestPayloadVersion}...\\n\\n${packageNames.map((p) => ` - ${p}`).join('\\n')}`,\n )\n\n const { success: updateSuccess } = await installPackages({\n packageManager,\n packagesToInstall: packagesToUpdate,\n projectDir,\n })\n\n if (!updateSuccess) {\n throw new Error('Failed to update Payload packages')\n }\n info('Payload packages updated successfully.')\n\n info(`Updating Payload Next.js files...`)\n const templateFilesPath = dirname.endsWith('dist')\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)')\n\n copyRecursiveSync(\n templateSrcDir,\n path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'),\n )\n\n return { message: 'Payload updated successfully.', success: true }\n}\n"],"names":["execa","fse","fileURLToPath","path","filename","url","dirname","copyRecursiveSync","info","getPackageManager","installPackages","updatePayloadInProject","appDetails","nextConfigPath","message","success","projectDir","packageObj","readJson","resolve","dependencies","Error","payloadVersion","payload","packageManager","exitCode","getLatestVersionExitCode","stdout","latestPayloadVersion","payloadPackages","Object","keys","filter","dep","startsWith","packageNames","packagesToUpdate","map","pkg","length","p","join","updateSuccess","packagesToInstall","templateFilesPath","endsWith","templateSrcDir","isSrcDir"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAI7B,SAASG,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,IAAI,QAAQ,kBAAiB;AACtC,SAASC,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,eAAe,QAAQ,wBAAuB;AAEvD,OAAO,eAAeC,uBACpBC,UAA0B;IAE1B,IAAI,CAACA,WAAWC,cAAc,EAAE,OAAO;QAAEC,SAAS;QAA2BC,SAAS;IAAM;IAE5F,MAAMC,aAAab,KAAKG,OAAO,CAACM,WAAWC,cAAc;IAEzD,MAAMI,aAAc,MAAMhB,IAAIiB,QAAQ,CAACf,KAAKgB,OAAO,CAACH,YAAY;IAGhE,IAAI,CAACC,YAAYG,cAAc;QAC7B,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,iBAAiBL,WAAWG,YAAY,EAAEG;IACh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AO,CAACb,SAAS;IAE1B,MAAMwC,iBAAiB3C,KAAKgB,OAAO,CAACyB,mBAAmB;IAEvDrC,kBACEuC,gBACA3C,KAAKgB,OAAO,CAACH,YAAYJ,WAAWmC,QAAQ,GAAG,YAAY,OAAO;IAGpE,OAAO;QAAEjC,SAAS;QAAiCC,SAAS;IAAK;AACnE"}
1
+ {"version":3,"sources":["../../src/lib/update-payload-in-project.ts"],"sourcesContent":["import execa from 'execa'\nimport fse from 'fs-extra'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport type { NextAppDetails } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { info } from '../utils/log.js'\nimport { getPackageManager } from './get-package-manager.js'\nimport { installPackages } from './install-packages.js'\n\nexport async function updatePayloadInProject(\n appDetails: NextAppDetails,\n): Promise<{ message: string; success: boolean }> {\n if (!appDetails.nextConfigPath) return { message: 'No Next.js config found', success: false }\n\n const projectDir = path.dirname(appDetails.nextConfigPath)\n\n const packageObj = (await fse.readJson(path.resolve(projectDir, 'package.json'))) as {\n dependencies?: Record<string, string>\n }\n if (!packageObj?.dependencies) {\n throw new Error('No package.json found in this project')\n }\n\n const payloadVersion = packageObj.dependencies?.payload\n if (!payloadVersion) {\n throw new Error('Payload is not installed in this project')\n }\n\n const packageManager = await getPackageManager({ projectDir })\n\n // Fetch latest Payload version from npm\n const { exitCode: getLatestVersionExitCode, stdout: latestPayloadVersion } = await execa('npm', [\n 'show',\n 'payload@beta',\n 'version',\n ])\n if (getLatestVersionExitCode !== 0) {\n throw new Error('Failed to fetch latest Payload version')\n }\n\n if (payloadVersion === latestPayloadVersion) {\n return { message: `Payload v${payloadVersion} is already up to date.`, success: true }\n }\n\n // Update all existing Payload packages\n const payloadPackages = Object.keys(packageObj.dependencies).filter((dep) =>\n dep.startsWith('@payloadcms/'),\n )\n\n const packageNames = ['payload', ...payloadPackages]\n\n const packagesToUpdate = packageNames.map((pkg) => `${pkg}@${latestPayloadVersion}`)\n\n info(`Using ${packageManager}.\\n`)\n info(\n `Updating ${packagesToUpdate.length} Payload packages to v${latestPayloadVersion}...\\n\\n${packageNames.map((p) => ` - ${p}`).join('\\n')}`,\n )\n\n const { success: updateSuccess } = await installPackages({\n packageManager,\n packagesToInstall: packagesToUpdate,\n projectDir,\n })\n\n if (!updateSuccess) {\n throw new Error('Failed to update Payload packages')\n }\n info('Payload packages updated successfully.')\n\n info(`Updating Payload Next.js files...`)\n const templateFilesPath = dirname.endsWith('dist')\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)')\n\n copyRecursiveSync(\n templateSrcDir,\n path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'),\n )\n\n return { message: 'Payload updated successfully.', success: true }\n}\n"],"names":["execa","fse","fileURLToPath","path","filename","url","dirname","copyRecursiveSync","info","getPackageManager","installPackages","updatePayloadInProject","appDetails","nextConfigPath","message","success","projectDir","packageObj","readJson","resolve","dependencies","Error","payloadVersion","payload","packageManager","exitCode","getLatestVersionExitCode","stdout","latestPayloadVersion","payloadPackages","Object","keys","filter","dep","startsWith","packageNames","packagesToUpdate","map","pkg","length","p","join","updateSuccess","packagesToInstall","templateFilesPath","endsWith","templateSrcDir","isSrcDir"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,SAAS,WAAU;AAC1B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAI7B,SAASG,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,IAAI,QAAQ,kBAAiB;AACtC,SAASC,iBAAiB,QAAQ,2BAA0B;AAC5D,SAASC,eAAe,QAAQ,wBAAuB;AA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E,CAAC,EAAEC,IAAI,CAAC,MAAM,CAAC;IAG5I,MAAM,EAAE1B,SAAS2B,aAAa,EAAE,GAAG,MAAMhC,gBAAgB;QACvDc;QACAmB,mBAAmBP;QACnBpB;IACF;IAEA,IAAI,CAAC0B,eAAe;QAClB,MAAM,IAAIrB,MAAM;IAClB;IACAb,KAAK;IAELA,KAAK,CAAC,iCAAiC,CAAC;IACxC,MAAMoC,oBAAoBtC,QAAQuC,QAAQ,CAAC,UACvC1C,KAAKgB,OAAO,CAACb,SAAS,SAAS,mBAC/BH,KAAKgB,OAAO,CAACb,SAAS;IAE1B,MAAMwC,iBAAiB3C,KAAKgB,OAAO,CAACyB,mBAAmB;IAEvDrC,kBACEuC,gBACA3C,KAAKgB,OAAO,CAACH,YAAYJ,WAAWmC,QAAQ,GAAG,YAAY,OAAO;IAGpE,OAAO;QAAEjC,SAAS;QAAiCC,SAAS;IAAK;AACnE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/wrap-next-config.ts"],"sourcesContent":["import type { Program } from 'esprima-next'\n\nimport chalk from 'chalk'\nimport { Syntax, parseModule } from 'esprima-next'\nimport fs from 'fs'\n\nimport { log, warning } from '../utils/log.js'\n\nexport const withPayloadStatement = {\n cjs: `const { withPayload } = require('@payloadcms/next/withPayload')\\n`,\n esm: `import { withPayload } from '@payloadcms/next/withPayload'\\n`,\n}\n\ntype NextConfigType = 'cjs' | 'esm'\n\nexport const wrapNextConfig = (args: {\n nextConfigPath: string\n nextConfigType: NextConfigType\n}) => {\n const { nextConfigPath, nextConfigType: configType } = args\n const configContent = fs.readFileSync(nextConfigPath, 'utf8')\n const { modifiedConfigContent: newConfig, success } = parseAndModifyConfigContent(\n configContent,\n configType,\n )\n\n if (!success) {\n return\n }\n\n fs.writeFileSync(nextConfigPath, newConfig)\n}\n\n/**\n * Parses config content with AST and wraps it with withPayload function\n */\nexport function parseAndModifyConfigContent(\n content: string,\n configType: NextConfigType,\n): { modifiedConfigContent: string; success: boolean } {\n content = withPayloadStatement[configType] + content\n\n let ast: Program | undefined\n try {\n ast = parseModule(content, { loc: true })\n } catch (error: unknown) {\n if (error instanceof Error) {\n warning(`Unable to parse Next config. Error: ${error.message} `)\n warnUserWrapNotSuccessful(configType)\n }\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n\n if (configType === 'esm') {\n const exportDefaultDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportDefaultDeclaration,\n ) as Directive | undefined\n\n const exportNamedDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportNamedDeclaration,\n ) as ExportNamedDeclaration | undefined\n\n if (!exportDefaultDeclaration && !exportNamedDeclaration) {\n throw new Error('Could not find ExportDefaultDeclaration in next.config.js')\n }\n\n if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n exportDefaultDeclaration.declaration.loc,\n )\n return { modifiedConfigContent, success: true }\n } else if (exportNamedDeclaration) {\n const exportSpecifier = exportNamedDeclaration.specifiers.find(\n (s) =>\n s.type === 'ExportSpecifier' &&\n s.exported?.name === 'default' &&\n s.local?.type === 'Identifier' &&\n s.local?.name,\n )\n\n if (exportSpecifier) {\n warning('Could not automatically wrap next.config.js with withPayload.')\n warning('Automatic wrapping of named exports as default not supported yet.')\n\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n } else if (configType === 'cjs') {\n // Find `module.exports = X`\n const moduleExports = ast.body.find(\n (p) =>\n p.type === Syntax.ExpressionStatement &&\n p.expression?.type === Syntax.AssignmentExpression &&\n p.expression.left?.type === Syntax.MemberExpression &&\n p.expression.left.object?.type === Syntax.Identifier &&\n p.expression.left.object.name === 'module' &&\n p.expression.left.property?.type === Syntax.Identifier &&\n p.expression.left.property.name === 'exports',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any\n\n if (moduleExports && moduleExports.expression.right?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n moduleExports.expression.right.loc,\n )\n return { modifiedConfigContent, success: true }\n }\n\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n}\n\nfunction warnUserWrapNotSuccessful(configType: NextConfigType) {\n // Output directions for user to update next.config.js\n const withPayloadMessage = `\n\n ${chalk.bold(`Please manually wrap your existing next.config.js with the withPayload function. Here is an example:`)}\n\n ${withPayloadStatement[configType]}\n\n const nextConfig = {\n // Your Next.js config here\n }\n\n ${configType === 'esm' ? 'export default withPayload(nextConfig)' : 'module.exports = withPayload(nextConfig)'}\n\n`\n\n log(withPayloadMessage)\n}\n\ntype Directive = {\n declaration?: {\n loc: Loc\n }\n}\n\ntype ExportNamedDeclaration = {\n declaration: null\n loc: Loc\n specifiers: {\n exported: {\n loc: Loc\n name: string\n type: string\n }\n loc: Loc\n local: {\n loc: Loc\n name: string\n type: string\n }\n type: string\n }[]\n type: string\n}\n\ntype Loc = {\n end: { column: number; line: number }\n start: { column: number; line: number }\n}\n\nfunction insertBeforeAndAfter(content: string, loc: Loc) {\n const { end, start } = loc\n const lines = content.split('\\n')\n\n const insert = (line: string, column: number, text: string) => {\n return line.slice(0, column) + text + line.slice(column)\n }\n\n // insert ) after end\n lines[end.line - 1] = insert(lines[end.line - 1], end.column, ')')\n // insert withPayload before start\n if (start.line === end.line) {\n lines[end.line - 1] = insert(lines[end.line - 1], start.column, 'withPayload(')\n } else {\n lines[start.line - 1] = insert(lines[start.line - 1], start.column, 'withPayload(')\n }\n\n return lines.join('\\n')\n}\n"],"names":["chalk","Syntax","parseModule","fs","log","warning","withPayloadStatement","cjs","esm","wrapNextConfig","args","nextConfigPath","nextConfigType","configType","configContent","readFileSync","modifiedConfigContent","newConfig","success","parseAndModifyConfigContent","writeFileSync","content","ast","loc","error","Error","message","warnUserWrapNotSuccessful","exportDefaultDeclaration","body","find","p","type","ExportDefaultDeclaration","exportNamedDeclaration","ExportNamedDeclaration","declaration","insertBeforeAndAfter","exportSpecifier","specifiers","s","exported","name","local","moduleExports","ExpressionStatement","expression","AssignmentExpression","left","MemberExpression","object","Identifier","property","right","withPayloadMessage","bold","end","start","lines","split","insert","line","column","text","slice","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,WAAW,QAAO;AACzB,SAASC,MAAM,EAAEC,WAAW,QAAQ,eAAc;AAClD,OAAOC,QAAQ,KAAI;AAEnB,SAASC,GAAG,EAAEC,OAAO,QAAQ,kBAAiB;AAE9C,OAAO,MAAMC,uBAAuB;IAClCC,KAAK,CAAC,iEAAiE,CAAC;IACxEC,KAAK,CAAC,4DAA4D,CAAC;AACrE,EAAC;AAID,OAAO,MAAMC,iBAAiB,CAACC;IAI7B,MAAM,EAAEC,cAAc,EAAEC,gBAAgBC,UAAU,EAAE,GAAGH;IACvD,MAAMI,gBAAgBX,GAAGY,YAAY,CAACJ,gBAAgB;IACtD,MAAM,EAAEK,uBAAuBC,SAAS,EAAEC,OAAO,EAAE,GAAGC,4BACpDL,eACAD;IAGF,IAAI,CAACK,SAAS;QACZ;IACF;IAEAf,GAAGiB,aAAa,CAACT,gBAAgBM;AACnC,EAAC;AAED;;CAEC,GACD,OAAO,SAASE,4BACdE,OAAe,EACfR,UAA0B;IAE1BQ,UAAUf,oBAAoB,CAACO,WAAW,GAAGQ;IAE7C,IAAIC;IACJ,IAAI;QACFA,MAAMpB,YAAYmB,SAAS;YAAEE,KAAK;QAAK;IACzC,EAAE,OAAOC,OAAgB;QACvB,IAAIA,iBAAiBC,OAAO;YAC1BpB,Q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AEA,qBAAqB;IACrBJ,KAAK,CAACF,IAAIK,IAAI,GAAG,EAAE,GAAGD,OAAOF,KAAK,CAACF,IAAIK,IAAI,GAAG,EAAE,EAAEL,IAAIM,MAAM,EAAE;IAC9D,kCAAkC;IAClC,IAAIL,MAAMI,IAAI,KAAKL,IAAIK,IAAI,EAAE;QAC3BH,KAAK,CAACF,IAAIK,IAAI,GAAG,EAAE,GAAGD,OAAOF,KAAK,CAACF,IAAIK,IAAI,GAAG,EAAE,EAAEJ,MAAMK,MAAM,EAAE;IAClE,OAAO;QACLJ,KAAK,CAACD,MAAMI,IAAI,GAAG,EAAE,GAAGD,OAAOF,KAAK,CAACD,MAAMI,IAAI,GAAG,EAAE,EAAEJ,MAAMK,MAAM,EAAE;IACtE;IAEA,OAAOJ,MAAMO,IAAI,CAAC;AACpB"}
1
+ {"version":3,"sources":["../../src/lib/wrap-next-config.ts"],"sourcesContent":["import type { Program } from 'esprima-next'\n\nimport chalk from 'chalk'\nimport { Syntax, parseModule } from 'esprima-next'\nimport fs from 'fs'\n\nimport { log, warning } from '../utils/log.js'\n\nexport const withPayloadStatement = {\n cjs: `const { withPayload } = require('@payloadcms/next/withPayload')\\n`,\n esm: `import { withPayload } from '@payloadcms/next/withPayload'\\n`,\n}\n\ntype NextConfigType = 'cjs' | 'esm'\n\nexport const wrapNextConfig = (args: {\n nextConfigPath: string\n nextConfigType: NextConfigType\n}) => {\n const { nextConfigPath, nextConfigType: configType } = args\n const configContent = fs.readFileSync(nextConfigPath, 'utf8')\n const { modifiedConfigContent: newConfig, success } = parseAndModifyConfigContent(\n configContent,\n configType,\n )\n\n if (!success) {\n return\n }\n\n fs.writeFileSync(nextConfigPath, newConfig)\n}\n\n/**\n * Parses config content with AST and wraps it with withPayload function\n */\nexport function parseAndModifyConfigContent(\n content: string,\n configType: NextConfigType,\n): { modifiedConfigContent: string; success: boolean } {\n content = withPayloadStatement[configType] + content\n\n let ast: Program | undefined\n try {\n ast = parseModule(content, { loc: true })\n } catch (error: unknown) {\n if (error instanceof Error) {\n warning(`Unable to parse Next config. Error: ${error.message} `)\n warnUserWrapNotSuccessful(configType)\n }\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n\n if (configType === 'esm') {\n const exportDefaultDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportDefaultDeclaration,\n ) as Directive | undefined\n\n const exportNamedDeclaration = ast.body.find(\n (p) => p.type === Syntax.ExportNamedDeclaration,\n ) as ExportNamedDeclaration | undefined\n\n if (!exportDefaultDeclaration && !exportNamedDeclaration) {\n throw new Error('Could not find ExportDefaultDeclaration in next.config.js')\n }\n\n if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n exportDefaultDeclaration.declaration.loc,\n )\n return { modifiedConfigContent, success: true }\n } else if (exportNamedDeclaration) {\n const exportSpecifier = exportNamedDeclaration.specifiers.find(\n (s) =>\n s.type === 'ExportSpecifier' &&\n s.exported?.name === 'default' &&\n s.local?.type === 'Identifier' &&\n s.local?.name,\n )\n\n if (exportSpecifier) {\n warning('Could not automatically wrap next.config.js with withPayload.')\n warning('Automatic wrapping of named exports as default not supported yet.')\n\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n } else if (configType === 'cjs') {\n // Find `module.exports = X`\n const moduleExports = ast.body.find(\n (p) =>\n p.type === Syntax.ExpressionStatement &&\n p.expression?.type === Syntax.AssignmentExpression &&\n p.expression.left?.type === Syntax.MemberExpression &&\n p.expression.left.object?.type === Syntax.Identifier &&\n p.expression.left.object.name === 'module' &&\n p.expression.left.property?.type === Syntax.Identifier &&\n p.expression.left.property.name === 'exports',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any\n\n if (moduleExports && moduleExports.expression.right?.loc) {\n const modifiedConfigContent = insertBeforeAndAfter(\n content,\n moduleExports.expression.right.loc,\n )\n return { modifiedConfigContent, success: true }\n }\n\n return {\n modifiedConfigContent: content,\n success: false,\n }\n }\n\n warning('Could not automatically wrap Next config with withPayload.')\n warnUserWrapNotSuccessful(configType)\n return {\n modifiedConfigContent: content,\n success: false,\n }\n}\n\nfunction warnUserWrapNotSuccessful(configType: NextConfigType) {\n // Output directions for user to update next.config.js\n const withPayloadMessage = `\n\n ${chalk.bold(`Please manually wrap your existing next.config.js with the withPayload function. Here is an example:`)}\n\n ${withPayloadStatement[configType]}\n\n const nextConfig = {\n // Your Next.js config here\n }\n\n ${configType === 'esm' ? 'export default withPayload(nextConfig)' : 'module.exports = withPayload(nextConfig)'}\n\n`\n\n log(withPayloadMessage)\n}\n\ntype Directive = {\n declaration?: {\n loc: Loc\n }\n}\n\ntype ExportNamedDeclaration = {\n declaration: null\n loc: Loc\n specifiers: {\n exported: {\n loc: Loc\n name: string\n type: string\n }\n loc: Loc\n local: {\n loc: Loc\n name: string\n type: string\n }\n type: string\n }[]\n type: string\n}\n\ntype Loc = {\n end: { column: number; line: number }\n start: { column: number; line: number }\n}\n\nfunction insertBeforeAndAfter(content: string, loc: Loc) {\n const { end, start } = loc\n const lines = content.split('\\n')\n\n const insert = (line: string, column: number, text: string) => {\n return line.slice(0, column) + text + line.slice(column)\n }\n\n // insert ) after end\n lines[end.line - 1] = insert(lines[end.line - 1], end.column, ')')\n // insert withPayload before start\n if (start.line === end.line) {\n lines[end.line - 1] = insert(lines[end.line - 1], start.column, 'withPayload(')\n } else {\n lines[start.line - 1] = insert(lines[start.line - 1], start.column, 'withPayload(')\n }\n\n return lines.join('\\n')\n}\n"],"names":["chalk","Syntax","parseModule","fs","log","warning","withPayloadStatement","cjs","esm","wrapNextConfig","args","nextConfigPath","nextConfigType","configType","configContent","readFileSync","modifiedConfigContent","newConfig","success","parseAndModifyConfigContent","writeFileSync","content","ast","loc","error","Error","message","warnUserWrapNotSuccessful","exportDefaultDeclaration","body","find","p","type","ExportDefaultDeclaration","exportNamedDeclaration","ExportNamedDeclaration","declaration","insertBeforeAndAfter","exportSpecifier","specifiers","s","exported","name","local","moduleExports","ExpressionStatement","expression","AssignmentExpression","left","MemberExpression","object","Identifier","property","right","withPayloadMessage","bold","end","start","lines","split","insert","line","column","text","slice","join"],"mappings":"AAEA,OAAOA,WAAW,QAAO;AACzB,SAASC,MAAM,EAAEC,WAAW,QAAQ,eAAc;AAClD,OAAOC,QAAQ,KAAI;AAEnB,SAASC,GAAG,EAAEC,OAAO,QAAQ,kBAAiB;AAE9C,OAAO,MAAMC,uBAAuB;IAClCC,KAAK,CAAC,iEAAiE,CAAC;IACxEC,KAAK,CAAC,4DAA4D,CAAC;AACrE,EAAC;AAID,OAAO,MAAMC,iBAAiB,CAACC;IAI7B,MAAM,EAAEC,cAAc,EAAEC,gBAAgBC,UAAU,EAAE,GAAGH;IACvD,MAAMI,gBAAgBX,GAAGY,YAAY,CAACJ,gBAAgB;IACtD,MAAM,EAAEK,uBAAuBC,SAAS,EAAEC,OAAO,EAAE,GAAGC,4BACpDL,eACAD;IAGF,IAAI,CAACK,SAAS;QACZ;IACF;IAEAf,GAAGiB,aAAa,CAACT,gBAAgBM;AACnC,EAAC;AAED;;CAEC,GACD,OAAO,SAASE,4BACdE,OAAe,EACfR,UAA0B;IAE1BQ,UAAUf,oBAAoB,CAACO,WAAW,GAAGQ;IAE7C,IAAIC;IACJ,IAAI;QACFA,MAAMpB,YAAYmB,SAAS;YAAEE,KAAK;QAAK;IACzC,EAAE,OAAOC,OAAgB;QACvB,IAAIA,iBAAiBC,OAAO;YAC1BpB,QAAQ,CAAC,oCAAoC,EAAEmB,MAAME,OAAO,CAAC,CAAC,CAAC;YAC/DC,0BAA0Bd;QAC5B;QACA,OAAO;YACLG,uBAAuBK;YACvBH,SAAS;QACX;IACF;IAEA,IAAIL,eAAe,OAAO;QACxB,MAAMe,2BAA2BN,IAAIO,IAAI,CAACC,IAAI,CAC5C,CAACC,IA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F,IAAIK,IAAI,GAAG,EAAE,GAAGD,OAAOF,KAAK,CAACF,IAAIK,IAAI,GAAG,EAAE,EAAEJ,MAAMK,MAAM,EAAE;IAClE,OAAO;QACLJ,KAAK,CAACD,MAAMI,IAAI,GAAG,EAAE,GAAGD,OAAOF,KAAK,CAACD,MAAMI,IAAI,GAAG,EAAE,EAAEJ,MAAMK,MAAM,EAAE;IACtE;IAEA,OAAOJ,MAAMO,IAAI,CAAC;AACpB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/wrap-next-config.spec.ts"],"sourcesContent":["import { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js'\nimport * as p from '@clack/prompts'\nimport { jest } from '@jest/globals'\n\nconst esmConfigs = {\n defaultNextConfig: `/** @type {import('next').NextConfig} */\nconst nextConfig = {};\nexport default nextConfig;\n`,\n nextConfigWithFunc: `const nextConfig = {};\nexport default someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `const nextConfig = {};;\nexport default someFunc(\n nextConfig\n);\n`,\n nextConfigExportNamedDefault: `const nextConfig = {};\nconst wrapped = someFunc(asdf);\nexport { wrapped as default };\n`,\n nextConfigWithSpread: `const nextConfig = {\n ...someConfig,\n};\nexport default nextConfig;\n`,\n}\n\nconst cjsConfigs = {\n defaultNextConfig: `\n /** @type {import('next').NextConfig} */\nconst nextConfig = {};\nmodule.exports = nextConfig;\n`,\n anonConfig: `module.exports = {};`,\n nextConfigWithFunc: `const nextConfig = {};\nmodule.exports = someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `const nextConfig = {};\nmodule.exports = someFunc(\n nextConfig\n);\n`,\n nextConfigExportNamedDefault: `const nextConfig = {};\nconst wrapped = someFunc(asdf);\nmodule.exports = wrapped;\n`,\n nextConfigWithSpread: `const nextConfig = { ...someConfig };\nmodule.exports = nextConfig;\n`,\n}\n\ndescribe('parseAndInsertWithPayload', () => {\n describe('esm', () => {\n const configType = 'esm'\n const importStatement = withPayloadStatement[configType]\n it('should parse the default next config', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.defaultNextConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n it('should parse the config with a function', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))')\n })\n\n it('should parse the config with a function on a new line', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n nextConfig\\n\\)\\)/)\n })\n\n it('should parse the config with a spread', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.nextConfigWithSpread,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n\n // Unsupported: export { wrapped as default }\n it('should give warning with a named export as default', () => {\n const warnLogSpy = jest.spyOn(p.log, 'warn').mockImplementation(() => {})\n\n const { modifiedConfigContent, success } = parseAndModifyConfigContent(\n esmConfigs.nextConfigExportNamedDefault,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(success).toBe(false)\n\n expect(warnLogSpy).toHaveBeenCalledWith(\n expect.stringContaining('Could not automatically wrap'),\n )\n })\n })\n\n describe('cjs', () => {\n const configType = 'cjs'\n const requireStatement = withPayloadStatement[configType]\n it('should parse the default next config', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.defaultNextConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n it('should parse anonymous default config', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.anonConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload({})')\n })\n it('should parse the config with a function', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))')\n })\n it('should parse the config with a function on a new line', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n nextConfig\\n\\)\\)/)\n })\n it('should parse the config with a named export as default', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigExportNamedDefault,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(wrapped)')\n })\n\n it('should parse the config with a spread', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithSpread,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n })\n})\n"],"names":["parseAndModifyConfigContent","withPayloadStatement","p","jest","esmConfigs","defaultNextConfig","nextConfigWithFunc","nextConfigWithFuncMultiline","nextConfigExportNamedDefault","nextConfigWithSpread","cjsConfigs","anonConfig","describe","configType","importStatement","it","modifiedConfigContent","expect","toContain","toMatch","warnLogSpy","spyOn","log","mockImplementation","success","toBe","toHaveBeenCalledWith","stringContaining","requireStatement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,2BAA2B,EAAEC,oBAAoB,QAAQ,wBAAuB;AACzF,YAAYC,OAAO,iBAAgB;AACnC,SAASC,IAAI,QAAQ,gBAAe;AAE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D,uBAAuBE,SAAS,CAAC;QAC1C;QAEAH,GAAG,yCAAyC;YAC1C,MAAM,EAAEC,qBAAqB,EAAE,GAAGhB,4BAChCU,WAAWD,oBAAoB,EAC/BI;YAEFI,OAAOD,uBAAuBE,SAAS,CAACU;YACxCX,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/lib/wrap-next-config.spec.ts"],"sourcesContent":["import { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js'\nimport * as p from '@clack/prompts'\nimport { jest } from '@jest/globals'\n\nconst esmConfigs = {\n defaultNextConfig: `/** @type {import('next').NextConfig} */\nconst nextConfig = {};\nexport default nextConfig;\n`,\n nextConfigWithFunc: `const nextConfig = {};\nexport default someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `const nextConfig = {};;\nexport default someFunc(\n nextConfig\n);\n`,\n nextConfigExportNamedDefault: `const nextConfig = {};\nconst wrapped = someFunc(asdf);\nexport { wrapped as default };\n`,\n nextConfigWithSpread: `const nextConfig = {\n ...someConfig,\n};\nexport default nextConfig;\n`,\n}\n\nconst cjsConfigs = {\n defaultNextConfig: `\n /** @type {import('next').NextConfig} */\nconst nextConfig = {};\nmodule.exports = nextConfig;\n`,\n anonConfig: `module.exports = {};`,\n nextConfigWithFunc: `const nextConfig = {};\nmodule.exports = someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `const nextConfig = {};\nmodule.exports = someFunc(\n nextConfig\n);\n`,\n nextConfigExportNamedDefault: `const nextConfig = {};\nconst wrapped = someFunc(asdf);\nmodule.exports = wrapped;\n`,\n nextConfigWithSpread: `const nextConfig = { ...someConfig };\nmodule.exports = nextConfig;\n`,\n}\n\ndescribe('parseAndInsertWithPayload', () => {\n describe('esm', () => {\n const configType = 'esm'\n const importStatement = withPayloadStatement[configType]\n it('should parse the default next config', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.defaultNextConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n it('should parse the config with a function', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))')\n })\n\n it('should parse the config with a function on a new line', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n nextConfig\\n\\)\\)/)\n })\n\n it('should parse the config with a spread', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n esmConfigs.nextConfigWithSpread,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n\n // Unsupported: export { wrapped as default }\n it('should give warning with a named export as default', () => {\n const warnLogSpy = jest.spyOn(p.log, 'warn').mockImplementation(() => {})\n\n const { modifiedConfigContent, success } = parseAndModifyConfigContent(\n esmConfigs.nextConfigExportNamedDefault,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(success).toBe(false)\n\n expect(warnLogSpy).toHaveBeenCalledWith(\n expect.stringContaining('Could not automatically wrap'),\n )\n })\n })\n\n describe('cjs', () => {\n const configType = 'cjs'\n const requireStatement = withPayloadStatement[configType]\n it('should parse the default next config', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.defaultNextConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n it('should parse anonymous default config', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.anonConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload({})')\n })\n it('should parse the config with a function', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))')\n })\n it('should parse the config with a function on a new line', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n nextConfig\\n\\)\\)/)\n })\n it('should parse the config with a named export as default', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigExportNamedDefault,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(wrapped)')\n })\n\n it('should parse the config with a spread', () => {\n const { modifiedConfigContent } = parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithSpread,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n })\n})\n"],"names":["parseAndModifyConfigContent","withPayloadStatement","p","jest","esmConfigs","defaultNextConfig","nextConfigWithFunc","nextConfigWithFuncMultiline","nextConfigExportNamedDefault","nextConfigWithSpread","cjsConfigs","anonConfig","describe","configType","importStatement","it","modifiedConfigContent","expect","toContain","toMatch","warnLogSpy","spyOn","log","mockImplementation","success","toBe","toHaveBeenCalledWith","stringContaining","requireStatement"],"mappings":"AAAA,SAASA,2BAA2B,EAAEC,oBAAoB,QAAQ,wBAAuB;AACzF,YAAYC,OAAO,iBAAgB;AACnC,SAASC,IAAI,QAAQ,gBAAe;AAEpC,MAAMC,aAAa;IACjBC,mBAAmB,CAAC;;;AAGtB,CAAC;IACCC,oBAAoB,CAAC;;AAEvB,CAAC;IACCC,6BAA6B,CAAC;;;;AAIhC,CAAC;IACCC,8BAA8B,CAAC;;;AAGjC,CAAC;IACCC,sBAAsB,CAAC;;;;AAIzB,CAAC;AACD;AAEA,MAAMC,aAAa;IACjBL,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@@
1
- {"version":3,"sources":["../../src/lib/write-env-file.ts"],"sourcesContent":["import fs from 'fs-extra'\nimport path from 'path'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nimport { debug, error } from '../utils/log.js'\n\n/** Parse and swap .env.example values and write .env */\nexport async function writeEnvFile(args: {\n cliArgs: CliArgs\n databaseUri: string\n payloadSecret: string\n projectDir: string\n template?: ProjectTemplate\n}): Promise<void> {\n const { cliArgs, databaseUri, payloadSecret, projectDir, template } = args\n\n if (cliArgs['--dry-run']) {\n debug(`DRY RUN: .env file created`)\n return\n }\n\n const envOutputPath = path.join(projectDir, '.env')\n\n try {\n if (fs.existsSync(envOutputPath)) {\n if (template?.type === 'starter') {\n // Parse .env file into key/value pairs\n const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8')\n const envWithValues: string[] = envFile\n .split('\\n')\n .filter((e) => e)\n .map((line) => {\n if (line.startsWith('#') || !line.includes('=')) return line\n\n const split = line.split('=')\n const key = split[0]\n let value = split[1]\n\n if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI') {\n value = databaseUri\n }\n if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') {\n value = payloadSecret\n }\n\n return `${key}=${value}`\n })\n\n // Write new .env file\n await fs.writeFile(envOutputPath, envWithValues.join('\\n'))\n } else {\n const existingEnv = await fs.readFile(envOutputPath, 'utf8')\n const newEnv =\n existingEnv + `\\nDATABASE_URI=${databaseUri}\\nPAYLOAD_SECRET=${payloadSecret}\\n`\n await fs.writeFile(envOutputPath, newEnv)\n }\n } else {\n const content = `DATABASE_URI=${databaseUri}\\nPAYLOAD_SECRET=${payloadSecret}`\n await fs.outputFile(`${projectDir}/.env`, content)\n }\n } catch (err: unknown) {\n error('Unable to write .env file')\n if (err instanceof Error) {\n error(err.message)\n }\n process.exit(1)\n }\n}\n"],"names":["fs","path","debug","error","writeEnvFile","args","cliArgs","databaseUri","payloadSecret","projectDir","template","envOutputPath","join","existsSync","type","envFile","readFile","envWithValues","split","filter","e","map","line","startsWith","includes","key","value","writeFile","existingEnv","newEnv","content","outputFile","err","Error","message","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,QAAQ,WAAU;AACzB,OAAOC,UAAU,OAAM;AAIvB,SAASC,KAAK,EAAEC,KAAK,QAAQ,kBAAiB;AAE9C,sDAAsD,GACtD,OAAO,eAAeC,aAAaC,IAMlC;IACC,MAAM,EAAEC,OAAO,EAAEC,WAAW,EAAEC,aAAa,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGL;IAEtE,IAAIC,OAAO,CAAC,YAAY,EAAE;QACxBJ,MAAM,CAAC,0BAA0B,CAAC;QAClC;IACF;IAEA,MAAMS,gBAAgBV,KAAKW,IAAI,CAACH,YAAY;IAE5C,IAAI;QACF,IAAIT,GAAGa,UAAU,CAACF,gBAAgB;YAChC,IAAID,UAAUI,SAAS,WAAW;gBAChC,uCAAuC;gBACvC,MAAMC,UAAU,MAAMf,GAAGgB,QAAQ,CAACf,KAAKW,IAAI,CAACH,YAAY,iBAAiB;gBACzE,MAAMQ,gBAA0BF,QAC7BG,KAAK,CAAC,MACNC,MAAM,CAAC,CAACC,IAAMA,GACdC,GAAG,CAAC,CAACC;oBACJ,IAAIA,KAAKC,UAAU,CAAC,QAAQ,CAACD,KAAKE,QAAQ,CAAC,MAAM,OAAOF;oBAExD,MAAMJ,QAAQI,KAAKJ,KAAK,CAAC;oBACzB,MAAMO,MAAMP,KAAK,CAAC,EAAE;oBACpB,IAAIQ,QAAQR,KAAK,CAAC,EAAE;oBAEpB,IAAIO,QAAQ,iBAAiBA,QAAQ,eAAeA,QAAQ,gBAAgB;wBAC1EC,QAAQnB;oBACV;oBACA,IAAIkB,QAAQ,oBAAoBA,QAAQ,sBAAsB;wBAC5DC,QAAQlB;oBACV;oBAEA,OAAO,CAAC,EAAEiB,IAAI,CAAC,EAAEC,MAAM,CAAC;gBAC1B;gBAEF,sBAAsB;gBACtB,MAAM1B,GAAG2B,SAAS,CAAChB,eAAeM,cAAcL,IAAI,CAAC;YACvD,OAAO;gBACL,MAAMgB,cAAc,MAAM5B,GAAGgB,QAAQ,CAACL,eAAe;gBACrD,MAAMkB,SACJD,cAAc,CAAC,eAAe,EAAErB,YAAY,iBAAiB,EAAEC,cAAc,EAAE,CAAC;gBAClF,MAAMR,GAAG2B,SAAS,CAAChB,eAAekB;YACpC;QACF,OAAO;YACL,MAAMC,UAAU,CAAC,aAAa,EAAEvB,YAAY,iBAAiB,EAAEC,cAAc,CAAC;YAC9E,MAAMR,GAAG+B,UAAU,CAAC,CAAC,EAAEtB,WAAW,KAAK,CAAC,EAAEqB;QAC5C;IACF,EAAE,OAAOE,KAAc;QACrB7B,MAAM;QACN,IAAI6B,eAAeC,OAAO;YACxB9B,MAAM6B,IAAIE,OAAO;QACnB;QACAC,QAAQC,IAAI,CAAC;IACf;AACF"}
1
+ {"version":3,"sources":["../../src/lib/write-env-file.ts"],"sourcesContent":["import fs from 'fs-extra'\nimport path from 'path'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nimport { debug, error } from '../utils/log.js'\n\n/** Parse and swap .env.example values and write .env */\nexport async function writeEnvFile(args: {\n cliArgs: CliArgs\n databaseUri: string\n payloadSecret: string\n projectDir: string\n template?: ProjectTemplate\n}): Promise<void> {\n const { cliArgs, databaseUri, payloadSecret, projectDir, template } = args\n\n if (cliArgs['--dry-run']) {\n debug(`DRY RUN: .env file created`)\n return\n }\n\n const envOutputPath = path.join(projectDir, '.env')\n\n try {\n if (fs.existsSync(envOutputPath)) {\n if (template?.type === 'starter') {\n // Parse .env file into key/value pairs\n const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8')\n const envWithValues: string[] = envFile\n .split('\\n')\n .filter((e) => e)\n .map((line) => {\n if (line.startsWith('#') || !line.includes('=')) return line\n\n const split = line.split('=')\n const key = split[0]\n let value = split[1]\n\n if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI') {\n value = databaseUri\n }\n if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') {\n value = payloadSecret\n }\n\n return `${key}=${value}`\n })\n\n // Write new .env file\n await fs.writeFile(envOutputPath, envWithValues.join('\\n'))\n } else {\n const existingEnv = await fs.readFile(envOutputPath, 'utf8')\n const newEnv =\n existingEnv + `\\nDATABASE_URI=${databaseUri}\\nPAYLOAD_SECRET=${payloadSecret}\\n`\n await fs.writeFile(envOutputPath, newEnv)\n }\n } else {\n const content = `DATABASE_URI=${databaseUri}\\nPAYLOAD_SECRET=${payloadSecret}`\n await fs.outputFile(`${projectDir}/.env`, content)\n }\n } catch (err: unknown) {\n error('Unable to write .env file')\n if (err instanceof Error) {\n error(err.message)\n }\n process.exit(1)\n }\n}\n"],"names":["fs","path","debug","error","writeEnvFile","args","cliArgs","databaseUri","payloadSecret","projectDir","template","envOutputPath","join","existsSync","type","envFile","readFile","envWithValues","split","filter","e","map","line","startsWith","includes","key","value","writeFile","existingEnv","newEnv","content","outputFile","err","Error","message","process","exit"],"mappings":"AAAA,OAAOA,QAAQ,WAAU;AACzB,OAAOC,UAAU,OAAM;AAIvB,SAASC,KAAK,EAAEC,KAAK,QAAQ,kBAAiB;AAE9C,sDAAsD,GACtD,OAAO,eAAeC,aAAaC,IAMlC;IACC,MAAM,EAAEC,OAAO,EAAEC,WAAW,EAAEC,aAAa,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGL;IAEtE,IAAIC,OAAO,CAAC,YAAY,EAAE;QACxBJ,MAAM,CAAC,0BAA0B,CAAC;QAClC;IACF;IAEA,MAAMS,gBAAgBV,KAAKW,IAAI,CAACH,YAAY;IAE5C,IAAI;QACF,IAAIT,GAAGa,UAAU,CAACF,gBAAgB;YAChC,IAAID,UAAUI,SAAS,WAAW;gBAChC,uCAAuC;gBACvC,MAAMC,UAAU,MAAMf,GAAGgB,QAAQ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import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\nimport arg from 'arg'\nimport chalk from 'chalk'\nimport figures from 'figures'\nimport path from 'path'\n\nimport type { CliArgs } from './types.js'\n\nimport { configurePayloadConfig } from './lib/configure-payload-config.js'\nimport { createProject } from './lib/create-project.js'\nimport { generateSecret } from './lib/generate-secret.js'\nimport { getPackageManager } from './lib/get-package-manager.js'\nimport { getNextAppDetails, initNext } from './lib/init-next.js'\nimport { parseProjectName } from './lib/parse-project-name.js'\nimport { parseTemplate } from './lib/parse-template.js'\nimport { selectDb } from './lib/select-db.js'\nimport { getValidTemplates, validateTemplate } from './lib/templates.js'\nimport { updatePayloadInProject } from './lib/update-payload-in-project.js'\nimport { writeEnvFile } from './lib/write-env-file.js'\nimport { error, info } from './utils/log.js'\nimport {\n feedbackOutro,\n helpMessage,\n moveMessage,\n successMessage,\n successfulNextInit,\n} from './utils/messages.js'\n\nexport class Main {\n args: CliArgs\n\n constructor() {\n // @ts-expect-error bad typings\n this.args = arg(\n {\n '--db': String,\n '--db-accept-recommended': Boolean,\n '--db-connection-string': String,\n '--help': Boolean,\n '--local-template': String,\n '--name': String,\n '--secret': String,\n '--template': String,\n '--template-branch': String,\n\n // Next.js\n '--init-next': Boolean, // TODO: Is this needed if we detect if inside Next.js project?\n\n // Package manager\n '--no-deps': Boolean,\n '--use-npm': Boolean,\n '--use-pnpm': Boolean,\n '--use-yarn': Boolean,\n\n // Other\n '--no-git': Boolean,\n\n // Flags\n '--beta': Boolean,\n '--debug': Boolean,\n '--dry-run': Boolean,\n\n // Aliases\n '-d': '--db',\n '-h': '--help',\n '-n': '--name',\n '-t': '--template',\n },\n { permissive: true },\n )\n }\n\n async init(): Promise<void> {\n try {\n if (this.args['--help']) {\n helpMessage()\n process.exit(0)\n }\n\n // eslint-disable-next-line no-console\n console.log('\\n')\n p.intro(chalk.bgCyan(chalk.black(' create-payload-app ')))\n p.note(\"Welcome to Payload. Let's create a project!\")\n\n // Detect if inside Next.js project\n const nextAppDetails = await getNextAppDetails(process.cwd())\n const { hasTopLevelLayout, isPayloadInstalled, nextAppDir, nextConfigPath } = nextAppDetails\n\n // Upgrade Payload in existing project\n if (isPayloadInstalled && nextConfigPath) {\n p.log.warn(`Payload installation detected in current project.`)\n const shouldUpdate = await p.confirm({\n initialValue: false,\n message: chalk.bold(`Upgrade Payload in this project?`),\n })\n\n if (!p.isCancel(shouldUpdate) && shouldUpdate) {\n const { message, success: updateSuccess } = await updatePayloadInProject(nextAppDetails)\n if (updateSuccess) {\n info(message)\n } else {\n error(message)\n }\n }\n\n p.outro(feedbackOutro())\n process.exit(0)\n }\n\n if (nextConfigPath) {\n this.args['--name'] = slugify(path.basename(path.dirname(nextConfigPath)))\n }\n\n const projectName = await parseProjectName(this.args)\n const projectDir = nextConfigPath\n ? path.dirname(nextConfigPath)\n : path.resolve(process.cwd(), slugify(projectName))\n\n const packageManager = await getPackageManager({ cliArgs: this.args, projectDir })\n\n if (nextConfigPath) {\n p.log.step(\n chalk.bold(`${chalk.bgBlack(` ${figures.triangleUp} Next.js `)} project detected!`),\n )\n\n const proceed = await p.confirm({\n initialValue: true,\n message: chalk.bold(`Install ${chalk.green('Payload')} in this project?`),\n })\n if (p.isCancel(proceed) || !proceed) {\n p.outro(feedbackOutro())\n process.exit(0)\n }\n\n // Check for top-level layout.tsx\n if (nextAppDir && hasTopLevelLayout) {\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n p.outro(feedbackOutro())\n process.exit(0)\n }\n\n const dbDetails = await selectDb(this.args, projectName)\n\n const result = await initNext({\n ...this.args,\n dbType: dbDetails.type,\n nextAppDetails,\n packageManager,\n projectDir,\n })\n\n if (result.success === false) {\n p.outro(feedbackOutro())\n process.exit(1)\n }\n\n await configurePayloadConfig({\n dbType: dbDetails?.type,\n projectDirOrConfigPath: {\n payloadConfigPath: result.payloadConfigPath,\n },\n })\n\n await writeEnvFile({\n cliArgs: this.args,\n databaseUri: dbDetails.dbUri,\n payloadSecret: generateSecret(),\n projectDir,\n })\n\n info('Payload project successfully initialized!')\n p.note(successfulNextInit(), chalk.bgGreen(chalk.black(' Documentation ')))\n p.outro(feedbackOutro())\n return\n }\n\n const templateArg = this.args['--template']\n if (templateArg) {\n const valid = validateTemplate(templateArg)\n if (!valid) {\n helpMessage()\n process.exit(1)\n }\n }\n\n const validTemplates = getValidTemplates()\n const template = await parseTemplate(this.args, validTemplates)\n if (!template) {\n p.log.error('Invalid template given')\n p.outro(feedbackOutro())\n process.exit(1)\n }\n\n switch (template.type) {\n case 'starter': {\n const dbDetails = await selectDb(this.args, projectName)\n const payloadSecret = generateSecret()\n await createProject({\n cliArgs: this.args,\n dbDetails,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n await writeEnvFile({\n cliArgs: this.args,\n databaseUri: dbDetails.dbUri,\n payloadSecret,\n projectDir,\n template,\n })\n break\n }\n case 'plugin': {\n await createProject({\n cliArgs: this.args,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n break\n }\n }\n\n info('Payload project successfully created!')\n p.note(successMessage(projectDir, packageManager), chalk.bgGreen(chalk.black(' Next Steps ')))\n p.outro(feedbackOutro())\n } catch (err: unknown) {\n error(err instanceof Error ? err.message : 'An error occurred')\n }\n }\n}\n"],"names":["p","slugify","arg","chalk","figures","path","configurePayloadConfig","createProject","generateSecret","getPackageManager","getNextAppDetails","initNext","parseProjectName","parseTemplate","selectDb","getValidTemplates","validateTemplate","updatePayloadInProject","writeEnvFile","error","info","feedbackOutro","helpMessage","moveMessage","successMessage","successfulNextInit","Main","args","constructor","String","Boolean","permissive","init","process","exit","console","log","intro","bgCyan","black","note","nextAppDetails","cwd","hasTopLevelLayout","isPayloadInstalled","nextAppDir","nextConfigPath","warn","shouldUpdate","confirm","initialValue","message","bold","isCancel","success","updateSuccess","outro","basename","dirname","projectName","projectDir","resolve","packageManager","cliArgs","step","bgBlack","triangleUp","proceed","green","dbDetails","result","dbType","type","projectDirOrConfigPath","payloadConfigPath","databaseUri","dbUri","payloadSec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M3E,cAAc;4BAClBwD,SAAS,IAAI,CAACpC,IAAI;4BAClBmC;4BACAF;4BACAD;4BACAuB;wBACF;wBACA;oBACF;YACF;YAEA9D,KAAK;YACLpB,EAAEwC,IAAI,CAAChB,eAAeoC,YAAYE,iBAAiB3D,MAAM2E,OAAO,CAAC3E,MAAMoC,KAAK,CAAC;YAC7EvC,EAAEwD,KAAK,CAACnC;QACV,EAAE,OAAO8D,KAAc;YACrBhE,MAAMgE,eAAeC,QAAQD,IAAIhC,OAAO,GAAG;QAC7C;IACF;AACF"}
1
+ {"version":3,"sources":["../src/main.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\nimport arg from 'arg'\nimport chalk from 'chalk'\nimport figures from 'figures'\nimport path from 'path'\n\nimport type { CliArgs } from './types.js'\n\nimport { configurePayloadConfig } from './lib/configure-payload-config.js'\nimport { createProject } from './lib/create-project.js'\nimport { generateSecret } from './lib/generate-secret.js'\nimport { getPackageManager } from './lib/get-package-manager.js'\nimport { getNextAppDetails, initNext } from './lib/init-next.js'\nimport { parseProjectName } from './lib/parse-project-name.js'\nimport { parseTemplate } from './lib/parse-template.js'\nimport { selectDb } from './lib/select-db.js'\nimport { getValidTemplates, validateTemplate } from './lib/templates.js'\nimport { updatePayloadInProject } from './lib/update-payload-in-project.js'\nimport { writeEnvFile } from './lib/write-env-file.js'\nimport { error, info } from './utils/log.js'\nimport {\n feedbackOutro,\n helpMessage,\n moveMessage,\n successMessage,\n successfulNextInit,\n} from './utils/messages.js'\n\nexport class Main {\n args: CliArgs\n\n constructor() {\n // @ts-expect-error bad typings\n this.args = arg(\n {\n '--db': String,\n '--db-accept-recommended': Boolean,\n '--db-connection-string': String,\n '--help': Boolean,\n '--local-template': String,\n '--name': String,\n '--secret': String,\n '--template': String,\n '--template-branch': String,\n\n // Next.js\n '--init-next': Boolean, // TODO: Is this needed if we detect if inside Next.js project?\n\n // Package manager\n '--no-deps': Boolean,\n '--use-npm': Boolean,\n '--use-pnpm': Boolean,\n '--use-yarn': Boolean,\n\n // Other\n '--no-git': Boolean,\n\n // Flags\n '--beta': Boolean,\n '--debug': Boolean,\n '--dry-run': Boolean,\n\n // Aliases\n '-d': '--db',\n '-h': '--help',\n '-n': '--name',\n '-t': '--template',\n },\n { permissive: true },\n )\n }\n\n async init(): Promise<void> {\n try {\n if (this.args['--help']) {\n helpMessage()\n process.exit(0)\n }\n\n // eslint-disable-next-line no-console\n console.log('\\n')\n p.intro(chalk.bgCyan(chalk.black(' create-payload-app ')))\n p.note(\"Welcome to Payload. Let's create a project!\")\n\n // Detect if inside Next.js project\n const nextAppDetails = await getNextAppDetails(process.cwd())\n const { hasTopLevelLayout, isPayloadInstalled, nextAppDir, nextConfigPath } = nextAppDetails\n\n // Upgrade Payload in existing project\n if (isPayloadInstalled && nextConfigPath) {\n p.log.warn(`Payload installation detected in current project.`)\n const shouldUpdate = await p.confirm({\n initialValue: false,\n message: chalk.bold(`Upgrade Payload in this project?`),\n })\n\n if (!p.isCancel(shouldUpdate) && shouldUpdate) {\n const { message, success: updateSuccess } = await updatePayloadInProject(nextAppDetails)\n if (updateSuccess) {\n info(message)\n } else {\n error(message)\n }\n }\n\n p.outro(feedbackOutro())\n process.exit(0)\n }\n\n if (nextConfigPath) {\n this.args['--name'] = slugify(path.basename(path.dirname(nextConfigPath)))\n }\n\n const projectName = await parseProjectName(this.args)\n const projectDir = nextConfigPath\n ? path.dirname(nextConfigPath)\n : path.resolve(process.cwd(), slugify(projectName))\n\n const packageManager = await getPackageManager({ cliArgs: this.args, projectDir })\n\n if (nextConfigPath) {\n p.log.step(\n chalk.bold(`${chalk.bgBlack(` ${figures.triangleUp} Next.js `)} project detected!`),\n )\n\n const proceed = await p.confirm({\n initialValue: true,\n message: chalk.bold(`Install ${chalk.green('Payload')} in this project?`),\n })\n if (p.isCancel(proceed) || !proceed) {\n p.outro(feedbackOutro())\n process.exit(0)\n }\n\n // Check for top-level layout.tsx\n if (nextAppDir && hasTopLevelLayout) {\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n p.outro(feedbackOutro())\n process.exit(0)\n }\n\n const dbDetails = await selectDb(this.args, projectName)\n\n const result = await initNext({\n ...this.args,\n dbType: dbDetails.type,\n nextAppDetails,\n packageManager,\n projectDir,\n })\n\n if (result.success === false) {\n p.outro(feedbackOutro())\n process.exit(1)\n }\n\n await configurePayloadConfig({\n dbType: dbDetails?.type,\n projectDirOrConfigPath: {\n payloadConfigPath: result.payloadConfigPath,\n },\n })\n\n await writeEnvFile({\n cliArgs: this.args,\n databaseUri: dbDetails.dbUri,\n payloadSecret: generateSecret(),\n projectDir,\n })\n\n info('Payload project successfully initialized!')\n p.note(successfulNextInit(), chalk.bgGreen(chalk.black(' Documentation ')))\n p.outro(feedbackOutro())\n return\n }\n\n const templateArg = this.args['--template']\n if (templateArg) {\n const valid = validateTemplate(templateArg)\n if (!valid) {\n helpMessage()\n process.exit(1)\n }\n }\n\n const validTemplates = getValidTemplates()\n const template = await parseTemplate(this.args, validTemplates)\n if (!template) {\n p.log.error('Invalid template given')\n p.outro(feedbackOutro())\n process.exit(1)\n }\n\n switch (template.type) {\n case 'starter': {\n const dbDetails = await selectDb(this.args, projectName)\n const payloadSecret = generateSecret()\n await createProject({\n cliArgs: this.args,\n dbDetails,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n await writeEnvFile({\n cliArgs: this.args,\n databaseUri: dbDetails.dbUri,\n payloadSecret,\n projectDir,\n template,\n })\n break\n }\n case 'plugin': {\n await createProject({\n cliArgs: this.args,\n packageManager,\n projectDir,\n projectName,\n template,\n })\n break\n }\n }\n\n info('Payload project successfully created!')\n p.note(successMessage(projectDir, packageManager), chalk.bgGreen(chalk.black(' Next Steps ')))\n p.outro(feedbackOutro())\n } catch (err: unknown) {\n error(err instanceof Error ? err.message : 'An error occurred')\n }\n }\n}\n"],"names":["p","slugify","arg","chalk","figures","path","configurePayloadConfig","createProject","generateSecret","getPackageManager","getNextAppDetails","initNext","parseProjectName","parseTemplate","selectDb","getValidTemplates","validateTemplate","updatePayloadInProject","writeEnvFile","error","info","feedbackOutro","helpMessage","moveMessage","successMessage","successfulNextInit","Main","args","constructor","String","Boolean","permissive","init","process","exit","console","log","intro","bgCyan","black","note","nextAppDetails","cwd","hasTopLevelLayout","isPayloadInstalled","nextAppDir","nextConfigPath","warn","shouldUpdate","confirm","initialValue","message","bold","isCancel","success","updateSuccess","outro","basename","dirname","projectName","projectDir","resolve","packageManager","cliArgs","step","bgBlack","triangleUp","proceed","green","dbDetails","result","dbType","type","projectDirOrConfigPath","payloadConfigPath","databaseUri","dbUri","payloadSecret","bgGreen","templateArg","valid","validTemplates","template","err","Error"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAC3C,OAAOC,SAAS,MAAK;AACrB,OAAOC,WAAW,QAAO;AACzB,OAAOC,aAAa,UAAS;AAC7B,OAAOC,UAAU,OAAM;AAIvB,SAASC,sBAAsB,QAAQ,oCAAmC;AAC1E,SAASC,aAAa,QAAQ,0BAAyB;AACvD,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,iBAAiB,EAAEC,QAAQ,QAAQ,qBAAoB;AAChE,SAASC,gBAAgB,QAAQ,8BAA6B;AAC9D,SAASC,aAAa,QAAQ,0BAAyB;AACvD,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,iBAAiB,EAAEC,gBAAgB,QAAQ,qBAAoB;AACxE,SAASC,sBAAsB,QAAQ,qCAAoC;AAC3E,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,KAAK,EAAEC,IAAI,QAAQ,iBAAgB;AAC5C,SACEC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,cAAc,EACdC,kBAAkB,QACb,sBAAqB;AAE5B,OAAO,MAAMC;IACXC,KAAa;IAEbC,aAAc;QACZ,+BAA+B;QAC/B,IAAI,CAACD,IAAI,GAAGzB,IAC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6C,SAAS,IAAI,CAACpC,IAAI;4BAClBgD,aAAaN,UAAUO,KAAK;4BAC5BC;4BACAjB;4BACAsB;wBACF;wBACA;oBACF;gBACA,KAAK;oBAAU;wBACb,MAAM3E,cAAc;4BAClBwD,SAAS,IAAI,CAACpC,IAAI;4BAClBmC;4BACAF;4BACAD;4BACAuB;wBACF;wBACA;oBACF;YACF;YAEA9D,KAAK;YACLpB,EAAEwC,IAAI,CAAChB,eAAeoC,YAAYE,iBAAiB3D,MAAM2E,OAAO,CAAC3E,MAAMoC,KAAK,CAAC;YAC7EvC,EAAEwD,KAAK,CAACnC;QACV,EAAE,OAAO8D,KAAc;YACrBhE,MAAMgE,eAAeC,QAAQD,IAAIhC,OAAO,GAAG;QAC7C;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/scripts/pack-template-files.ts"],"sourcesContent":["import fs from 'fs'\nimport fsp from 'fs/promises'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\nmain()\n\n/**\n * Copy the necessary template files from `templates/blank-3.0` to `dist/template`\n *\n * Eventually, this should be replaced with using tar.x to stream from the git repo\n */\n\nasync function main() {\n const root = path.resolve(dirname, '../../../../')\n const outputPath = path.resolve(dirname, '../../dist/template')\n const sourceTemplatePath = path.resolve(root, 'templates/blank-3.0')\n\n if (!fs.existsSync(sourceTemplatePath)) {\n throw new Error(`Source path does not exist: ${sourceTemplatePath}`)\n }\n\n if (!fs.existsSync(outputPath)) {\n fs.mkdirSync(outputPath, { recursive: true })\n }\n\n // Copy the src directory from `templates/blank-3.0` to `dist`\n const srcPath = path.resolve(sourceTemplatePath, 'src')\n const distSrcPath = path.resolve(outputPath, 'src')\n // Copy entire file structure from src to dist\n await fsp.cp(srcPath, distSrcPath, { recursive: true })\n}\n"],"names":["fs","fsp","fileURLToPath","path","filename","url","dirname","main","root","resolve","outputPath","sourceTemplatePath","existsSync","Error","mkdirSync","recursive","srcPath","distSrcPath","cp"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,SAAS,cAAa;AAC7B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAE7B,mEAAmE;AACnEG;AAEA;;;;CAIC,GAED,eAAeA;IACb,MAAMC,OAAOL,KAAKM,OAAO,CAACH,SAAS;IACnC,MAAMI,aAAaP,KAAKM,OAAO,CAACH,SAAS;IACzC,MAAMK,qBAAqBR,KAAKM,OAAO,CAACD,MAAM;IAE9C,IAAI,CAACR,GAAGY,UAAU,CAACD,qBAAqB;QACtC,MAAM,IAAIE,MAAM,CAAC,4BAA4B,EAAEF,mBAAmB,CAAC;IACrE;IAEA,IAAI,CAACX,GAAGY,UAAU,CAACF,aAAa;QAC9BV,GAAGc,SAAS,CAACJ,YAAY;YAAEK,WAAW;QAAK;IAC7C;IAEA,8DAA8D;IAC9D,MAAMC,UAAUb,KAAKM,OAAO,CAACE,oBAAoB;IACjD,MAAMM,cAAcd,KAAKM,OAAO,CAACC,YAAY;IAC7C,8CAA8C;IAC9C,MAAMT,IAAIiB,EAAE,CAACF,SAASC,aAAa;QAAEF,WAAW;IAAK;AACvD"}
1
+ {"version":3,"sources":["../../src/scripts/pack-template-files.ts"],"sourcesContent":["import fs from 'fs'\nimport fsp from 'fs/promises'\nimport { fileURLToPath } from 'node:url'\nimport path from 'path'\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\n// eslint-disable-next-line @typescript-eslint/no-floating-promises\nmain()\n\n/**\n * Copy the necessary template files from `templates/blank-3.0` to `dist/template`\n *\n * Eventually, this should be replaced with using tar.x to stream from the git repo\n */\n\nasync function main() {\n const root = path.resolve(dirname, '../../../../')\n const outputPath = path.resolve(dirname, '../../dist/template')\n const sourceTemplatePath = path.resolve(root, 'templates/blank-3.0')\n\n if (!fs.existsSync(sourceTemplatePath)) {\n throw new Error(`Source path does not exist: ${sourceTemplatePath}`)\n }\n\n if (!fs.existsSync(outputPath)) {\n fs.mkdirSync(outputPath, { recursive: true })\n }\n\n // Copy the src directory from `templates/blank-3.0` to `dist`\n const srcPath = path.resolve(sourceTemplatePath, 'src')\n const distSrcPath = path.resolve(outputPath, 'src')\n // Copy entire file structure from src to dist\n await fsp.cp(srcPath, distSrcPath, { recursive: true })\n}\n"],"names":["fs","fsp","fileURLToPath","path","filename","url","dirname","main","root","resolve","outputPath","sourceTemplatePath","existsSync","Error","mkdirSync","recursive","srcPath","distSrcPath","cp"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,SAAS,cAAa;AAC7B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AACvB,MAAMC,WAAWF,cAAc,YAAYG,GAAG;AAC9C,MAAMC,UAAUH,KAAKG,OAAO,CAACF;AAE7B,mEAAmE;AACnEG;AAEA;;;;CAIC,GAED,eAAeA;IACb,MAAMC,OAAOL,KAAKM,OAAO,CAACH,SAAS;IACnC,MAAMI,aAAaP,KAAKM,OAAO,CAACH,SAAS;IACzC,MAAMK,qBAAqBR,KAAKM,OAAO,CAACD,MAAM;IAE9C,IAAI,CAACR,GAAGY,UAAU,CAACD,qBAAqB;QACtC,MAAM,IAAIE,MAAM,CAAC,4BAA4B,EAAEF,mBAAmB,CAAC;IACrE;IAEA,IAAI,CAACX,GAAGY,UAAU,CAACF,aAAa;QAC9BV,GAAGc,SAAS,CAACJ,YAAY;YAAEK,WAAW;QAAK;IAC7C;IAEA,8DAA8D;IAC9D,MAAMC,UAAUb,KAAKM,OAAO,CAACE,oBAAoB;IACjD,MAAMM,cAAcd,KAAKM,OAAO,CAACC,YAAY;IAC7C,8CAA8C;IAC9C,MAAMT,IAAIiB,EAAE,CAACF,SAASC,aAAa;QAAEF,WAAW;IAAK;AACvD"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type arg from 'arg'\n\nexport interface Args extends arg.Spec {\n '--beta': BooleanConstructor\n '--db': StringConstructor\n '--db-accept-recommended': BooleanConstructor\n '--db-connection-string': StringConstructor\n '--debug': BooleanConstructor\n '--dry-run': BooleanConstructor\n '--help': BooleanConstructor\n '--init-next': BooleanConstructor\n '--local-template': StringConstructor\n '--name': StringConstructor\n '--no-deps': BooleanConstructor\n '--no-git': BooleanConstructor\n '--secret': StringConstructor\n '--template': StringConstructor\n '--template-branch': StringConstructor\n '--use-npm': BooleanConstructor\n '--use-pnpm': BooleanConstructor\n '--use-yarn': BooleanConstructor\n\n // Aliases\n\n '-h': string\n '-n': string\n '-t': string\n}\n\nexport type CliArgs = arg.Result<Args>\n\nexport type ProjectTemplate = GitTemplate | PluginTemplate\n\n/**\n * Template that is cloned verbatim from a git repo\n * Performs .env manipulation based upon input\n */\nexport interface GitTemplate extends Template {\n type: 'starter'\n url: string\n}\n\n/**\n * Type specifically for the plugin template\n * No .env manipulation is done\n */\nexport interface PluginTemplate extends Template {\n type: 'plugin'\n url: string\n}\n\ninterface Template {\n description?: string\n name: string\n type: ProjectTemplate['type']\n}\n\nexport type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn'\n\nexport type DbType = 'mongodb' | 'postgres'\n\nexport type DbDetails = {\n dbUri: string\n type: DbType\n}\n\nexport type EditorType = 'lexical' | 'slate'\n\nexport type NextAppDetails = {\n hasTopLevelLayout: boolean\n isPayloadInstalled?: boolean\n isSrcDir: boolean\n nextAppDir?: string\n nextConfigPath?: string\n nextConfigType?: NextConfigType\n}\n\nexport type NextConfigType = 'cjs' | 'esm'\n\nexport type StorageAdapterType = 'localDisk' | 'payloadCloud' | 'vercelBlobStorage'\n"],"names":[],"rangeMappings":"","mappings":"AA+EA,WAAmF"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type arg from 'arg'\n\nexport interface Args extends arg.Spec {\n '--beta': BooleanConstructor\n '--db': StringConstructor\n '--db-accept-recommended': BooleanConstructor\n '--db-connection-string': StringConstructor\n '--debug': BooleanConstructor\n '--dry-run': BooleanConstructor\n '--help': BooleanConstructor\n '--init-next': BooleanConstructor\n '--local-template': StringConstructor\n '--name': StringConstructor\n '--no-deps': BooleanConstructor\n '--no-git': BooleanConstructor\n '--secret': StringConstructor\n '--template': StringConstructor\n '--template-branch': StringConstructor\n '--use-npm': BooleanConstructor\n '--use-pnpm': BooleanConstructor\n '--use-yarn': BooleanConstructor\n\n // Aliases\n\n '-h': string\n '-n': string\n '-t': string\n}\n\nexport type CliArgs = arg.Result<Args>\n\nexport type ProjectTemplate = GitTemplate | PluginTemplate\n\n/**\n * Template that is cloned verbatim from a git repo\n * Performs .env manipulation based upon input\n */\nexport interface GitTemplate extends Template {\n type: 'starter'\n url: string\n}\n\n/**\n * Type specifically for the plugin template\n * No .env manipulation is done\n */\nexport interface PluginTemplate extends Template {\n type: 'plugin'\n url: string\n}\n\ninterface Template {\n description?: string\n name: string\n type: ProjectTemplate['type']\n}\n\nexport type PackageManager = 'bun' | 'npm' | 'pnpm' | 'yarn'\n\nexport type DbType = 'mongodb' | 'postgres'\n\nexport type DbDetails = {\n dbUri: string\n type: DbType\n}\n\nexport type EditorType = 'lexical' | 'slate'\n\nexport type NextAppDetails = {\n hasTopLevelLayout: boolean\n isPayloadInstalled?: boolean\n isSrcDir: boolean\n nextAppDir?: string\n nextConfigPath?: string\n nextConfigType?: NextConfigType\n}\n\nexport type NextConfigType = 'cjs' | 'esm'\n\nexport type StorageAdapterType = 'localDisk' | 'payloadCloud' | 'vercelBlobStorage'\n"],"names":[],"mappings":"AA+EA,WAAmF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/copy-recursive-sync.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\n/**\n * Recursively copy files from src to dest\n *\n * @internal\n */\nexport function copyRecursiveSync(src: string, dest: string, debug?: boolean) {\n const exists = fs.existsSync(src)\n const stats = exists && fs.statSync(src)\n const isDirectory = exists && stats !== false && stats.isDirectory()\n if (isDirectory) {\n fs.mkdirSync(dest, { recursive: true })\n fs.readdirSync(src).forEach((childItemName) => {\n copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName))\n })\n } else {\n fs.copyFileSync(src, dest)\n }\n}\n"],"names":["fs","path","copyRecursiveSync","src","dest","debug","exists","existsSync","stats","statSync","isDirectory","mkdirSync","recursive","readdirSync","forEach","childItemName","join","copyFileSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AAEvB;;;;CAIC,GACD,OAAO,SAASC,kBAAkBC,GAAW,EAAEC,IAAY,EAAEC,KAAe;IAC1E,MAAMC,SAASN,GAAGO,UAAU,CAACJ;IAC7B,MAAMK,QAAQF,UAAUN,GAAGS,QAAQ,CAACN;IACpC,MAAMO,cAAcJ,UAAUE,UAAU,SAASA,MAAME,WAAW;IAClE,IAAIA,aAAa;QACfV,GAAGW,SAAS,CAACP,MAAM;YAAEQ,WAAW;QAAK;QACrCZ,GAAGa,WAAW,CAACV,KAAKW,OAAO,CAAC,CAACC;YAC3Bb,kBAAkBD,KAAKe,IAAI,CAACb,KAAKY,gBAAgBd,KAAKe,IAAI,CAACZ,MAAMW;QACnE;IACF,OAAO;QACLf,GAAGiB,YAAY,CAACd,KAAKC;IACvB;AACF"}
1
+ {"version":3,"sources":["../../src/utils/copy-recursive-sync.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\n/**\n * Recursively copy files from src to dest\n *\n * @internal\n */\nexport function copyRecursiveSync(src: string, dest: string, debug?: boolean) {\n const exists = fs.existsSync(src)\n const stats = exists && fs.statSync(src)\n const isDirectory = exists && stats !== false && stats.isDirectory()\n if (isDirectory) {\n fs.mkdirSync(dest, { recursive: true })\n fs.readdirSync(src).forEach((childItemName) => {\n copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName))\n })\n } else {\n fs.copyFileSync(src, dest)\n }\n}\n"],"names":["fs","path","copyRecursiveSync","src","dest","debug","exists","existsSync","stats","statSync","isDirectory","mkdirSync","recursive","readdirSync","forEach","childItemName","join","copyFileSync"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AAEvB;;;;CAIC,GACD,OAAO,SAASC,kBAAkBC,GAAW,EAAEC,IAAY,EAAEC,KAAe;IAC1E,MAAMC,SAASN,GAAGO,UAAU,CAACJ;IAC7B,MAAMK,QAAQF,UAAUN,GAAGS,QAAQ,CAACN;IACpC,MAAMO,cAAcJ,UAAUE,UAAU,SAASA,MAAME,WAAW;IAClE,IAAIA,aAAa;QACfV,GAAGW,SAAS,CAACP,MAAM;YAAEQ,WAAW;QAAK;QACrCZ,GAAGa,WAAW,CAACV,KAAKW,OAAO,CAAC,CAACC;YAC3Bb,kBAAkBD,KAAKe,IAAI,CAACb,KAAKY,gBAAgBd,KAAKe,IAAI,CAACZ,MAAMW;QACnE;IACF,OAAO;QACLf,GAAGiB,YAAY,CAACd,KAAKC;IACvB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/git.ts"],"sourcesContent":["import type { ExecSyncOptions } from 'child_process'\n\nimport { execSync } from 'child_process'\n\nimport { warning } from './log.js'\n\nexport function tryInitRepoAndCommit(args: { cwd: string }): void {\n const execOpts: ExecSyncOptions = { cwd: args.cwd, stdio: 'ignore' }\n try {\n // Check if git is available\n execSync('git -v', execOpts)\n\n // Do nothing if already in a git repo\n if (isGitRepo(execOpts)) {\n return\n }\n\n // Initialize\n execSync('git init', execOpts)\n if (!ensureHasDefaultBranch(execOpts)) {\n execSync('git checkout -b main', execOpts)\n }\n\n // Add and commit files\n execSync('git add -A', execOpts)\n execSync('git commit -m \"feat: initial commit\"', execOpts)\n } catch (_) {\n warning('Failed to initialize git repository.')\n }\n}\n\nfunction isGitRepo(opts: ExecSyncOptions): boolean {\n try {\n execSync('git rev-parse --is-inside-work-tree', opts)\n return true\n } catch (_) {\n // Ignore errors\n }\n return false\n}\n\nfunction ensureHasDefaultBranch(opts: ExecSyncOptions): boolean {\n try {\n execSync(`git config init.defaultBranch`, opts)\n return true\n } catch (_) {\n // Ignore errros\n }\n return false\n}\n"],"names":["execSync","warning","tryInitRepoAndCommit","args","execOpts","cwd","stdio","isGitRepo","ensureHasDefaultBranch","_","opts"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAExC,SAASC,OAAO,QAAQ,WAAU;AAElC,OAAO,SAASC,qBAAqBC,IAAqB;IACxD,MAAMC,WAA4B;QAAEC,KAAKF,KAAKE,GAAG;QAAEC,OAAO;IAAS;IACnE,IAAI;QACF,4BAA4B;QAC5BN,SAAS,UAAUI;QAEnB,sCAAsC;QACtC,IAAIG,UAAUH,WAAW;YACvB;QACF;QAEA,aAAa;QACbJ,SAAS,YAAYI;QACrB,IAAI,CAACI,uBAAuBJ,WAAW;YACrCJ,SAAS,wBAAwBI;QACnC;QAEA,uBAAuB;QACvBJ,SAAS,cAAcI;QACvBJ,SAAS,wCAAwCI;IACnD,EAAE,OAAOK,GAAG;QACVR,QAAQ;IACV;AACF;AAEA,SAASM,UAAUG,IAAqB;IACtC,IAAI;QACFV,SAAS,uCAAuCU;QAChD,OAAO;IACT,EAAE,OAAOD,GAAG;IACV,gBAAgB;IAClB;IACA,OAAO;AACT;AAEA,SAASD,uBAAuBE,IAAqB;IACnD,IAAI;QACFV,SAAS,CAAC,6BAA6B,CAAC,EAAEU;QAC1C,OAAO;IACT,EAAE,OAAOD,GAAG;IACV,gBAAgB;IAClB;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../src/utils/git.ts"],"sourcesContent":["import type { ExecSyncOptions } from 'child_process'\n\nimport { execSync } from 'child_process'\n\nimport { warning } from './log.js'\n\nexport function tryInitRepoAndCommit(args: { cwd: string }): void {\n const execOpts: ExecSyncOptions = { cwd: args.cwd, stdio: 'ignore' }\n try {\n // Check if git is available\n execSync('git -v', execOpts)\n\n // Do nothing if already in a git repo\n if (isGitRepo(execOpts)) {\n return\n }\n\n // Initialize\n execSync('git init', execOpts)\n if (!ensureHasDefaultBranch(execOpts)) {\n execSync('git checkout -b main', execOpts)\n }\n\n // Add and commit files\n execSync('git add -A', execOpts)\n execSync('git commit -m \"feat: initial commit\"', execOpts)\n } catch (_) {\n warning('Failed to initialize git repository.')\n }\n}\n\nfunction isGitRepo(opts: ExecSyncOptions): boolean {\n try {\n execSync('git rev-parse --is-inside-work-tree', opts)\n return true\n } catch (_) {\n // Ignore errors\n }\n return false\n}\n\nfunction ensureHasDefaultBranch(opts: ExecSyncOptions): boolean {\n try {\n execSync(`git config init.defaultBranch`, opts)\n return true\n } catch (_) {\n // Ignore errros\n }\n return false\n}\n"],"names":["execSync","warning","tryInitRepoAndCommit","args","execOpts","cwd","stdio","isGitRepo","ensureHasDefaultBranch","_","opts"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,gBAAe;AAExC,SAASC,OAAO,QAAQ,WAAU;AAElC,OAAO,SAASC,qBAAqBC,IAAqB;IACxD,MAAMC,WAA4B;QAAEC,KAAKF,KAAKE,GAAG;QAAEC,OAAO;IAAS;IACnE,IAAI;QACF,4BAA4B;QAC5BN,SAAS,UAAUI;QAEnB,sCAAsC;QACtC,IAAIG,UAAUH,WAAW;YACvB;QACF;QAEA,aAAa;QACbJ,SAAS,YAAYI;QACrB,IAAI,CAACI,uBAAuBJ,WAAW;YACrCJ,SAAS,wBAAwBI;QACnC;QAEA,uBAAuB;QACvBJ,SAAS,cAAcI;QACvBJ,SAAS,wCAAwCI;IACnD,EAAE,OAAOK,GAAG;QACVR,QAAQ;IACV;AACF;AAEA,SAASM,UAAUG,IAAqB;IACtC,IAAI;QACFV,SAAS,uCAAuCU;QAChD,OAAO;IACT,EAAE,OAAOD,GAAG;IACV,gBAAgB;IAClB;IACA,OAAO;AACT;AAEA,SAASD,uBAAuBE,IAAqB;IACnD,IAAI;QACFV,SAAS,CAAC,6BAA6B,CAAC,EAAEU;QAC1C,OAAO;IACT,EAAE,OAAOD,GAAG;IACV,gBAAgB;IAClB;IACA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/log.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport * as p from '@clack/prompts'\nimport chalk from 'chalk'\n\nexport const warning = (message: string): void => {\n p.log.warn(chalk.yellow('? ') + chalk.bold(message))\n}\n\nexport const info = (message: string): void => {\n p.log.step(chalk.bold(message))\n}\n\nexport const error = (message: string): void => {\n p.log.error(chalk.bold(message))\n}\n\nexport const debug = (message: string): void => {\n p.log.step(`${chalk.bgGray('[DEBUG]')} ${chalk.gray(message)}`)\n}\n\nexport const log = (message: string): void => {\n p.log.message(message)\n}\n"],"names":["p","chalk","warning","message","log","warn","yellow","bold","info","step","error","debug","bgGray","gray"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAAA,6BAA6B,GAC7B,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,UAAU,CAACC;IACtBH,EAAEI,GAAG,CAACC,IAAI,CAACJ,MAAMK,MAAM,CAAC,QAAQL,MAAMM,IAAI,CAACJ;AAC7C,EAAC;AAED,OAAO,MAAMK,OAAO,CAACL;IACnBH,EAAEI,GAAG,CAACK,IAAI,CAACR,MAAMM,IAAI,CAACJ;AACxB,EAAC;AAED,OAAO,MAAMO,QAAQ,CAACP;IACpBH,EAAEI,GAAG,CAACM,KAAK,CAACT,MAAMM,IAAI,CAACJ;AACzB,EAAC;AAED,OAAO,MAAMQ,QAAQ,CAACR;IACpBH,EAAEI,GAAG,CAACK,IAAI,CAAC,CAAC,EAAER,MAAMW,MAAM,CAAC,WAAW,CAAC,EAAEX,MAAMY,IAAI,CAACV,SAAS,CAAC;AAChE,EAAC;AAED,OAAO,MAAMC,MAAM,CAACD;IAClBH,EAAEI,GAAG,CAACD,OAAO,CAACA;AAChB,EAAC"}
1
+ {"version":3,"sources":["../../src/utils/log.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport * as p from '@clack/prompts'\nimport chalk from 'chalk'\n\nexport const warning = (message: string): void => {\n p.log.warn(chalk.yellow('? ') + chalk.bold(message))\n}\n\nexport const info = (message: string): void => {\n p.log.step(chalk.bold(message))\n}\n\nexport const error = (message: string): void => {\n p.log.error(chalk.bold(message))\n}\n\nexport const debug = (message: string): void => {\n p.log.step(`${chalk.bgGray('[DEBUG]')} ${chalk.gray(message)}`)\n}\n\nexport const log = (message: string): void => {\n p.log.message(message)\n}\n"],"names":["p","chalk","warning","message","log","warn","yellow","bold","info","step","error","debug","bgGray","gray"],"mappings":"AAAA,6BAA6B,GAC7B,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,WAAW,QAAO;AAEzB,OAAO,MAAMC,UAAU,CAACC;IACtBH,EAAEI,GAAG,CAACC,IAAI,CAACJ,MAAMK,MAAM,CAAC,QAAQL,MAAMM,IAAI,CAACJ;AAC7C,EAAC;AAED,OAAO,MAAMK,OAAO,CAACL;IACnBH,EAAEI,GAAG,CAACK,IAAI,CAACR,MAAMM,IAAI,CAACJ;AACxB,EAAC;AAED,OAAO,MAAMO,QAAQ,CAACP;IACpBH,EAAEI,GAAG,CAACM,KAAK,CAACT,MAAMM,IAAI,CAACJ;AACzB,EAAC;AAED,OAAO,MAAMQ,QAAQ,CAACR;IACpBH,EAAEI,GAAG,CAACK,IAAI,CAAC,CAAC,EAAER,MAAMW,MAAM,CAAC,WAAW,CAAC,EAAEX,MAAMY,IAAI,CAACV,SAAS,CAAC;AAChE,EAAC;AAED,OAAO,MAAMC,MAAM,CAACD;IAClBH,EAAEI,GAAG,CAACD,OAAO,CAACA;AAChB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/messages.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport chalk from 'chalk'\nimport path from 'path'\nimport terminalLink from 'terminal-link'\n\nimport type { PackageManager, ProjectTemplate } from '../types.js'\n\nimport { getValidTemplates } from '../lib/templates.js'\n\nconst header = (message: string): string => chalk.bold(message)\n\nexport const welcomeMessage = chalk`\n {green Welcome to Payload. Let's create a project! }\n`\n\nconst spacer = ' '.repeat(8)\n\nexport function helpMessage(): void {\n const validTemplates = getValidTemplates()\n console.log(chalk`\n {bold USAGE}\n\n {dim Inside of an existing Next.js project}\n\n {dim $} {bold npx create-payload-app}\n\n {dim Create a new project from scratch}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t template-name\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ${formatTemplates(validTemplates)}}\n\n --use-npm Use npm to install dependencies\n --use-yarn Use yarn to install dependencies\n --use-pnpm Use pnpm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n`)\n}\n\nfunction formatTemplates(templates: ProjectTemplate[]) {\n return `\\n\\n${spacer}${templates\n .map((t) => `${t.name}${' '.repeat(28 - t.name.length)}${t.description}`)\n .join(`\\n${spacer}`)}`\n}\n\nexport function successMessage(projectDir: string, packageManager: PackageManager): string {\n const relativePath = path.relative(process.cwd(), projectDir)\n return `\n${header('Launch Application:')}\n\n - cd ./${relativePath}\n - ${\n packageManager === 'npm' ? 'npm run' : packageManager\n } dev or follow directions in ${createTerminalLink(\n 'README.md',\n `file://${path.resolve(projectDir, 'README.md')}`,\n )}\n\n${header('Documentation:')}\n\n - ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n - ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n\n`\n}\n\nexport function successfulNextInit(): string {\n return `- ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n- ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n`\n}\n\nexport function moveMessage(args: { nextAppDir: string; projectDir: string }): string {\n const relativeAppDir = path.relative(process.cwd(), args.nextAppDir)\n return `\n${header('Next Steps:')}\n\nPayload does not support a top-level layout.tsx file in the app directory.\n\n${chalk.bold('To continue:')}\n\n- Create a new directory in ./${relativeAppDir} such as ./${relativeAppDir}/${chalk.bold('(app)')}\n- Move all files from ./${relativeAppDir} into that directory\n\nIt is recommended to do this from your IDE if your app has existing file references.\n\nOnce moved, rerun the create-payload-app command again.\n`\n}\n\nexport function feedbackOutro(): string {\n return `${chalk.bgCyan(chalk.black(' Have feedback? '))} Visit us on ${createTerminalLink('GitHub', 'https://github.com/payloadcms/payload')}.`\n}\n\n// Create terminalLink with fallback for unsupported terminals\nfunction createTerminalLink(text: string, url: string) {\n return terminalLink(text, url, {\n fallback: (text, url) => `${text}: ${url}`,\n })\n}\n"],"names":["chalk","path","terminalLink","getValidTemplates","header","message","bold","welcomeMessage","spacer","repeat","helpMessage","validTemplates","console","log","formatTemplates","templates","map","t","name","length","description","join","successMessage","projectDir","packageManager","relativePath","relative","process","cwd","createTerminalLink","resolve","successfulNextInit","moveMessage","args","relativeAppDir","nextAppDir","feedbackOutro","bgCyan","black","text","url","fallback"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,6BAA6B,GAC7B,OAAOA,WAAW,QAAO;AACzB,OAAOC,UAAU,OAAM;AACvB,OAAOC,kBAAkB,gBAAe;AAIxC,SAASC,iBAAiB,QAAQ,sBAAqB;AAEvD,MAAMC,SAAS,CAACC,UAA4BL,MAAMM,IAAI,CAACD;AAEvD,OAAO,MAAME,iBAAiBP,KAAK,CAAC;;AAEpC,CAAC,CAAA;AAED,MAAMQ,SAAS,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AC,gBAAgB;;8BAEC,EAAE4B,eAAe,WAAW,EAAEA,eAAe,CAAC,EAAElC,MAAMM,IAAI,CAAC,SAAS;wBAC1E,EAAE4B,eAAe;;;;;AAKzC,CAAC;AACD;AAEA,OAAO,SAASE;IACd,OAAO,CAAC,EAAEpC,MAAMqC,MAAM,CAACrC,MAAMsC,KAAK,CAAC,qBAAqB,aAAa,EAAET,mBAAmB,UAAU,yCAAyC,CAAC,CAAC;AACjJ;AAEA,8DAA8D;AAC9D,SAASA,mBAAmBU,IAAY,EAAEC,GAAW;IACnD,OAAOtC,aAAaqC,MAAMC,KAAK;QAC7BC,UAAU,CAACF,MAAMC,MAAQ,CAAC,EAAED,KAAK,EAAE,EAAEC,IAAI,CAAC;IAC5C;AACF"}
1
+ {"version":3,"sources":["../../src/utils/messages.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport chalk from 'chalk'\nimport path from 'path'\nimport terminalLink from 'terminal-link'\n\nimport type { PackageManager, ProjectTemplate } from '../types.js'\n\nimport { getValidTemplates } from '../lib/templates.js'\n\nconst header = (message: string): string => chalk.bold(message)\n\nexport const welcomeMessage = chalk`\n {green Welcome to Payload. Let's create a project! }\n`\n\nconst spacer = ' '.repeat(8)\n\nexport function helpMessage(): void {\n const validTemplates = getValidTemplates()\n console.log(chalk`\n {bold USAGE}\n\n {dim Inside of an existing Next.js project}\n\n {dim $} {bold npx create-payload-app}\n\n {dim Create a new project from scratch}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t template-name\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ${formatTemplates(validTemplates)}}\n\n --use-npm Use npm to install dependencies\n --use-yarn Use yarn to install dependencies\n --use-pnpm Use pnpm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n`)\n}\n\nfunction formatTemplates(templates: ProjectTemplate[]) {\n return `\\n\\n${spacer}${templates\n .map((t) => `${t.name}${' '.repeat(28 - t.name.length)}${t.description}`)\n .join(`\\n${spacer}`)}`\n}\n\nexport function successMessage(projectDir: string, packageManager: PackageManager): string {\n const relativePath = path.relative(process.cwd(), projectDir)\n return `\n${header('Launch Application:')}\n\n - cd ./${relativePath}\n - ${\n packageManager === 'npm' ? 'npm run' : packageManager\n } dev or follow directions in ${createTerminalLink(\n 'README.md',\n `file://${path.resolve(projectDir, 'README.md')}`,\n )}\n\n${header('Documentation:')}\n\n - ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n - ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n\n`\n}\n\nexport function successfulNextInit(): string {\n return `- ${createTerminalLink(\n 'Getting Started',\n 'https://payloadcms.com/docs/getting-started/what-is-payload',\n )}\n- ${createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview')}\n`\n}\n\nexport function moveMessage(args: { nextAppDir: string; projectDir: string }): string {\n const relativeAppDir = path.relative(process.cwd(), args.nextAppDir)\n return `\n${header('Next Steps:')}\n\nPayload does not support a top-level layout.tsx file in the app directory.\n\n${chalk.bold('To continue:')}\n\n- Create a new directory in ./${relativeAppDir} such as ./${relativeAppDir}/${chalk.bold('(app)')}\n- Move all files from ./${relativeAppDir} into that directory\n\nIt is recommended to do this from your IDE if your app has existing file references.\n\nOnce moved, rerun the create-payload-app command again.\n`\n}\n\nexport function feedbackOutro(): string {\n return `${chalk.bgCyan(chalk.black(' Have feedback? '))} Visit us on ${createTerminalLink('GitHub', 'https://github.com/payloadcms/payload')}.`\n}\n\n// Create terminalLink with fallback for unsupported terminals\nfunction createTerminalLink(text: string, url: string) {\n return terminalLink(text, url, {\n fallback: (text, url) => `${text}: ${url}`,\n })\n}\n"],"names":["chalk","path","terminalLink","getValidTemplates","header","message","bold","welcomeMessage","spacer","repeat","helpMessage","validTemplates","console","log","formatTemplates","templates","map","t","name","length","description","join","successMessage","projectDir","packageManager","relativePath","relative","process","cwd","createTerminalLink","resolve","successfulNextInit","moveMessage","args","relativeAppDir","nextAppDir","feedbackOutro","bgCyan","black","text","url","fallback"],"mappings":"AAAA,6BAA6B,GAC7B,OAAOA,WAAW,QAAO;AACzB,OAAOC,UAAU,OAAM;AACvB,OAAOC,kBAAkB,gBAAe;AAIxC,SAASC,iBAAiB,QAAQ,sBAAqB;AAEvD,MAAMC,SAAS,CAACC,UAA4BL,MAAMM,IAAI,CAACD;AAEvD,OAAO,MAAME,iBAAiBP,KAAK,CAAC;;AAEpC,CAAC,CAAA;AAED,MAAMQ,SAAS,IAAIC,MAAM,CAAC;AAE1B,OAAO,SAASC;IACd,MAAMC,iBAAiBR;IACvBS,QAAQC,GAAG,CAACb,KAAK,CAAC;;;;;;;;;;;;;;;;;;kCAkBc,EAAEc,gBAAgBH,gBAAgB;;;;;;;AAOpE,CAAC;AACD;AAEA,SAASG,gBAAgBC,SAA4B;IACnD,OAAO,CAAC,IAAI,EAAEP,OAAO,EAAEO,UACpBC,GAAG,CAAC,CAACC,IAAM,CAAC,EAAEA,EAAEC,IAAI,CAAC,EAAE,IAAIT,MAAM,CAAC,KAAKQ,EAAEC,IAAI,CAACC,MAAM,EAAE,EAAEF,EAAEG,WAAW,CAAC,CAAC,EACvEC,IAAI,CAAC,CAAC,EAAE,EAAEb,OAAO,CAAC,EAAE,CAAC;AAC1B;AAEA,OAAO,SAASc,eAAeC,UAAkB,EAAEC,cAA8B;IAC/E,MAAMC,eAAexB,KAAKyB,QAAQ,CAACC,QAAQC,GAAG,IAAIL;IAClD,OAAO,CAAC;AACV,EAAEnB,OAAO,uBAAuB;;SAEvB,EAAEqB,aAAa;IACpB,EACAD,mBAAmB,QAAQ,YAAYA,eACxC,6BAA6B,EAAEK,mBAC9B,aACA,CAAC,OAAO,EAAE5B,KAAK6B,OAAO,CAACP,YAAY,aAAa,CAAC,EACjD;;AAEJ,EAAEnB,OAAO,kBAAkB;;IAEvB,EAAEyB,mBACF,mBACA,+DACA;IACA,EAAEA,mBAAmB,iBAAiB,sDAAsD;;AAEhG,CAAC;AACD;AAEA,OAAO,SAASE;IACd,OAAO,CAAC,EAAE,EAAEF,mBACV,mBACA,+DACA;EACF,EAAEA,mBAAmB,iBAAiB,sDAAsD;AAC9F,CAAC;AACD;AAEA,OAAO,SAASG,YAAYC,IAAgD;IAC1E,MAAMC,iBAAiBjC,KAAKyB,QAAQ,CAACC,QAAQC,GAAG,IAAIK,KAAKE,UAAU;IACnE,OAAO,CAAC;AACV,EAAE/B,OAAO,eAAe;;;;AAIxB,EAAEJ,MAAMM,IAAI,CAAC,gBAAgB;;8BAEC,EAAE4B,eAAe,WAAW,EAAEA,eAAe,CAAC,EAAElC,MAAMM,IAAI,CAAC,SAAS;wBAC1E,EAAE4B,eAAe;;;;;AAKzC,CAAC;AACD;AAEA,OAAO,SAASE;IACd,OAAO,CAAC,EAAEpC,MAAMqC,MAAM,CAACrC,MAAMsC,KAAK,CAAC,qBAAqB,aAAa,EAAET,mBAAmB,UAAU,yCAAyC,CAAC,CAAC;AACjJ;AAEA,8DAA8D;AAC9D,SAASA,mBAAmBU,IAAY,EAAEC,GAAW;IACnD,OAAOtC,aAAaqC,MAAMC,KAAK;QAC7BC,UAAU,CAACF,MAAMC,MAAQ,CAAC,EAAED,KAAK,EAAE,EAAEC,IAAI,CAAC;IAC5C;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-payload-app",
3
- "version": "3.0.0-canary.8223f17",
3
+ "version": "3.0.0-canary.926cbeb",
4
4
  "homepage": "https://payloadcms.com",
5
5
  "repository": {
6
6
  "type": "git",