create-payload-app 0.2.0 → 0.3.4

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',
@@ -10,7 +10,7 @@
10
10
  "serve": "NODE_ENV=production node server.js"
11
11
  },
12
12
  "dependencies": {
13
- "payload": "0.1.145",
13
+ "payload": "0.13.6",
14
14
  "dotenv": "^8.2.0",
15
15
  "express": "^4.17.1"
16
16
  },
@@ -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,
@@ -10,7 +10,7 @@
10
10
  "serve": "NODE_ENV=production node server.js"
11
11
  },
12
12
  "dependencies": {
13
- "payload": "0.1.145",
13
+ "payload": "0.13.6",
14
14
  "dotenv": "^8.2.0",
15
15
  "express": "^4.17.1"
16
16
  },
@@ -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,
@@ -10,7 +10,7 @@
10
10
  "serve": "NODE_ENV=production node server.js"
11
11
  },
12
12
  "dependencies": {
13
- "payload": "0.1.145",
13
+ "payload": "0.13.6",
14
14
  "dotenv": "^8.2.0",
15
15
  "express": "^4.17.1"
16
16
  },
@@ -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,
@@ -9,10 +9,11 @@
9
9
  "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
10
10
  "build:server": "tsc",
11
11
  "build": "yarn build:payload && yarn build:server",
12
- "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js"
12
+ "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
13
+ "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
13
14
  },
14
15
  "dependencies": {
15
- "payload": "0.1.145",
16
+ "payload": "0.13.6",
16
17
  "dotenv": "^8.2.0",
17
18
  "express": "^4.17.1"
18
19
  },
@@ -1,4 +1,5 @@
1
1
  import { buildConfig } from 'payload/config';
2
+ import path from 'path';
2
3
  // import Examples from './collections/Examples';
3
4
  import Users from './collections/Users';
4
5
 
@@ -12,4 +13,7 @@ export default buildConfig({
12
13
  // Add Collections here
13
14
  // Examples,
14
15
  ],
16
+ typescript: {
17
+ outputFile: path.resolve(__dirname, 'payload-types.ts')
18
+ },
15
19
  });
@@ -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,
@@ -9,10 +9,11 @@
9
9
  "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
10
10
  "build:server": "tsc",
11
11
  "build": "yarn build:payload && yarn build:server",
12
- "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js"
12
+ "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
13
+ "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
13
14
  },
14
15
  "dependencies": {
15
- "payload": "0.1.144",
16
+ "payload": "0.13.6",
16
17
  "dotenv": "^8.2.0",
17
18
  "express": "^4.17.1"
18
19
  },
@@ -1,4 +1,5 @@
1
1
  import { buildConfig } from 'payload/config';
2
+ import path from 'path';
2
3
  import Categories from './collections/Categories';
3
4
  import Posts from './collections/Posts';
4
5
  import Tags from './collections/Tags';
@@ -15,4 +16,7 @@ export default buildConfig({
15
16
  Tags,
16
17
  Users,
17
18
  ],
19
+ typescript: {
20
+ outputFile: path.resolve(__dirname, 'payload-types.ts')
21
+ },
18
22
  });
@@ -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,
@@ -9,10 +9,11 @@
9
9
  "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
10
10
  "build:server": "tsc",
11
11
  "build": "yarn build:payload && yarn build:server",
12
- "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js"
12
+ "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
13
+ "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
13
14
  },
14
15
  "dependencies": {
15
- "payload": "0.1.145",
16
+ "payload": "0.13.6",
16
17
  "dotenv": "^8.2.0",
17
18
  "express": "^4.17.1"
18
19
  },
@@ -1,4 +1,5 @@
1
1
  import { buildConfig } from 'payload/config';
2
+ import path from 'path';
2
3
  import TodoLists from './collections/TodoLists';
3
4
  import Users from './collections/Users';
4
5
 
@@ -11,4 +12,7 @@ export default buildConfig({
11
12
  TodoLists,
12
13
  Users,
13
14
  ],
15
+ typescript: {
16
+ outputFile: path.resolve(__dirname, 'payload-types.ts')
17
+ },
14
18
  });
@@ -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.2.0",
34
+ "version": "0.3.4",
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
  }