create-payload-app 0.4.2 → 0.5.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ "configurations": [
5
+ {
6
+ "command": "ts-node -T ./src/index.ts -n asdf -t blank --db mongodb --no-deps",
7
+ "cwd": "${workspaceFolder}",
8
+ "name": "Debug",
9
+ "request": "launch",
10
+ "type": "node-terminal"
11
+ },
12
+ ]
13
+ }
package/README.md CHANGED
@@ -9,15 +9,26 @@ CLI for easily starting new Payload project
9
9
  USAGE
10
10
 
11
11
  $ npx create-payload-app
12
+ $ npx create-payload-app my-project
13
+ $ npx create-payload-app -n my-project -t blog
12
14
 
13
15
  OPTIONS
14
16
 
15
- --name my-payload-app Set project name
16
- --template template_name Choose specific template
17
+ -n my-payload-app Set project name
18
+ -t template_name Choose specific template
17
19
 
18
- Available templates: blank, blog, todo
20
+ Available templates:
19
21
 
20
- --use-npm Use npm to install dependencies
21
- --no-deps Do not install any dependencies
22
- --help Show help
22
+ blank Blank Template
23
+ website Website Template
24
+ ecommerce E-commerce Template
25
+ plugin Template for creating a Payload plugin
26
+ payload-demo Payload demo site at https://demo.payloadcms.com
27
+ payload-website Payload website CMS at https://payloadcms.com
28
+
29
+ --use-npm Use npm to install dependencies
30
+ --use-yarn Use yarn to install dependencies
31
+ --use-pnpm Use pnpm to install dependencies
32
+ --no-deps Do not install any dependencies
33
+ -h Show help
23
34
  ```
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.configurePayloadConfig = void 0;
52
+ var fs_extra_1 = __importDefault(require("fs-extra"));
53
+ var path_1 = __importDefault(require("path"));
54
+ var log_1 = require("../utils/log");
55
+ var packages_1 = require("./packages");
56
+ /** Update payload config with necessary imports and adapters */
57
+ function configurePayloadConfig(args) {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var packageJsonPath, packageObj, dbPackage, bundlerPackage, err_1, possiblePaths, payloadConfigPath_1, configContent, configLines_1, dbReplacement_1, bundlerReplacement_1, dbConfigStartLineIndex_1, dbConfigEndLineIndex_1;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ if (!args.dbDetails) {
64
+ return [2 /*return*/];
65
+ }
66
+ packageJsonPath = path_1.default.resolve(args.projectDir, 'package.json');
67
+ _a.label = 1;
68
+ case 1:
69
+ _a.trys.push([1, 4, , 5]);
70
+ return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
71
+ case 2:
72
+ packageObj = _a.sent();
73
+ dbPackage = packages_1.dbPackages[args.dbDetails.type];
74
+ bundlerPackage = packages_1.bundlerPackages['webpack'];
75
+ packageObj.dependencies[dbPackage.packageName] = 'latest';
76
+ packageObj.dependencies[bundlerPackage.packageName] = 'latest';
77
+ return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })];
78
+ case 3:
79
+ _a.sent();
80
+ return [3 /*break*/, 5];
81
+ case 4:
82
+ err_1 = _a.sent();
83
+ (0, log_1.warning)('Unable to update name in package.json');
84
+ return [3 /*break*/, 5];
85
+ case 5:
86
+ try {
87
+ possiblePaths = [
88
+ path_1.default.resolve(args.projectDir, 'src/payload.config.ts'),
89
+ path_1.default.resolve(args.projectDir, 'src/payload/payload.config.ts'),
90
+ ];
91
+ possiblePaths.forEach(function (p) {
92
+ if (fs_extra_1.default.pathExistsSync(p) && !payloadConfigPath_1) {
93
+ payloadConfigPath_1 = p;
94
+ }
95
+ });
96
+ if (!payloadConfigPath_1) {
97
+ (0, log_1.warning)('Unable to update payload.config.ts with plugins');
98
+ return [2 /*return*/];
99
+ }
100
+ configContent = fs_extra_1.default.readFileSync(payloadConfigPath_1, 'utf-8');
101
+ configLines_1 = configContent.split('\n');
102
+ dbReplacement_1 = packages_1.dbPackages[args.dbDetails.type];
103
+ bundlerReplacement_1 = packages_1.bundlerPackages['webpack'];
104
+ configLines_1.forEach(function (l, i) {
105
+ if (l.includes('// database-adapter-import')) {
106
+ configLines_1[i] = dbReplacement_1.importReplacement;
107
+ }
108
+ if (l.includes('// bundler-import')) {
109
+ configLines_1[i] = bundlerReplacement_1.importReplacement;
110
+ }
111
+ if (l.includes('// bundler-config')) {
112
+ configLines_1[i] = bundlerReplacement_1.configReplacement;
113
+ }
114
+ if (l.includes('// database-adapter-config-start')) {
115
+ dbConfigStartLineIndex_1 = i;
116
+ }
117
+ if (l.includes('// database-adapter-config-end')) {
118
+ dbConfigEndLineIndex_1 = i;
119
+ }
120
+ });
121
+ if (!dbConfigStartLineIndex_1 || !dbConfigEndLineIndex_1) {
122
+ (0, log_1.warning)('Unable to update payload.config.ts with database adapter import');
123
+ }
124
+ else {
125
+ // Replaces lines between `// database-adapter-config-start` and `// database-adapter-config-end`
126
+ configLines_1.splice.apply(configLines_1, __spreadArray([dbConfigStartLineIndex_1,
127
+ dbConfigEndLineIndex_1 - dbConfigStartLineIndex_1 + 1], dbReplacement_1.configReplacement, false));
128
+ }
129
+ fs_extra_1.default.writeFileSync(payloadConfigPath_1, configLines_1.join('\n'));
130
+ }
131
+ catch (err) {
132
+ (0, log_1.warning)('Unable to update payload.config.ts with plugins');
133
+ }
134
+ return [2 /*return*/];
135
+ }
136
+ });
137
+ });
138
+ }
139
+ exports.configurePayloadConfig = configurePayloadConfig;
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.createProject = exports.updatePackageJSONName = void 0;
42
+ exports.updatePackageJSON = exports.createProject = void 0;
43
43
  var path_1 = __importDefault(require("path"));
44
44
  var chalk_1 = __importDefault(require("chalk"));
45
45
  var fs_extra_1 = __importDefault(require("fs-extra"));
@@ -47,6 +47,7 @@ var execa_1 = __importDefault(require("execa"));
47
47
  var ora_1 = __importDefault(require("ora"));
48
48
  var degit_1 = __importDefault(require("degit"));
49
49
  var log_1 = require("../utils/log");
50
+ var configure_payload_config_1 = require("./configure-payload-config");
50
51
  function createOrFindProjectDir(projectDir) {
51
52
  return __awaiter(this, void 0, void 0, function () {
52
53
  var pathExists;
@@ -67,7 +68,7 @@ function createOrFindProjectDir(projectDir) {
67
68
  }
68
69
  function installDeps(args) {
69
70
  return __awaiter(this, void 0, void 0, function () {
70
- var cliArgs, projectDir, packageManager, cmd, err_1;
71
+ var cliArgs, projectDir, packageManager, installCmd, err_1;
71
72
  return __generator(this, function (_a) {
72
73
  switch (_a.label) {
73
74
  case 0:
@@ -75,11 +76,17 @@ function installDeps(args) {
75
76
  if (cliArgs['--no-deps']) {
76
77
  return [2 /*return*/, true];
77
78
  }
78
- cmd = packageManager === 'yarn' ? 'yarn' : 'npm install --legacy-peer-deps';
79
+ installCmd = 'npm install --legacy-peer-deps';
80
+ if (packageManager === 'yarn') {
81
+ installCmd = 'yarn';
82
+ }
83
+ else if (packageManager === 'pnpm') {
84
+ installCmd = 'pnpm install';
85
+ }
79
86
  _a.label = 1;
80
87
  case 1:
81
88
  _a.trys.push([1, 3, , 4]);
82
- return [4 /*yield*/, execa_1.default.command(cmd, {
89
+ return [4 /*yield*/, execa_1.default.command(installCmd, {
83
90
  cwd: path_1.default.resolve(projectDir),
84
91
  })];
85
92
  case 2:
@@ -94,42 +101,13 @@ function installDeps(args) {
94
101
  });
95
102
  });
96
103
  }
97
- function updatePackageJSONName(args) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var projectName, projectDir, packageJsonPath, packageObj, err_2;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0:
103
- projectName = args.projectName, projectDir = args.projectDir;
104
- packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
105
- _a.label = 1;
106
- case 1:
107
- _a.trys.push([1, 4, , 5]);
108
- return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
109
- case 2:
110
- packageObj = _a.sent();
111
- packageObj.name = projectName;
112
- return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })];
113
- case 3:
114
- _a.sent();
115
- return [3 /*break*/, 5];
116
- case 4:
117
- err_2 = _a.sent();
118
- (0, log_1.warning)('Unable to update name in package.json');
119
- return [3 /*break*/, 5];
120
- case 5: return [2 /*return*/];
121
- }
122
- });
123
- });
124
- }
125
- exports.updatePackageJSONName = updatePackageJSONName;
126
104
  function createProject(args) {
127
105
  return __awaiter(this, void 0, void 0, function () {
128
- var cliArgs, projectName, projectDir, template, packageManager, emitter, spinner, lockPath, result;
106
+ var cliArgs, projectName, projectDir, template, packageManager, dbDetails, emitter, spinner, lockPath, result;
129
107
  return __generator(this, function (_a) {
130
108
  switch (_a.label) {
131
109
  case 0:
132
- cliArgs = args.cliArgs, projectName = args.projectName, projectDir = args.projectDir, template = args.template, packageManager = args.packageManager;
110
+ cliArgs = args.cliArgs, projectName = args.projectName, projectDir = args.projectDir, template = args.template, packageManager = args.packageManager, dbDetails = args.dbDetails;
133
111
  return [4 /*yield*/, createOrFindProjectDir(projectDir)];
134
112
  case 1:
135
113
  _a.sent();
@@ -142,21 +120,24 @@ function createProject(args) {
142
120
  _a.label = 3;
143
121
  case 3:
144
122
  spinner = (0, ora_1.default)('Checking latest Payload version...').start();
145
- return [4 /*yield*/, updatePackageJSONName({ projectName: projectName, projectDir: projectDir })
123
+ return [4 /*yield*/, updatePackageJSON({ projectName: projectName, projectDir: projectDir })];
124
+ case 4:
125
+ _a.sent();
126
+ return [4 /*yield*/, (0, configure_payload_config_1.configurePayloadConfig)({ projectDir: projectDir, dbDetails: dbDetails })
146
127
  // Remove yarn.lock file. This is only desired in Payload Cloud.
147
128
  ];
148
- case 4:
129
+ case 5:
149
130
  _a.sent();
150
131
  lockPath = path_1.default.resolve(projectDir, 'yarn.lock');
151
- if (!fs_extra_1.default.existsSync(lockPath)) return [3 /*break*/, 6];
132
+ if (!fs_extra_1.default.existsSync(lockPath)) return [3 /*break*/, 7];
152
133
  return [4 /*yield*/, fs_extra_1.default.remove(lockPath)];
153
- case 5:
154
- _a.sent();
155
- _a.label = 6;
156
134
  case 6:
135
+ _a.sent();
136
+ _a.label = 7;
137
+ case 7:
157
138
  spinner.text = 'Installing dependencies...';
158
139
  return [4 /*yield*/, installDeps({ cliArgs: cliArgs, projectDir: projectDir, packageManager: packageManager })];
159
- case 7:
140
+ case 8:
160
141
  result = _a.sent();
161
142
  spinner.stop();
162
143
  spinner.clear();
@@ -172,3 +153,32 @@ function createProject(args) {
172
153
  });
173
154
  }
174
155
  exports.createProject = createProject;
156
+ function updatePackageJSON(args) {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var projectName, projectDir, packageJsonPath, packageObj, err_2;
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0:
162
+ projectName = args.projectName, projectDir = args.projectDir;
163
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
164
+ _a.label = 1;
165
+ case 1:
166
+ _a.trys.push([1, 4, , 5]);
167
+ return [4 /*yield*/, fs_extra_1.default.readJson(packageJsonPath)];
168
+ case 2:
169
+ packageObj = _a.sent();
170
+ packageObj.name = projectName;
171
+ return [4 /*yield*/, fs_extra_1.default.writeJson(packageJsonPath, packageObj, { spaces: 2 })];
172
+ case 3:
173
+ _a.sent();
174
+ return [3 /*break*/, 5];
175
+ case 4:
176
+ err_2 = _a.sent();
177
+ (0, log_1.warning)('Unable to update name in package.json');
178
+ return [3 /*break*/, 5];
179
+ case 5: return [2 /*return*/];
180
+ }
181
+ });
182
+ });
183
+ }
184
+ exports.updatePackageJSON = updatePackageJSON;
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var fs_extra_1 = __importDefault(require("fs-extra"));
43
43
  var path_1 = __importDefault(require("path"));
44
44
  var create_project_1 = require("./create-project");
45
+ var packages_1 = require("./packages");
45
46
  var projectDir = path_1.default.resolve(__dirname, './tmp');
46
47
  describe('createProject', function () {
47
48
  beforeAll(function () {
@@ -59,7 +60,11 @@ describe('createProject', function () {
59
60
  });
60
61
  describe('#createProject', function () {
61
62
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
62
- var args = { _: ['project-name'], '--no-deps': true };
63
+ var args = {
64
+ _: ['project-name'],
65
+ '--db': 'mongodb',
66
+ '--no-deps': true,
67
+ };
63
68
  var packageManager = 'yarn';
64
69
  it('creates starter project', function () { return __awaiter(void 0, void 0, void 0, function () {
65
70
  var projectName, template, packageJsonPath, packageJson;
@@ -119,5 +124,58 @@ describe('createProject', function () {
119
124
  }
120
125
  });
121
126
  }); });
127
+ describe('db adapters and bundlers', function () {
128
+ it.each([
129
+ ['mongodb', 'webpack'],
130
+ ['postgres', 'webpack'],
131
+ ])('update config and deps: %s, %s', function (db, bundler) { return __awaiter(void 0, void 0, void 0, function () {
132
+ var projectName, template, dbReplacement, bundlerReplacement, packageJsonPath, packageJson, payloadConfigPath, content;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ projectName = 'starter-project';
137
+ template = {
138
+ name: 'blank',
139
+ type: 'starter',
140
+ url: 'https://github.com/payloadcms/payload/templates/blank#2.0',
141
+ description: 'Blank Template',
142
+ };
143
+ return [4 /*yield*/, (0, create_project_1.createProject)({
144
+ cliArgs: args,
145
+ projectName: projectName,
146
+ projectDir: projectDir,
147
+ template: template,
148
+ packageManager: packageManager,
149
+ dbDetails: {
150
+ dbUri: "".concat(db, "://localhost:27017/create-project-test"),
151
+ type: db,
152
+ },
153
+ })];
154
+ case 1:
155
+ _a.sent();
156
+ dbReplacement = packages_1.dbPackages[db];
157
+ bundlerReplacement = packages_1.bundlerPackages[bundler];
158
+ packageJsonPath = path_1.default.resolve(projectDir, 'package.json');
159
+ packageJson = fs_extra_1.default.readJsonSync(packageJsonPath);
160
+ // Check deps
161
+ expect(packageJson.dependencies[dbReplacement.packageName]).toBeDefined();
162
+ expect(packageJson.dependencies[bundlerReplacement.packageName]).toBeDefined();
163
+ payloadConfigPath = path_1.default.resolve(projectDir, 'src/payload.config.ts');
164
+ content = fs_extra_1.default.readFileSync(payloadConfigPath, 'utf-8');
165
+ // Check payload.config.ts
166
+ expect(content).not.toContain('// database-adapter-import');
167
+ expect(content).toContain(dbReplacement.importReplacement);
168
+ expect(content).not.toContain('// database-adapter-config-start');
169
+ expect(content).not.toContain('// database-adapter-config-end');
170
+ expect(content).toContain(dbReplacement.configReplacement.join('\n'));
171
+ expect(content).not.toContain('// bundler-config-import');
172
+ expect(content).toContain(bundlerReplacement.importReplacement);
173
+ expect(content).not.toContain('// bundler-config');
174
+ expect(content).toContain(bundlerReplacement.configReplacement);
175
+ return [2 /*return*/];
176
+ }
177
+ });
178
+ }); });
179
+ });
122
180
  });
123
181
  });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bundlerPackages = exports.dbPackages = void 0;
4
+ var mongodbReplacement = {
5
+ packageName: '@payloadcms/db-mongodb',
6
+ importReplacement: "import { mongooseAdapter } from '@payloadcms/db-mongodb'",
7
+ // Replacement between `// database-adapter-config-start` and `// database-adapter-config-end`
8
+ configReplacement: [
9
+ ' db: mongooseAdapter({',
10
+ ' url: process.env.DATABASE_URI,',
11
+ ' }),',
12
+ ],
13
+ };
14
+ var postgresqlReplacement = {
15
+ packageName: '@payloadcms/db-postgresql',
16
+ importReplacement: "import { postgresqlAdapter } from '@payloadcms/db-postgresql'",
17
+ configReplacement: [
18
+ ' db: postgresqlAdapter({',
19
+ ' client: {',
20
+ ' connectionString: process.env.DATABASE_URI,',
21
+ ' },',
22
+ ' }),',
23
+ ],
24
+ };
25
+ exports.dbPackages = {
26
+ mongodb: mongodbReplacement,
27
+ postgres: postgresqlReplacement,
28
+ };
29
+ var webpackReplacement = {
30
+ packageName: '@payloadcms/bundler-webpack',
31
+ importReplacement: "import { webpackBundler } from '@payloadcms/bundler-webpack'",
32
+ // Replacement of line containing `// bundler-config`
33
+ configReplacement: ' bundler: webpackBundler(),',
34
+ };
35
+ var viteReplacement = {
36
+ packageName: '@payloadcms/bundler-vite',
37
+ importReplacement: "import { viteBundler } from '@payloadcms/bundler-vite'",
38
+ configReplacement: ' bundler: viteBundler(),',
39
+ };
40
+ exports.bundlerPackages = {
41
+ webpack: webpackReplacement,
42
+ vite: viteReplacement,
43
+ };
@@ -39,22 +39,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getDatabaseConnection = void 0;
42
+ exports.selectDb = void 0;
43
43
  var prompts_1 = __importDefault(require("prompts"));
44
44
  var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
45
- function getDatabaseConnection(args, projectName) {
45
+ var dbChoiceRecord = {
46
+ mongodb: {
47
+ value: 'mongodb',
48
+ title: 'MongoDB',
49
+ dbConnectionPrefix: 'mongodb://127.0.0.1/',
50
+ },
51
+ postgres: {
52
+ value: 'postgres',
53
+ title: 'PostgreSQL',
54
+ dbConnectionPrefix: 'postgres://127.0.0.1:5432/',
55
+ },
56
+ };
57
+ function selectDb(args, projectName) {
46
58
  return __awaiter(this, void 0, void 0, function () {
47
- var response;
59
+ var dbType, dbTypeRes, dbChoice, dbUriRes;
48
60
  return __generator(this, function (_a) {
49
61
  switch (_a.label) {
50
62
  case 0:
51
- if (args['--db'])
52
- return [2 /*return*/, args['--db']];
63
+ dbType = undefined;
64
+ if (!args['--db']) return [3 /*break*/, 1];
65
+ if (!Object.values(dbChoiceRecord).some(function (dbChoice) { return dbChoice.value === args['--db']; })) {
66
+ throw new Error("Invalid database type given. Valid types are: ".concat(Object.values(dbChoiceRecord)
67
+ .map(function (dbChoice) { return dbChoice.value; })
68
+ .join(', ')));
69
+ }
70
+ dbType = args['--db'];
71
+ return [3 /*break*/, 3];
72
+ case 1: return [4 /*yield*/, (0, prompts_1.default)({
73
+ type: 'select',
74
+ name: 'value',
75
+ message: 'Select a database',
76
+ choices: Object.values(dbChoiceRecord).map(function (dbChoice) {
77
+ return {
78
+ title: dbChoice.title,
79
+ value: dbChoice.value,
80
+ };
81
+ }),
82
+ validate: function (value) { return !!value.length; },
83
+ }, {
84
+ onCancel: function () {
85
+ process.exit(0);
86
+ },
87
+ })];
88
+ case 2:
89
+ dbTypeRes = _a.sent();
90
+ dbType = dbTypeRes.value;
91
+ _a.label = 3;
92
+ case 3:
93
+ dbChoice = dbChoiceRecord[dbType];
53
94
  return [4 /*yield*/, (0, prompts_1.default)({
54
95
  type: 'text',
55
96
  name: 'value',
56
- message: 'Enter MongoDB connection',
57
- initial: "mongodb://127.0.0.1/".concat(projectName === '.'
97
+ message: "Enter ".concat(dbChoice.title, " connection string"),
98
+ initial: "".concat(dbChoice.dbConnectionPrefix).concat(projectName === '.'
58
99
  ? "payload-".concat(getRandomDigitSuffix())
59
100
  : (0, slugify_1.default)(projectName)),
60
101
  validate: function (value) { return !!value.length; },
@@ -63,14 +104,17 @@ function getDatabaseConnection(args, projectName) {
63
104
  process.exit(0);
64
105
  },
65
106
  })];
66
- case 1:
67
- response = _a.sent();
68
- return [2 /*return*/, response.value];
107
+ case 4:
108
+ dbUriRes = _a.sent();
109
+ return [2 /*return*/, {
110
+ type: dbChoice.value,
111
+ dbUri: dbUriRes.value,
112
+ }];
69
113
  }
70
114
  });
71
115
  });
72
116
  }
73
- exports.getDatabaseConnection = getDatabaseConnection;
117
+ exports.selectDb = selectDb;
74
118
  function getRandomDigitSuffix() {
75
119
  return (Math.random() * Math.pow(10, 6)).toFixed(0);
76
120
  }
@@ -64,19 +64,19 @@ function getValidTemplates() {
64
64
  {
65
65
  name: 'blank',
66
66
  type: 'starter',
67
- url: 'https://github.com/payloadcms/payload/templates/blank',
67
+ url: 'https://github.com/payloadcms/payload/templates/blank#2.0',
68
68
  description: 'Blank Template',
69
69
  },
70
70
  {
71
71
  name: 'website',
72
72
  type: 'starter',
73
- url: 'https://github.com/payloadcms/payload/templates/website',
73
+ url: 'https://github.com/payloadcms/payload/templates/website#2.0',
74
74
  description: 'Website Template',
75
75
  },
76
76
  {
77
77
  name: 'ecommerce',
78
78
  type: 'starter',
79
- url: 'https://github.com/payloadcms/payload/templates/ecommerce',
79
+ url: 'https://github.com/payloadcms/payload/templates/ecommerce#2.0',
80
80
  description: 'E-commerce Template',
81
81
  },
82
82
  {
@@ -68,7 +68,9 @@ function writeEnvFile(args) {
68
68
  var split = line.split('=');
69
69
  var key = split[0];
70
70
  var value = split[1];
71
- if (key === 'MONGODB_URI' || key === 'MONGO_URL') {
71
+ if (key === 'MONGODB_URI' ||
72
+ key === 'MONGO_URL' ||
73
+ key === 'DATABASE_URI') {
72
74
  value = databaseUri;
73
75
  }
74
76
  if (key === 'PAYLOAD_SECRET' || key === 'PAYLOAD_SECRET_KEY') {
package/dist/main.js CHANGED
@@ -44,7 +44,7 @@ var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
44
44
  var arg_1 = __importDefault(require("arg"));
45
45
  var command_exists_1 = __importDefault(require("command-exists"));
46
46
  var create_project_1 = require("./lib/create-project");
47
- var get_db_connection_1 = require("./lib/get-db-connection");
47
+ var select_db_1 = require("./lib/select-db");
48
48
  var generate_secret_1 = require("./lib/generate-secret");
49
49
  var parse_project_name_1 = require("./lib/parse-project-name");
50
50
  var parse_template_1 = require("./lib/parse-template");
@@ -62,6 +62,8 @@ var Main = /** @class */ (function () {
62
62
  '--db': String,
63
63
  '--secret': String,
64
64
  '--use-npm': Boolean,
65
+ '--use-yarn': Boolean,
66
+ '--use-pnpm': Boolean,
65
67
  '--no-deps': Boolean,
66
68
  '--dry-run': Boolean,
67
69
  '--beta': Boolean,
@@ -72,7 +74,7 @@ var Main = /** @class */ (function () {
72
74
  }
73
75
  Main.prototype.init = function () {
74
76
  return __awaiter(this, void 0, void 0, function () {
75
- var _a, _b, templateArg, valid, _c, _d, projectName, validTemplates, template, projectDir, packageManager, databaseUri, payloadSecret, error_1;
77
+ var _a, _b, templateArg, valid, _c, _d, projectName, validTemplates, template, projectDir, packageManager, dbDetails, payloadSecret, error_1;
76
78
  return __generator(this, function (_e) {
77
79
  switch (_e.label) {
78
80
  case 0:
@@ -113,9 +115,9 @@ var Main = /** @class */ (function () {
113
115
  case 9:
114
116
  packageManager = _e.sent();
115
117
  if (!(template.type !== 'plugin')) return [3 /*break*/, 15];
116
- return [4 /*yield*/, (0, get_db_connection_1.getDatabaseConnection)(this.args, projectName)];
118
+ return [4 /*yield*/, (0, select_db_1.selectDb)(this.args, projectName)];
117
119
  case 10:
118
- databaseUri = _e.sent();
120
+ dbDetails = _e.sent();
119
121
  return [4 /*yield*/, (0, generate_secret_1.generateSecret)()];
120
122
  case 11:
121
123
  payloadSecret = _e.sent();
@@ -126,11 +128,12 @@ var Main = /** @class */ (function () {
126
128
  projectDir: projectDir,
127
129
  template: template,
128
130
  packageManager: packageManager,
131
+ dbDetails: dbDetails,
129
132
  })];
130
133
  case 12:
131
134
  _e.sent();
132
135
  return [4 /*yield*/, (0, write_env_file_1.writeEnvFile)({
133
- databaseUri: databaseUri,
136
+ databaseUri: dbDetails.dbUri,
134
137
  payloadSecret: payloadSecret,
135
138
  template: template,
136
139
  projectDir: projectDir,
@@ -173,21 +176,37 @@ function getPackageManager(args) {
173
176
  return __generator(this, function (_a) {
174
177
  switch (_a.label) {
175
178
  case 0:
179
+ packageManager = 'npm';
176
180
  if (!args['--use-npm']) return [3 /*break*/, 1];
177
181
  packageManager = 'npm';
178
- return [3 /*break*/, 4];
182
+ return [3 /*break*/, 9];
179
183
  case 1:
180
- _a.trys.push([1, 3, , 4]);
181
- return [4 /*yield*/, (0, command_exists_1.default)('yarn')];
182
- case 2:
183
- _a.sent();
184
+ if (!args['--use-yarn']) return [3 /*break*/, 2];
184
185
  packageManager = 'yarn';
185
- return [3 /*break*/, 4];
186
+ return [3 /*break*/, 9];
187
+ case 2:
188
+ if (!args['--use-pnpm']) return [3 /*break*/, 3];
189
+ packageManager = 'pnpm';
190
+ return [3 /*break*/, 9];
186
191
  case 3:
192
+ _a.trys.push([3, 8, , 9]);
193
+ return [4 /*yield*/, (0, command_exists_1.default)('yarn')];
194
+ case 4:
195
+ if (!_a.sent()) return [3 /*break*/, 5];
196
+ packageManager = 'yarn';
197
+ return [3 /*break*/, 7];
198
+ case 5: return [4 /*yield*/, (0, command_exists_1.default)('pnpm')];
199
+ case 6:
200
+ if (_a.sent()) {
201
+ packageManager = 'pnpm';
202
+ }
203
+ _a.label = 7;
204
+ case 7: return [3 /*break*/, 9];
205
+ case 8:
187
206
  error_2 = _a.sent();
188
207
  packageManager = 'npm';
189
- return [3 /*break*/, 4];
190
- case 4: return [2 /*return*/, packageManager];
208
+ return [3 /*break*/, 9];
209
+ case 9: return [2 /*return*/, packageManager];
191
210
  }
192
211
  });
193
212
  });
@@ -62,7 +62,7 @@ function helpMessage() {
62
62
  case 0: return [4 /*yield*/, (0, templates_1.getValidTemplates)()];
63
63
  case 1:
64
64
  validTemplates = _a.sent();
65
- return [2 /*return*/, (0, chalk_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"])), formatTemplates(validTemplates))];
65
+ return [2 /*return*/, (0, chalk_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --use-yarn Use yarn to install dependencies\n --use-pnpm Use pnpm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n {dim $} {bold npx create-payload-app} my-project\n {dim $} {bold npx create-payload-app} -n my-project -t blog\n\n {bold OPTIONS}\n\n -n {underline my-payload-app} Set project name\n -t {underline template_name} Choose specific template\n\n {dim Available templates: ", "}\n\n --use-npm Use npm to install dependencies\n --use-yarn Use yarn to install dependencies\n --use-pnpm Use pnpm to install dependencies\n --no-deps Do not install any dependencies\n -h Show help\n"])), formatTemplates(validTemplates))];
66
66
  }
67
67
  });
68
68
  });
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "prompts": "^2.4.2",
38
38
  "terminal-link": "^2.1.1"
39
39
  },
40
- "version": "0.4.2",
40
+ "version": "0.5.0-beta.0",
41
41
  "devDependencies": {
42
42
  "@types/command-exists": "^1.2.0",
43
43
  "@types/degit": "^2.8.3",