forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skip-docs-change.js
51 lines (42 loc) · 1.37 KB
/
skip-docs-change.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
const { promisify } = require('util')
const { exec: execOrig, spawn } = require('child_process')
const exec = promisify(execOrig)
const DOCS_FOLDERS = ['bench', 'docs', 'errors', 'examples']
async function main() {
await exec('git fetch origin canary')
const { stdout: changedFilesOutput } = await exec(
'git diff $(git merge-base --fork-point canary) --name-only'
)
const changedFiles = changedFilesOutput
.split('\n')
.map((file) => file && file.trim())
.filter(Boolean)
let hasNonDocsChange = changedFiles.some((file) => {
return !DOCS_FOLDERS.some((folder) => file.startsWith(folder + '/'))
})
const args = process.argv.slice(process.argv.indexOf(__filename) + 1)
if (args.length === 0) {
console.log(process.argv, args)
console.log('no script provided, exiting...')
}
if (hasNonDocsChange) {
const cmd = spawn(args[0], args.slice(1))
cmd.stdout.pipe(process.stdout)
cmd.stderr.pipe(process.stderr)
await new Promise((resolve, reject) => {
cmd.on('exit', (code) => {
if (code !== 0) {
return reject(new Error('command failed with code: ' + code))
}
resolve()
})
cmd.on('error', (err) => reject(err))
})
} else {
console.log('Only docs changes exiting...')
}
}
main().catch((err) => {
console.error('Failed to detect doc changes', err)
process.exit(1)
})