create-payload-app 0.3.27 → 0.3.29-beta.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -160,13 +160,12 @@ function updatePayloadVersion(projectDir, betaFlag) {
160
160
  exports.updatePayloadVersion = updatePayloadVersion;
161
161
  function createProject(args, projectDir, template, packageManager) {
162
162
  return __awaiter(this, void 0, void 0, function () {
163
- var templateDir, emitter, err_4, msg, spinner, result;
163
+ var emitter, templateDir, err_4, msg, spinner, result;
164
164
  return __generator(this, function (_a) {
165
165
  switch (_a.label) {
166
166
  case 0: return [4 /*yield*/, createOrFindProjectDir(projectDir)];
167
167
  case 1:
168
168
  _a.sent();
169
- templateDir = path_1.default.resolve(__dirname, "../templates/".concat(template.name));
170
169
  console.log("\n Creating a new Payload app in ".concat(chalk_1.default.green(path_1.default.resolve(projectDir)), "\n"));
171
170
  if (!(template.type === 'starter')) return [3 /*break*/, 3];
172
171
  emitter = (0, degit_1.default)(template.url);
@@ -176,6 +175,7 @@ function createProject(args, projectDir, template, packageManager) {
176
175
  return [3 /*break*/, 7];
177
176
  case 3:
178
177
  _a.trys.push([3, 6, , 7]);
178
+ templateDir = path_1.default.resolve(__dirname, "../templates/".concat(template.directory));
179
179
  return [4 /*yield*/, fs_extra_1.default.copy(templateDir, projectDir, { recursive: true })];
180
180
  case 4:
181
181
  _a.sent();
@@ -188,19 +188,20 @@ function createProject(args, projectDir, template, packageManager) {
188
188
  err_4 = _a.sent();
189
189
  msg = 'Unable to copy template files. Please check template name or directory permissions.';
190
190
  (0, log_1.error)(msg);
191
- if (err_4 instanceof Error) {
192
- console.error({ err: err_4 });
193
- }
191
+ console.error({ err: err_4 });
194
192
  process.exit(1);
195
193
  return [3 /*break*/, 7];
196
194
  case 7:
197
195
  spinner = (0, ora_1.default)('Checking latest Payload version...').start();
196
+ if (!(template.type === 'static')) return [3 /*break*/, 9];
198
197
  return [4 /*yield*/, updatePayloadVersion(projectDir, args['--beta'])];
199
198
  case 8:
200
199
  _a.sent();
200
+ _a.label = 9;
201
+ case 9:
201
202
  spinner.text = 'Installing dependencies...';
202
203
  return [4 /*yield*/, installDeps(args, projectDir, packageManager)];
203
- case 9:
204
+ case 10:
204
205
  result = _a.sent();
205
206
  spinner.stop();
206
207
  spinner.clear();
@@ -72,6 +72,7 @@ describe('createProject', function () {
72
72
  template = {
73
73
  name: templateName,
74
74
  type: 'static',
75
+ directory: 'todo',
75
76
  };
76
77
  return [4 /*yield*/, (0, create_project_1.createProject)(args, projectDir, template, packageManager)];
77
78
  case 2:
@@ -43,7 +43,7 @@ exports.parseTemplate = void 0;
43
43
  var prompts_1 = __importDefault(require("prompts"));
44
44
  function parseTemplate(args, validTemplates) {
45
45
  return __awaiter(this, void 0, void 0, function () {
46
- var templateName_1, template_1, filteredTemplates, response, template;
46
+ var templateName_1, template_1, response, template;
47
47
  return __generator(this, function (_a) {
48
48
  switch (_a.label) {
49
49
  case 0:
@@ -54,13 +54,16 @@ function parseTemplate(args, validTemplates) {
54
54
  throw new Error('Invalid template given');
55
55
  return [2 /*return*/, template_1];
56
56
  }
57
- filteredTemplates = validTemplates.map(function (t) { return t.name; });
58
57
  return [4 /*yield*/, (0, prompts_1.default)({
59
58
  type: 'select',
60
59
  name: 'value',
61
60
  message: 'Choose project template',
62
- choices: filteredTemplates.map(function (p) {
63
- return { title: p, value: p };
61
+ choices: validTemplates.map(function (p) {
62
+ return {
63
+ title: p.name,
64
+ value: p.name,
65
+ description: p.description,
66
+ };
64
67
  }),
65
68
  validate: function (value) { return !!value.length; },
66
69
  }, {
@@ -35,13 +35,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
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));
40
46
  };
41
47
  Object.defineProperty(exports, "__esModule", { value: true });
42
48
  exports.getValidTemplates = exports.validateTemplate = void 0;
43
- var path_1 = __importDefault(require("path"));
44
- var fs_1 = __importDefault(require("fs"));
45
49
  var log_1 = require("../utils/log");
46
50
  function validateTemplate(templateName) {
47
51
  return __awaiter(this, void 0, void 0, function () {
@@ -53,7 +57,7 @@ function validateTemplate(templateName) {
53
57
  validTemplates = _a.sent();
54
58
  if (!validTemplates.map(function (t) { return t.name; }).includes(templateName)) {
55
59
  (0, log_1.error)("'".concat(templateName, "' is not a valid template."));
56
- (0, log_1.info)("Valid templates: ".concat(validTemplates.join(', ')));
60
+ (0, log_1.info)("Valid templates: ".concat(validTemplates.map(function (t) { return t.name; }).join(', ')));
57
61
  return [2 /*return*/, false];
58
62
  }
59
63
  return [2 /*return*/, true];
@@ -64,23 +68,62 @@ function validateTemplate(templateName) {
64
68
  exports.validateTemplate = validateTemplate;
65
69
  function getValidTemplates() {
66
70
  return __awaiter(this, void 0, void 0, function () {
67
- var templateDir, dirs, templates;
71
+ var templates, starters;
68
72
  return __generator(this, function (_a) {
69
- templateDir = path_1.default.resolve(__dirname, '../templates');
70
- dirs = getDirectories(templateDir);
71
- templates = dirs.map(function (name) {
72
- return {
73
- name: name,
73
+ templates = [
74
+ {
75
+ name: 'blank',
76
+ type: 'static',
77
+ description: 'Blank',
78
+ directory: 'ts-blank',
79
+ },
80
+ {
81
+ name: 'todo',
82
+ type: 'static',
83
+ description: 'Todo list',
84
+ directory: 'ts-todo',
85
+ },
86
+ {
87
+ name: 'blog',
74
88
  type: 'static',
75
- };
76
- });
77
- return [2 /*return*/, templates];
89
+ description: 'Blog',
90
+ directory: 'ts-blog',
91
+ },
92
+ ];
93
+ starters = [
94
+ {
95
+ name: 'payload-demo',
96
+ type: 'starter',
97
+ url: 'https://github.com/payloadcms/public-demo',
98
+ description: 'Payload demo site at https://demo.payloadcms.com',
99
+ },
100
+ {
101
+ name: 'payload-website',
102
+ type: 'starter',
103
+ url: 'https://github.com/payloadcms/website-cms',
104
+ description: 'Payload website CMS at https://payloadcms.com',
105
+ },
106
+ {
107
+ name: 'cloud-template-blank',
108
+ type: 'starter',
109
+ url: 'https://github.com/payloadcms/template-blank',
110
+ description: 'Blank template for Payload Cloud',
111
+ },
112
+ {
113
+ name: 'cloud-template-website',
114
+ type: 'starter',
115
+ url: 'https://github.com/payloadcms/template-website',
116
+ description: 'Website template for Payload Cloud',
117
+ },
118
+ {
119
+ name: 'cloud-template-ecommerce',
120
+ type: 'starter',
121
+ url: 'https://github.com/payloadcms/template-ecommerce',
122
+ description: 'E-commerce template for Payload Cloud',
123
+ },
124
+ ];
125
+ return [2 /*return*/, __spreadArray(__spreadArray([], templates, true), starters, true)];
78
126
  });
79
127
  });
80
128
  }
81
129
  exports.getValidTemplates = getValidTemplates;
82
- function getDirectories(dir) {
83
- return fs_1.default.readdirSync(dir).filter(function (file) {
84
- return fs_1.default.statSync("".concat(dir, "/").concat(file)).isDirectory();
85
- });
86
- }
@@ -40,34 +40,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.writeEnvFile = void 0;
43
- var slugify_1 = __importDefault(require("@sindresorhus/slugify"));
43
+ var path_1 = __importDefault(require("path"));
44
44
  var fs_extra_1 = __importDefault(require("fs-extra"));
45
45
  var log_1 = require("../utils/log");
46
- function writeEnvFile(projectName, databaseUri, payloadSecret) {
46
+ function writeEnvFile(args) {
47
47
  return __awaiter(this, void 0, void 0, function () {
48
- var content, projectDir, err_1;
48
+ var databaseUri, payloadSecret, template, projectDir, envFile, envFileLines, envFilePairs, newEnvFilePairs, newEnvFileLines, content, err_1;
49
49
  return __generator(this, function (_a) {
50
50
  switch (_a.label) {
51
51
  case 0:
52
- content = "MONGODB_URI=".concat(databaseUri, "\nPAYLOAD_SECRET=").concat(payloadSecret);
52
+ databaseUri = args.databaseUri, payloadSecret = args.payloadSecret, template = args.template, projectDir = args.projectDir;
53
53
  _a.label = 1;
54
54
  case 1:
55
- _a.trys.push([1, 3, , 4]);
56
- projectDir = "./".concat((0, slugify_1.default)(projectName));
57
- return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(projectDir, "/.env"), content)];
55
+ _a.trys.push([1, 6, , 7]);
56
+ if (!(template.type === 'starter' &&
57
+ fs_extra_1.default.existsSync(path_1.default.join(projectDir, '.env.example')))) return [3 /*break*/, 4];
58
+ return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join(projectDir, '.env.example'), 'utf8')];
58
59
  case 2:
60
+ envFile = _a.sent();
61
+ envFileLines = envFile.split('\n').filter(function (e) { return e; });
62
+ envFilePairs = envFileLines.map(function (line) {
63
+ var _a = line.split('='), key = _a[0], value = _a[1];
64
+ return { key: key, value: value };
65
+ });
66
+ newEnvFilePairs = envFilePairs.map(function (pair) {
67
+ if (pair.key === 'MONGODB_URI' || pair.key === 'MONGO_URL') {
68
+ return { key: pair.key, value: databaseUri };
69
+ }
70
+ if (pair.key === 'PAYLOAD_SECRET' || pair.key === 'PAYLOAD_SECRET_KEY') {
71
+ return { key: pair.key, value: payloadSecret };
72
+ }
73
+ return pair;
74
+ });
75
+ newEnvFileLines = newEnvFilePairs.map(function (pair) { return "".concat(pair.key, "=").concat(pair.value); });
76
+ return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.join(projectDir, '.env'), newEnvFileLines.join('\n'))];
77
+ case 3:
78
+ _a.sent();
79
+ return [2 /*return*/];
80
+ case 4:
81
+ content = "MONGODB_URI=".concat(databaseUri, "\nPAYLOAD_SECRET=").concat(payloadSecret);
82
+ return [4 /*yield*/, fs_extra_1.default.outputFile("".concat(projectDir, "/.env"), content)];
83
+ case 5:
59
84
  _a.sent();
60
85
  (0, log_1.success)('.env file created');
61
- return [3 /*break*/, 4];
62
- case 3:
86
+ return [3 /*break*/, 7];
87
+ case 6:
63
88
  err_1 = _a.sent();
64
89
  (0, log_1.error)('Unable to write .env file');
65
90
  if (err_1 instanceof Error) {
66
91
  (0, log_1.error)(err_1.message);
67
92
  }
68
93
  process.exit(1);
69
- return [3 /*break*/, 4];
70
- case 4: return [2 /*return*/];
94
+ return [3 /*break*/, 7];
95
+ case 7: return [2 /*return*/];
71
96
  }
72
97
  });
73
98
  });
package/dist/main.js CHANGED
@@ -122,7 +122,12 @@ var Main = /** @class */ (function () {
122
122
  return [4 /*yield*/, (0, create_project_1.createProject)(this.args, projectDir, template, packageManager)];
123
123
  case 12:
124
124
  _e.sent();
125
- return [4 /*yield*/, (0, write_env_file_1.writeEnvFile)(projectName, databaseUri, payloadSecret)];
125
+ return [4 /*yield*/, (0, write_env_file_1.writeEnvFile)({
126
+ databaseUri: databaseUri,
127
+ payloadSecret: payloadSecret,
128
+ template: template,
129
+ projectDir: projectDir,
130
+ })];
126
131
  case 13:
127
132
  _e.sent();
128
133
  _e.label = 14;
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import Users from './collections/Users';
5
5
 
6
6
  export default buildConfig({
7
- serverURL: 'http://127.0.0.1:3000',
7
+ serverURL: 'http://localhost:3000',
8
8
  admin: {
9
9
  user: Users.slug,
10
10
  },
@@ -7,7 +7,7 @@ import Users from './collections/Users';
7
7
  import Media from './collections/Media';
8
8
 
9
9
  export default buildConfig({
10
- serverURL: 'http://127.0.0.1:3000',
10
+ serverURL: 'http://localhost:3000',
11
11
  admin: {
12
12
  user: Users.slug,
13
13
  },
@@ -4,7 +4,7 @@ import TodoLists from './collections/TodoLists';
4
4
  import Users from './collections/Users';
5
5
 
6
6
  export default buildConfig({
7
- serverURL: 'http://127.0.0.1:3000',
7
+ serverURL: 'http://localhost:3000',
8
8
  admin: {
9
9
  user: Users.slug,
10
10
  },
@@ -52,6 +52,7 @@ var header = function (message) {
52
52
  return "".concat(chalk_1.default.yellow(figures_1.default.star), " ").concat(chalk_1.default.bold(message));
53
53
  };
54
54
  exports.welcomeMessage = (0, chalk_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n {green Welcome to Payload. Let's create a project! }\n"], ["\n {green Welcome to Payload. Let's create a project! }\n"])));
55
+ var spacer = ' '.repeat(8);
55
56
  function helpMessage() {
56
57
  return __awaiter(this, void 0, void 0, function () {
57
58
  var validTemplates;
@@ -60,12 +61,17 @@ function helpMessage() {
60
61
  case 0: return [4 /*yield*/, (0, templates_1.getValidTemplates)()];
61
62
  case 1:
62
63
  validTemplates = _a.sent();
63
- return [2 /*return*/, (0, chalk_1.default)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n\n {bold OPTIONS}\n\n --name {underline my-payload-app} Set project name\n --template {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 --help Show help\n"], ["\n {bold USAGE}\n\n {dim $} {bold npx create-payload-app}\n\n {bold OPTIONS}\n\n --name {underline my-payload-app} Set project name\n --template {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 --help Show help\n"])), validTemplates.map(function (t) { return t.name; }).join(', '))];
64
+ 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))];
64
65
  }
65
66
  });
66
67
  });
67
68
  }
68
69
  exports.helpMessage = helpMessage;
70
+ function formatTemplates(templates) {
71
+ return "\n\n".concat(spacer).concat(templates
72
+ .map(function (t) { return "".concat(t.name).concat(' '.repeat(18 - t.name.length)).concat(t.description); })
73
+ .join("\n".concat(spacer)));
74
+ }
69
75
  function successMessage(projectDir, packageManager) {
70
76
  return "\n ".concat(header('Launch Application:'), "\n\n - cd ").concat(projectDir, "\n - ").concat(packageManager === 'yarn' ? 'yarn' : 'npm run', " dev\n\n ").concat(header('Documentation:'), "\n\n - ").concat(createTerminalLink('Getting Started', 'https://payloadcms.com/docs/getting-started/what-is-payload'), "\n - ").concat(createTerminalLink('Configuration', 'https://payloadcms.com/docs/configuration/overview'), "\n\n");
71
77
  }
package/package.json CHANGED
@@ -34,17 +34,17 @@
34
34
  "fs-extra": "^9.0.1",
35
35
  "handlebars": "^4.7.7",
36
36
  "ora": "^5.1.0",
37
- "prompts": "^2.4.0",
37
+ "prompts": "^2.4.2",
38
38
  "terminal-link": "^2.1.1"
39
39
  },
40
- "version": "0.3.27",
40
+ "version": "0.3.29-beta.0",
41
41
  "devDependencies": {
42
42
  "@types/command-exists": "^1.2.0",
43
43
  "@types/degit": "^2.8.3",
44
44
  "@types/fs-extra": "^9.0.12",
45
45
  "@types/jest": "^27.0.3",
46
46
  "@types/node": "^16.6.2",
47
- "@types/prompts": "^2.4.0",
47
+ "@types/prompts": "^2.4.1",
48
48
  "@typescript-eslint/eslint-plugin": "^5.41.0",
49
49
  "@typescript-eslint/parser": "^5.41.0",
50
50
  "copyfiles": "^2.4.1",