Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 3afc944

Browse files
committed
Display progress when running next-on-netlify
Write progress to console.log when running next-on-netlify. This also shows which pages are being set up as SSR, which ones as pre-rendered HTML, as well as the redirects set up by next-on-netlify. This also helps alert users that out/ is the new output folder (rather than public/).
1 parent 5b7d20d commit 3afc944

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

next-on-netlify.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const ROUTER_TEMPLATE_PATH = join(__dirname, "lib", "routerTemplate.js")
2929
// The folder name of the NextRouter Netlify function
3030
const ROUTER_FUNCTION_NAME = "nextRouter"
3131

32+
console.log("\x1b[1m🚀 Next on Netlify 🚀\x1b[22m")
33+
console.log(` * Functions directory: ${FUNCTIONS_PATH}`)
34+
console.log(` * Publish directory: ${OUTPUT_PATH}`)
3235

3336
// 1. Get a collection of our NextJS pages
3437
// For each page, evaluate:
@@ -51,6 +54,7 @@ const htmlPages = filteredPages.filter(({ isHTML }) => isHTML)
5154

5255

5356
// 2. SSR Setup
57+
console.log(`\x1b[1m💫 Preparing Netlify Function for SSR pages: ${join(FUNCTIONS_PATH, ROUTER_FUNCTION_NAME)}\x1b[22m`)
5458

5559
// 2.1 SSR Setup: Clean existing Netlify function folder
5660
emptyDirSync(
@@ -66,6 +70,8 @@ copySync(
6670
// 2.3 SSR Setup: Copy SSR pages to functions/_next/pages
6771
// From there, they can be served by our nextRouter Netlify function.
6872
ssrPages.forEach(({ file }) => {
73+
console.log(` > ${file}`)
74+
6975
copySync(
7076
join(NEXT_DIST_DIR, "serverless", file),
7177
join(FUNCTIONS_PATH, ROUTER_FUNCTION_NAME, file)
@@ -99,12 +105,18 @@ writeFileSync(
99105
emptyDirSync(OUTPUT_PATH)
100106

101107
// 3.2 HTML Setup: Copy files from public folder to output path
102-
if(existsSync(PUBLIC_PATH))
108+
if(existsSync(PUBLIC_PATH)) {
109+
console.log(`\x1b[1m🌍️ Copying ${PUBLIC_PATH} folder to ${OUTPUT_PATH}\x1b[22m`)
103110
copySync(PUBLIC_PATH, OUTPUT_PATH)
111+
}
104112

105113
// 3.3 HTML Setup: Copy HTML pages to the output folder
106114
// These are static, so they do not need to be handled by our nextRouter.
115+
console.log(`\x1b[1m🔥 Writing pre-rendered HTML pages to ${OUTPUT_PATH}\x1b[22m`)
116+
107117
htmlPages.forEach(({ file }) => {
118+
console.log(` > ${file}`)
119+
108120
// The path to the file, relative to the pages directory
109121
const relativePath = relative("pages", file)
110122

@@ -120,6 +132,8 @@ htmlPages.forEach(({ file }) => {
120132

121133

122134
// 4. Prepare NextJS static assets
135+
console.log(`\x1b[1m💼 Copying static NextJS assets to ${OUTPUT_PATH}\x1b[22m`)
136+
123137
// Copy the NextJS' static assets from /.next/static to /out/_next/static.
124138
// These need to be available for NextJS to work.
125139
copySync(
@@ -133,6 +147,8 @@ copySync(
133147

134148

135149
// 5. Generate the _redirects file
150+
console.log("\x1b[1m🔀 Setting up redirects\x1b[22m")
151+
136152
// These redirects route all requests to the appropriate location: Either the
137153
// nextRouter Netlify function or one of our static HTML pages. They are merged
138154
// with the _redirects file from the public/ folder, so you can still define
@@ -146,7 +162,11 @@ const htmlRedirects = htmlPages.map(({ route, file }) => {
146162
const ssrRedirects = ssrPages.map(({ route }) => (
147163
`${route} /.netlify/functions/${ROUTER_FUNCTION_NAME} 200`
148164
))
149-
const nextjsRedirects = [...htmlRedirects, ...ssrRedirects].join("\n")
165+
const nextjsRedirects = [...htmlRedirects, ...ssrRedirects]
166+
167+
nextjsRedirects.forEach(redirect => (
168+
console.log(` ${redirect}`)
169+
))
150170

151171
// Read user-defined redirects
152172
let userRedirects = ""
@@ -156,7 +176,11 @@ if(existsSync(USER_REDIRECTS_PATH)) {
156176

157177
writeFileSync(
158178
join(OUTPUT_PATH, "_redirects"),
159-
userRedirects + "\n\n" +
160-
"# Next-on-Netlify Redirects" + "\n" +
161-
nextjsRedirects
179+
userRedirects + "\n\n" +
180+
"# Next-on-Netlify Redirects" + "\n" +
181+
nextjsRedirects.join("\n")
162182
)
183+
184+
185+
// Done!
186+
console.log("\x1b[1m✅ Success! All done!\x1b[22m")

tests/defaults.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,19 @@ beforeAll(
5757

5858
describe('Next', () => {
5959
test('builds successfully', () => {
60+
// NextJS output
6061
expect(BUILD_OUTPUT).toMatch("Creating an optimized production build...")
6162
expect(BUILD_OUTPUT).toMatch("Automatically optimizing pages...")
6263
expect(BUILD_OUTPUT).toMatch("First Load JS shared by all")
64+
65+
// Next on Netlify output
66+
expect(BUILD_OUTPUT).toMatch("Next on Netlify")
67+
expect(BUILD_OUTPUT).toMatch("Preparing Netlify Function for SSR pages: functions/nextRouter")
68+
expect(BUILD_OUTPUT).toMatch("Copying public/ folder to out/")
69+
expect(BUILD_OUTPUT).toMatch("Writing pre-rendered HTML pages to out/")
70+
expect(BUILD_OUTPUT).toMatch("Copying static NextJS assets to out/")
71+
expect(BUILD_OUTPUT).toMatch("Setting up redirects")
72+
expect(BUILD_OUTPUT).toMatch("Success! All done!")
6373
})
6474
})
6575

0 commit comments

Comments
 (0)