create-payload-app 0.3.1 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,19 +50,19 @@ var log_1 = require("../utils/log");
50
50
  var usage_1 = require("../utils/usage");
51
51
  function createProjectDir(projectDir) {
52
52
  return __awaiter(this, void 0, void 0, function () {
53
- var readDir;
53
+ var pathExists;
54
54
  return __generator(this, function (_a) {
55
55
  switch (_a.label) {
56
- case 0: return [4 /*yield*/, fs_extra_1.default.mkdir(projectDir)];
56
+ case 0: return [4 /*yield*/, fs_extra_1.default.pathExists(projectDir)];
57
57
  case 1:
58
- _a.sent();
59
- return [4 /*yield*/, fs_extra_1.default.readdir(projectDir)];
60
- case 2:
61
- readDir = _a.sent();
62
- if (readDir && readDir.length > 0) {
63
- log_1.error("The project directory '" + projectDir + "' is not empty");
58
+ pathExists = _a.sent();
59
+ if (pathExists) {
60
+ log_1.error("The project directory '" + projectDir + "' already exists");
64
61
  process.exit(1);
65
62
  }
63
+ return [4 /*yield*/, fs_extra_1.default.mkdir(projectDir)];
64
+ case 2:
65
+ _a.sent();
66
66
  return [2 /*return*/];
67
67
  }
68
68
  });
@@ -95,14 +95,20 @@ function installDeps(args, dir, packageManager) {
95
95
  });
96
96
  });
97
97
  }
98
- function getLatestPayloadVersion() {
98
+ function getLatestPayloadVersion(betaFlag) {
99
+ if (betaFlag === void 0) { betaFlag = false; }
99
100
  return __awaiter(this, void 0, void 0, function () {
100
- var stdout, error_2;
101
+ var packageWithTag, stdout, error_2;
101
102
  return __generator(this, function (_a) {
102
103
  switch (_a.label) {
103
104
  case 0:
104
105
  _a.trys.push([0, 2, , 3]);
105
- return [4 /*yield*/, execa_1.default('npm info payload version', [], { shell: true })];
106
+ packageWithTag = 'payload';
107
+ if (betaFlag)
108
+ packageWithTag += '@beta';
109
+ return [4 /*yield*/, execa_1.default("npm info " + packageWithTag + " version", [], {
110
+ shell: true,
111
+ })];
106
112
  case 1:
107
113
  stdout = (_a.sent()).stdout;
108
114
  return [2 /*return*/, "^" + stdout];
@@ -115,12 +121,13 @@ function getLatestPayloadVersion() {
115
121
  });
116
122
  }
117
123
  exports.getLatestPayloadVersion = getLatestPayloadVersion;
118
- function updatePayloadVersion(projectDir) {
124
+ function updatePayloadVersion(projectDir, betaFlag) {
125
+ if (betaFlag === void 0) { betaFlag = false; }
119
126
  return __awaiter(this, void 0, void 0, function () {
120
127
  var payloadVersion, packageJsonPath, packageObj, err_1;
121
128
  return __generator(this, function (_a) {
122
129
  switch (_a.label) {
123
- case 0: return [4 /*yield*/, getLatestPayloadVersion()];
130
+ case 0: return [4 /*yield*/, getLatestPayloadVersion(betaFlag)];
124
131
  case 1:
125
132
  payloadVersion = _a.sent();
126
133
  if (!payloadVersion) {
@@ -155,37 +162,38 @@ function createProject(args, projectDir, template, packageManager) {
155
162
  var templateDir, emitter, err_2, msg, spinner, result;
156
163
  return __generator(this, function (_a) {
157
164
  switch (_a.label) {
158
- case 0:
159
- createProjectDir(projectDir);
165
+ case 0: return [4 /*yield*/, createProjectDir(projectDir)];
166
+ case 1:
167
+ _a.sent();
160
168
  templateDir = path_1.default.resolve(__dirname, "../templates/" + template.name);
161
169
  console.log("\n Creating a new Payload app in " + chalk_1.default.green(path_1.default.resolve(projectDir)) + "\n");
162
- if (!(template.type === 'starter')) return [3 /*break*/, 2];
170
+ if (!(template.type === 'starter')) return [3 /*break*/, 3];
163
171
  emitter = degit_1.default(template.url);
164
172
  return [4 /*yield*/, emitter.clone(projectDir)];
165
- case 1:
166
- _a.sent();
167
- return [3 /*break*/, 5];
168
173
  case 2:
169
- _a.trys.push([2, 4, , 5]);
170
- return [4 /*yield*/, fs_extra_1.default.copy(templateDir, projectDir, { recursive: true })];
174
+ _a.sent();
175
+ return [3 /*break*/, 6];
171
176
  case 3:
177
+ _a.trys.push([3, 5, , 6]);
178
+ return [4 /*yield*/, fs_extra_1.default.copy(templateDir, projectDir, { recursive: true })];
179
+ case 4:
172
180
  _a.sent();
173
181
  log_1.success('Project directory created');
174
- return [3 /*break*/, 5];
175
- case 4:
182
+ return [3 /*break*/, 6];
183
+ case 5:
176
184
  err_2 = _a.sent();
177
185
  msg = 'Unable to copy template files. Please check template name or directory permissions.';
178
186
  log_1.error(msg);
179
187
  process.exit(1);
180
- return [3 /*break*/, 5];
181
- case 5:
182
- spinner = ora_1.default('Checking latest Payload version...').start();
183
- return [4 /*yield*/, updatePayloadVersion(projectDir)];
188
+ return [3 /*break*/, 6];
184
189
  case 6:
190
+ spinner = ora_1.default('Checking latest Payload version...').start();
191
+ return [4 /*yield*/, updatePayloadVersion(projectDir, args['--beta'])];
192
+ case 7:
185
193
  _a.sent();
186
194
  spinner.text = 'Installing dependencies...';
187
195
  return [4 /*yield*/, installDeps(args, projectDir, packageManager)];
188
- case 7:
196
+ case 8:
189
197
  result = _a.sent();
190
198
  spinner.stop();
191
199
  spinner.clear();
package/dist/main.js CHANGED
@@ -65,6 +65,7 @@ var Main = /** @class */ (function () {
65
65
  '--use-npm': Boolean,
66
66
  '--no-deps': Boolean,
67
67
  '--dry-run': Boolean,
68
+ '--beta': Boolean,
68
69
  '-h': '--help',
69
70
  '-n': '--name',
70
71
  '-t': '--template',
@@ -4,6 +4,11 @@ const payload = require('payload');
4
4
  require('dotenv').config();
5
5
  const app = express();
6
6
 
7
+ // Redirect root to Admin panel
8
+ app.get('/', (_, res) => {
9
+ res.redirect('/admin');
10
+ });
11
+
7
12
  // Initialize Payload
8
13
  payload.init({
9
14
  secret: process.env.PAYLOAD_SECRET,
@@ -1,11 +1,3 @@
1
- const onlyNameIfPublic = ({ req: { user }, doc }) => {
2
- // Only return name if not logged in
3
- if (!user) {
4
- return { name: doc.name };
5
- }
6
- return doc;
7
- };
8
-
9
1
  const Users = {
10
2
  slug: 'users',
11
3
  auth: true,
@@ -15,9 +7,6 @@ const Users = {
15
7
  access: {
16
8
  read: () => true,
17
9
  },
18
- hooks: {
19
- beforeRead: [onlyNameIfPublic]
20
- },
21
10
  fields: [
22
11
  // Email added by default
23
12
  {
@@ -4,6 +4,11 @@ const payload = require('payload');
4
4
  require('dotenv').config();
5
5
  const app = express();
6
6
 
7
+ // Redirect root to Admin panel
8
+ app.get('/', (_, res) => {
9
+ res.redirect('/admin');
10
+ });
11
+
7
12
  // Initialize Payload
8
13
  payload.init({
9
14
  secret: process.env.PAYLOAD_SECRET,
@@ -4,6 +4,11 @@ const payload = require('payload');
4
4
  require('dotenv').config();
5
5
  const app = express();
6
6
 
7
+ // Redirect root to Admin panel
8
+ app.get('/', (_, res) => {
9
+ res.redirect('/admin');
10
+ });
11
+
7
12
  // Initialize Payload
8
13
  payload.init({
9
14
  secret: process.env.PAYLOAD_SECRET,
@@ -4,6 +4,11 @@ import payload from 'payload';
4
4
  require('dotenv').config();
5
5
  const app = express();
6
6
 
7
+ // Redirect root to Admin panel
8
+ app.get('/', (_, res) => {
9
+ res.redirect('/admin');
10
+ });
11
+
7
12
  // Initialize Payload
8
13
  payload.init({
9
14
  secret: process.env.PAYLOAD_SECRET,
@@ -1,14 +1,5 @@
1
- import { BeforeReadHook } from 'payload/dist/collections/config/types';
2
1
  import { CollectionConfig } from 'payload/types';
3
2
 
4
- const onlyNameIfPublic: BeforeReadHook = ({ req: { user }, doc }) => {
5
- // Only return name if not logged in
6
- if (!user) {
7
- return { name: doc.name };
8
- }
9
- return doc;
10
- };
11
-
12
3
  const Users: CollectionConfig = {
13
4
  slug: 'users',
14
5
  auth: true,
@@ -18,9 +9,6 @@ const Users: CollectionConfig = {
18
9
  access: {
19
10
  read: () => true,
20
11
  },
21
- hooks: {
22
- beforeRead: [onlyNameIfPublic]
23
- },
24
12
  fields: [
25
13
  // Email added by default
26
14
  {
@@ -4,6 +4,11 @@ import payload from 'payload';
4
4
  require('dotenv').config();
5
5
  const app = express();
6
6
 
7
+ // Redirect root to Admin panel
8
+ app.get('/', (_, res) => {
9
+ res.redirect('/admin');
10
+ });
11
+
7
12
  // Initialize Payload
8
13
  payload.init({
9
14
  secret: process.env.PAYLOAD_SECRET,
@@ -4,6 +4,11 @@ import payload from 'payload';
4
4
  require('dotenv').config();
5
5
  const app = express();
6
6
 
7
+ // Redirect root to Admin panel
8
+ app.get('/', (_, res) => {
9
+ res.redirect('/admin');
10
+ });
11
+
7
12
  // Initialize Payload
8
13
  payload.init({
9
14
  secret: process.env.PAYLOAD_SECRET,
package/package.json CHANGED
@@ -8,7 +8,9 @@
8
8
  "build": "tsc && yarn copyfiles",
9
9
  "copyfiles": "copyfiles -u 1 \"src/templates/**\" dist",
10
10
  "typecheck": "tsc --noEmit",
11
- "lint": "eslint \"src/**/*.ts\""
11
+ "lint": "eslint \"src/**/*.ts\"",
12
+ "test": "jest",
13
+ "prepublish": "yarn test && yarn build"
12
14
  },
13
15
  "files": [
14
16
  "package.json",
@@ -29,12 +31,12 @@
29
31
  "prompts": "^2.4.0",
30
32
  "terminal-link": "^2.1.1"
31
33
  },
32
- "version": "0.3.1",
34
+ "version": "0.3.5",
33
35
  "devDependencies": {
34
36
  "@types/command-exists": "^1.2.0",
35
37
  "@types/degit": "^2.8.3",
36
38
  "@types/fs-extra": "^9.0.12",
37
- "@types/jest": "^27.0.1",
39
+ "@types/jest": "^27.0.3",
38
40
  "@types/node": "^16.6.2",
39
41
  "@types/prompts": "^2.4.0",
40
42
  "@typescript-eslint/eslint-plugin": "^4.29.2",
@@ -44,9 +46,9 @@
44
46
  "eslint-config-airbnb-base": "^14.2.1",
45
47
  "eslint-config-prettier": "^8.3.0",
46
48
  "eslint-plugin-prettier": "^3.4.0",
47
- "jest": "^27.0.6",
49
+ "jest": "^27.4.5",
48
50
  "prettier": "^2.3.2",
49
- "ts-jest": "^27.0.5",
51
+ "ts-jest": "^27.1.1",
50
52
  "typescript": "^4.3.5"
51
53
  }
52
54
  }