This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathprepareBuildManifests.js
78 lines (69 loc) · 2.01 KB
/
prepareBuildManifests.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copied from serverless-next.js (v1.9.10)
// https://github.com/danielcondemarin/serverless-next.js/blob/master/packages/serverless-nextjs-component/serverless.js
// This file is for reference purposes only.
async prepareBuildManifests(nextConfigPath) {
const pagesManifest = await this.readPagesManifest(nextConfigPath);
const defaultBuildManifest = {
pages: {
ssr: {
dynamic: {},
nonDynamic: {}
},
html: {
dynamic: {},
nonDynamic: {}
}
},
publicFiles: {},
cloudFrontOrigins: {}
};
const apiBuildManifest = {
apis: {
dynamic: {},
nonDynamic: {}
}
};
const ssrPages = defaultBuildManifest.pages.ssr;
const htmlPages = defaultBuildManifest.pages.html;
const apiPages = apiBuildManifest.apis;
const isHtmlPage = p => p.endsWith(".html");
const isApiPage = p => p.startsWith("pages/api");
Object.entries(pagesManifest).forEach(([route, pageFile]) => {
const dynamicRoute = isDynamicRoute(route);
const expressRoute = dynamicRoute ? expressifyDynamicRoute(route) : null;
if (isHtmlPage(pageFile)) {
if (dynamicRoute) {
htmlPages.dynamic[expressRoute] = {
file: pageFile,
regex: pathToRegexStr(expressRoute)
};
} else {
htmlPages.nonDynamic[route] = pageFile;
}
} else if (isApiPage(pageFile)) {
if (dynamicRoute) {
apiPages.dynamic[expressRoute] = {
file: pageFile,
regex: pathToRegexStr(expressRoute)
};
} else {
apiPages.nonDynamic[route] = pageFile;
}
} else if (dynamicRoute) {
ssrPages.dynamic[expressRoute] = {
file: pageFile,
regex: pathToRegexStr(expressRoute)
};
} else {
ssrPages.nonDynamic[route] = pageFile;
}
});
const publicFiles = await this.readPublicFiles(nextConfigPath);
publicFiles.forEach(pf => {
defaultBuildManifest.publicFiles["/" + pf] = pf;
});
return {
defaultBuildManifest,
apiBuildManifest
};
}