create-payload-app 3.0.0-alpha.55 → 3.0.0-alpha.60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/bin/cli.js +3 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +10 -9
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/configure-payload-config.js +12 -27
  7. package/dist/lib/configure-payload-config.js.map +1 -1
  8. package/dist/lib/create-project.js +32 -96
  9. package/dist/lib/create-project.js.map +1 -1
  10. package/dist/lib/create-project.spec.js +24 -33
  11. package/dist/lib/create-project.spec.js.map +1 -1
  12. package/dist/lib/generate-secret.js +3 -13
  13. package/dist/lib/generate-secret.js.map +1 -1
  14. package/dist/lib/init-next.js +40 -104
  15. package/dist/lib/init-next.js.map +1 -1
  16. package/dist/lib/packages.js +1 -11
  17. package/dist/lib/packages.js.map +1 -1
  18. package/dist/lib/parse-project-name.js +8 -64
  19. package/dist/lib/parse-project-name.js.map +1 -1
  20. package/dist/lib/parse-template.js +4 -55
  21. package/dist/lib/parse-template.js.map +1 -1
  22. package/dist/lib/select-db.js +8 -64
  23. package/dist/lib/select-db.js.map +1 -1
  24. package/dist/lib/templates.js +5 -23
  25. package/dist/lib/templates.js.map +1 -1
  26. package/dist/lib/wrap-next-config.js +18 -41
  27. package/dist/lib/wrap-next-config.js.map +1 -1
  28. package/dist/lib/wrap-next-config.spec.js +10 -55
  29. package/dist/lib/wrap-next-config.spec.js.map +1 -1
  30. package/dist/lib/write-env-file.js +11 -26
  31. package/dist/lib/write-env-file.js.map +1 -1
  32. package/dist/main.js +60 -115
  33. package/dist/main.js.map +1 -1
  34. package/dist/scripts/pack-template-files.js +15 -24
  35. package/dist/scripts/pack-template-files.js.map +1 -1
  36. package/dist/types.js +1 -4
  37. package/dist/types.js.map +1 -1
  38. package/dist/utils/copy-recursive-sync.js +11 -24
  39. package/dist/utils/copy-recursive-sync.js.map +1 -1
  40. package/dist/utils/log.js +12 -85
  41. package/dist/utils/log.js.map +1 -1
  42. package/dist/utils/messages.js +20 -55
  43. package/dist/utils/messages.js.map +1 -1
  44. package/package.json +2 -2
@@ -1,84 +1,20 @@
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) {
1
+ import * as p from '@clack/prompts';
2
+ import { parse, stringify } from 'comment-json';
3
+ import execa from 'execa';
4
+ import fs from 'fs';
5
+ import globby from 'globby';
6
+ import path from 'path';
7
+ import { promisify } from 'util';
8
+ const readFile = promisify(fs.readFile);
9
+ const writeFile = promisify(fs.writeFile);
10
+ const filename = fileURLToPath(import.meta.url);
11
+ const dirname = path.dirname(filename);
12
+ import { fileURLToPath } from 'node:url';
13
+ import { copyRecursiveSync } from '../utils/copy-recursive-sync.js';
14
+ import { debug as origDebug, warning } from '../utils/log.js';
15
+ import { moveMessage } from '../utils/messages.js';
16
+ import { wrapNextConfig } from './wrap-next-config.js';
17
+ export async function initNext(args) {
82
18
  const { dbType: dbType, packageManager, projectDir } = args;
83
19
  const nextAppDetails = args.nextAppDetails || await getNextAppDetails(projectDir);
84
20
  const { hasTopLevelLayout, isSrcDir, nextAppDir } = nextAppDetails || await getNextAppDetails(projectDir);
@@ -91,7 +27,7 @@ async function initNext(args) {
91
27
  }
92
28
  if (hasTopLevelLayout) {
93
29
  // Output directions for user to move all files from app to top-level directory named `(app)`
94
- _prompts.log.warn((0, _messages.moveMessage)({
30
+ p.log.warn(moveMessage({
95
31
  nextAppDir,
96
32
  projectDir
97
33
  }));
@@ -102,7 +38,7 @@ async function initNext(args) {
102
38
  success: false
103
39
  };
104
40
  }
105
- const installSpinner = _prompts.spinner();
41
+ const installSpinner = p.spinner();
106
42
  installSpinner.start('Installing Payload and dependencies...');
107
43
  const configurationResult = installAndConfigurePayload({
108
44
  ...args,
@@ -138,11 +74,11 @@ async function initNext(args) {
138
74
  };
139
75
  }
140
76
  async function addPayloadConfigToTsConfig(projectDir, isSrcDir) {
141
- const tsConfigPath = _path.default.resolve(projectDir, 'tsconfig.json');
77
+ const tsConfigPath = path.resolve(projectDir, 'tsconfig.json');
142
78
  const userTsConfigContent = await readFile(tsConfigPath, {
143
79
  encoding: 'utf8'
144
80
  });
145
- const userTsConfig = (0, _commentjson.parse)(userTsConfigContent);
81
+ const userTsConfig = parse(userTsConfigContent);
146
82
  if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {
147
83
  userTsConfig.compilerOptions = {};
148
84
  }
@@ -153,7 +89,7 @@ async function addPayloadConfigToTsConfig(projectDir, isSrcDir) {
153
89
  `./${isSrcDir ? 'src/' : ''}payload.config.ts`
154
90
  ]
155
91
  };
156
- await writeFile(tsConfigPath, (0, _commentjson.stringify)(userTsConfig, null, 2), {
92
+ await writeFile(tsConfigPath, stringify(userTsConfig, null, 2), {
157
93
  encoding: 'utf8'
158
94
  });
159
95
  }
@@ -167,17 +103,17 @@ function installAndConfigurePayload(args) {
167
103
  };
168
104
  }
169
105
  const logDebug = (message)=>{
170
- if (debug) (0, _log.debug)(message);
106
+ if (debug) origDebug(message);
171
107
  };
172
- if (!_fs.default.existsSync(projectDir)) {
108
+ if (!fs.existsSync(projectDir)) {
173
109
  return {
174
110
  reason: `Could not find specified project directory at ${projectDir}`,
175
111
  success: false
176
112
  };
177
113
  }
178
- const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? _path.default.resolve(dirname, '../..', 'dist/template') : _path.default.resolve(dirname, '../../../../templates/blank-3.0');
114
+ const templateFilesPath = dirname.endsWith('dist') || useDistFiles ? path.resolve(dirname, '../..', 'dist/template') : path.resolve(dirname, '../../../../templates/blank-3.0');
179
115
  logDebug(`Using template files from: ${templateFilesPath}`);
180
- if (!_fs.default.existsSync(templateFilesPath)) {
116
+ if (!fs.existsSync(templateFilesPath)) {
181
117
  return {
182
118
  reason: `Could not find template source files from ${templateFilesPath}`,
183
119
  success: false
@@ -186,20 +122,20 @@ function installAndConfigurePayload(args) {
186
122
  logDebug('Found template source files');
187
123
  }
188
124
  logDebug(`Copying template files from ${templateFilesPath} to ${nextAppDir}`);
189
- const templateSrcDir = _path.default.resolve(templateFilesPath, isSrcDir ? '' : 'src');
125
+ const templateSrcDir = path.resolve(templateFilesPath, isSrcDir ? '' : 'src');
190
126
  logDebug(`templateSrcDir: ${templateSrcDir}`);
191
127
  logDebug(`nextAppDir: ${nextAppDir}`);
192
128
  logDebug(`projectDir: ${projectDir}`);
193
129
  logDebug(`nextConfigPath: ${nextConfigPath}`);
194
- logDebug(`isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${_path.default.dirname(nextConfigPath)}`);
130
+ logDebug(`isSrcDir: ${isSrcDir}. source: ${templateSrcDir}. dest: ${path.dirname(nextConfigPath)}`);
195
131
  // This is a little clunky and needs to account for isSrcDir
196
- (0, _copyrecursivesync.copyRecursiveSync)(templateSrcDir, _path.default.dirname(nextConfigPath), debug);
132
+ copyRecursiveSync(templateSrcDir, path.dirname(nextConfigPath), debug);
197
133
  // Wrap next.config.js with withPayload
198
- (0, _wrapnextconfig.wrapNextConfig)({
134
+ wrapNextConfig({
199
135
  nextConfigPath
200
136
  });
201
137
  return {
202
- payloadConfigPath: _path.default.resolve(nextAppDir, '../payload.config.ts'),
138
+ payloadConfigPath: path.resolve(nextAppDir, '../payload.config.ts'),
203
139
  success: true
204
140
  };
205
141
  }
@@ -214,7 +150,7 @@ async function installDeps(projectDir, packageManager, dbType) {
214
150
  switch(packageManager){
215
151
  case 'npm':
216
152
  {
217
- ({ exitCode } = await (0, _execa.default)('npm', [
153
+ ({ exitCode } = await execa('npm', [
218
154
  'install',
219
155
  '--save',
220
156
  ...packagesToInstall
@@ -226,7 +162,7 @@ async function installDeps(projectDir, packageManager, dbType) {
226
162
  case 'yarn':
227
163
  case 'pnpm':
228
164
  {
229
- ({ exitCode } = await (0, _execa.default)(packageManager, [
165
+ ({ exitCode } = await execa(packageManager, [
230
166
  'add',
231
167
  ...packagesToInstall
232
168
  ], {
@@ -236,8 +172,8 @@ async function installDeps(projectDir, packageManager, dbType) {
236
172
  }
237
173
  case 'bun':
238
174
  {
239
- (0, _log.warning)('Bun support is untested.');
240
- ({ exitCode } = await (0, _execa.default)('bun', [
175
+ warning('Bun support is untested.');
176
+ ({ exitCode } = await execa('bun', [
241
177
  'add',
242
178
  ...packagesToInstall
243
179
  ], {
@@ -250,9 +186,9 @@ async function installDeps(projectDir, packageManager, dbType) {
250
186
  success: exitCode === 0
251
187
  };
252
188
  }
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', {
189
+ export async function getNextAppDetails(projectDir) {
190
+ const isSrcDir = fs.existsSync(path.resolve(projectDir, 'src'));
191
+ const nextConfigPath = (await globby('next.config.*js', {
256
192
  absolute: true,
257
193
  cwd: projectDir
258
194
  }))?.[0];
@@ -263,7 +199,7 @@ async function getNextAppDetails(projectDir) {
263
199
  nextConfigPath: undefined
264
200
  };
265
201
  }
266
- let nextAppDir = (await (0, _globby.default)([
202
+ let nextAppDir = (await globby([
267
203
  '**/app'
268
204
  ], {
269
205
  absolute: true,
@@ -273,7 +209,7 @@ async function getNextAppDetails(projectDir) {
273
209
  if (!nextAppDir || nextAppDir.length === 0) {
274
210
  nextAppDir = undefined;
275
211
  }
276
- const hasTopLevelLayout = nextAppDir ? _fs.default.existsSync(_path.default.resolve(nextAppDir, 'layout.tsx')) : false;
212
+ const hasTopLevelLayout = nextAppDir ? fs.existsSync(path.resolve(nextAppDir, 'layout.tsx')) : false;
277
213
  return {
278
214
  hasTopLevelLayout,
279
215
  isSrcDir,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/init-next.ts"],"sourcesContent":["import type { CompilerOptions } from 'typescript'\n\nimport * as p from '@clack/prompts'\nimport { parse, stringify } from 'comment-json'\nimport execa from 'execa'\nimport fs from 'fs'\nimport 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,i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kBA,eAAeqB,MAAM,KAAK,GAAG;QAClD,OAAO;YACLlD,mBAAmB;YACnBC;YACA4B,gBAAgBsB;QAClB;IACF;IAEA,IAAIjD,aACF,CAAA,MAAM8C,IAAAA,eAAM,EAAC;QAAC;KAAS,EAAE;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"}
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":["p","parse","stringify","execa","fs","globby","path","promisify","readFile","writeFile","filename","fileURLToPath","url","dirname","copyRecursiveSync","debug","origDebug","warning","moveMessage","wrapNextConfig","initNext","args","dbType","packageManager","projectDir","nextAppDetails","getNextAppDetails","hasTopLevelLayout","isSrcDir","nextAppDir","reason","success","log","warn","installSpinner","spinner","start","configurationResult","installAndConfigurePayload","useDistFiles","stop","installSuccess","installDeps","addPayloadConfigToTsConfig","tsConfigPath","resolve","userTsConfigContent","encoding","userTsConfig","compilerOptions","paths","nextConfigPath","logDebug","message","existsSync","templateFilesPath","endsWith","templateSrcDir","payloadConfigPath","packagesToInstall","map","pkg","push","exitCode","cwd","absolute","length","undefined","onlyDirectories"],"mappings":"AAEA,YAAYA,OAAO,iBAAgB;AACnC,SAASC,KAAK,EAAEC,SAAS,QAAQ,eAAc;AAC/C,OAAOC,WAAW,QAAO;AACzB,OAAOC,QAAQ,KAAI;AACnB,OAAOC,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,QAAQ,OAAM;AAEhC,MAAMC,WAAWD,UAAUH,GAAGI,QAAQ;AACtC,MAAMC,YAAYF,UAAUH,GAAGK,SAAS;AAExC,MAAMC,WAAWC,cAAc,YAAYC,GAAG;AAC9C,MAAMC,UAAUP,KAAKO,OAAO,CAACH;AAE7B,SAASC,aAAa,QAAQ,WAAU;AAIxC,SAASG,iBAAiB,QAAQ,kCAAiC;AACnE,SAASC,SAASC,SAAS,EAAEC,OAAO,QAAQ,kBAAiB;AAC7D,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,cAAc,QAAQ,wBAAuB;AAmBtD,OAAO,eAAeC,SAASC,IAAkB;IAC/C,MAAM,EAAEC,QAAQA,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGH;IAEvD,MAAMI,iBAAiBJ,KAAKI,cAAc,IAAK,MAAMC,kBAAkBF;IAEvE,MAAM,EAAEG,iBAAiB,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAC/CJ,kBAAmB,MAAMC,kBAAkBF;IAE7C,IAAI,CAACK,YAAY;QACf,OAAO;YAAED;YAAUE,QAAQ,CAAC,gCAAgC,EAAEN,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AKxC;gBAAW,EAAC;gBACtF;YACF;IACF;IAEA,OAAO;QAAEO,SAASgC,aAAa;IAAE;AACnC;AASA,OAAO,eAAerC,kBAAkBF,UAAkB;IACxD,MAAMI,WAAWxB,GAAGkD,UAAU,CAAChD,KAAKuC,OAAO,CAACrB,YAAY;IAExD,MAAM2B,iBACJ,CAAA,MAAM9C,OAAO,mBAAmB;QAAE4D,UAAU;QAAMD,KAAKxC;IAAW,EAAC,GAClE,CAAC,EAAE;IACN,IAAI,CAAC2B,kBAAkBA,eAAee,MAAM,KAAK,GAAG;QAClD,OAAO;YACLvC,mBAAmB;YACnBC;YACAuB,gBAAgBgB;QAClB;IACF;IAEA,IAAItC,aACF,CAAA,MAAMxB,OAAO;QAAC;KAAS,EAAE;QACvB4D,UAAU;QACVD,KAAKxC;QACL4C,iBAAiB;IACnB,EAAC,GACA,CAAC,EAAE;IAEN,IAAI,CAACvC,cAAcA,WAAWqC,MAAM,KAAK,GAAG;QAC1CrC,aAAasC;IACf;IAEA,MAAMxC,oBAAoBE,aACtBzB,GAAGkD,UAAU,CAAChD,KAAKuC,OAAO,CAAChB,YAAY,iBACvC;IAEJ,OAAO;QAAEF;QAAmBC;QAAUC;QAAYsB;IAAe;AACnE"}
@@ -1,13 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "dbReplacements", {
6
- enumerable: true,
7
- get: function() {
8
- return dbReplacements;
9
- }
10
- });
11
1
  const mongodbReplacement = {
12
2
  importReplacement: "import { mongooseAdapter } from '@payloadcms/db-mongodb'",
13
3
  packageName: '@payloadcms/db-mongodb',
@@ -29,7 +19,7 @@ const postgresReplacement = {
29
19
  importReplacement: "import { postgresAdapter } from '@payloadcms/db-postgres'",
30
20
  packageName: '@payloadcms/db-postgres'
31
21
  };
32
- const dbReplacements = {
22
+ export const dbReplacements = {
33
23
  mongodb: mongodbReplacement,
34
24
  postgres: postgresReplacement
35
25
  };
@@ -1 +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"}
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":["mongodbReplacement","importReplacement","packageName","configReplacement","postgresReplacement","dbReplacements","mongodb","postgres"],"mappings":"AAQA,MAAMA,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;AAEA,OAAO,MAAMG,iBAAuD;IAClEC,SAASN;IACTO,UAAUH;AACZ,EAAC"}
@@ -1,74 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "parseProjectName", {
6
- enumerable: true,
7
- get: function() {
8
- return parseProjectName;
9
- }
10
- });
11
- const _prompts = /*#__PURE__*/ _interop_require_wildcard(require("@clack/prompts"));
12
- const _slugify = /*#__PURE__*/ _interop_require_default(require("@sindresorhus/slugify"));
13
- function _interop_require_default(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
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
- }
59
- async function parseProjectName(args) {
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({
1
+ import * as p from '@clack/prompts';
2
+ import slugify from '@sindresorhus/slugify';
3
+ export async function parseProjectName(args) {
4
+ if (args['--name']) return slugify(args['--name']);
5
+ if (args._[0]) return slugify(args._[0]);
6
+ const projectName = await p.text({
63
7
  message: 'Project name?',
64
8
  validate: (value)=>{
65
9
  if (!value) return 'Please enter a project name.';
66
10
  }
67
11
  });
68
- if (_prompts.isCancel(projectName)) {
12
+ if (p.isCancel(projectName)) {
69
13
  process.exit(0);
70
14
  }
71
- return (0, _slugify.default)(projectName);
15
+ return slugify(projectName);
72
16
  }
73
17
 
74
18
  //# sourceMappingURL=parse-project-name.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["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"}
1
+ {"version":3,"sources":["../../src/lib/parse-project-name.ts"],"sourcesContent":["import * as p from '@clack/prompts'\nimport slugify from '@sindresorhus/slugify'\n\nimport type { CliArgs } from '../types.js'\n\nexport async function parseProjectName(args: CliArgs): Promise<string> {\n if (args['--name']) return slugify(args['--name'])\n if (args._[0]) return slugify(args._[0])\n\n const projectName = await p.text({\n message: 'Project name?',\n validate: (value) => {\n if (!value) return 'Please enter a project name.'\n },\n })\n if (p.isCancel(projectName)) {\n process.exit(0)\n }\n return slugify(projectName)\n}\n"],"names":["p","slugify","parseProjectName","args","_","projectName","text","message","validate","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AACnC,OAAOC,aAAa,wBAAuB;AAI3C,OAAO,eAAeC,iBAAiBC,IAAa;IAClD,IAAIA,IAAI,CAAC,SAAS,EAAE,OAAOF,QAAQE,IAAI,CAAC,SAAS;IACjD,IAAIA,KAAKC,CAAC,CAAC,EAAE,EAAE,OAAOH,QAAQE,KAAKC,CAAC,CAAC,EAAE;IAEvC,MAAMC,cAAc,MAAML,EAAEM,IAAI,CAAC;QAC/BC,SAAS;QACTC,UAAU,CAACC;YACT,IAAI,CAACA,OAAO,OAAO;QACrB;IACF;IACA,IAAIT,EAAEU,QAAQ,CAACL,cAAc;QAC3BM,QAAQC,IAAI,CAAC;IACf;IACA,OAAOX,QAAQI;AACjB"}
@@ -1,63 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "parseTemplate", {
6
- enumerable: true,
7
- get: function() {
8
- return parseTemplate;
9
- }
10
- });
11
- const _prompts = /*#__PURE__*/ _interop_require_wildcard(require("@clack/prompts"));
12
- function _getRequireWildcardCache(nodeInterop) {
13
- if (typeof WeakMap !== "function") return null;
14
- var cacheBabelInterop = new WeakMap();
15
- var cacheNodeInterop = new WeakMap();
16
- return (_getRequireWildcardCache = function(nodeInterop) {
17
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
18
- })(nodeInterop);
19
- }
20
- function _interop_require_wildcard(obj, nodeInterop) {
21
- if (!nodeInterop && obj && obj.__esModule) {
22
- return obj;
23
- }
24
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
- return {
26
- default: obj
27
- };
28
- }
29
- var cache = _getRequireWildcardCache(nodeInterop);
30
- if (cache && cache.has(obj)) {
31
- return cache.get(obj);
32
- }
33
- var newObj = {
34
- __proto__: null
35
- };
36
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
37
- for(var key in obj){
38
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
39
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
40
- if (desc && (desc.get || desc.set)) {
41
- Object.defineProperty(newObj, key, desc);
42
- } else {
43
- newObj[key] = obj[key];
44
- }
45
- }
46
- }
47
- newObj.default = obj;
48
- if (cache) {
49
- cache.set(obj, newObj);
50
- }
51
- return newObj;
52
- }
53
- async function parseTemplate(args, validTemplates) {
1
+ import * as p from '@clack/prompts';
2
+ export async function parseTemplate(args, validTemplates) {
54
3
  if (args['--template']) {
55
4
  const templateName = args['--template'];
56
5
  const template = validTemplates.find((t)=>t.name === templateName);
57
6
  if (!template) throw new Error('Invalid template given');
58
7
  return template;
59
8
  }
60
- const response = await _prompts.select({
9
+ const response = await p.select({
61
10
  message: 'Choose project template',
62
11
  options: validTemplates.map((p)=>{
63
12
  return {
@@ -66,7 +15,7 @@ async function parseTemplate(args, validTemplates) {
66
15
  };
67
16
  })
68
17
  });
69
- if (_prompts.isCancel(response)) {
18
+ if (p.isCancel(response)) {
70
19
  process.exit(0);
71
20
  }
72
21
  const template = validTemplates.find((t)=>t.name === response);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-template.ts"],"sourcesContent":["import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n args: CliArgs,\n validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n if (args['--template']) {\n const templateName = args['--template']\n const template = validTemplates.find((t) => t.name === templateName)\n if (!template) throw new Error('Invalid template given')\n return template\n }\n\n const response = await p.select<{ label: string; value: string }[], string>({\n message: 'Choose project template',\n options: validTemplates.map((p) => {\n return {\n label: p.name,\n value: p.name,\n }\n }),\n })\n if (p.isCancel(response)) {\n process.exit(0)\n }\n\n const template = validTemplates.find((t) => t.name === response)\n\n return template\n}\n"],"names":["parseTemplate","args","validTemplates","templateName","template","find","t","name","Error","response","p","select","message","options","map","label","value","isCancel","process","exit"],"mappings":";;;;+BAIsBA;;;eAAAA;;;iEAJH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIZ,eAAeA,cACpBC,IAAa,EACbC,cAAiC;IAEjC,IAAID,IAAI,CAAC,aAAa,EAAE;QACtB,MAAME,eAAeF,IAAI,CAAC,aAAa;QACvC,MAAMG,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QACvD,IAAI,CAACC,UAAU,MAAM,IAAII,MAAM;QAC/B,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMC,SAAEC,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASX,eAAeY,GAAG,CAAC,CAACJ;YAC3B,OAAO;gBACLK,OAAOL,EAAEH,IAAI;gBACbS,OAAON,EAAEH,IAAI;YACf;QACF;IACF;IACA,IAAIG,SAAEO,QAAQ,CAACR,WAAW;QACxBS,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMf,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
1
+ {"version":3,"sources":["../../src/lib/parse-template.ts"],"sourcesContent":["import * as p from '@clack/prompts'\n\nimport type { CliArgs, ProjectTemplate } from '../types.js'\n\nexport async function parseTemplate(\n args: CliArgs,\n validTemplates: ProjectTemplate[],\n): Promise<ProjectTemplate | undefined> {\n if (args['--template']) {\n const templateName = args['--template']\n const template = validTemplates.find((t) => t.name === templateName)\n if (!template) throw new Error('Invalid template given')\n return template\n }\n\n const response = await p.select<{ label: string; value: string }[], string>({\n message: 'Choose project template',\n options: validTemplates.map((p) => {\n return {\n label: p.name,\n value: p.name,\n }\n }),\n })\n if (p.isCancel(response)) {\n process.exit(0)\n }\n\n const template = validTemplates.find((t) => t.name === response)\n\n return template\n}\n"],"names":["p","parseTemplate","args","validTemplates","templateName","template","find","t","name","Error","response","select","message","options","map","label","value","isCancel","process","exit"],"mappings":"AAAA,YAAYA,OAAO,iBAAgB;AAInC,OAAO,eAAeC,cACpBC,IAAa,EACbC,cAAiC;IAEjC,IAAID,IAAI,CAAC,aAAa,EAAE;QACtB,MAAME,eAAeF,IAAI,CAAC,aAAa;QACvC,MAAMG,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ;QACvD,IAAI,CAACC,UAAU,MAAM,IAAII,MAAM;QAC/B,OAAOJ;IACT;IAEA,MAAMK,WAAW,MAAMV,EAAEW,MAAM,CAA6C;QAC1EC,SAAS;QACTC,SAASV,eAAeW,GAAG,CAAC,CAACd;YAC3B,OAAO;gBACLe,OAAOf,EAAEQ,IAAI;gBACbQ,OAAOhB,EAAEQ,IAAI;YACf;QACF;IACF;IACA,IAAIR,EAAEiB,QAAQ,CAACP,WAAW;QACxBQ,QAAQC,IAAI,CAAC;IACf;IAEA,MAAMd,WAAWF,eAAeG,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKE;IAEvD,OAAOL;AACT"}
@@ -1,61 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "selectDb", {
6
- enumerable: true,
7
- get: function() {
8
- return selectDb;
9
- }
10
- });
11
- const _prompts = /*#__PURE__*/ _interop_require_wildcard(require("@clack/prompts"));
12
- const _slugify = /*#__PURE__*/ _interop_require_default(require("@sindresorhus/slugify"));
13
- function _interop_require_default(obj) {
14
- return obj && obj.__esModule ? obj : {
15
- default: obj
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
- }
1
+ import * as p from '@clack/prompts';
2
+ import slugify from '@sindresorhus/slugify';
59
3
  const dbChoiceRecord = {
60
4
  mongodb: {
61
5
  dbConnectionPrefix: 'mongodb://127.0.0.1/',
@@ -68,7 +12,7 @@ const dbChoiceRecord = {
68
12
  value: 'postgres'
69
13
  }
70
14
  };
71
- async function selectDb(args, projectName) {
15
+ export async function selectDb(args, projectName) {
72
16
  let dbType = undefined;
73
17
  if (args['--db']) {
74
18
  if (!Object.values(dbChoiceRecord).some((dbChoice)=>dbChoice.value === args['--db'])) {
@@ -76,7 +20,7 @@ async function selectDb(args, projectName) {
76
20
  }
77
21
  dbType = args['--db'];
78
22
  } else {
79
- dbType = await _prompts.select({
23
+ dbType = await p.select({
80
24
  initialValue: 'mongodb',
81
25
  message: `Select a database`,
82
26
  options: [
@@ -90,21 +34,21 @@ async function selectDb(args, projectName) {
90
34
  }
91
35
  ]
92
36
  });
93
- if (_prompts.isCancel(dbType)) process.exit(0);
37
+ if (p.isCancel(dbType)) process.exit(0);
94
38
  }
95
39
  const dbChoice = dbChoiceRecord[dbType];
96
40
  let dbUri = undefined;
97
- const initialDbUri = `${dbChoice.dbConnectionPrefix}${projectName === '.' ? `payload-${getRandomDigitSuffix()}` : (0, _slugify.default)(projectName)}`;
41
+ const initialDbUri = `${dbChoice.dbConnectionPrefix}${projectName === '.' ? `payload-${getRandomDigitSuffix()}` : slugify(projectName)}`;
98
42
  if (args['--db-accept-recommended']) {
99
43
  dbUri = initialDbUri;
100
44
  } else if (args['--db-connection-string']) {
101
45
  dbUri = args['--db-connection-string'];
102
46
  } else {
103
- dbUri = await _prompts.text({
47
+ dbUri = await p.text({
104
48
  initialValue: initialDbUri,
105
49
  message: `Enter ${dbChoice.title.split(' ')[0]} connection string`
106
50
  });
107
- if (_prompts.isCancel(dbUri)) process.exit(0);
51
+ if (p.isCancel(dbUri)) process.exit(0);
108
52
  }
109
53
  return {
110
54
  type: dbChoice.value,