create-payload-app 1.0.0-beta.0 → 3.0.0-alpha.50
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -0
- package/dist/lib/configure-payload-config.d.ts +11 -0
- package/dist/lib/configure-payload-config.d.ts.map +1 -0
- package/dist/lib/configure-payload-config.js +15 -53
- package/dist/lib/configure-payload-config.js.map +1 -0
- package/dist/lib/create-project.d.ts +14 -0
- package/dist/lib/create-project.d.ts.map +1 -0
- package/dist/lib/create-project.js +84 -24
- package/dist/lib/create-project.js.map +1 -0
- package/dist/lib/create-project.spec.d.ts +2 -0
- package/dist/lib/create-project.spec.d.ts.map +1 -0
- package/dist/lib/create-project.spec.js +30 -75
- package/dist/lib/create-project.spec.js.map +1 -0
- package/dist/lib/generate-secret.d.ts +2 -0
- package/dist/lib/generate-secret.d.ts.map +1 -0
- package/dist/lib/generate-secret.js +1 -1
- package/dist/lib/generate-secret.js.map +1 -0
- package/dist/lib/init-next.d.ts +29 -0
- package/dist/lib/init-next.d.ts.map +1 -0
- package/dist/lib/init-next.js +285 -0
- package/dist/lib/init-next.js.map +1 -0
- package/dist/lib/packages.d.ts +9 -0
- package/dist/lib/packages.d.ts.map +1 -0
- package/dist/lib/packages.js +8 -52
- package/dist/lib/packages.js.map +1 -0
- package/dist/lib/parse-project-name.d.ts +3 -0
- package/dist/lib/parse-project-name.d.ts.map +1 -0
- package/dist/lib/parse-project-name.js +53 -12
- package/dist/lib/parse-project-name.js.map +1 -0
- package/dist/lib/parse-template.d.ts +3 -0
- package/dist/lib/parse-template.d.ts.map +1 -0
- package/dist/lib/parse-template.js +50 -20
- package/dist/lib/parse-template.js.map +1 -0
- package/dist/lib/select-db.d.ts +3 -0
- package/dist/lib/select-db.d.ts.map +1 -0
- package/dist/lib/select-db.js +72 -31
- package/dist/lib/select-db.js.map +1 -0
- package/dist/lib/templates.d.ts +4 -0
- package/dist/lib/templates.d.ts.map +1 -0
- package/dist/lib/templates.js +17 -11
- package/dist/lib/templates.js.map +1 -0
- package/dist/lib/wrap-next-config.d.ts +12 -0
- package/dist/lib/wrap-next-config.d.ts.map +1 -0
- package/dist/lib/wrap-next-config.js +110 -0
- package/dist/lib/wrap-next-config.js.map +1 -0
- package/dist/lib/wrap-next-config.spec.d.ts +2 -0
- package/dist/lib/wrap-next-config.spec.d.ts.map +1 -0
- package/dist/lib/wrap-next-config.spec.js +98 -0
- package/dist/lib/wrap-next-config.spec.js.map +1 -0
- package/dist/lib/write-env-file.d.ts +10 -0
- package/dist/lib/write-env-file.d.ts.map +1 -0
- package/dist/lib/write-env-file.js +9 -6
- package/dist/lib/write-env-file.js.map +1 -0
- package/dist/main.d.ts +7 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +176 -60
- package/dist/main.js.map +1 -0
- package/dist/scripts/pack-template-files.d.ts +2 -0
- package/dist/scripts/pack-template-files.d.ts.map +1 -0
- package/dist/scripts/pack-template-files.js +43 -0
- package/dist/scripts/pack-template-files.js.map +1 -0
- package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +17 -0
- package/dist/template/src/app/(payload)/api/[...slug]/route.ts +9 -0
- package/dist/template/src/app/(payload)/api/graphql/route.ts +6 -0
- package/dist/template/src/app/(payload)/api/graphql-playground/route.ts +6 -0
- package/dist/template/src/app/(payload)/custom.scss +0 -0
- package/dist/template/src/app/(payload)/layout.tsx +16 -0
- package/dist/template/src/app/my-route/route.ts +14 -0
- package/dist/template/src/collections/Users.ts +13 -0
- package/dist/template/src/payload.config.ts +38 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -0
- package/dist/utils/copy-recursive-sync.d.ts +5 -0
- package/dist/utils/copy-recursive-sync.d.ts.map +1 -0
- package/dist/utils/copy-recursive-sync.js +34 -0
- package/dist/utils/copy-recursive-sync.js.map +1 -0
- package/dist/utils/log.d.ts +6 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +62 -15
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/messages.d.ts +11 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +47 -16
- package/dist/utils/messages.js.map +1 -0
- package/package.json +27 -10
@@ -13,4 +13,4 @@ function generateSecret() {
|
|
13
13
|
return (0, _crypto.randomBytes)(32).toString('hex').slice(0, 24);
|
14
14
|
}
|
15
15
|
|
16
|
-
//# sourceMappingURL=
|
16
|
+
//# sourceMappingURL=generate-secret.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/lib/generate-secret.ts"],"sourcesContent":["import { randomBytes } from 'crypto'\n\nexport function generateSecret(): string {\n return randomBytes(32).toString('hex').slice(0, 24)\n}\n"],"names":["generateSecret","randomBytes","toString","slice"],"mappings":";;;;+BAEgBA;;;eAAAA;;;wBAFY;AAErB,SAASA;IACd,OAAOC,IAAAA,mBAAW,EAAC,IAAIC,QAAQ,CAAC,OAAOC,KAAK,CAAC,GAAG;AAClD"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import type { CliArgs, DbType, PackageManager } from '../types.js';
|
2
|
+
type InitNextArgs = Pick<CliArgs, '--debug'> & {
|
3
|
+
dbType: DbType;
|
4
|
+
nextAppDetails?: NextAppDetails;
|
5
|
+
packageManager: PackageManager;
|
6
|
+
projectDir: string;
|
7
|
+
useDistFiles?: boolean;
|
8
|
+
};
|
9
|
+
type InitNextResult = {
|
10
|
+
isSrcDir: boolean;
|
11
|
+
nextAppDir: string;
|
12
|
+
payloadConfigPath: string;
|
13
|
+
success: true;
|
14
|
+
} | {
|
15
|
+
isSrcDir: boolean;
|
16
|
+
nextAppDir?: string;
|
17
|
+
reason: string;
|
18
|
+
success: false;
|
19
|
+
};
|
20
|
+
export declare function initNext(args: InitNextArgs): Promise<InitNextResult>;
|
21
|
+
type NextAppDetails = {
|
22
|
+
hasTopLevelLayout: boolean;
|
23
|
+
isSrcDir: boolean;
|
24
|
+
nextAppDir?: string;
|
25
|
+
nextConfigPath?: string;
|
26
|
+
};
|
27
|
+
export declare function getNextAppDetails(projectDir: string): Promise<NextAppDetails>;
|
28
|
+
export {};
|
29
|
+
//# sourceMappingURL=init-next.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"init-next.d.ts","sourceRoot":"","sources":["../../src/lib/init-next.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOlE,KAAK,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,KAAK,cAAc,GACf;IACE,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,OAAO,EAAE,IAAI,CAAA;CACd,GACD;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAA;AAE9E,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAoD1E;AAiID,KAAK,cAAc,GAAG;IACpB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA+BnF"}
|
@@ -0,0 +1,285 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
7
|
+
enumerable: true,
|
8
|
+
get: all[name]
|
9
|
+
});
|
10
|
+
}
|
11
|
+
_export(exports, {
|
12
|
+
getNextAppDetails: function() {
|
13
|
+
return getNextAppDetails;
|
14
|
+
},
|
15
|
+
initNext: function() {
|
16
|
+
return initNext;
|
17
|
+
}
|
18
|
+
});
|
19
|
+
const _prompts = /*#__PURE__*/ _interop_require_wildcard(require("@clack/prompts"));
|
20
|
+
const _commentjson = require("comment-json");
|
21
|
+
const _execa = /*#__PURE__*/ _interop_require_default(require("execa"));
|
22
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
23
|
+
const _globby = /*#__PURE__*/ _interop_require_default(require("globby"));
|
24
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
25
|
+
const _util = require("util");
|
26
|
+
const _nodeurl = require("node:url");
|
27
|
+
const _copyrecursivesync = require("../utils/copy-recursive-sync.js");
|
28
|
+
const _log = require("../utils/log.js");
|
29
|
+
const _messages = require("../utils/messages.js");
|
30
|
+
const _wrapnextconfig = require("./wrap-next-config.js");
|
31
|
+
function _interop_require_default(obj) {
|
32
|
+
return obj && obj.__esModule ? obj : {
|
33
|
+
default: obj
|
34
|
+
};
|
35
|
+
}
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
37
|
+
if (typeof WeakMap !== "function") return null;
|
38
|
+
var cacheBabelInterop = new WeakMap();
|
39
|
+
var cacheNodeInterop = new WeakMap();
|
40
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
41
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
42
|
+
})(nodeInterop);
|
43
|
+
}
|
44
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
45
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
46
|
+
return obj;
|
47
|
+
}
|
48
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
49
|
+
return {
|
50
|
+
default: obj
|
51
|
+
};
|
52
|
+
}
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
54
|
+
if (cache && cache.has(obj)) {
|
55
|
+
return cache.get(obj);
|
56
|
+
}
|
57
|
+
var newObj = {
|
58
|
+
__proto__: null
|
59
|
+
};
|
60
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
61
|
+
for(var key in obj){
|
62
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
63
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
64
|
+
if (desc && (desc.get || desc.set)) {
|
65
|
+
Object.defineProperty(newObj, key, desc);
|
66
|
+
} else {
|
67
|
+
newObj[key] = obj[key];
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
newObj.default = obj;
|
72
|
+
if (cache) {
|
73
|
+
cache.set(obj, newObj);
|
74
|
+
}
|
75
|
+
return newObj;
|
76
|
+
}
|
77
|
+
const readFile = (0, _util.promisify)(_fs.default.readFile);
|
78
|
+
const writeFile = (0, _util.promisify)(_fs.default.writeFile);
|
79
|
+
const filename = (0, _nodeurl.fileURLToPath)(require("url").pathToFileURL(__filename).toString());
|
80
|
+
const dirname = _path.default.dirname(filename);
|
81
|
+
async function initNext(args) {
|
82
|
+
const { dbType: dbType, packageManager, projectDir } = args;
|
83
|
+
const nextAppDetails = args.nextAppDetails || await getNextAppDetails(projectDir);
|
84
|
+
const { hasTopLevelLayout, isSrcDir, nextAppDir } = nextAppDetails || await getNextAppDetails(projectDir);
|
85
|
+
if (!nextAppDir) {
|
86
|
+
return {
|
87
|
+
isSrcDir,
|
88
|
+
reason: `Could not find app directory in ${projectDir}`,
|
89
|
+
success: false
|
90
|
+
};
|
91
|
+
}
|
92
|
+
if (hasTopLevelLayout) {
|
93
|
+
// Output directions for user to move all files from app to top-level directory named `(app)`
|
94
|
+
_prompts.log.warn((0, _messages.moveMessage)({
|
95
|
+
nextAppDir,
|
96
|
+
projectDir
|
97
|
+
}));
|
98
|
+
return {
|
99
|
+
isSrcDir,
|
100
|
+
nextAppDir,
|
101
|
+
reason: 'Found existing layout.tsx in app directory',
|
102
|
+
success: false
|
103
|
+
};
|
104
|
+
}
|
105
|
+
const installSpinner = _prompts.spinner();
|
106
|
+
installSpinner.start('Installing Payload and dependencies...');
|
107
|
+
const configurationResult = installAndConfigurePayload({
|
108
|
+
...args,
|
109
|
+
nextAppDetails,
|
110
|
+
useDistFiles: true
|
111
|
+
});
|
112
|
+
if (configurationResult.success === false) {
|
113
|
+
installSpinner.stop(configurationResult.reason, 1);
|
114
|
+
return {
|
115
|
+
...configurationResult,
|
116
|
+
isSrcDir,
|
117
|
+
success: false
|
118
|
+
};
|
119
|
+
}
|
120
|
+
const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType);
|
121
|
+
if (!installSuccess) {
|
122
|
+
installSpinner.stop('Failed to install dependencies', 1);
|
123
|
+
return {
|
124
|
+
...configurationResult,
|
125
|
+
isSrcDir,
|
126
|
+
reason: 'Failed to install dependencies',
|
127
|
+
success: false
|
128
|
+
};
|
129
|
+
}
|
130
|
+
// Add `@payload-config` to tsconfig.json `paths`
|
131
|
+
await addPayloadConfigToTsConfig(projectDir, isSrcDir);
|
132
|
+
installSpinner.stop('Successfully installed Payload and dependencies');
|
133
|
+
return {
|
134
|
+
...configurationResult,
|
135
|
+
isSrcDir,
|
136
|
+
nextAppDir,
|
137
|
+
success: true
|
138
|
+
};
|
139
|
+
}
|
140
|
+
async function addPayloadConfigToTsConfig(projectDir, isSrcDir) {
|
141
|
+
const tsConfigPath = _path.default.resolve(projectDir, 'tsconfig.json');
|
142
|
+
const userTsConfigContent = await readFile(tsConfigPath, {
|
143
|
+
encoding: 'utf8'
|
144
|
+
});
|
145
|
+
const userTsConfig = (0, _commentjson.parse)(userTsConfigContent);
|
146
|
+
if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {
|
147
|
+
userTsConfig.compilerOptions = {};
|
148
|
+
}
|
149
|
+
if (!userTsConfig.compilerOptions?.paths?.['@payload-config'] && userTsConfig.compilerOptions?.paths) {
|
150
|
+
userTsConfig.compilerOptions.paths = {
|
151
|
+
...userTsConfig.compilerOptions.paths || {},
|
152
|
+
'@payload-config': [
|
153
|
+
`./${isSrcDir ? 'src/' : ''}payload.config.ts`
|
154
|
+
]
|
155
|
+
};
|
156
|
+
await writeFile(tsConfigPath, (0, _commentjson.stringify)(userTsConfig, null, 2), {
|
157
|
+
encoding: 'utf8'
|
158
|
+
});
|
159
|
+
}
|
160
|
+
}
|
161
|
+
function installAndConfigurePayload(args) {
|
162
|
+
const { '--debug': debug, nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {}, projectDir, useDistFiles } = args;
|
163
|
+
if (!nextAppDir || !nextConfigPath) {
|
164
|
+
return {
|
165
|
+
reason: 'Could not find app directory or next.config.js',
|
166
|
+
success: false
|
167
|
+
};
|
168
|
+
}
|
169
|
+
const logDebug = (message)=>{
|
170
|
+
if (debug) (0, _log.debug)(message);
|
171
|
+
};
|
172
|
+
if (!_fs.default.existsSync(projectDir)) {
|
173
|
+
return {
|
174
|
+
reason: `Could not find specified project directory at ${projectDir}`,
|
175
|
+
success: false
|
176
|
+
};
|
177
|
+
}
|
178
|
+
const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? _path.default.resolve(dirname, '../..', 'dist/template') : _path.default.resolve(dirname, '../../../../templates/blank-3.0');
|
179
|
+
logDebug(`Using template files from: ${templateFilesPath}`);
|
180
|
+
if (!_fs.default.existsSync(templateFilesPath)) {
|
181
|
+
return {
|
182
|
+
reason: `Could not find template source files from ${templateFilesPath}`,
|
183
|
+
success: false
|
184
|
+
};
|
185
|
+
} else {
|
186
|
+
logDebug('Found template source files');
|
187
|
+
}
|
188
|
+
logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`);
|
189
|
+
const templateSrcDir = _path.default.resolve(templateFilesPath, isSrcDir ? '' : 'src');
|
190
|
+
logDebug(`templateSrcDir: ${templateSrcDir}`);
|
191
|
+
logDebug(`nextAppDir: ${nextAppDir}`);
|
192
|
+
logDebug(`projectDir: ${projectDir}`);
|
193
|
+
logDebug(`nextConfigPath: ${nextConfigPath}`);
|
194
|
+
logDebug(`isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${_path.default.dirname(nextConfigPath)}`);
|
195
|
+
// This is a little clunky and needs to account for isSrcDir
|
196
|
+
(0, _copyrecursivesync.copyRecursiveSync)(templateSrcDir, _path.default.dirname(nextConfigPath), debug);
|
197
|
+
// Wrap next.config.js with withPayload
|
198
|
+
(0, _wrapnextconfig.wrapNextConfig)({
|
199
|
+
nextConfigPath
|
200
|
+
});
|
201
|
+
return {
|
202
|
+
payloadConfigPath: _path.default.resolve(nextAppDir, '../payload.config.ts'),
|
203
|
+
success: true
|
204
|
+
};
|
205
|
+
}
|
206
|
+
async function installDeps(projectDir, packageManager, dbType) {
|
207
|
+
const packagesToInstall = [
|
208
|
+
'payload',
|
209
|
+
'@payloadcms/next',
|
210
|
+
'@payloadcms/richtext-lexical'
|
211
|
+
].map((pkg)=>`${pkg}@alpha`);
|
212
|
+
packagesToInstall.push(`@payloadcms/db-${dbType}@alpha`);
|
213
|
+
let exitCode = 0;
|
214
|
+
switch(packageManager){
|
215
|
+
case 'npm':
|
216
|
+
{
|
217
|
+
({ exitCode } = await (0, _execa.default)('npm', [
|
218
|
+
'install',
|
219
|
+
'--save',
|
220
|
+
...packagesToInstall
|
221
|
+
], {
|
222
|
+
cwd: projectDir
|
223
|
+
}));
|
224
|
+
break;
|
225
|
+
}
|
226
|
+
case 'yarn':
|
227
|
+
case 'pnpm':
|
228
|
+
{
|
229
|
+
({ exitCode } = await (0, _execa.default)(packageManager, [
|
230
|
+
'add',
|
231
|
+
...packagesToInstall
|
232
|
+
], {
|
233
|
+
cwd: projectDir
|
234
|
+
}));
|
235
|
+
break;
|
236
|
+
}
|
237
|
+
case 'bun':
|
238
|
+
{
|
239
|
+
(0, _log.warning)('Bun support is untested.');
|
240
|
+
({ exitCode } = await (0, _execa.default)('bun', [
|
241
|
+
'add',
|
242
|
+
...packagesToInstall
|
243
|
+
], {
|
244
|
+
cwd: projectDir
|
245
|
+
}));
|
246
|
+
break;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
return {
|
250
|
+
success: exitCode === 0
|
251
|
+
};
|
252
|
+
}
|
253
|
+
async function getNextAppDetails(projectDir) {
|
254
|
+
const isSrcDir = _fs.default.existsSync(_path.default.resolve(projectDir, 'src'));
|
255
|
+
const nextConfigPath = (await (0, _globby.default)('next.config.*js', {
|
256
|
+
absolute: true,
|
257
|
+
cwd: projectDir
|
258
|
+
}))?.[0];
|
259
|
+
if (!nextConfigPath || nextConfigPath.length === 0) {
|
260
|
+
return {
|
261
|
+
hasTopLevelLayout: false,
|
262
|
+
isSrcDir,
|
263
|
+
nextConfigPath: undefined
|
264
|
+
};
|
265
|
+
}
|
266
|
+
let nextAppDir = (await (0, _globby.default)([
|
267
|
+
'**/app'
|
268
|
+
], {
|
269
|
+
absolute: true,
|
270
|
+
cwd: projectDir,
|
271
|
+
onlyDirectories: true
|
272
|
+
}))?.[0];
|
273
|
+
if (!nextAppDir || nextAppDir.length === 0) {
|
274
|
+
nextAppDir = undefined;
|
275
|
+
}
|
276
|
+
const hasTopLevelLayout = nextAppDir ? _fs.default.existsSync(_path.default.resolve(nextAppDir, 'layout.tsx')) : false;
|
277
|
+
return {
|
278
|
+
hasTopLevelLayout,
|
279
|
+
isSrcDir,
|
280
|
+
nextAppDir,
|
281
|
+
nextConfigPath
|
282
|
+
};
|
283
|
+
}
|
284
|
+
|
285
|
+
//# sourceMappingURL=init-next.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport globby from 'globby'\nimport path from 'path'\nimport { promisify } from 'util'\n\nconst readFile = promisify(fs.readFile)\nconst writeFile = promisify(fs.writeFile)\n\nconst filename = fileURLToPath(import.meta.url)\nconst dirname = path.dirname(filename)\n\nimport { fileURLToPath } from 'node:url'\n\nimport type { CliArgs, DbType, PackageManager } from '../types.js'\n\nimport { copyRecursiveSync } from '../utils/copy-recursive-sync.js'\nimport { debug as origDebug, warning } from '../utils/log.js'\nimport { moveMessage } from '../utils/messages.js'\nimport { wrapNextConfig } from './wrap-next-config.js'\n\ntype InitNextArgs = Pick<CliArgs, '--debug'> & {\n dbType: DbType\n nextAppDetails?: NextAppDetails\n packageManager: PackageManager\n projectDir: string\n useDistFiles?: boolean\n}\n\ntype InitNextResult =\n | {\n isSrcDir: boolean\n nextAppDir: string\n payloadConfigPath: string\n success: true\n }\n | { isSrcDir: boolean; nextAppDir?: string; reason: string; success: false }\n\nexport async function initNext(args: InitNextArgs): Promise<InitNextResult> {\n const { dbType: dbType, packageManager, projectDir } = args\n\n const nextAppDetails = args.nextAppDetails || (await getNextAppDetails(projectDir))\n\n const { hasTopLevelLayout, isSrcDir, nextAppDir } =\n nextAppDetails || (await getNextAppDetails(projectDir))\n\n if (!nextAppDir) {\n return { isSrcDir, reason: `Could not find app directory in ${projectDir}`, success: false }\n }\n\n if (hasTopLevelLayout) {\n // Output directions for user to move all files from app to top-level directory named `(app)`\n p.log.warn(moveMessage({ nextAppDir, projectDir }))\n return {\n isSrcDir,\n nextAppDir,\n reason: 'Found existing layout.tsx in app directory',\n success: false,\n }\n }\n\n const installSpinner = p.spinner()\n installSpinner.start('Installing Payload and dependencies...')\n\n const configurationResult = installAndConfigurePayload({\n ...args,\n nextAppDetails,\n useDistFiles: true, // Requires running 'pnpm pack-template-files' in cpa\n })\n\n if (configurationResult.success === false) {\n installSpinner.stop(configurationResult.reason, 1)\n return { ...configurationResult, isSrcDir, success: false }\n }\n\n const { success: installSuccess } = await installDeps(projectDir, packageManager, dbType)\n if (!installSuccess) {\n installSpinner.stop('Failed to install dependencies', 1)\n return {\n ...configurationResult,\n isSrcDir,\n reason: 'Failed to install dependencies',\n success: false,\n }\n }\n\n // Add `@payload-config` to tsconfig.json `paths`\n await addPayloadConfigToTsConfig(projectDir, isSrcDir)\n installSpinner.stop('Successfully installed Payload and dependencies')\n return { ...configurationResult, isSrcDir, nextAppDir, success: true }\n}\n\nasync function addPayloadConfigToTsConfig(projectDir: string, isSrcDir: boolean) {\n const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')\n const userTsConfigContent = await readFile(tsConfigPath, {\n encoding: 'utf8',\n })\n const userTsConfig = parse(userTsConfigContent) as {\n compilerOptions?: CompilerOptions\n }\n if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {\n userTsConfig.compilerOptions = {}\n }\n\n if (\n !userTsConfig.compilerOptions?.paths?.['@payload-config'] &&\n userTsConfig.compilerOptions?.paths\n ) {\n userTsConfig.compilerOptions.paths = {\n ...(userTsConfig.compilerOptions.paths || {}),\n '@payload-config': [`./${isSrcDir ? 'src/' : ''}payload.config.ts`],\n }\n await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), { encoding: 'utf8' })\n }\n}\n\nfunction installAndConfigurePayload(\n args: InitNextArgs & { nextAppDetails: NextAppDetails; useDistFiles?: boolean },\n):\n | { payloadConfigPath: string; success: true }\n | { payloadConfigPath?: string; reason: string; success: false } {\n const {\n '--debug': debug,\n nextAppDetails: { isSrcDir, nextAppDir, nextConfigPath } = {},\n projectDir,\n useDistFiles,\n } = args\n\n if (!nextAppDir || !nextConfigPath) {\n return {\n reason: 'Could not find app directory or next.config.js',\n success: false,\n }\n }\n\n const logDebug = (message: string) => {\n if (debug) origDebug(message)\n }\n\n if (!fs.existsSync(projectDir)) {\n return {\n reason: `Could not find specified project directory at ${projectDir}`,\n success: false,\n }\n }\n\n const templateFilesPath =\n dirname.endsWith('dist') || useDistFiles\n ? path.resolve(dirname, '../..', 'dist/template')\n : path.resolve(dirname, '../../../../templates/blank-3.0')\n\n logDebug(`Using template files from: ${templateFilesPath}`)\n\n if (!fs.existsSync(templateFilesPath)) {\n return {\n reason: `Could not find template source files from ${templateFilesPath}`,\n success: false,\n }\n } else {\n logDebug('Found template source files')\n }\n\n logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`)\n\n const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src')\n\n logDebug(`templateSrcDir: ${templateSrcDir}`)\n logDebug(`nextAppDir: ${nextAppDir}`)\n logDebug(`projectDir: ${projectDir}`)\n logDebug(`nextConfigPath: ${nextConfigPath}`)\n\n logDebug(\n `isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`,\n )\n\n // This is a little clunky and needs to account for isSrcDir\n copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug)\n\n // Wrap next.config.js with withPayload\n wrapNextConfig({ nextConfigPath })\n\n return {\n payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),\n success: true,\n }\n}\n\nasync function installDeps(projectDir: string, packageManager: PackageManager, dbType: DbType) {\n const packagesToInstall = ['payload', '@payloadcms/next', '@payloadcms/richtext-lexical'].map(\n (pkg) => `${pkg}@alpha`,\n )\n\n packagesToInstall.push(`@payloadcms/db-${dbType}@alpha`)\n\n let exitCode = 0\n switch (packageManager) {\n case 'npm': {\n ;({ exitCode } = await execa('npm', ['install', '--save', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'yarn':\n case 'pnpm': {\n ;({ exitCode } = await execa(packageManager, ['add', ...packagesToInstall], {\n cwd: projectDir,\n }))\n break\n }\n case 'bun': {\n warning('Bun support is untested.')\n ;({ exitCode } = await execa('bun', ['add', ...packagesToInstall], { cwd: projectDir }))\n break\n }\n }\n\n return { success: exitCode === 0 }\n}\n\ntype NextAppDetails = {\n hasTopLevelLayout: boolean\n isSrcDir: boolean\n nextAppDir?: string\n nextConfigPath?: string\n}\n\nexport async function getNextAppDetails(projectDir: string): Promise<NextAppDetails> {\n const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'))\n\n const nextConfigPath: string | undefined = (\n await globby('next.config.*js', { absolute: true, cwd: projectDir })\n )?.[0]\n if (!nextConfigPath || nextConfigPath.length === 0) {\n return {\n hasTopLevelLayout: false,\n isSrcDir,\n nextConfigPath: undefined,\n }\n }\n\n let nextAppDir: string | undefined = (\n await globby(['**/app'], {\n absolute: true,\n cwd: projectDir,\n onlyDirectories: true,\n })\n )?.[0]\n\n if (!nextAppDir || nextAppDir.length === 0) {\n nextAppDir = undefined\n }\n\n const hasTopLevelLayout = nextAppDir\n ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx'))\n : false\n\n return { hasTopLevelLayout, isSrcDir, nextAppDir, nextConfigPath }\n}\n"],"names":["getNextAppDetails","initNext","readFile","promisify","fs","writeFile","filename","fileURLToPath","dirname","path","args","dbType","packageManager","projectDir","nextAppDetails","hasTopLevelLayout","isSrcDir","nextAppDir","reason","success","p","log","warn","moveMessage","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","resolve","userTsConfigContent","encoding","userTsConfig","parse","compilerOptions","paths","stringify","debug","nextConfigPath","logDebug","message","origDebug","existsSync","templateFilesPath","endsWith","templateSrcDir","copyRecursiveSync","wrapNextConfig","payloadConfigPath","packagesToInstall","map","pkg","push","exitCode","execa","cwd","warning","globby","absolute","length","undefined","onlyDirectories"],"mappings":";;;;;;;;;;;IAsOsBA,iBAAiB;eAAjBA;;IA5LAC,QAAQ;eAARA;;;iEAxCH;6BACc;8DACf;2DACH;+DACI;6DACF;sBACS;yBAQI;mCAII;qBACU;0BAChB;gCACG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AE;QACvBC,UAAU;QACVH,KAAKhD;QACLsD,iBAAiB;IACnB,EAAC,GACA,CAAC,EAAE;IAEN,IAAI,CAAClD,cAAcA,WAAWgD,MAAM,KAAK,GAAG;QAC1ChD,aAAaiD;IACf;IAEA,MAAMnD,oBAAoBE,aACtBb,WAAE,CAAC4C,UAAU,CAACvC,aAAI,CAAC0B,OAAO,CAAClB,YAAY,iBACvC;IAEJ,OAAO;QAAEF;QAAmBC;QAAUC;QAAY2B;IAAe;AACnE"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { DbType } from '../types.js';
|
2
|
+
type DbAdapterReplacement = {
|
3
|
+
configReplacement: string[];
|
4
|
+
importReplacement: string;
|
5
|
+
packageName: string;
|
6
|
+
};
|
7
|
+
export declare const dbReplacements: Record<DbType, DbAdapterReplacement>;
|
8
|
+
export {};
|
9
|
+
//# sourceMappingURL=packages.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"packages.d.ts","sourceRoot":"","sources":["../../src/lib/packages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,KAAK,oBAAoB,GAAG;IAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAqBD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAG/D,CAAA"}
|
package/dist/lib/packages.js
CHANGED
@@ -2,21 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
3
3
|
value: true
|
4
4
|
});
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
});
|
10
|
-
}
|
11
|
-
_export(exports, {
|
12
|
-
dbPackages: function() {
|
13
|
-
return dbPackages;
|
14
|
-
},
|
15
|
-
bundlerPackages: function() {
|
16
|
-
return bundlerPackages;
|
17
|
-
},
|
18
|
-
editorPackages: function() {
|
19
|
-
return editorPackages;
|
5
|
+
Object.defineProperty(exports, "dbReplacements", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return dbReplacements;
|
20
9
|
}
|
21
10
|
});
|
22
11
|
const mongodbReplacement = {
|
@@ -27,8 +16,7 @@ const mongodbReplacement = {
|
|
27
16
|
' db: mongooseAdapter({',
|
28
17
|
' url: process.env.DATABASE_URI,',
|
29
18
|
' }),'
|
30
|
-
]
|
31
|
-
version: '^1.0.0'
|
19
|
+
]
|
32
20
|
};
|
33
21
|
const postgresReplacement = {
|
34
22
|
configReplacement: [
|
@@ -39,43 +27,11 @@ const postgresReplacement = {
|
|
39
27
|
' }),'
|
40
28
|
],
|
41
29
|
importReplacement: "import { postgresAdapter } from '@payloadcms/db-postgres'",
|
42
|
-
packageName: '@payloadcms/db-postgres'
|
43
|
-
version: '^0.x'
|
30
|
+
packageName: '@payloadcms/db-postgres'
|
44
31
|
};
|
45
|
-
const
|
32
|
+
const dbReplacements = {
|
46
33
|
mongodb: mongodbReplacement,
|
47
34
|
postgres: postgresReplacement
|
48
35
|
};
|
49
|
-
const webpackReplacement = {
|
50
|
-
importReplacement: "import { webpackBundler } from '@payloadcms/bundler-webpack'",
|
51
|
-
packageName: '@payloadcms/bundler-webpack',
|
52
|
-
// Replacement of line containing `// bundler-config`
|
53
|
-
configReplacement: ' bundler: webpackBundler(),',
|
54
|
-
version: '^1.0.0'
|
55
|
-
};
|
56
|
-
const viteReplacement = {
|
57
|
-
configReplacement: ' bundler: viteBundler(),',
|
58
|
-
importReplacement: "import { viteBundler } from '@payloadcms/bundler-vite'",
|
59
|
-
packageName: '@payloadcms/bundler-vite',
|
60
|
-
version: '^0.x'
|
61
|
-
};
|
62
|
-
const bundlerPackages = {
|
63
|
-
vite: viteReplacement,
|
64
|
-
webpack: webpackReplacement
|
65
|
-
};
|
66
|
-
const editorPackages = {
|
67
|
-
lexical: {
|
68
|
-
configReplacement: ' editor: lexicalEditor({}),',
|
69
|
-
importReplacement: "import { lexicalEditor } from '@payloadcms/richtext-lexical'",
|
70
|
-
packageName: '@payloadcms/richtext-lexical',
|
71
|
-
version: '^0.x'
|
72
|
-
},
|
73
|
-
slate: {
|
74
|
-
configReplacement: ' editor: slateEditor({}),',
|
75
|
-
importReplacement: "import { slateEditor } from '@payloadcms/richtext-slate'",
|
76
|
-
packageName: '@payloadcms/richtext-slate',
|
77
|
-
version: '^1.0.0'
|
78
|
-
}
|
79
|
-
};
|
80
36
|
|
81
|
-
//# sourceMappingURL=
|
37
|
+
//# sourceMappingURL=packages.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/lib/packages.ts"],"sourcesContent":["import type { DbType } from '../types.js'\n\ntype DbAdapterReplacement = {\n configReplacement: string[]\n importReplacement: string\n packageName: string\n}\n\nconst mongodbReplacement: DbAdapterReplacement = {\n importReplacement: \"import { mongooseAdapter } from '@payloadcms/db-mongodb'\",\n packageName: '@payloadcms/db-mongodb',\n // Replacement between `// database-adapter-config-start` and `// database-adapter-config-end`\n configReplacement: [' db: mongooseAdapter({', ' url: process.env.DATABASE_URI,', ' }),'],\n}\n\nconst postgresReplacement: DbAdapterReplacement = {\n configReplacement: [\n ' db: postgresAdapter({',\n ' pool: {',\n ' connectionString: process.env.DATABASE_URI,',\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"],"names":["dbReplacements","mongodbReplacement","importReplacement","packageName","configReplacement","postgresReplacement","mongodb","postgres"],"mappings":";;;;+BA2BaA;;;eAAAA;;;AAnBb,MAAMC,qBAA2C;IAC/CC,mBAAmB;IACnBC,aAAa;IACb,8FAA8F;IAC9FC,mBAAmB;QAAC;QAA2B;QAAsC;KAAQ;AAC/F;AAEA,MAAMC,sBAA4C;IAChDD,mBAAmB;QACjB;QACA;QACA;QACA;QACA;KACD;IACDF,mBAAmB;IACnBC,aAAa;AACf;AAEO,MAAMH,iBAAuD;IAClEM,SAASL;IACTM,UAAUF;AACZ"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parse-project-name.d.ts","sourceRoot":"","sources":["../../src/lib/parse-project-name.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAcrE"}
|
@@ -8,26 +8,67 @@ Object.defineProperty(exports, "parseProjectName", {
|
|
8
8
|
return parseProjectName;
|
9
9
|
}
|
10
10
|
});
|
11
|
-
const _prompts = /*#__PURE__*/
|
11
|
+
const _prompts = /*#__PURE__*/ _interop_require_wildcard(require("@clack/prompts"));
|
12
|
+
const _slugify = /*#__PURE__*/ _interop_require_default(require("@sindresorhus/slugify"));
|
12
13
|
function _interop_require_default(obj) {
|
13
14
|
return obj && obj.__esModule ? obj : {
|
14
15
|
default: obj
|
15
16
|
};
|
16
17
|
}
|
18
|
+
function _getRequireWildcardCache(nodeInterop) {
|
19
|
+
if (typeof WeakMap !== "function") return null;
|
20
|
+
var cacheBabelInterop = new WeakMap();
|
21
|
+
var cacheNodeInterop = new WeakMap();
|
22
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
23
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
24
|
+
})(nodeInterop);
|
25
|
+
}
|
26
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
27
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
28
|
+
return obj;
|
29
|
+
}
|
30
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
31
|
+
return {
|
32
|
+
default: obj
|
33
|
+
};
|
34
|
+
}
|
35
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
36
|
+
if (cache && cache.has(obj)) {
|
37
|
+
return cache.get(obj);
|
38
|
+
}
|
39
|
+
var newObj = {
|
40
|
+
__proto__: null
|
41
|
+
};
|
42
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
43
|
+
for(var key in obj){
|
44
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
45
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
46
|
+
if (desc && (desc.get || desc.set)) {
|
47
|
+
Object.defineProperty(newObj, key, desc);
|
48
|
+
} else {
|
49
|
+
newObj[key] = obj[key];
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
newObj.default = obj;
|
54
|
+
if (cache) {
|
55
|
+
cache.set(obj, newObj);
|
56
|
+
}
|
57
|
+
return newObj;
|
58
|
+
}
|
17
59
|
async function parseProjectName(args) {
|
18
|
-
if (args['--name']) return args['--name'];
|
19
|
-
if (args._[0]) return args._[0];
|
20
|
-
const
|
21
|
-
name: 'value',
|
60
|
+
if (args['--name']) return (0, _slugify.default)(args['--name']);
|
61
|
+
if (args._[0]) return (0, _slugify.default)(args._[0]);
|
62
|
+
const projectName = await _prompts.text({
|
22
63
|
message: 'Project name?',
|
23
|
-
|
24
|
-
|
25
|
-
}, {
|
26
|
-
onCancel: ()=>{
|
27
|
-
process.exit(0);
|
64
|
+
validate: (value)=>{
|
65
|
+
if (!value) return 'Please enter a project name.';
|
28
66
|
}
|
29
67
|
});
|
30
|
-
|
68
|
+
if (_prompts.isCancel(projectName)) {
|
69
|
+
process.exit(0);
|
70
|
+
}
|
71
|
+
return (0, _slugify.default)(projectName);
|
31
72
|
}
|
32
73
|
|
33
|
-
//# sourceMappingURL=
|
74
|
+
//# sourceMappingURL=parse-project-name.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["parseProjectName","args","slugify","_","projectName","p","text","message","validate","value","isCancel","process","exit"],"mappings":";;;;+BAKsBA;;;eAAAA;;;iEALH;gEACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIb,eAAeA,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOC,IAAAA,gBAAO,EAACD,IAAI,CAAC,SAAS;IACjD,IAAIA,KAAKE,CAAC,CAAC,EAAE,EAAE,OAAOD,IAAAA,gBAAO,EAACD,KAAKE,CAAC,CAAC,EAAE;IAEvC,MAAMC,cAAc,MAAMC,SAAEC,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO,OAAO;QACrB;IACF;IACA,IAAIJ,SAAEK,QAAQ,CAACN,cAAc;QAC3BO,QAAQC,IAAI,CAAC;IACf;IACA,OAAOV,IAAAA,gBAAO,EAACE;AACjB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parse-template.d.ts","sourceRoot":"","sources":["../../src/lib/parse-template.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE3D,wBAAsB,aAAa,CACjC,IAAI,EAAE,OAAO,EACb,cAAc,EAAE,eAAe,EAAE,GAChC,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAwBtC"}
|