create-payload-app 3.0.0-canary.d6053cd → 3.0.0-canary.dc8b1fe
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/lib/constants.d.ts +2 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +9 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/create-project.d.ts.map +1 -1
- package/dist/lib/create-project.js +9 -4
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/create-project.spec.js +5 -7
- package/dist/lib/create-project.spec.js.map +1 -1
- package/dist/lib/download-template.d.ts +10 -0
- package/dist/lib/download-template.d.ts.map +1 -0
- package/dist/lib/download-template.js +21 -0
- package/dist/lib/download-template.js.map +1 -0
- package/dist/lib/get-package-manager.js +26 -5
- package/dist/lib/get-package-manager.js.map +1 -1
- package/dist/lib/init-next.d.ts.map +1 -1
- package/dist/lib/init-next.js +54 -12
- package/dist/lib/init-next.js.map +1 -1
- package/dist/lib/parse-project-name.d.ts.map +1 -1
- package/dist/lib/parse-project-name.js +9 -3
- package/dist/lib/parse-project-name.js.map +1 -1
- package/dist/lib/parse-template.d.ts.map +1 -1
- package/dist/lib/parse-template.js +3 -1
- package/dist/lib/parse-template.js.map +1 -1
- package/dist/lib/replacements.d.ts.map +1 -1
- package/dist/lib/replacements.js +27 -3
- package/dist/lib/replacements.js.map +1 -1
- package/dist/lib/select-db.d.ts.map +1 -1
- package/dist/lib/select-db.js +23 -14
- package/dist/lib/select-db.js.map +1 -1
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +3 -2
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/update-payload-in-project.d.ts.map +1 -1
- package/dist/lib/update-payload-in-project.js +7 -5
- package/dist/lib/update-payload-in-project.js.map +1 -1
- package/dist/lib/wrap-next-config.d.ts +5 -5
- package/dist/lib/wrap-next-config.d.ts.map +1 -1
- package/dist/lib/wrap-next-config.js +119 -59
- package/dist/lib/wrap-next-config.js.map +1 -1
- package/dist/lib/wrap-next-config.spec.js +72 -22
- package/dist/lib/wrap-next-config.spec.js.map +1 -1
- package/dist/lib/write-env-file.d.ts +2 -1
- package/dist/lib/write-env-file.d.ts.map +1 -1
- package/dist/lib/write-env-file.js +9 -4
- package/dist/lib/write-env-file.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +16 -3
- package/dist/main.js.map +1 -1
- package/dist/scripts/pack-template-files.js +3 -3
- package/dist/scripts/pack-template-files.js.map +1 -1
- package/dist/template/src/app/(payload)/admin/[[...segments]]/not-found.tsx +8 -6
- package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +8 -6
- package/dist/template/src/app/(payload)/admin/importMap.js +1 -0
- package/dist/template/src/app/(payload)/api/[...slug]/route.ts +11 -2
- package/dist/template/src/app/(payload)/api/graphql/route.ts +4 -2
- package/dist/template/src/app/(payload)/api/graphql-playground/route.ts +2 -1
- package/dist/template/src/app/(payload)/layout.tsx +19 -4
- package/dist/template/src/payload-types.ts +127 -0
- package/dist/template/src/payload.config.ts +3 -0
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/copy-recursive-sync.d.ts +1 -1
- package/dist/utils/copy-recursive-sync.d.ts.map +1 -1
- package/dist/utils/copy-recursive-sync.js +1 -1
- package/dist/utils/copy-recursive-sync.js.map +1 -1
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +1 -0
- package/dist/utils/messages.js.map +1 -1
- package/package.json +10 -5
@@ -3,7 +3,9 @@ export async function parseTemplate(args, validTemplates) {
|
|
3
3
|
if (args['--template']) {
|
4
4
|
const templateName = args['--template'];
|
5
5
|
const template = validTemplates.find((t)=>t.name === templateName);
|
6
|
-
if (!template)
|
6
|
+
if (!template) {
|
7
|
+
throw new Error('Invalid template given');
|
8
|
+
}
|
7
9
|
return template;
|
8
10
|
}
|
9
11
|
const response = await p.select({
|
@@ -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"],"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;
|
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) {\n throw new Error('Invalid template given')\n }\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;YACb,MAAM,IAAII,MAAM;QAClB;QACA,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMV,EAAEW,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASV,eAAeW,GAAG,CAAC,CAACd;YAC3B,OAAO;gBACLe,OAAOf,EAAEQ,IAAI;gBACbQ,OAAOhB,EAAEQ,IAAI;YACf;QACF;IACF;IACA,IAAIR,EAAEiB,QAAQ,CAACP,WAAW;QACxBQ,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMd,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"replacements.d.ts","sourceRoot":"","sources":["../../src/lib/replacements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,oBAAoB,GAAG;IAC1B,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;IACjD,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;
|
1
|
+
{"version":3,"file":"replacements.d.ts","sourceRoot":"","sources":["../../src/lib/replacements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE7D,KAAK,oBAAoB,GAAG;IAC1B,iBAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;IACjD,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAiDD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAK/D,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AA4BD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,kBAAkB,EAAE,yBAAyB,CAIrF,CAAA;AAED;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACvB,iBAAiB,EAAE;QACjB,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,EAAE,MAAM,CAAA;KACpB,CAAA;IACD,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAUhE,CAAA"}
|
package/dist/lib/replacements.js
CHANGED
@@ -19,9 +19,33 @@ const postgresReplacement = {
|
|
19
19
|
importReplacement: "import { postgresAdapter } from '@payloadcms/db-postgres'",
|
20
20
|
packageName: '@payloadcms/db-postgres'
|
21
21
|
};
|
22
|
+
const vercelPostgresReplacement = {
|
23
|
+
configReplacement: (envName = 'POSTGRES_URL')=>[
|
24
|
+
' db: vercelPostgresAdapter({',
|
25
|
+
' pool: {',
|
26
|
+
` connectionString: process.env.${envName} || '',`,
|
27
|
+
' },',
|
28
|
+
' }),'
|
29
|
+
],
|
30
|
+
importReplacement: "import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'",
|
31
|
+
packageName: '@payloadcms/db-vercel-postgres'
|
32
|
+
};
|
33
|
+
const sqliteReplacement = {
|
34
|
+
configReplacement: (envName = 'DATABASE_URI')=>[
|
35
|
+
' db: sqliteAdapter({',
|
36
|
+
' client: {',
|
37
|
+
` url: process.env.${envName} || '',`,
|
38
|
+
' },',
|
39
|
+
' }),'
|
40
|
+
],
|
41
|
+
importReplacement: "import { sqliteAdapter } from '@payloadcms/db-sqlite'",
|
42
|
+
packageName: '@payloadcms/db-sqlite'
|
43
|
+
};
|
22
44
|
export const dbReplacements = {
|
23
45
|
mongodb: mongodbReplacement,
|
24
|
-
postgres: postgresReplacement
|
46
|
+
postgres: postgresReplacement,
|
47
|
+
sqlite: sqliteReplacement,
|
48
|
+
'vercel-postgres': vercelPostgresReplacement
|
25
49
|
};
|
26
50
|
const vercelBlobStorageReplacement = {
|
27
51
|
// Replacement of `// storage-adapter-placeholder`
|
@@ -40,8 +64,8 @@ const payloadCloudReplacement = {
|
|
40
64
|
configReplacement: [
|
41
65
|
' payloadCloudPlugin(),'
|
42
66
|
],
|
43
|
-
importReplacement: "import { payloadCloudPlugin } from '@payloadcms/
|
44
|
-
packageName: '@payloadcms/
|
67
|
+
importReplacement: "import { payloadCloudPlugin } from '@payloadcms/payload-cloud'",
|
68
|
+
packageName: '@payloadcms/payload-cloud'
|
45
69
|
};
|
46
70
|
// Removes placeholders
|
47
71
|
const diskReplacement = {
|
@@ -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/
|
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\nconst vercelPostgresReplacement: DbAdapterReplacement = {\n configReplacement: (envName = 'POSTGRES_URL') => [\n ' db: vercelPostgresAdapter({',\n ' pool: {',\n ` connectionString: process.env.${envName} || '',`,\n ' },',\n ' }),',\n ],\n importReplacement: \"import { vercelPostgresAdapter } from '@payloadcms/db-vercel-postgres'\",\n packageName: '@payloadcms/db-vercel-postgres',\n}\n\nconst sqliteReplacement: DbAdapterReplacement = {\n configReplacement: (envName = 'DATABASE_URI') => [\n ' db: sqliteAdapter({',\n ' client: {',\n ` url: process.env.${envName} || '',`,\n ' },',\n ' }),',\n ],\n importReplacement: \"import { sqliteAdapter } from '@payloadcms/db-sqlite'\",\n packageName: '@payloadcms/db-sqlite',\n}\n\nexport const dbReplacements: Record<DbType, DbAdapterReplacement> = {\n mongodb: mongodbReplacement,\n postgres: postgresReplacement,\n sqlite: sqliteReplacement,\n 'vercel-postgres': vercelPostgresReplacement,\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/payload-cloud'\",\n packageName: '@payloadcms/payload-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","vercelPostgresReplacement","sqliteReplacement","dbReplacements","mongodb","postgres","sqlite","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,MAAME,4BAAkD;IACtDL,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA;YACA,CAAC,oCAAoC,EAAEA,QAAQ,OAAO,CAAC;YACvD;YACA;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMG,oBAA0C;IAC9CN,mBAAmB,CAACC,UAAU,cAAc,GAAK;YAC/C;YACA;YACA,CAAC,uBAAuB,EAAEA,QAAQ,OAAO,CAAC;YAC1C;YACA;SACD;IACDC,mBAAmB;IACnBC,aAAa;AACf;AAEA,OAAO,MAAMI,iBAAuD;IAClEC,SAAST;IACTU,UAAUL;IACVM,QAAQJ;IACR,mBAAmBD;AACrB,EAAC;AAQD,MAAMM,+BAA0D;IAC9D,kDAAkD;IAClDX,mBAAmB;QACjB;QACA;QACA;QACA;QACA;QACA;KACD;IACDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,MAAMS,0BAAqD;IACzDZ,mBAAmB;QAAC;KAA4B;IAChDE,mBAAmB;IACnBC,aAAa;AACf;AAEA,uBAAuB;AACvB,MAAMU,kBAA6C;IACjDb,mBAAmB,EAAE;IACrBE,mBAAmB;AACrB;AAEA,OAAO,MAAMY,sBAA6E;IACxFC,WAAWF;IACXG,cAAcJ;IACdK,mBAAmBN;AACrB,EAAC;AAcD,OAAO,MAAMO,qBAAwD;IACnEC,OAAO;QACL,0CAA0C;QAC1CnB,mBAAmB;YACjBoB,OAAO;YACPC,aAAa;QACf;QACAnB,mBAAmB;QACnBC,aAAa;IACf;AACF,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"select-db.d.ts","sourceRoot":"","sources":["../../src/lib/select-db.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAU,MAAM,aAAa,CAAA;
|
1
|
+
{"version":3,"file":"select-db.d.ts","sourceRoot":"","sources":["../../src/lib/select-db.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAU,MAAM,aAAa,CAAA;AAiC7D,wBAAsB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAkDrF"}
|
package/dist/lib/select-db.js
CHANGED
@@ -8,8 +8,19 @@ const dbChoiceRecord = {
|
|
8
8
|
},
|
9
9
|
postgres: {
|
10
10
|
dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',
|
11
|
-
title: 'PostgreSQL
|
11
|
+
title: 'PostgreSQL',
|
12
12
|
value: 'postgres'
|
13
|
+
},
|
14
|
+
sqlite: {
|
15
|
+
dbConnectionPrefix: 'file:./',
|
16
|
+
dbConnectionSuffix: '.db',
|
17
|
+
title: 'SQLite (beta)',
|
18
|
+
value: 'sqlite'
|
19
|
+
},
|
20
|
+
'vercel-postgres': {
|
21
|
+
dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',
|
22
|
+
title: 'Vercel Postgres (beta)',
|
23
|
+
value: 'vercel-postgres'
|
13
24
|
}
|
14
25
|
};
|
15
26
|
export async function selectDb(args, projectName) {
|
@@ -23,22 +34,18 @@ export async function selectDb(args, projectName) {
|
|
23
34
|
dbType = await p.select({
|
24
35
|
initialValue: 'mongodb',
|
25
36
|
message: `Select a database`,
|
26
|
-
options:
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
},
|
31
|
-
{
|
32
|
-
label: 'Postgres',
|
33
|
-
value: 'postgres'
|
34
|
-
}
|
35
|
-
]
|
37
|
+
options: Object.values(dbChoiceRecord).map((dbChoice)=>({
|
38
|
+
label: dbChoice.title,
|
39
|
+
value: dbChoice.value
|
40
|
+
}))
|
36
41
|
});
|
37
|
-
if (p.isCancel(dbType))
|
42
|
+
if (p.isCancel(dbType)) {
|
43
|
+
process.exit(0);
|
44
|
+
}
|
38
45
|
}
|
39
46
|
const dbChoice = dbChoiceRecord[dbType];
|
40
47
|
let dbUri = undefined;
|
41
|
-
const initialDbUri = `${dbChoice.dbConnectionPrefix}${projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)}`;
|
48
|
+
const initialDbUri = `${dbChoice.dbConnectionPrefix}${projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)}${dbChoice.dbConnectionSuffix || ''}`;
|
42
49
|
if (args['--db-accept-recommended']) {
|
43
50
|
dbUri = initialDbUri;
|
44
51
|
} else if (args['--db-connection-string']) {
|
@@ -48,7 +55,9 @@ export async function selectDb(args, projectName) {
|
|
48
55
|
initialValue: initialDbUri,
|
49
56
|
message: `Enter ${dbChoice.title.split(' ')[0]} connection string`
|
50
57
|
});
|
51
|
-
if (p.isCancel(dbUri))
|
58
|
+
if (p.isCancel(dbUri)) {
|
59
|
+
process.exit(0);
|
60
|
+
}
|
52
61
|
}
|
53
62
|
return {
|
54
63
|
type: dbChoice.value,
|
@@ -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:
|
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 dbConnectionSuffix?: 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',\n value: 'postgres',\n },\n sqlite: {\n dbConnectionPrefix: 'file:./',\n dbConnectionSuffix: '.db',\n title: 'SQLite (beta)',\n value: 'sqlite',\n },\n 'vercel-postgres': {\n dbConnectionPrefix: 'postgres://postgres:<password>@127.0.0.1:5432/',\n title: 'Vercel Postgres (beta)',\n value: 'vercel-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: Object.values(dbChoiceRecord).map((dbChoice) => ({\n label: dbChoice.title,\n value: dbChoice.value,\n })),\n })\n if (p.isCancel(dbType)) {\n process.exit(0)\n }\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 }${dbChoice.dbConnectionSuffix || ''}`\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)) {\n process.exit(0)\n }\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","sqlite","dbConnectionSuffix","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;AAW3C,MAAMC,iBAA2C;IAC/CC,SAAS;QACPC,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;IACAC,UAAU;QACRH,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;IACAE,QAAQ;QACNJ,oBAAoB;QACpBK,oBAAoB;QACpBJ,OAAO;QACPC,OAAO;IACT;IACA,mBAAmB;QACjBF,oBAAoB;QACpBC,OAAO;QACPC,OAAO;IACT;AACF;AAEA,OAAO,eAAeI,SAASC,IAAa,EAAEC,WAAmB;IAC/D,IAAIC,SAAsCC;IAC1C,IAAIH,IAAI,CAAC,OAAO,EAAE;QAChB,IAAI,CAACI,OAAOC,MAAM,CAACd,gBAAgBe,IAAI,CAAC,CAACC,WAAaA,SAASZ,KAAK,KAAKK,IAAI,CAAC,OAAO,GAAG;YACtF,MAAM,IAAIQ,MACR,CAAC,8CAA8C,EAAEJ,OAAOC,MAAM,CAACd,gBAC5DkB,GAAG,CAAC,CAACF,WAAaA,SAASZ,KAAK,EAChCe,IAAI,CAAC,MAAM,CAAC;QAEnB;QACAR,SAASF,IAAI,CAAC,OAAO;IACvB,OAAO;QACLE,SAAS,MAAMb,EAAEsB,MAAM,CAA6C;YAClEC,cAAc;YACdC,SAAS,CAAC,iBAAiB,CAAC;YAC5BC,SAASV,OAAOC,MAAM,CAACd,gBAAgBkB,GAAG,CAAC,CAACF,WAAc,CAAA;oBACxDQ,OAAOR,SAASb,KAAK;oBACrBC,OAAOY,SAASZ,KAAK;gBACvB,CAAA;QACF;QACA,IAAIN,EAAE2B,QAAQ,CAACd,SAAS;YACtBe,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,MAAMX,WAAWhB,cAAc,CAACW,OAAO;IAEvC,IAAIiB,QAAqChB;IACzC,MAAMiB,eAAe,CAAC,EAAEb,SAASd,kBAAkB,CAAC,EAClDQ,gBAAgB,MAAM,CAAC,QAAQ,EAAEoB,uBAAuB,CAAC,GAAG/B,QAAQW,aACrE,EAAEM,SAAST,kBAAkB,IAAI,GAAG,CAAC;IAEtC,IAAIE,IAAI,CAAC,0BAA0B,EAAE;QACnCmB,QAAQC;IACV,OAAO,IAAIpB,IAAI,CAAC,yBAAyB,EAAE;QACzCmB,QAAQnB,IAAI,CAAC,yBAAyB;IACxC,OAAO;QACLmB,QAAQ,MAAM9B,EAAEiC,IAAI,CAAC;YACnBV,cAAcQ;YACdP,SAAS,CAAC,MAAM,EAAEN,SAASb,KAAK,CAAC6B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC;QACpE;QACA,IAAIlC,EAAE2B,QAAQ,CAACG,QAAQ;YACrBF,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,OAAO;QACLM,MAAMjB,SAASZ,KAAK;QACpBwB;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,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/lib/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/lib/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAQ9D;AAED,wBAAgB,iBAAiB,IAAI,eAAe,EAAE,CAgDrD"}
|
package/dist/lib/templates.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { error, info } from '../utils/log.js';
|
2
|
+
import { PACKAGE_VERSION } from './constants.js';
|
2
3
|
export function validateTemplate(templateName) {
|
3
4
|
const validTemplates = getValidTemplates();
|
4
5
|
if (!validTemplates.map((t)=>t.name).includes(templateName)) {
|
@@ -14,13 +15,13 @@ export function getValidTemplates() {
|
|
14
15
|
name: 'blank',
|
15
16
|
type: 'starter',
|
16
17
|
description: 'Blank 3.0 Template',
|
17
|
-
url:
|
18
|
+
url: `https://github.com/payloadcms/payload/templates/blank#v${PACKAGE_VERSION}`
|
18
19
|
},
|
19
20
|
{
|
20
21
|
name: 'website',
|
21
22
|
type: 'starter',
|
22
23
|
description: 'Website Template',
|
23
|
-
url:
|
24
|
+
url: `https://github.com/payloadcms/payload/templates/website#v${PACKAGE_VERSION}`
|
24
25
|
}
|
25
26
|
];
|
26
27
|
}
|
@@ -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:
|
1
|
+
{"version":3,"sources":["../../src/lib/templates.ts"],"sourcesContent":["import type { ProjectTemplate } from '../types.js'\n\nimport { error, info } from '../utils/log.js'\nimport { PACKAGE_VERSION } from './constants.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#v${PACKAGE_VERSION}`,\n },\n {\n name: 'website',\n type: 'starter',\n description: 'Website Template',\n url: `https://github.com/payloadcms/payload/templates/website#v${PACKAGE_VERSION}`,\n },\n\n // Remove these until they have been updated for 3.0\n\n // {\n // name: 'blank',\n // type: 'starter',\n // description: 'Blank Template',\n // url: 'https://github.com/payloadcms/payload/templates/blank',\n // },\n // {\n // name: 'ecommerce',\n // type: 'starter',\n // description: 'E-commerce Template',\n // url: 'https://github.com/payloadcms/payload/templates/ecommerce',\n // },\n // {\n // name: 'plugin',\n // type: 'plugin',\n // description: 'Template for creating a Payload plugin',\n // url: 'https://github.com/payloadcms/payload-plugin-template#beta',\n // },\n // {\n // name: 'payload-demo',\n // type: 'starter',\n // description: 'Payload demo site at https://demo.payloadcms.com',\n // url: 'https://github.com/payloadcms/public-demo',\n // },\n // {\n // name: 'payload-website',\n // type: 'starter',\n // description: 'Payload website CMS at https://payloadcms.com',\n // url: 'https://github.com/payloadcms/website-cms',\n // },\n ]\n}\n"],"names":["error","info","PACKAGE_VERSION","validateTemplate","templateName","validTemplates","getValidTemplates","map","t","name","includes","join","type","description","url"],"mappings":"AAEA,SAASA,KAAK,EAAEC,IAAI,QAAQ,kBAAiB;AAC7C,SAASC,eAAe,QAAQ,iBAAgB;AAEhD,OAAO,SAASC,iBAAiBC,YAAoB;IACnD,MAAMC,iBAAiBC;IACvB,IAAI,CAACD,eAAeE,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,QAAQ,CAACN,eAAe;QAC7DJ,MAAM,CAAC,CAAC,EAAEI,aAAa,0BAA0B,CAAC;QAClDH,KAAK,CAAC,iBAAiB,EAAEI,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,CAAC,uDAAuD,EAAEZ,gBAAgB,CAAC;QAClF;QACA;YACEO,MAAM;YACNG,MAAM;YACNC,aAAa;YACbC,KAAK,CAAC,yDAAyD,EAAEZ,gBAAgB,CAAC;QACpF;KAkCD;AACH"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"update-payload-in-project.d.ts","sourceRoot":"","sources":["../../src/lib/update-payload-in-project.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOjD,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,
|
1
|
+
{"version":3,"file":"update-payload-in-project.d.ts","sourceRoot":"","sources":["../../src/lib/update-payload-in-project.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOjD,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CA2EhD"}
|
@@ -9,10 +9,12 @@ import { info } from '../utils/log.js';
|
|
9
9
|
import { getPackageManager } from './get-package-manager.js';
|
10
10
|
import { installPackages } from './install-packages.js';
|
11
11
|
export async function updatePayloadInProject(appDetails) {
|
12
|
-
if (!appDetails.nextConfigPath)
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if (!appDetails.nextConfigPath) {
|
13
|
+
return {
|
14
|
+
message: 'No Next.js config found',
|
15
|
+
success: false
|
16
|
+
};
|
17
|
+
}
|
16
18
|
const projectDir = path.dirname(appDetails.nextConfigPath);
|
17
19
|
const packageObj = await fse.readJson(path.resolve(projectDir, 'package.json'));
|
18
20
|
if (!packageObj?.dependencies) {
|
@@ -59,7 +61,7 @@ export async function updatePayloadInProject(appDetails) {
|
|
59
61
|
}
|
60
62
|
info('Payload packages updated successfully.');
|
61
63
|
info(`Updating Payload Next.js files...`);
|
62
|
-
const templateFilesPath =
|
64
|
+
const templateFilesPath = process.env.JEST_WORKER_ID !== undefined ? path.resolve(dirname, '../../../../templates/blank') : path.resolve(dirname, '../..', 'dist/template');
|
63
65
|
const templateSrcDir = path.resolve(templateFilesPath, 'src/app/(payload)');
|
64
66
|
copyRecursiveSync(templateSrcDir, path.resolve(projectDir, appDetails.isSrcDir ? 'src/app' : 'app', '(payload)'));
|
65
67
|
return {
|
@@ -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
|
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) {\n return { message: 'No Next.js config found', success: false }\n }\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\n const templateFilesPath =\n process.env.JEST_WORKER_ID !== undefined\n ? path.resolve(dirname, '../../../../templates/blank')\n : path.resolve(dirname, '../..', 'dist/template')\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","process","env","JEST_WORKER_ID","undefined","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;AAEvD,OAAO,eAAeC,uBACpBC,UAA0B;IAE1B,IAAI,CAACA,WAAWC,cAAc,EAAE;QAC9B,OAAO;YAAEC,SAAS;YAA2BC,SAAS;QAAM;IAC9D;IAEA,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;IAChD,IAAI,CAACD,gBAAgB;QACnB,MAAM,IAAID,MAAM;IAClB;IAEA,MAAMG,iBAAiB,MAAMf,kBAAkB;QAAEO;IAAW;IAE5D,wCAAwC;IACxC,MAAM,EAAES,UAAUC,wBAAwB,EAAEC,QAAQC,oBAAoB,EAAE,GAAG,MAAM5B,MAAM,OAAO;QAC9F;QACA;QACA;KACD;IACD,IAAI0B,6BAA6B,GAAG;QAClC,MAAM,IAAIL,MAAM;IAClB;IAEA,IAAIC,mBAAmBM,sBAAsB;QAC3C,OAAO;YAAEd,SAAS,CAAC,SAAS,EAAEQ,eAAe,uBAAuB,CAAC;YAAEP,SAAS;QAAK;IACvF;IAEA,uCAAuC;IACvC,MAAMc,kBAAkBC,OAAOC,IAAI,CAACd,WAAWG,YAAY,EAAEY,MAAM,CAAC,CAACC,MACnEA,IAAIC,UAAU,CAAC;IAGjB,MAAMC,eAAe;QAAC;WAAcN;KAAgB;IAEpD,MAAMO,mBAAmBD,aAAaE,GAAG,CAAC,CAACC,MAAQ,CAAC,EAAEA,IAAI,CAAC,EAAEV,qBAAqB,CAAC;IAEnFpB,KAAK,CAAC,MAAM,EAAEgB,eAAe,GAAG,CAAC;IACjChB,KACE,CAAC,SAAS,EAAE4B,iBAAiBG,MAAM,CAAC,sBAAsB,EAAEX,qBAAqB,OAAO,EAAEO,aAAaE,GAAG,CAAC,CAACG,IAAM,CAAC,IAAI,EAAEA,EAAE,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;IAExC,MAAMoC,oBACJC,QAAQC,GAAG,CAACC,cAAc,KAAKC,YAC3B7C,KAAKgB,OAAO,CAACb,SAAS,iCACtBH,KAAKgB,OAAO,CAACb,SAAS,SAAS;IAErC,MAAM2C,iBAAiB9C,KAAKgB,OAAO,CAACyB,mBAAmB;IAEvDrC,kBACE0C,gBACA9C,KAAKgB,OAAO,CAACH,YAAYJ,WAAWsC,QAAQ,GAAG,YAAY,OAAO;IAGpE,OAAO;QAAEpC,SAAS;QAAiCC,SAAS;IAAK;AACnE"}
|
@@ -1,18 +1,18 @@
|
|
1
|
+
import type { NextConfigType } from '../types.js';
|
1
2
|
export declare const withPayloadStatement: {
|
2
3
|
cjs: string;
|
3
4
|
esm: string;
|
5
|
+
ts: string;
|
4
6
|
};
|
5
|
-
type NextConfigType = 'cjs' | 'esm';
|
6
7
|
export declare const wrapNextConfig: (args: {
|
7
8
|
nextConfigPath: string;
|
8
9
|
nextConfigType: NextConfigType;
|
9
|
-
}) => void
|
10
|
+
}) => Promise<void>;
|
10
11
|
/**
|
11
12
|
* Parses config content with AST and wraps it with withPayload function
|
12
13
|
*/
|
13
|
-
export declare function parseAndModifyConfigContent(content: string, configType: NextConfigType): {
|
14
|
+
export declare function parseAndModifyConfigContent(content: string, configType: NextConfigType): Promise<{
|
14
15
|
modifiedConfigContent: string;
|
15
16
|
success: boolean;
|
16
|
-
}
|
17
|
-
export {};
|
17
|
+
}>;
|
18
18
|
//# sourceMappingURL=wrap-next-config.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"wrap-next-config.d.ts","sourceRoot":"","sources":["../../src/lib/wrap-next-config.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"wrap-next-config.d.ts","sourceRoot":"","sources":["../../src/lib/wrap-next-config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD,eAAO,MAAM,oBAAoB;;;;CAIhC,CAAA;AAED,eAAO,MAAM,cAAc,SAAgB;IACzC,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,cAAc,CAAA;CAC/B,kBAaA,CAAA;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,cAAc,GACzB,OAAO,CAAC;IAAE,qBAAqB,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CA4H9D"}
|
@@ -1,15 +1,17 @@
|
|
1
|
+
import { parse } from '@swc/core';
|
1
2
|
import chalk from 'chalk';
|
2
|
-
import {
|
3
|
+
import { parseModule, Syntax } from 'esprima-next';
|
3
4
|
import fs from 'fs';
|
4
5
|
import { log, warning } from '../utils/log.js';
|
5
6
|
export const withPayloadStatement = {
|
6
|
-
cjs: `const { withPayload } = require(
|
7
|
-
esm: `import { withPayload } from
|
7
|
+
cjs: `const { withPayload } = require("@payloadcms/next/withPayload");`,
|
8
|
+
esm: `import { withPayload } from "@payloadcms/next/withPayload";`,
|
9
|
+
ts: `import { withPayload } from "@payloadcms/next/withPayload";`
|
8
10
|
};
|
9
|
-
export const wrapNextConfig = (args)=>{
|
11
|
+
export const wrapNextConfig = async (args)=>{
|
10
12
|
const { nextConfigPath, nextConfigType: configType } = args;
|
11
13
|
const configContent = fs.readFileSync(nextConfigPath, 'utf8');
|
12
|
-
const { modifiedConfigContent: newConfig, success } = parseAndModifyConfigContent(configContent, configType);
|
14
|
+
const { modifiedConfigContent: newConfig, success } = await parseAndModifyConfigContent(configContent, configType);
|
13
15
|
if (!success) {
|
14
16
|
return;
|
15
17
|
}
|
@@ -17,80 +19,99 @@ export const wrapNextConfig = (args)=>{
|
|
17
19
|
};
|
18
20
|
/**
|
19
21
|
* Parses config content with AST and wraps it with withPayload function
|
20
|
-
*/ export function parseAndModifyConfigContent(content, configType) {
|
21
|
-
content = withPayloadStatement[configType] + content;
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
22
|
+
*/ export async function parseAndModifyConfigContent(content, configType) {
|
23
|
+
content = withPayloadStatement[configType] + '\n' + content;
|
24
|
+
if (configType === 'cjs' || configType === 'esm') {
|
25
|
+
try {
|
26
|
+
const ast = parseModule(content, {
|
27
|
+
loc: true
|
28
|
+
});
|
29
|
+
if (configType === 'cjs') {
|
30
|
+
// Find `module.exports = X`
|
31
|
+
const moduleExports = ast.body.find((p)=>p.type === Syntax.ExpressionStatement && p.expression?.type === Syntax.AssignmentExpression && p.expression.left?.type === Syntax.MemberExpression && p.expression.left.object?.type === Syntax.Identifier && p.expression.left.object.name === 'module' && p.expression.left.property?.type === Syntax.Identifier && p.expression.left.property.name === 'exports');
|
32
|
+
if (moduleExports && moduleExports.expression.right?.loc) {
|
33
|
+
const modifiedConfigContent = insertBeforeAndAfter(content, moduleExports.expression.right.loc);
|
34
|
+
return {
|
35
|
+
modifiedConfigContent,
|
36
|
+
success: true
|
37
|
+
};
|
38
|
+
}
|
39
|
+
return Promise.resolve({
|
40
|
+
modifiedConfigContent: content,
|
41
|
+
success: false
|
42
|
+
});
|
43
|
+
} else if (configType === 'esm') {
|
44
|
+
const exportDefaultDeclaration = ast.body.find((p)=>p.type === Syntax.ExportDefaultDeclaration);
|
45
|
+
const exportNamedDeclaration = ast.body.find((p)=>p.type === Syntax.ExportNamedDeclaration);
|
46
|
+
if (!exportDefaultDeclaration && !exportNamedDeclaration) {
|
47
|
+
throw new Error('Could not find ExportDefaultDeclaration in next.config.js');
|
48
|
+
}
|
49
|
+
if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) {
|
50
|
+
const modifiedConfigContent = insertBeforeAndAfter(content, exportDefaultDeclaration.declaration.loc);
|
51
|
+
return {
|
52
|
+
modifiedConfigContent,
|
53
|
+
success: true
|
54
|
+
};
|
55
|
+
} else if (exportNamedDeclaration) {
|
56
|
+
const exportSpecifier = exportNamedDeclaration.specifiers.find((s)=>s.type === 'ExportSpecifier' && s.exported?.name === 'default' && s.local?.type === 'Identifier' && s.local?.name);
|
57
|
+
if (exportSpecifier) {
|
58
|
+
warning('Could not automatically wrap next.config.js with withPayload.');
|
59
|
+
warning('Automatic wrapping of named exports as default not supported yet.');
|
60
|
+
warnUserWrapNotSuccessful(configType);
|
61
|
+
return {
|
62
|
+
modifiedConfigContent: content,
|
63
|
+
success: false
|
64
|
+
};
|
65
|
+
}
|
66
|
+
}
|
67
|
+
warning('Could not automatically wrap Next config with withPayload.');
|
68
|
+
warnUserWrapNotSuccessful(configType);
|
69
|
+
return Promise.resolve({
|
70
|
+
modifiedConfigContent: content,
|
71
|
+
success: false
|
72
|
+
});
|
73
|
+
}
|
74
|
+
} catch (error) {
|
75
|
+
if (error instanceof Error) {
|
76
|
+
warning(`Unable to parse Next config. Error: ${error.message} `);
|
77
|
+
warnUserWrapNotSuccessful(configType);
|
78
|
+
}
|
45
79
|
return {
|
46
|
-
modifiedConfigContent,
|
47
|
-
success:
|
80
|
+
modifiedConfigContent: content,
|
81
|
+
success: false
|
48
82
|
};
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
83
|
+
}
|
84
|
+
} else if (configType === 'ts') {
|
85
|
+
const { moduleItems, parseOffset } = await compileTypeScriptFileToAST(content);
|
86
|
+
const exportDefaultDeclaration = moduleItems.find((m)=>m.type === 'ExportDefaultExpression' && (m.expression.type === 'Identifier' || m.expression.type === 'CallExpression'));
|
87
|
+
if (exportDefaultDeclaration) {
|
88
|
+
if (!('span' in exportDefaultDeclaration.expression)) {
|
89
|
+
warning('Could not automatically wrap Next config with withPayload.');
|
54
90
|
warnUserWrapNotSuccessful(configType);
|
55
|
-
return {
|
91
|
+
return Promise.resolve({
|
56
92
|
modifiedConfigContent: content,
|
57
93
|
success: false
|
58
|
-
};
|
94
|
+
});
|
59
95
|
}
|
60
|
-
|
61
|
-
warning('Could not automatically wrap Next config with withPayload.');
|
62
|
-
warnUserWrapNotSuccessful(configType);
|
63
|
-
return {
|
64
|
-
modifiedConfigContent: content,
|
65
|
-
success: false
|
66
|
-
};
|
67
|
-
} else if (configType === 'cjs') {
|
68
|
-
// Find `module.exports = X`
|
69
|
-
const moduleExports = ast.body.find((p)=>p.type === Syntax.ExpressionStatement && p.expression?.type === Syntax.AssignmentExpression && p.expression.left?.type === Syntax.MemberExpression && p.expression.left.object?.type === Syntax.Identifier && p.expression.left.object.name === 'module' && p.expression.left.property?.type === Syntax.Identifier && p.expression.left.property.name === 'exports');
|
70
|
-
if (moduleExports && moduleExports.expression.right?.loc) {
|
71
|
-
const modifiedConfigContent = insertBeforeAndAfter(content, moduleExports.expression.right.loc);
|
96
|
+
const modifiedConfigContent = insertBeforeAndAfterSWC(content, exportDefaultDeclaration.expression.span, parseOffset);
|
72
97
|
return {
|
73
98
|
modifiedConfigContent,
|
74
99
|
success: true
|
75
100
|
};
|
76
101
|
}
|
77
|
-
return {
|
78
|
-
modifiedConfigContent: content,
|
79
|
-
success: false
|
80
|
-
};
|
81
102
|
}
|
82
103
|
warning('Could not automatically wrap Next config with withPayload.');
|
83
104
|
warnUserWrapNotSuccessful(configType);
|
84
|
-
return {
|
105
|
+
return Promise.resolve({
|
85
106
|
modifiedConfigContent: content,
|
86
107
|
success: false
|
87
|
-
};
|
108
|
+
});
|
88
109
|
}
|
89
110
|
function warnUserWrapNotSuccessful(configType) {
|
90
111
|
// Output directions for user to update next.config.js
|
91
112
|
const withPayloadMessage = `
|
92
113
|
|
93
|
-
${chalk.bold(`Please manually wrap your existing
|
114
|
+
${chalk.bold(`Please manually wrap your existing Next config with the withPayload function. Here is an example:`)}
|
94
115
|
|
95
116
|
${withPayloadStatement[configType]}
|
96
117
|
|
@@ -98,7 +119,7 @@ function warnUserWrapNotSuccessful(configType) {
|
|
98
119
|
// Your Next.js config here
|
99
120
|
}
|
100
121
|
|
101
|
-
${configType === '
|
122
|
+
${configType === 'cjs' ? 'module.exports = withPayload(nextConfig)' : 'export default withPayload(nextConfig)'}
|
102
123
|
|
103
124
|
`;
|
104
125
|
log(withPayloadMessage);
|
@@ -119,5 +140,44 @@ function insertBeforeAndAfter(content, loc) {
|
|
119
140
|
}
|
120
141
|
return lines.join('\n');
|
121
142
|
}
|
143
|
+
function insertBeforeAndAfterSWC(content, span, /**
|
144
|
+
* WARNING: This is ONLY for unit tests. Defaults to 0 otherwise.
|
145
|
+
*
|
146
|
+
* @see compileTypeScriptFileToAST
|
147
|
+
*/ parseOffset) {
|
148
|
+
const { end: preOffsetEnd, start: preOffsetStart } = span;
|
149
|
+
const start = preOffsetStart - parseOffset;
|
150
|
+
const end = preOffsetEnd - parseOffset;
|
151
|
+
const insert = (pos, text)=>{
|
152
|
+
return content.slice(0, pos) + text + content.slice(pos);
|
153
|
+
};
|
154
|
+
// insert ) after end
|
155
|
+
content = insert(end - 1, ')');
|
156
|
+
// insert withPayload before start
|
157
|
+
content = insert(start - 1, 'withPayload(');
|
158
|
+
return content;
|
159
|
+
}
|
160
|
+
/**
|
161
|
+
* Compile typescript to AST using the swc compiler
|
162
|
+
*/ async function compileTypeScriptFileToAST(fileContent) {
|
163
|
+
let parseOffset = 0;
|
164
|
+
/**
|
165
|
+
* WARNING: This is ONLY for unit tests.
|
166
|
+
*
|
167
|
+
* Multiple instances of swc DO NOT reset the .span.end value.
|
168
|
+
* During unit tests, the .spawn.end value is read and accounted for.
|
169
|
+
*
|
170
|
+
* https://github.com/swc-project/swc/issues/1366
|
171
|
+
*/ if (process.env.NODE_ENV === 'test') {
|
172
|
+
parseOffset = (await parse('')).span.end;
|
173
|
+
}
|
174
|
+
const module = await parse(fileContent, {
|
175
|
+
syntax: 'typescript'
|
176
|
+
});
|
177
|
+
return {
|
178
|
+
moduleItems: module.body,
|
179
|
+
parseOffset
|
180
|
+
};
|
181
|
+
}
|
122
182
|
|
123
183
|
//# sourceMappingURL=wrap-next-config.js.map
|