forked from payloadcms/next-payload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
44 lines (35 loc) · 1.23 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const path = require("path");
const fs = require("fs");
const copyRecursiveSync = require("./utilities/copyRecursiveSync");
const copyFile = require("./utilities/copyFile");
module.exports = () => {
const useSrc =
fs.existsSync(path.resolve(process.cwd(), "./src/app")) ||
fs.existsSync(path.resolve(process.cwd(), "./src/pages"));
const basePath = useSrc ? "./src" : ".";
// Copy handlers into /api
copyRecursiveSync(
path.resolve(__dirname, "./templates/pages/api"),
path.resolve(process.cwd(), `${basePath}/pages/api`)
);
// Copy admin into /app
copyRecursiveSync(
path.resolve(__dirname, "./templates/app"),
path.resolve(process.cwd(), `${basePath}/app`)
);
const payloadConfigPath = path.resolve(process.cwd(), `${basePath}/payload`);
if (!fs.existsSync(payloadConfigPath)) {
fs.mkdirSync(payloadConfigPath);
}
// Copy payload initialization
copyFile(
path.resolve(__dirname, "./templates/payloadClient.ts"),
path.resolve(process.cwd(), `${basePath}/payload/payloadClient.ts`)
);
// Copy base payload config
copyFile(
path.resolve(__dirname, "./templates/payload.config.ts"),
path.resolve(process.cwd(), `${basePath}/payload/payload.config.ts`)
);
process.exit(0);
};