create-payload-app 0.3.20 → 0.3.21-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/lib/common-files/nodemon.json +4 -0
- package/dist/lib/common-files/package.template.json +30 -0
- package/dist/lib/common-files/tsconfig.json +34 -0
- package/dist/lib/create-project.test.js +4 -4
- package/dist/lib/parse-template.js +4 -8
- package/dist/lib/templates.js +0 -1
- package/dist/lib/write-common-files.js +11 -11
- package/dist/main.js +17 -21
- package/dist/templates/blank/src/collections/Examples.ts +17 -0
- package/dist/templates/blank/src/collections/Users.ts +18 -0
- package/dist/templates/blank/src/payload.config.ts +22 -0
- package/dist/templates/blank/src/server.ts +24 -0
- package/dist/templates/blog/src/collections/Categories.ts +20 -0
- package/dist/templates/blog/src/collections/Posts.ts +62 -0
- package/dist/templates/blog/src/collections/Tags.ts +20 -0
- package/dist/templates/blog/src/collections/Users.ts +21 -0
- package/dist/templates/blog/src/payload.config.ts +25 -0
- package/dist/templates/blog/src/server.ts +24 -0
- package/dist/templates/todo/src/collections/TodoLists.ts +38 -0
- package/dist/templates/todo/src/collections/Users.ts +18 -0
- package/dist/templates/todo/src/payload.config.ts +21 -0
- package/dist/templates/todo/src/server.ts +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -15,7 +15,7 @@ CLI for easily starting new Payload project
|
|
15
15
|
--name my-payload-app Set project name
|
16
16
|
--template template_name Choose specific template
|
17
17
|
|
18
|
-
Available templates:
|
18
|
+
Available templates: blank, blog, todo
|
19
19
|
|
20
20
|
--use-npm Use npm to install dependencies
|
21
21
|
--no-deps Do not install any dependencies
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"name": "{{projectName}}",
|
3
|
+
"description": "Payload project created from {{templateName}} template",
|
4
|
+
"version": "1.0.0",
|
5
|
+
"main": "dist/server.js",
|
6
|
+
"license": "MIT",
|
7
|
+
"scripts": {
|
8
|
+
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
|
9
|
+
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
|
10
|
+
"build:server": "tsc",
|
11
|
+
"build": "{{runCommand}} copyfiles && {{runCommand}} build:payload && {{runCommand}} build:server",
|
12
|
+
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
|
13
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
|
14
|
+
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
|
15
|
+
"generate:graphQLSchema": "PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
|
16
|
+
},
|
17
|
+
"dependencies": {
|
18
|
+
"payload": "1.1.17",
|
19
|
+
"dotenv": "^8.2.0",
|
20
|
+
"express": "^4.17.1"
|
21
|
+
},
|
22
|
+
"devDependencies": {
|
23
|
+
"@types/express": "^4.17.9",
|
24
|
+
"cross-env": "^7.0.3",
|
25
|
+
"nodemon": "^2.0.6",
|
26
|
+
"ts-node": "^9.1.1",
|
27
|
+
"copyfiles": "^2.4.1",
|
28
|
+
"typescript": "^4.8.4"
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "es5",
|
4
|
+
"lib": [
|
5
|
+
"dom",
|
6
|
+
"dom.iterable",
|
7
|
+
"esnext"
|
8
|
+
],
|
9
|
+
"allowJs": true,
|
10
|
+
"strict": false,
|
11
|
+
"esModuleInterop": true,
|
12
|
+
"skipLibCheck": true,
|
13
|
+
"outDir": "./dist",
|
14
|
+
"rootDir": "./src",
|
15
|
+
"jsx": "react",
|
16
|
+
"paths": {
|
17
|
+
"payload/generated-types": [
|
18
|
+
"./src/payload-types.ts",
|
19
|
+
],
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"include": [
|
23
|
+
"src"
|
24
|
+
],
|
25
|
+
"exclude": [
|
26
|
+
"node_modules",
|
27
|
+
"dist",
|
28
|
+
"build",
|
29
|
+
],
|
30
|
+
"ts-node": {
|
31
|
+
"transpileOnly": true,
|
32
|
+
"swc": true,
|
33
|
+
}
|
34
|
+
}
|
@@ -62,16 +62,16 @@ describe('createProject', function () {
|
|
62
62
|
var args = { _: ['project-name'], '--no-deps': true };
|
63
63
|
var packageManager = 'yarn';
|
64
64
|
it('creates static project', function () { return __awaiter(void 0, void 0, void 0, function () {
|
65
|
-
var expectedPayloadVersion, template, packageJsonPath, packageJson;
|
65
|
+
var expectedPayloadVersion, templateName, template, packageJsonPath, packageJson;
|
66
66
|
return __generator(this, function (_a) {
|
67
67
|
switch (_a.label) {
|
68
68
|
case 0: return [4 /*yield*/, (0, create_project_1.getLatestPayloadVersion)()];
|
69
69
|
case 1:
|
70
70
|
expectedPayloadVersion = _a.sent();
|
71
|
+
templateName = 'todo';
|
71
72
|
template = {
|
72
|
-
name:
|
73
|
+
name: templateName,
|
73
74
|
type: 'static',
|
74
|
-
language: 'typescript',
|
75
75
|
};
|
76
76
|
return [4 /*yield*/, (0, create_project_1.createProject)(args, projectDir, template, packageManager)];
|
77
77
|
case 2:
|
@@ -81,7 +81,7 @@ describe('createProject', function () {
|
|
81
81
|
expect(packageJson.dependencies.payload).toBe(expectedPayloadVersion);
|
82
82
|
// Check package name and description
|
83
83
|
expect(packageJson.name).toEqual(path_1.default.basename(projectDir));
|
84
|
-
expect(packageJson.description).toContain(
|
84
|
+
expect(packageJson.description).toContain(templateName);
|
85
85
|
// Check all common files are create
|
86
86
|
assertProjectFileExists('.npmrc');
|
87
87
|
assertProjectFileExists('.gitignore');
|
@@ -41,7 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
42
42
|
exports.parseTemplate = void 0;
|
43
43
|
var prompts_1 = __importDefault(require("prompts"));
|
44
|
-
function parseTemplate(args, validTemplates
|
44
|
+
function parseTemplate(args, validTemplates) {
|
45
45
|
return __awaiter(this, void 0, void 0, function () {
|
46
46
|
var templateName_1, template_1, filteredTemplates, response, template;
|
47
47
|
return __generator(this, function (_a) {
|
@@ -54,24 +54,20 @@ function parseTemplate(args, validTemplates, language) {
|
|
54
54
|
throw new Error('Invalid template given');
|
55
55
|
return [2 /*return*/, template_1];
|
56
56
|
}
|
57
|
-
filteredTemplates = validTemplates
|
58
|
-
.filter(function (d) { return d.name.startsWith(language); })
|
59
|
-
.map(function (t) { return t.name.replace("".concat(language, "-"), ''); });
|
57
|
+
filteredTemplates = validTemplates.map(function (t) { return t.name; });
|
60
58
|
return [4 /*yield*/, (0, prompts_1.default)({
|
61
59
|
type: 'select',
|
62
60
|
name: 'value',
|
63
61
|
message: 'Choose project template',
|
64
62
|
choices: filteredTemplates.map(function (p) {
|
65
|
-
return { title: p, value:
|
63
|
+
return { title: p, value: p };
|
66
64
|
}),
|
67
65
|
validate: function (value) { return !!value.length; },
|
68
66
|
}, {
|
69
67
|
onCancel: function () {
|
70
68
|
process.exit(0);
|
71
69
|
},
|
72
|
-
})
|
73
|
-
// const template = `${language}-${response.value}`
|
74
|
-
];
|
70
|
+
})];
|
75
71
|
case 1:
|
76
72
|
response = _a.sent();
|
77
73
|
template = validTemplates.find(function (t) { return t.name === response.value; });
|
package/dist/lib/templates.js
CHANGED
@@ -64,7 +64,7 @@ function writeCommonFiles(projectDir, template, packageManager) {
|
|
64
64
|
];
|
65
65
|
case 2:
|
66
66
|
_a.sent();
|
67
|
-
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir,
|
67
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'package.template.json'), 'utf8')];
|
68
68
|
case 3:
|
69
69
|
packageJsonTemplate = _a.sent();
|
70
70
|
packageJson = handlebars_1.default.compile(packageJsonTemplate)({
|
@@ -77,7 +77,7 @@ function writeCommonFiles(projectDir, template, packageManager) {
|
|
77
77
|
];
|
78
78
|
case 4:
|
79
79
|
_a.sent();
|
80
|
-
nodemon = path_1.default.resolve(commonFilesDir,
|
80
|
+
nodemon = path_1.default.resolve(commonFilesDir, 'nodemon.json');
|
81
81
|
nodemonDest = path_1.default.resolve(projectDir, 'nodemon.json');
|
82
82
|
return [4 /*yield*/, fs_extra_1.default.copy(nodemon, nodemonDest)
|
83
83
|
// README.md
|
@@ -96,15 +96,15 @@ function writeCommonFiles(projectDir, template, packageManager) {
|
|
96
96
|
];
|
97
97
|
case 7:
|
98
98
|
_a.sent();
|
99
|
-
|
100
|
-
tsconfig = path_1.default.resolve(commonFilesDir, template.language, 'tsconfig.json');
|
99
|
+
tsconfig = path_1.default.resolve(commonFilesDir, 'tsconfig.json');
|
101
100
|
tsconfigDest = path_1.default.resolve(projectDir, 'tsconfig.json');
|
102
|
-
return [4 /*yield*/, fs_extra_1.default.copy(tsconfig, tsconfigDest)
|
101
|
+
return [4 /*yield*/, fs_extra_1.default.copy(tsconfig, tsconfigDest)
|
102
|
+
// docker-compose.yml
|
103
|
+
];
|
103
104
|
case 8:
|
104
105
|
_a.sent();
|
105
|
-
|
106
|
-
case 9:
|
107
|
-
case 10:
|
106
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'docker-compose.template.yml'), 'utf8')];
|
107
|
+
case 9:
|
108
108
|
dockerComposeTemplate = _a.sent();
|
109
109
|
dockerCompose = handlebars_1.default.compile(dockerComposeTemplate)(packageManager === 'yarn'
|
110
110
|
? { installCmd: 'yarn install', devCmd: 'yarn dev' }
|
@@ -112,16 +112,16 @@ function writeCommonFiles(projectDir, template, packageManager) {
|
|
112
112
|
return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'docker-compose.yml'), dockerCompose)
|
113
113
|
// Dockerfile
|
114
114
|
];
|
115
|
-
case
|
115
|
+
case 10:
|
116
116
|
_a.sent();
|
117
117
|
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.resolve(commonFilesDir, 'Dockerfile.template'), 'utf8')];
|
118
|
-
case
|
118
|
+
case 11:
|
119
119
|
dockerfileTemplate = _a.sent();
|
120
120
|
dockerfile = handlebars_1.default.compile(dockerfileTemplate)(packageManager === 'yarn'
|
121
121
|
? { installCmd: 'yarn install', buildCmd: 'yarn build' }
|
122
122
|
: { installCmd: 'npm install', buildCmd: 'npm run build' });
|
123
123
|
return [4 /*yield*/, fs_extra_1.default.writeFile(path_1.default.resolve(projectDir, 'Dockerfile'), dockerfile)];
|
124
|
-
case
|
124
|
+
case 12:
|
125
125
|
_a.sent();
|
126
126
|
return [2 /*return*/];
|
127
127
|
}
|
package/dist/main.js
CHANGED
@@ -46,7 +46,6 @@ var command_exists_1 = __importDefault(require("command-exists"));
|
|
46
46
|
var create_project_1 = require("./lib/create-project");
|
47
47
|
var get_db_connection_1 = require("./lib/get-db-connection");
|
48
48
|
var generate_secret_1 = require("./lib/generate-secret");
|
49
|
-
var parse_language_1 = require("./lib/parse-language");
|
50
49
|
var parse_project_name_1 = require("./lib/parse-project-name");
|
51
50
|
var parse_template_1 = require("./lib/parse-template");
|
52
51
|
var templates_1 = require("./lib/templates");
|
@@ -73,11 +72,11 @@ var Main = /** @class */ (function () {
|
|
73
72
|
}
|
74
73
|
Main.prototype.init = function () {
|
75
74
|
return __awaiter(this, void 0, void 0, function () {
|
76
|
-
var _a, _b, templateArg, valid, _c, _d, projectName,
|
75
|
+
var _a, _b, templateArg, valid, _c, _d, projectName, validTemplates, template, databaseUri, payloadSecret, projectDir, packageManager, error_1;
|
77
76
|
return __generator(this, function (_e) {
|
78
77
|
switch (_e.label) {
|
79
78
|
case 0:
|
80
|
-
_e.trys.push([0,
|
79
|
+
_e.trys.push([0, 15, , 16]);
|
81
80
|
if (!this.args['--help']) return [3 /*break*/, 2];
|
82
81
|
_b = (_a = console).log;
|
83
82
|
return [4 /*yield*/, (0, messages_1.helpMessage)()];
|
@@ -103,42 +102,39 @@ var Main = /** @class */ (function () {
|
|
103
102
|
return [4 /*yield*/, (0, parse_project_name_1.parseProjectName)(this.args)];
|
104
103
|
case 6:
|
105
104
|
projectName = _e.sent();
|
106
|
-
return [4 /*yield*/, (0, parse_language_1.parseLanguage)(this.args)];
|
107
|
-
case 7:
|
108
|
-
language = _e.sent();
|
109
105
|
return [4 /*yield*/, (0, templates_1.getValidTemplates)()];
|
110
|
-
case
|
106
|
+
case 7:
|
111
107
|
validTemplates = _e.sent();
|
112
|
-
return [4 /*yield*/, (0, parse_template_1.parseTemplate)(this.args, validTemplates
|
113
|
-
case
|
108
|
+
return [4 /*yield*/, (0, parse_template_1.parseTemplate)(this.args, validTemplates)];
|
109
|
+
case 8:
|
114
110
|
template = _e.sent();
|
115
111
|
return [4 /*yield*/, (0, get_db_connection_1.getDatabaseConnection)(this.args, projectName)];
|
116
|
-
case
|
112
|
+
case 9:
|
117
113
|
databaseUri = _e.sent();
|
118
114
|
return [4 /*yield*/, (0, generate_secret_1.generateSecret)()];
|
119
|
-
case
|
115
|
+
case 10:
|
120
116
|
payloadSecret = _e.sent();
|
121
117
|
projectDir = projectName === '.' ? process.cwd() : "./".concat((0, slugify_1.default)(projectName));
|
122
118
|
return [4 /*yield*/, getPackageManager(this.args)];
|
123
|
-
case
|
119
|
+
case 11:
|
124
120
|
packageManager = _e.sent();
|
125
|
-
if (!!this.args['--dry-run']) return [3 /*break*/,
|
121
|
+
if (!!this.args['--dry-run']) return [3 /*break*/, 14];
|
126
122
|
return [4 /*yield*/, (0, create_project_1.createProject)(this.args, projectDir, template, packageManager)];
|
127
|
-
case
|
123
|
+
case 12:
|
128
124
|
_e.sent();
|
129
125
|
return [4 /*yield*/, (0, write_env_file_1.writeEnvFile)(projectName, databaseUri, payloadSecret)];
|
130
|
-
case
|
126
|
+
case 13:
|
131
127
|
_e.sent();
|
132
|
-
_e.label =
|
133
|
-
case
|
128
|
+
_e.label = 14;
|
129
|
+
case 14:
|
134
130
|
(0, log_1.success)('Payload project successfully created');
|
135
131
|
console.log((0, messages_1.successMessage)(projectDir, packageManager));
|
136
|
-
return [3 /*break*/,
|
137
|
-
case
|
132
|
+
return [3 /*break*/, 16];
|
133
|
+
case 15:
|
138
134
|
error_1 = _e.sent();
|
139
135
|
console.log(error_1);
|
140
|
-
return [3 /*break*/,
|
141
|
-
case
|
136
|
+
return [3 /*break*/, 16];
|
137
|
+
case 16: return [2 /*return*/];
|
142
138
|
}
|
143
139
|
});
|
144
140
|
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
// Example Collection - For reference only, this must be added to payload.config.ts to be used.
|
4
|
+
const Examples: CollectionConfig = {
|
5
|
+
slug: 'examples',
|
6
|
+
admin: {
|
7
|
+
useAsTitle: 'someField',
|
8
|
+
},
|
9
|
+
fields: [
|
10
|
+
{
|
11
|
+
name: 'someField',
|
12
|
+
type: 'text',
|
13
|
+
},
|
14
|
+
],
|
15
|
+
}
|
16
|
+
|
17
|
+
export default Examples;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Users: CollectionConfig = {
|
4
|
+
slug: 'users',
|
5
|
+
auth: true,
|
6
|
+
admin: {
|
7
|
+
useAsTitle: 'email',
|
8
|
+
},
|
9
|
+
access: {
|
10
|
+
read: () => true,
|
11
|
+
},
|
12
|
+
fields: [
|
13
|
+
// Email added by default
|
14
|
+
// Add more fields as needed
|
15
|
+
],
|
16
|
+
};
|
17
|
+
|
18
|
+
export default Users;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { buildConfig } from 'payload/config';
|
2
|
+
import path from 'path';
|
3
|
+
// import Examples from './collections/Examples';
|
4
|
+
import Users from './collections/Users';
|
5
|
+
|
6
|
+
export default buildConfig({
|
7
|
+
serverURL: 'http://localhost:3000',
|
8
|
+
admin: {
|
9
|
+
user: Users.slug,
|
10
|
+
},
|
11
|
+
collections: [
|
12
|
+
Users,
|
13
|
+
// Add Collections here
|
14
|
+
// Examples,
|
15
|
+
],
|
16
|
+
typescript: {
|
17
|
+
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
18
|
+
},
|
19
|
+
graphQL: {
|
20
|
+
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
|
21
|
+
},
|
22
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import express from 'express';
|
2
|
+
import payload from 'payload';
|
3
|
+
|
4
|
+
require('dotenv').config();
|
5
|
+
const app = express();
|
6
|
+
|
7
|
+
// Redirect root to Admin panel
|
8
|
+
app.get('/', (_, res) => {
|
9
|
+
res.redirect('/admin');
|
10
|
+
});
|
11
|
+
|
12
|
+
// Initialize Payload
|
13
|
+
payload.init({
|
14
|
+
secret: process.env.PAYLOAD_SECRET,
|
15
|
+
mongoURL: process.env.MONGODB_URI,
|
16
|
+
express: app,
|
17
|
+
onInit: () => {
|
18
|
+
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
19
|
+
},
|
20
|
+
})
|
21
|
+
|
22
|
+
// Add your own express routes here
|
23
|
+
|
24
|
+
app.listen(3000);
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Categories: CollectionConfig = {
|
4
|
+
slug: 'categories',
|
5
|
+
admin: {
|
6
|
+
useAsTitle: 'name',
|
7
|
+
},
|
8
|
+
access: {
|
9
|
+
read: () => true,
|
10
|
+
},
|
11
|
+
fields: [
|
12
|
+
{
|
13
|
+
name: 'name',
|
14
|
+
type: 'text',
|
15
|
+
},
|
16
|
+
],
|
17
|
+
timestamps: false,
|
18
|
+
}
|
19
|
+
|
20
|
+
export default Categories;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Posts: CollectionConfig = {
|
4
|
+
slug: 'posts',
|
5
|
+
admin: {
|
6
|
+
defaultColumns: ['title', 'author', 'category', 'tags', 'status'],
|
7
|
+
useAsTitle: 'title',
|
8
|
+
},
|
9
|
+
access: {
|
10
|
+
read: () => true,
|
11
|
+
},
|
12
|
+
fields: [
|
13
|
+
{
|
14
|
+
name: 'title',
|
15
|
+
type: 'text',
|
16
|
+
},
|
17
|
+
{
|
18
|
+
name: 'author',
|
19
|
+
type: 'relationship',
|
20
|
+
relationTo: 'users',
|
21
|
+
},
|
22
|
+
{
|
23
|
+
name: 'publishedDate',
|
24
|
+
type: 'date',
|
25
|
+
},
|
26
|
+
{
|
27
|
+
name: 'category',
|
28
|
+
type: 'relationship',
|
29
|
+
relationTo: 'categories'
|
30
|
+
},
|
31
|
+
{
|
32
|
+
name: 'tags',
|
33
|
+
type: 'relationship',
|
34
|
+
relationTo: 'tags',
|
35
|
+
hasMany: true,
|
36
|
+
},
|
37
|
+
{
|
38
|
+
name: 'content',
|
39
|
+
type: 'richText'
|
40
|
+
},
|
41
|
+
{
|
42
|
+
name: 'status',
|
43
|
+
type: 'select',
|
44
|
+
options: [
|
45
|
+
{
|
46
|
+
value: 'draft',
|
47
|
+
label: 'Draft',
|
48
|
+
},
|
49
|
+
{
|
50
|
+
value: 'published',
|
51
|
+
label: 'Published',
|
52
|
+
},
|
53
|
+
],
|
54
|
+
defaultValue: 'draft',
|
55
|
+
admin: {
|
56
|
+
position: 'sidebar',
|
57
|
+
}
|
58
|
+
}
|
59
|
+
],
|
60
|
+
}
|
61
|
+
|
62
|
+
export default Posts;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Tags: CollectionConfig = {
|
4
|
+
slug: 'tags',
|
5
|
+
admin: {
|
6
|
+
useAsTitle: 'name',
|
7
|
+
},
|
8
|
+
access: {
|
9
|
+
read: () => true,
|
10
|
+
},
|
11
|
+
fields: [
|
12
|
+
{
|
13
|
+
name: 'name',
|
14
|
+
type: 'text',
|
15
|
+
},
|
16
|
+
],
|
17
|
+
timestamps: false,
|
18
|
+
}
|
19
|
+
|
20
|
+
export default Tags;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Users: CollectionConfig = {
|
4
|
+
slug: 'users',
|
5
|
+
auth: true,
|
6
|
+
admin: {
|
7
|
+
useAsTitle: 'email',
|
8
|
+
},
|
9
|
+
access: {
|
10
|
+
read: () => true,
|
11
|
+
},
|
12
|
+
fields: [
|
13
|
+
// Email added by default
|
14
|
+
{
|
15
|
+
name: 'name',
|
16
|
+
type: 'text',
|
17
|
+
}
|
18
|
+
],
|
19
|
+
};
|
20
|
+
|
21
|
+
export default Users;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { buildConfig } from 'payload/config';
|
2
|
+
import path from 'path';
|
3
|
+
import Categories from './collections/Categories';
|
4
|
+
import Posts from './collections/Posts';
|
5
|
+
import Tags from './collections/Tags';
|
6
|
+
import Users from './collections/Users';
|
7
|
+
|
8
|
+
export default buildConfig({
|
9
|
+
serverURL: 'http://localhost:3000',
|
10
|
+
admin: {
|
11
|
+
user: Users.slug,
|
12
|
+
},
|
13
|
+
collections: [
|
14
|
+
Categories,
|
15
|
+
Posts,
|
16
|
+
Tags,
|
17
|
+
Users,
|
18
|
+
],
|
19
|
+
typescript: {
|
20
|
+
outputFile: path.resolve(__dirname, 'payload-types.ts')
|
21
|
+
},
|
22
|
+
graphQL: {
|
23
|
+
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
|
24
|
+
},
|
25
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import express from 'express';
|
2
|
+
import payload from 'payload';
|
3
|
+
|
4
|
+
require('dotenv').config();
|
5
|
+
const app = express();
|
6
|
+
|
7
|
+
// Redirect root to Admin panel
|
8
|
+
app.get('/', (_, res) => {
|
9
|
+
res.redirect('/admin');
|
10
|
+
});
|
11
|
+
|
12
|
+
// Initialize Payload
|
13
|
+
payload.init({
|
14
|
+
secret: process.env.PAYLOAD_SECRET,
|
15
|
+
mongoURL: process.env.MONGODB_URI,
|
16
|
+
express: app,
|
17
|
+
onInit: () => {
|
18
|
+
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
19
|
+
},
|
20
|
+
})
|
21
|
+
|
22
|
+
// Add your own express routes here
|
23
|
+
|
24
|
+
app.listen(3000);
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Todo: CollectionConfig = {
|
4
|
+
slug: 'todos',
|
5
|
+
admin: {
|
6
|
+
defaultColumns: ['listName', 'tasks', 'updatedAt'],
|
7
|
+
useAsTitle: 'listName',
|
8
|
+
},
|
9
|
+
access: {
|
10
|
+
create: () => true,
|
11
|
+
read: () => true,
|
12
|
+
update: () => true,
|
13
|
+
delete: () => true,
|
14
|
+
},
|
15
|
+
fields: [
|
16
|
+
{
|
17
|
+
name: 'listName',
|
18
|
+
type: 'text',
|
19
|
+
},
|
20
|
+
{
|
21
|
+
name: 'tasks',
|
22
|
+
type: 'array',
|
23
|
+
fields: [
|
24
|
+
{
|
25
|
+
name: 'name',
|
26
|
+
type: 'text',
|
27
|
+
},
|
28
|
+
{
|
29
|
+
name: 'complete',
|
30
|
+
type: 'checkbox',
|
31
|
+
defaultValue: false,
|
32
|
+
}
|
33
|
+
]
|
34
|
+
},
|
35
|
+
],
|
36
|
+
}
|
37
|
+
|
38
|
+
export default Todo;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { CollectionConfig } from 'payload/types';
|
2
|
+
|
3
|
+
const Users: CollectionConfig = {
|
4
|
+
slug: 'users',
|
5
|
+
auth: true,
|
6
|
+
admin: {
|
7
|
+
useAsTitle: 'email',
|
8
|
+
},
|
9
|
+
access: {
|
10
|
+
read: () => true,
|
11
|
+
},
|
12
|
+
fields: [
|
13
|
+
// Email added by default
|
14
|
+
// Add more fields as needed
|
15
|
+
],
|
16
|
+
};
|
17
|
+
|
18
|
+
export default Users;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { buildConfig } from 'payload/config';
|
2
|
+
import path from 'path';
|
3
|
+
import TodoLists from './collections/TodoLists';
|
4
|
+
import Users from './collections/Users';
|
5
|
+
|
6
|
+
export default buildConfig({
|
7
|
+
serverURL: 'http://localhost:3000',
|
8
|
+
admin: {
|
9
|
+
user: Users.slug,
|
10
|
+
},
|
11
|
+
collections: [
|
12
|
+
TodoLists,
|
13
|
+
Users,
|
14
|
+
],
|
15
|
+
typescript: {
|
16
|
+
outputFile: path.resolve(__dirname, 'payload-types.ts')
|
17
|
+
},
|
18
|
+
graphQL: {
|
19
|
+
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
|
20
|
+
},
|
21
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import express from 'express';
|
2
|
+
import payload from 'payload';
|
3
|
+
|
4
|
+
require('dotenv').config();
|
5
|
+
const app = express();
|
6
|
+
|
7
|
+
// Redirect root to Admin panel
|
8
|
+
app.get('/', (_, res) => {
|
9
|
+
res.redirect('/admin');
|
10
|
+
});
|
11
|
+
|
12
|
+
// Initialize Payload
|
13
|
+
payload.init({
|
14
|
+
secret: process.env.PAYLOAD_SECRET,
|
15
|
+
mongoURL: process.env.MONGODB_URI,
|
16
|
+
express: app,
|
17
|
+
onInit: () => {
|
18
|
+
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
19
|
+
},
|
20
|
+
})
|
21
|
+
|
22
|
+
// Add your own express routes here
|
23
|
+
|
24
|
+
app.listen(3000);
|