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

Commit 1708586

Browse files
committed
Add --max-log-lines option to set # of items to print per section
Add an optional CLI option --max-log-lines for setting the number of lines of build info to print for each section. All other lines in that section will be hidden and "+ X more" will be displayed instead. This prevents the log from becoming too long when working on apps with thousands of pages. The option defaults to showing 50 lines per build section: 50 lines for SSR pages, 50 lines for SSG pages, 50 lines of redirects, ... See: #26
1 parent c2bfb6b commit 1708586

File tree

4 files changed

+176
-101
lines changed

4 files changed

+176
-101
lines changed

lib/logger.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
11
// Helpers for writing info to console.log
2+
const { program } = require('commander')
3+
4+
// Number of items processed in current build step
5+
let itemsCount = 0
26

37
// Format in bold
4-
const logTitle = (...args) =>
8+
const logTitle = (...args) => {
9+
// Finish previous log section
10+
finishLogForBuildStep()
11+
12+
// Print title
513
log(`\x1b[1m${args.join(" ")}\x1b[22m`)
14+
}
615

716
// Indent by three spaces
8-
const logItem = (...args) =>
9-
log(' ', ...args)
17+
const logItem = (...args) => {
18+
// Display item if within max log lines
19+
if(itemsCount < program.maxLogLines)
20+
log(' ', ...args)
21+
22+
itemsCount += 1
23+
}
1024

1125
// Just console.log
1226
const log = (...args) =>
1327
console.log(...args)
1428

29+
// Finish log section: Write a single line for any suppressed/hidden items
30+
// and reset the item counter
31+
const finishLogForBuildStep = () => {
32+
// Display number of suppressed log lines
33+
if(itemsCount > program.maxLogLines) {
34+
const hiddenLines = itemsCount - program.maxLogLines
35+
log(' ', '+', hiddenLines, 'more',
36+
'(run next-on-netlify with --max-log-lines XX to',
37+
'show more or fewer lines)')
38+
}
39+
40+
// Reset counter
41+
itemsCount = 0
42+
}
43+
1544
module.exports = {
1645
logTitle,
1746
logItem,

next-on-netlify.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/usr/bin/env node
2+
const { program } = require('commander')
3+
4+
program
5+
.option('--max-log-lines [number]', 'lines of build output to show for each section', 50)
6+
.parse(process.argv)
27

38
const { logTitle } = require('./lib/logger')
49
const prepareFolders = require('./lib/prepareFolders')

package-lock.json

Lines changed: 138 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
"dependencies": {
4747
"@sls-next/lambda-at-edge": "^1.5.2",
48+
"commander": "^6.0.0",
4849
"fs-extra": "^9.0.1",
4950
"next-aws-lambda": "^2.5.0"
5051
}

0 commit comments

Comments
 (0)