create-payload-app 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb81f02

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/lib/configure-payload-config.d.ts +8 -2
  3. package/dist/lib/configure-payload-config.d.ts.map +1 -1
  4. package/dist/lib/configure-payload-config.js +74 -25
  5. package/dist/lib/configure-payload-config.js.map +1 -1
  6. package/dist/lib/create-project.d.ts.map +1 -1
  7. package/dist/lib/create-project.js +9 -2
  8. package/dist/lib/create-project.js.map +1 -1
  9. package/dist/lib/create-project.spec.js +24 -26
  10. package/dist/lib/create-project.spec.js.map +1 -1
  11. package/dist/lib/generate-secret.js.map +1 -1
  12. package/dist/lib/get-package-manager.d.ts +6 -0
  13. package/dist/lib/get-package-manager.d.ts.map +1 -0
  14. package/dist/lib/get-package-manager.js +38 -0
  15. package/dist/lib/get-package-manager.js.map +1 -0
  16. package/dist/lib/init-next.d.ts +3 -11
  17. package/dist/lib/init-next.d.ts.map +1 -1
  18. package/dist/lib/init-next.js +77 -56
  19. package/dist/lib/init-next.js.map +1 -1
  20. package/dist/lib/install-packages.d.ts +9 -0
  21. package/dist/lib/install-packages.d.ts.map +1 -0
  22. package/dist/lib/install-packages.js +43 -0
  23. package/dist/lib/install-packages.js.map +1 -0
  24. package/dist/lib/parse-project-name.js.map +1 -1
  25. package/dist/lib/parse-template.js.map +1 -1
  26. package/dist/lib/replacements.d.ts +27 -0
  27. package/dist/lib/replacements.d.ts.map +1 -0
  28. package/dist/lib/replacements.js +80 -0
  29. package/dist/lib/replacements.js.map +1 -0
  30. package/dist/lib/select-db.d.ts.map +1 -1
  31. package/dist/lib/select-db.js +11 -11
  32. package/dist/lib/select-db.js.map +1 -1
  33. package/dist/lib/templates.js +5 -24
  34. package/dist/lib/templates.js.map +1 -1
  35. package/dist/lib/update-payload-in-project.d.ts +6 -0
  36. package/dist/lib/update-payload-in-project.d.ts.map +1 -0
  37. package/dist/lib/update-payload-in-project.js +71 -0
  38. package/dist/lib/update-payload-in-project.js.map +1 -0
  39. package/dist/lib/wrap-next-config.d.ts +5 -5
  40. package/dist/lib/wrap-next-config.d.ts.map +1 -1
  41. package/dist/lib/wrap-next-config.js +123 -60
  42. package/dist/lib/wrap-next-config.js.map +1 -1
  43. package/dist/lib/wrap-next-config.spec.js +85 -34
  44. package/dist/lib/wrap-next-config.spec.js.map +1 -1
  45. package/dist/lib/write-env-file.d.ts.map +1 -1
  46. package/dist/lib/write-env-file.js +25 -25
  47. package/dist/lib/write-env-file.js.map +1 -1
  48. package/dist/main.d.ts.map +1 -1
  49. package/dist/main.js +33 -21
  50. package/dist/main.js.map +1 -1
  51. package/dist/scripts/pack-template-files.js.map +1 -1
  52. package/dist/template/src/collections/Media.ts +16 -0
  53. package/dist/template/src/collections/Users.ts +1 -1
  54. package/dist/template/src/payload.config.ts +10 -15
  55. package/dist/types.d.ts +14 -1
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/types.js.map +1 -1
  58. package/dist/utils/copy-recursive-sync.d.ts +2 -0
  59. package/dist/utils/copy-recursive-sync.d.ts.map +1 -1
  60. package/dist/utils/copy-recursive-sync.js +2 -0
  61. package/dist/utils/copy-recursive-sync.js.map +1 -1
  62. package/dist/utils/git.d.ts +4 -0
  63. package/dist/utils/git.d.ts.map +1 -0
  64. package/dist/utils/git.js +46 -0
  65. package/dist/utils/git.js.map +1 -0
  66. package/dist/utils/log.d.ts.map +1 -1
  67. package/dist/utils/log.js +1 -1
  68. package/dist/utils/log.js.map +1 -1
  69. package/dist/utils/messages.d.ts.map +1 -1
  70. package/dist/utils/messages.js.map +1 -1
  71. package/package.json +18 -6
  72. package/dist/lib/packages.d.ts +0 -9
  73. package/dist/lib/packages.d.ts.map +0 -1
  74. package/dist/lib/packages.js +0 -27
  75. package/dist/lib/packages.js.map +0 -1
@@ -1,9 +1,41 @@
1
- import { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js';
2
1
  import * as p from '@clack/prompts';
2
+ import { jest } from '@jest/globals';
3
+ import { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js';
4
+ const tsConfigs = {
5
+ defaultNextConfig: `import type { NextConfig } from "next";
6
+
7
+ const nextConfig: NextConfig = {};
8
+ export default nextConfig;`,
9
+ nextConfigExportNamedDefault: `import type { NextConfig } from "next";
10
+ const nextConfig: NextConfig = {};
11
+ const wrapped = someFunc(asdf);
12
+ export { wrapped as default };
13
+ `,
14
+ nextConfigWithFunc: `import type { NextConfig } from "next";
15
+ const nextConfig: NextConfig = {};
16
+ export default someFunc(nextConfig);
17
+ `,
18
+ nextConfigWithFuncMultiline: `import type { NextConfig } from "next";
19
+ const nextConfig: NextConfig = {};
20
+ export default someFunc(
21
+ nextConfig
22
+ );
23
+ `,
24
+ nextConfigWithSpread: `import type { NextConfig } from "next";
25
+ const nextConfig: NextConfig = {
26
+ ...someConfig,
27
+ };
28
+ export default nextConfig;
29
+ `
30
+ };
3
31
  const esmConfigs = {
4
32
  defaultNextConfig: `/** @type {import('next').NextConfig} */
5
33
  const nextConfig = {};
6
34
  export default nextConfig;
35
+ `,
36
+ nextConfigExportNamedDefault: `const nextConfig = {};
37
+ const wrapped = someFunc(asdf);
38
+ export { wrapped as default };
7
39
  `,
8
40
  nextConfigWithFunc: `const nextConfig = {};
9
41
  export default someFunc(nextConfig);
@@ -12,10 +44,6 @@ export default someFunc(nextConfig);
12
44
  export default someFunc(
13
45
  nextConfig
14
46
  );
15
- `,
16
- nextConfigExportNamedDefault: `const nextConfig = {};
17
- const wrapped = someFunc(asdf);
18
- export { wrapped as default };
19
47
  `,
20
48
  nextConfigWithSpread: `const nextConfig = {
21
49
  ...someConfig,
@@ -24,12 +52,16 @@ export default nextConfig;
24
52
  `
25
53
  };
26
54
  const cjsConfigs = {
55
+ anonConfig: `module.exports = {};`,
27
56
  defaultNextConfig: `
28
57
  /** @type {import('next').NextConfig} */
29
58
  const nextConfig = {};
30
59
  module.exports = nextConfig;
31
60
  `,
32
- anonConfig: `module.exports = {};`,
61
+ nextConfigExportNamedDefault: `const nextConfig = {};
62
+ const wrapped = someFunc(asdf);
63
+ module.exports = wrapped;
64
+ `,
33
65
  nextConfigWithFunc: `const nextConfig = {};
34
66
  module.exports = someFunc(nextConfig);
35
67
  `,
@@ -37,42 +69,61 @@ module.exports = someFunc(nextConfig);
37
69
  module.exports = someFunc(
38
70
  nextConfig
39
71
  );
40
- `,
41
- nextConfigExportNamedDefault: `const nextConfig = {};
42
- const wrapped = someFunc(asdf);
43
- module.exports = wrapped;
44
72
  `,
45
73
  nextConfigWithSpread: `const nextConfig = { ...someConfig };
46
74
  module.exports = nextConfig;
47
75
  `
48
76
  };
49
77
  describe('parseAndInsertWithPayload', ()=>{
78
+ describe('ts', ()=>{
79
+ const configType = 'ts';
80
+ const importStatement = withPayloadStatement[configType];
81
+ it('should parse the default next config', async ()=>{
82
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(tsConfigs.defaultNextConfig, configType);
83
+ expect(modifiedConfigContent).toContain(importStatement);
84
+ expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
85
+ });
86
+ it('should parse the config with a function', async ()=>{
87
+ const { modifiedConfigContent: modifiedConfigContent2 } = await parseAndModifyConfigContent(tsConfigs.nextConfigWithFunc, configType);
88
+ expect(modifiedConfigContent2).toContain('withPayload(someFunc(nextConfig))');
89
+ });
90
+ it('should parse the config with a multi-lined function', async ()=>{
91
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(tsConfigs.nextConfigWithFuncMultiline, configType);
92
+ expect(modifiedConfigContent).toContain(importStatement);
93
+ expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n {2}nextConfig\n\)\)/);
94
+ });
95
+ it('should parse the config with a spread', async ()=>{
96
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(tsConfigs.nextConfigWithSpread, configType);
97
+ expect(modifiedConfigContent).toContain(importStatement);
98
+ expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
99
+ });
100
+ });
50
101
  describe('esm', ()=>{
51
102
  const configType = 'esm';
52
103
  const importStatement = withPayloadStatement[configType];
53
- it('should parse the default next config', ()=>{
54
- const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.defaultNextConfig, configType);
104
+ it('should parse the default next config', async ()=>{
105
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(esmConfigs.defaultNextConfig, configType);
55
106
  expect(modifiedConfigContent).toContain(importStatement);
56
107
  expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
57
108
  });
58
- it('should parse the config with a function', ()=>{
59
- const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithFunc, configType);
109
+ it('should parse the config with a function', async ()=>{
110
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(esmConfigs.nextConfigWithFunc, configType);
60
111
  expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))');
61
112
  });
62
- it('should parse the config with a function on a new line', ()=>{
63
- const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithFuncMultiline, configType);
113
+ it('should parse the config with a multi-lined function', async ()=>{
114
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(esmConfigs.nextConfigWithFuncMultiline, configType);
64
115
  expect(modifiedConfigContent).toContain(importStatement);
65
- expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n nextConfig\n\)\)/);
116
+ expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n {2}nextConfig\n\)\)/);
66
117
  });
67
- it('should parse the config with a spread', ()=>{
68
- const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithSpread, configType);
118
+ it('should parse the config with a spread', async ()=>{
119
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(esmConfigs.nextConfigWithSpread, configType);
69
120
  expect(modifiedConfigContent).toContain(importStatement);
70
121
  expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
71
122
  });
72
123
  // Unsupported: export { wrapped as default }
73
- it('should give warning with a named export as default', ()=>{
124
+ it('should give warning with a named export as default', async ()=>{
74
125
  const warnLogSpy = jest.spyOn(p.log, 'warn').mockImplementation(()=>{});
75
- const { modifiedConfigContent, success } = parseAndModifyConfigContent(esmConfigs.nextConfigExportNamedDefault, configType);
126
+ const { modifiedConfigContent, success } = await parseAndModifyConfigContent(esmConfigs.nextConfigExportNamedDefault, configType);
76
127
  expect(modifiedConfigContent).toContain(importStatement);
77
128
  expect(success).toBe(false);
78
129
  expect(warnLogSpy).toHaveBeenCalledWith(expect.stringContaining('Could not automatically wrap'));
@@ -81,32 +132,32 @@ describe('parseAndInsertWithPayload', ()=>{
81
132
  describe('cjs', ()=>{
82
133
  const configType = 'cjs';
83
134
  const requireStatement = withPayloadStatement[configType];
84
- it('should parse the default next config', ()=>{
85
- const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.defaultNextConfig, configType);
135
+ it('should parse the default next config', async ()=>{
136
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(cjsConfigs.defaultNextConfig, configType);
86
137
  expect(modifiedConfigContent).toContain(requireStatement);
87
138
  expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
88
139
  });
89
- it('should parse anonymous default config', ()=>{
90
- const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.anonConfig, configType);
140
+ it('should parse anonymous default config', async ()=>{
141
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(cjsConfigs.anonConfig, configType);
91
142
  expect(modifiedConfigContent).toContain(requireStatement);
92
143
  expect(modifiedConfigContent).toContain('withPayload({})');
93
144
  });
94
- it('should parse the config with a function', ()=>{
95
- const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithFunc, configType);
145
+ it('should parse the config with a function', async ()=>{
146
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(cjsConfigs.nextConfigWithFunc, configType);
96
147
  expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))');
97
148
  });
98
- it('should parse the config with a function on a new line', ()=>{
99
- const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithFuncMultiline, configType);
149
+ it('should parse the config with a multi-lined function', async ()=>{
150
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(cjsConfigs.nextConfigWithFuncMultiline, configType);
100
151
  expect(modifiedConfigContent).toContain(requireStatement);
101
- expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n nextConfig\n\)\)/);
152
+ expect(modifiedConfigContent).toMatch(/withPayload\(someFunc\(\n {2}nextConfig\n\)\)/);
102
153
  });
103
- it('should parse the config with a named export as default', ()=>{
104
- const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigExportNamedDefault, configType);
154
+ it('should parse the config with a named export as default', async ()=>{
155
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(cjsConfigs.nextConfigExportNamedDefault, configType);
105
156
  expect(modifiedConfigContent).toContain(requireStatement);
106
157
  expect(modifiedConfigContent).toContain('withPayload(wrapped)');
107
158
  });
108
- it('should parse the config with a spread', ()=>{
109
- const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithSpread, configType);
159
+ it('should parse the config with a spread', async ()=>{
160
+ const { modifiedConfigContent } = await parseAndModifyConfigContent(cjsConfigs.nextConfigWithSpread, configType);
110
161
  expect(modifiedConfigContent).toContain(requireStatement);
111
162
  expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
112
163
  });
@@ -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'\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","esmConfigs","defaultNextConfig","nextConfigWithFunc","nextConfigWithFuncMultiline","nextConfigExportNamedDefault","nextConfigWithSpread","cjsConfigs","anonConfig","describe","configType","importStatement","it","modifiedConfigContent","expect","toContain","toMatch","warnLogSpy","jest","spyOn","log","mockImplementation","success","toBe","toHaveBeenCalledWith","stringContaining","requireStatement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,2BAA2B,EAAEC,oBAAoB,QAAQ,wBAAuB;AACzF,YAAYC,OAAO,iBAAgB;AAEnC,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,mBAAmB,CAAC;;;;AAItB,CAAC;IACCM,YAAY,CAAC,oBAAoB,CAAC;IAClCL,oBAAoB,CAAC;;AAEvB,CAAC;IACCC,6BAA6B,CAAC;;;;AAIhC,CAAC;IACCC,8BAA8B,CAAC;;;AAGjC,CAAC;IACCC,sBAAsB,CAAC;;AAEzB,CAAC;AACD;AAEAG,SAAS,6BAA6B;IACpCA,SAAS,OAAO;QACd,MAAMC,aAAa;QACnB,MAAMC,kBAAkBZ,oBAAoB,CAACW,WAAW;QACxDE,GAAG,wCAAwC;YACzC,MAAM,EAAEC,qBAAqB,EAAE,GAAGf,4BAChCG,WAAWC,iBAAiB,EAC5BQ;YAEFI,OAAOD,uBAAuBE,SAAS,CAACJ;YACxCG,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;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;YACxCZ,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;QACAH,GAAG,2CAA2C;YAC5C,MAAM,EAAEC,qBAAqB,EAAE,GAAGf,4BAChCS,WAAWJ,kBAAkB,EAC7BO;YAEFI,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;QACAH,GAAG,yDAAyD;YAC1D,MAAM,EAAEC,qBAAqB,EAAE,GAAGf,4BAChCS,WAAWH,2BAA2B,EACtCM;YAEFI,OAAOD,uBAAuBE,SAAS,CAACW;YACxCZ,OAAOD,uBAAuBG,OAAO,CAAC;QACxC;QACAJ,GAAG,0DAA0D;YAC3D,MAAM,EAAEC,qBAAqB,EAAE,GAAGf,4BAChCS,WAAWF,4BAA4B,EACvCK;YAEFI,OAAOD,uBAAuBE,SAAS,CAACW;YACxCZ,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;QAEAH,GAAG,yCAAyC;YAC1C,MAAM,EAAEC,qBAAqB,EAAE,GAAGf,4BAChCS,WAAWD,oBAAoB,EAC/BI;YAEFI,OAAOD,uBAAuBE,SAAS,CAACW;YACxCZ,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/lib/wrap-next-config.spec.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport { jest } from '@jest/globals'\n\nimport { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js'\n\nconst tsConfigs = {\n defaultNextConfig: `import type { NextConfig } from \"next\";\n\nconst nextConfig: NextConfig = {};\nexport default nextConfig;`,\n\n nextConfigExportNamedDefault: `import type { NextConfig } from \"next\";\nconst nextConfig: NextConfig = {};\nconst wrapped = someFunc(asdf);\nexport { wrapped as default };\n`,\n nextConfigWithFunc: `import type { NextConfig } from \"next\";\nconst nextConfig: NextConfig = {};\nexport default someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `import type { NextConfig } from \"next\";\nconst nextConfig: NextConfig = {};\nexport default someFunc(\n nextConfig\n);\n`,\n nextConfigWithSpread: `import type { NextConfig } from \"next\";\nconst nextConfig: NextConfig = {\n ...someConfig,\n};\nexport default nextConfig;\n`,\n}\n\nconst esmConfigs = {\n defaultNextConfig: `/** @type {import('next').NextConfig} */\nconst nextConfig = {};\nexport default nextConfig;\n`,\n nextConfigExportNamedDefault: `const nextConfig = {};\nconst wrapped = someFunc(asdf);\nexport { wrapped as default };\n`,\n nextConfigWithFunc: `const nextConfig = {};\nexport default someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `const nextConfig = {};;\nexport default someFunc(\n nextConfig\n);\n`,\n nextConfigWithSpread: `const nextConfig = {\n ...someConfig,\n};\nexport default nextConfig;\n`,\n}\n\nconst cjsConfigs = {\n anonConfig: `module.exports = {};`,\n defaultNextConfig: `\n /** @type {import('next').NextConfig} */\nconst nextConfig = {};\nmodule.exports = nextConfig;\n`,\n nextConfigExportNamedDefault: `const nextConfig = {};\nconst wrapped = someFunc(asdf);\nmodule.exports = wrapped;\n`,\n nextConfigWithFunc: `const nextConfig = {};\nmodule.exports = someFunc(nextConfig);\n`,\n nextConfigWithFuncMultiline: `const nextConfig = {};\nmodule.exports = someFunc(\n nextConfig\n);\n`,\n nextConfigWithSpread: `const nextConfig = { ...someConfig };\nmodule.exports = nextConfig;\n`,\n}\n\ndescribe('parseAndInsertWithPayload', () => {\n describe('ts', () => {\n const configType = 'ts'\n const importStatement = withPayloadStatement[configType]\n\n it('should parse the default next config', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n tsConfigs.defaultNextConfig,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n\n it('should parse the config with a function', async () => {\n const { modifiedConfigContent: modifiedConfigContent2 } = await parseAndModifyConfigContent(\n tsConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent2).toContain('withPayload(someFunc(nextConfig))')\n })\n\n it('should parse the config with a multi-lined function', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n tsConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n {2}nextConfig\\n\\)\\)/)\n })\n\n it('should parse the config with a spread', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n tsConfigs.nextConfigWithSpread,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n })\n describe('esm', () => {\n const configType = 'esm'\n const importStatement = withPayloadStatement[configType]\n it('should parse the default next config', async () => {\n const { modifiedConfigContent } = await 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', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n esmConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))')\n })\n\n it('should parse the config with a multi-lined function', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n esmConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(importStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n {2}nextConfig\\n\\)\\)/)\n })\n\n it('should parse the config with a spread', async () => {\n const { modifiedConfigContent } = await 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', async () => {\n const warnLogSpy = jest.spyOn(p.log, 'warn').mockImplementation(() => {})\n\n const { modifiedConfigContent, success } = await 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', async () => {\n const { modifiedConfigContent } = await 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', async () => {\n const { modifiedConfigContent } = await 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', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithFunc,\n configType,\n )\n expect(modifiedConfigContent).toContain('withPayload(someFunc(nextConfig))')\n })\n it('should parse the config with a multi-lined function', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithFuncMultiline,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toMatch(/withPayload\\(someFunc\\(\\n {2}nextConfig\\n\\)\\)/)\n })\n it('should parse the config with a named export as default', async () => {\n const { modifiedConfigContent } = await 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', async () => {\n const { modifiedConfigContent } = await parseAndModifyConfigContent(\n cjsConfigs.nextConfigWithSpread,\n configType,\n )\n expect(modifiedConfigContent).toContain(requireStatement)\n expect(modifiedConfigContent).toContain('withPayload(nextConfig)')\n })\n })\n})\n"],"names":["p","jest","parseAndModifyConfigContent","withPayloadStatement","tsConfigs","defaultNextConfig","nextConfigExportNamedDefault","nextConfigWithFunc","nextConfigWithFuncMultiline","nextConfigWithSpread","esmConfigs","cjsConfigs","anonConfig","describe","configType","importStatement","it","modifiedConfigContent","expect","toContain","modifiedConfigContent2","toMatch","warnLogSpy","spyOn","log","mockImplementation","success","toBe","toHaveBeenCalledWith","stringContaining","requireStatement"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,IAAI,QAAQ,gBAAe;AAEpC,SAASC,2BAA2B,EAAEC,oBAAoB,QAAQ,wBAAuB;AAEzF,MAAMC,YAAY;IAChBC,mBAAmB,CAAC;;;0BAGI,CAAC;IAEzBC,8BAA8B,CAAC;;;;AAIjC,CAAC;IACCC,oBAAoB,CAAC;;;AAGvB,CAAC;IACCC,6BAA6B,CAAC;;;;;AAKhC,CAAC;IACCC,sBAAsB,CAAC;;;;;AAKzB,CAAC;AACD;AAEA,MAAMC,aAAa;IACjBL,mBAAmB,CAAC;;;AAGtB,CAAC;IACCC,8BAA8B,CAAC;;;AAGjC,CAAC;IACCC,oBAAoB,CAAC;;AAEvB,CAAC;IACCC,6BAA6B,CAAC;;;;AAIhC,CAAC;IACCC,sBAAsB,CAAC;;;;AAIzB,CAAC;AACD;AAEA,MAAME,aAAa;IACjBC,YAAY,CAAC,oBAAoB,CAAC;IAClCP,mBAAmB,CAAC;;;;AAItB,CAAC;IACCC,8BAA8B,CAAC;;;AAGjC,CAAC;IACCC,oBAAoB,CAAC;;AAEvB,CAAC;IACCC,6BAA6B,CAAC;;;;AAIhC,CAAC;IACCC,sBAAsB,CAAC;;AAEzB,CAAC;AACD;AAEAI,SAAS,6BAA6B;IACpCA,SAAS,MAAM;QACb,MAAMC,aAAa;QACnB,MAAMC,kBAAkBZ,oBAAoB,CAACW,WAAW;QAExDE,GAAG,wCAAwC;YACzC,MAAM,EAAEC,qBAAqB,EAAE,GAAG,MAAMf,4BACtCE,UAAUC,iBAAiB,EAC3BS;YAEFI,OAAOD,uBAAuBE,SAAS,CAACJ;YACxCG,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;QAE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AEC,qBAAqB,EAAE,GAAG,MAAMf,4BACtCS,WAAWL,4BAA4B,EACvCQ;YAEFI,OAAOD,uBAAuBE,SAAS,CAACW;YACxCZ,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;QAEAH,GAAG,yCAAyC;YAC1C,MAAM,EAAEC,qBAAqB,EAAE,GAAG,MAAMf,4BACtCS,WAAWF,oBAAoB,EAC/BK;YAEFI,OAAOD,uBAAuBE,SAAS,CAACW;YACxCZ,OAAOD,uBAAuBE,SAAS,CAAC;QAC1C;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"write-env-file.d.ts","sourceRoot":"","sources":["../../src/lib/write-env-file.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAI3D,wDAAwD;AACxD,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,eAAe,CAAA;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDhB"}
1
+ {"version":3,"file":"write-env-file.d.ts","sourceRoot":"","sources":["../../src/lib/write-env-file.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAI3D,wDAAwD;AACxD,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,eAAe,CAAA;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CA0DhB"}
@@ -9,33 +9,33 @@ import { debug, error } from '../utils/log.js';
9
9
  }
10
10
  const envOutputPath = path.join(projectDir, '.env');
11
11
  try {
12
+ let fileContents;
13
+ if (template?.type === 'starter') {
14
+ // Parse .env file into key/value pairs
15
+ const envExample = path.join(projectDir, '.env.example');
16
+ const envFile = await fs.readFile(envExample, 'utf8');
17
+ fileContents = `# Added by Payload\n` + envFile.split('\n').filter((e)=>e).map((line)=>{
18
+ if (line.startsWith('#') || !line.includes('=')) return line;
19
+ const split = line.split('=');
20
+ const key = split[0];
21
+ let value = split[1];
22
+ if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI') {
23
+ value = databaseUri;
24
+ }
25
+ if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') {
26
+ value = payloadSecret;
27
+ }
28
+ return `${key}=${value}`;
29
+ }).join('\n');
30
+ } else {
31
+ fileContents = `# Added by Payload\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`;
32
+ }
12
33
  if (fs.existsSync(envOutputPath)) {
13
- if (template?.type === 'starter') {
14
- // Parse .env file into key/value pairs
15
- const envFile = await fs.readFile(path.join(projectDir, '.env.example'), 'utf8');
16
- const envWithValues = envFile.split('\n').filter((e)=>e).map((line)=>{
17
- if (line.startsWith('#') || !line.includes('=')) return line;
18
- const split = line.split('=');
19
- const key = split[0];
20
- let value = split[1];
21
- if (key === 'MONGODB_URI' || key === 'MONGO_URL' || key === 'DATABASE_URI') {
22
- value = databaseUri;
23
- }
24
- if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') {
25
- value = payloadSecret;
26
- }
27
- return `${key}=${value}`;
28
- });
29
- // Write new .env file
30
- await fs.writeFile(envOutputPath, envWithValues.join('\n'));
31
- } else {
32
- const existingEnv = await fs.readFile(envOutputPath, 'utf8');
33
- const newEnv = existingEnv + `\nDATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}\n`;
34
- await fs.writeFile(envOutputPath, newEnv);
35
- }
34
+ const existingEnv = await fs.readFile(envOutputPath, 'utf8');
35
+ const newEnv = existingEnv + '\n# Added by Payload' + fileContents;
36
+ await fs.writeFile(envOutputPath, newEnv);
36
37
  } else {
37
- const content = `DATABASE_URI=${databaseUri}\nPAYLOAD_SECRET=${payloadSecret}`;
38
- await fs.outputFile(`${projectDir}/.env`, content);
38
+ await fs.writeFile(envOutputPath, fileContents);
39
39
  }
40
40
  } catch (err) {
41
41
  error('Unable to write .env file');
@@ -1 +1 @@
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 let fileContents: string\n\n if (template?.type === 'starter') {\n // Parse .env file into key/value pairs\n const envExample = path.join(projectDir, '.env.example')\n const envFile = await fs.readFile(envExample, 'utf8')\n\n fileContents =\n `# Added by Payload\\n` +\n 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 .join('\\n')\n } else {\n fileContents = `# Added by Payload\\nDATABASE_URI=${databaseUri}\\nPAYLOAD_SECRET=${payloadSecret}\\n`\n }\n\n if (fs.existsSync(envOutputPath)) {\n const existingEnv = await fs.readFile(envOutputPath, 'utf8')\n const newEnv = existingEnv + '\\n# Added by Payload' + fileContents\n await fs.writeFile(envOutputPath, newEnv)\n } else {\n await fs.writeFile(envOutputPath, fileContents)\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","fileContents","type","envExample","envFile","readFile","split","filter","e","map","line","startsWith","includes","key","value","existsSync","existingEnv","newEnv","writeFile","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,EA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B,MAAM4B,IAAIE,OAAO;QACnB;QACAC,QAAQC,IAAI,CAAC;IACf;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAkB,MAAM,YAAY,CAAA;AAoBzD,qBAAa,IAAI;IACf,IAAI,EAAE,OAAO,CAAA;;IAwCP,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA4I5B"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAsBzC,qBAAa,IAAI;IACf,IAAI,EAAE,OAAO,CAAA;;IA2CP,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAgL5B"}
package/dist/main.js CHANGED
@@ -2,18 +2,18 @@ import * as p from '@clack/prompts';
2
2
  import slugify from '@sindresorhus/slugify';
3
3
  import arg from 'arg';
4
4
  import chalk from 'chalk';
5
- // @ts-expect-error no types
6
- import { detect } from 'detect-package-manager';
7
5
  import figures from 'figures';
8
6
  import path from 'path';
9
7
  import { configurePayloadConfig } from './lib/configure-payload-config.js';
10
8
  import { createProject } from './lib/create-project.js';
11
9
  import { generateSecret } from './lib/generate-secret.js';
10
+ import { getPackageManager } from './lib/get-package-manager.js';
12
11
  import { getNextAppDetails, initNext } from './lib/init-next.js';
13
12
  import { parseProjectName } from './lib/parse-project-name.js';
14
13
  import { parseTemplate } from './lib/parse-template.js';
15
14
  import { selectDb } from './lib/select-db.js';
16
15
  import { getValidTemplates, validateTemplate } from './lib/templates.js';
16
+ import { updatePayloadInProject } from './lib/update-payload-in-project.js';
17
17
  import { writeEnvFile } from './lib/write-env-file.js';
18
18
  import { error, info } from './utils/log.js';
19
19
  import { feedbackOutro, helpMessage, moveMessage, successMessage, successfulNextInit } from './utils/messages.js';
@@ -38,6 +38,8 @@ export class Main {
38
38
  '--use-npm': Boolean,
39
39
  '--use-pnpm': Boolean,
40
40
  '--use-yarn': Boolean,
41
+ // Other
42
+ '--no-git': Boolean,
41
43
  // Flags
42
44
  '--beta': Boolean,
43
45
  '--debug': Boolean,
@@ -63,13 +65,39 @@ export class Main {
63
65
  p.note("Welcome to Payload. Let's create a project!");
64
66
  // Detect if inside Next.js project
65
67
  const nextAppDetails = await getNextAppDetails(process.cwd());
66
- const { hasTopLevelLayout, nextAppDir, nextConfigPath } = nextAppDetails;
68
+ const { hasTopLevelLayout, isPayloadInstalled, isSupportedNextVersion, nextAppDir, nextConfigPath, nextVersion } = nextAppDetails;
69
+ if (nextConfigPath && !isSupportedNextVersion) {
70
+ p.log.warn(`Next.js v${nextVersion} is unsupported. Next.js >= 15 is required to use Payload.`);
71
+ p.outro(feedbackOutro());
72
+ process.exit(0);
73
+ }
74
+ // Upgrade Payload in existing project
75
+ if (isPayloadInstalled && nextConfigPath) {
76
+ p.log.warn(`Payload installation detected in current project.`);
77
+ const shouldUpdate = await p.confirm({
78
+ initialValue: false,
79
+ message: chalk.bold(`Upgrade Payload in this project?`)
80
+ });
81
+ if (!p.isCancel(shouldUpdate) && shouldUpdate) {
82
+ const { message, success: updateSuccess } = await updatePayloadInProject(nextAppDetails);
83
+ if (updateSuccess) {
84
+ info(message);
85
+ } else {
86
+ error(message);
87
+ }
88
+ }
89
+ p.outro(feedbackOutro());
90
+ process.exit(0);
91
+ }
67
92
  if (nextConfigPath) {
68
93
  this.args['--name'] = slugify(path.basename(path.dirname(nextConfigPath)));
69
94
  }
70
95
  const projectName = await parseProjectName(this.args);
71
96
  const projectDir = nextConfigPath ? path.dirname(nextConfigPath) : path.resolve(process.cwd(), slugify(projectName));
72
- const packageManager = await getPackageManager(this.args, projectDir);
97
+ const packageManager = await getPackageManager({
98
+ cliArgs: this.args,
99
+ projectDir
100
+ });
73
101
  if (nextConfigPath) {
74
102
  p.log.step(chalk.bold(`${chalk.bgBlack(` ${figures.triangleUp} Next.js `)} project detected!`));
75
103
  const proceed = await p.confirm({
@@ -102,7 +130,7 @@ export class Main {
102
130
  process.exit(1);
103
131
  }
104
132
  await configurePayloadConfig({
105
- dbDetails,
133
+ dbType: dbDetails?.type,
106
134
  projectDirOrConfigPath: {
107
135
  payloadConfigPath: result.payloadConfigPath
108
136
  }
@@ -175,21 +203,5 @@ export class Main {
175
203
  }
176
204
  }
177
205
  }
178
- async function getPackageManager(args, projectDir) {
179
- let packageManager = 'npm';
180
- if (args['--use-npm']) {
181
- packageManager = 'npm';
182
- } else if (args['--use-yarn']) {
183
- packageManager = 'yarn';
184
- } else if (args['--use-pnpm']) {
185
- packageManager = 'pnpm';
186
- } else {
187
- const detected = await detect({
188
- cwd: projectDir
189
- });
190
- packageManager = detected || 'npm';
191
- }
192
- return packageManager;
193
- }
194
206
 
195
207
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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'\n// @ts-expect-error no types\nimport { detect } from 'detect-package-manager'\nimport figures from 'figures'\nimport path from 'path'\n\nimport type { CliArgs, PackageManager } 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 { 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 { 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 // 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, nextAppDir, nextConfigPath } = nextAppDetails\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(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 dbDetails,\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\nasync function getPackageManager(args: CliArgs, projectDir: string): Promise<PackageManager> {\n let packageManager: PackageManager = 'npm'\n\n if (args['--use-npm']) {\n packageManager = 'npm'\n } else if (args['--use-yarn']) {\n packageManager = 'yarn'\n } else if (args['--use-pnpm']) {\n packageManager = 'pnpm'\n } else {\n const detected = await detect({ cwd: projectDir })\n packageManager = detected || 'npm'\n }\n return packageManager\n}\n"],"names":["p","slugify","arg","chalk","detect","figures","path","configurePayloadConfig","createProject","generateSecret","getNextAppDetails","initNext","parseProjectName","parseTemplate","selectDb","getValidTemplates","validateTemplate","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","nextAppDir","nextConfigPath","basename","dirname","projectName","projectDir","resolve","packageManager","getPackageManager","step","bold","bgBlack","triangleUp","proceed","confirm","initialValue","message","green","isCancel","outro","warn","dbDetails","result","dbType","type","success","projectDirOrConfigPath","payloadConfigPath","cliArgs","databaseUri","dbUri","payloadSecret","bgGreen","templateArg","valid","validTemplates","template","err","Error","detected"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAC3C,OAAOC,SAAS,MAAK;AACrB,OAAOC,WAAW,QAAO;AACzB,4BAA4B;AAC5B,SAASC,MAAM,QAAQ,yBAAwB;AAC/C,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,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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CAACxE,MAAMmC,KAAK,CAAC;YAC7EtC,EAAE8D,KAAK,CAAC1C;QACV,EAAE,OAAO4D,KAAc;YACrB9D,MAAM8D,eAAeC,QAAQD,IAAIrB,OAAO,GAAG;QAC7C;IACF;AACF;AAEA,eAAeR,kBAAkBzB,IAAa,EAAEsB,UAAkB;IAChE,IAAIE,iBAAiC;IAErC,IAAIxB,IAAI,CAAC,YAAY,EAAE;QACrBwB,iBAAiB;IACnB,OAAO,IAAIxB,IAAI,CAAC,aAAa,EAAE;QAC7BwB,iBAAiB;IACnB,OAAO,IAAIxB,IAAI,CAAC,aAAa,EAAE;QAC7BwB,iBAAiB;IACnB,OAAO;QACL,MAAMgC,WAAW,MAAM9E,OAAO;YAAEqC,KAAKO;QAAW;QAChDE,iBAAiBgC,YAAY;IAC/B;IACA,OAAOhC;AACT"}
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 {\n hasTopLevelLayout,\n isPayloadInstalled,\n isSupportedNextVersion,\n nextAppDir,\n nextConfigPath,\n nextVersion,\n } = nextAppDetails\n\n if (nextConfigPath && !isSupportedNextVersion) {\n p.log.warn(\n `Next.js v${nextVersion} is unsupported. Next.js >= 15 is required to use Payload.`,\n )\n p.outro(feedbackOutro())\n process.exit(0)\n }\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","isSupportedNextVersion","nextAppDir","nextConfigPath","nextVersion","warn","outro","shouldUpdate","confirm","initialValue","message","bold","isCancel","success","updateSuccess","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,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f,MAAMC,QAAQlE,iBAAiBiE;gBAC/B,IAAI,CAACC,OAAO;oBACV5D;oBACAW,QAAQC,IAAI,CAAC;gBACf;YACF;YAEA,MAAMiD,iBAAiBpE;YACvB,MAAMqE,WAAW,MAAMvE,cAAc,IAAI,CAACc,IAAI,EAAEwD;YAChD,IAAI,CAACC,UAAU;gBACbpF,EAAEoC,GAAG,CAACjB,KAAK,CAAC;gBACZnB,EAAEkD,KAAK,CAAC7B;gBACRY,QAAQC,IAAI,CAAC;YACf;YAEA,OAAQkD,SAASV,IAAI;gBACnB,KAAK;oBAAW;wBACd,MAAMH,YAAY,MAAMzD,SAAS,IAAI,CAACa,IAAI,EAAEkC;wBAC5C,MAAMkB,gBAAgBvE;wBACtB,MAAMD,cAAc;4BAClB0D,SAAS,IAAI,CAACtC,IAAI;4BAClB4C;4BACAP;4BACAF;4BACAD;4BACAuB;wBACF;wBACA,MAAMlE,aAAa;4BACjB+C,SAAS,IAAI,CAACtC,IAAI;4BAClBkD,aAAaN,UAAUO,KAAK;4BAC5BC;4BACAjB;4BACAsB;wBACF;wBACA;oBACF;gBACA,KAAK;oBAAU;wBACb,MAAM7E,cAAc;4BAClB0D,SAAS,IAAI,CAACtC,IAAI;4BAClBqC;4BACAF;4BACAD;4BACAuB;wBACF;wBACA;oBACF;YACF;YAEAhE,KAAK;YACLpB,EAAEwC,IAAI,CAAChB,eAAesC,YAAYE,iBAAiB7D,MAAM6E,OAAO,CAAC7E,MAAMoC,KAAK,CAAC;YAC7EvC,EAAEkD,KAAK,CAAC7B;QACV,EAAE,OAAOgE,KAAc;YACrBlE,MAAMkE,eAAeC,QAAQD,IAAI/B,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"}
@@ -0,0 +1,16 @@
1
+ import type { CollectionConfig } from 'payload'
2
+
3
+ export const Media: CollectionConfig = {
4
+ slug: 'media',
5
+ access: {
6
+ read: () => true,
7
+ },
8
+ fields: [
9
+ {
10
+ name: 'alt',
11
+ type: 'text',
12
+ required: true,
13
+ },
14
+ ],
15
+ upload: true,
16
+ }
@@ -1,4 +1,4 @@
1
- import type { CollectionConfig } from 'payload/types'
1
+ import type { CollectionConfig } from 'payload'
2
2
 
3
3
  export const Users: CollectionConfig = {
4
4
  slug: 'users',
@@ -1,12 +1,13 @@
1
+ // storage-adapter-import-placeholder
1
2
  import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import
2
- // import { payloadCloud } from '@payloadcms/plugin-cloud'
3
3
  import { lexicalEditor } from '@payloadcms/richtext-lexical'
4
4
  import path from 'path'
5
- import { buildConfig } from 'payload/config'
6
- // import sharp from 'sharp'
5
+ import { buildConfig } from 'payload'
7
6
  import { fileURLToPath } from 'url'
7
+ import sharp from 'sharp'
8
8
 
9
9
  import { Users } from './collections/Users'
10
+ import { Media } from './collections/Media'
10
11
 
11
12
  const filename = fileURLToPath(import.meta.url)
12
13
  const dirname = path.dirname(filename)
@@ -15,9 +16,8 @@ export default buildConfig({
15
16
  admin: {
16
17
  user: Users.slug,
17
18
  },
18
- collections: [Users],
19
- editor: lexicalEditor({}),
20
- // plugins: [payloadCloud()], // TODO: Re-enable when cloud supports 3.0
19
+ collections: [Users, Media],
20
+ editor: lexicalEditor(),
21
21
  secret: process.env.PAYLOAD_SECRET || '',
22
22
  typescript: {
23
23
  outputFile: path.resolve(dirname, 'payload-types.ts'),
@@ -27,13 +27,8 @@ export default buildConfig({
27
27
  url: process.env.DATABASE_URI || '',
28
28
  }),
29
29
  // database-adapter-config-end
30
-
31
- // Sharp is now an optional dependency -
32
- // if you want to resize images, crop, set focal point, etc.
33
- // make sure to install it and pass it to the config.
34
-
35
- // This is temporary - we may make an adapter pattern
36
- // for this before reaching 3.0 stable
37
-
38
- // sharp,
30
+ sharp,
31
+ plugins: [
32
+ // storage-adapter-placeholder
33
+ ],
39
34
  })