forked from kentcdodds/advanced-react-patterns-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautofill-feedback-email.js
62 lines (59 loc) · 1.65 KB
/
autofill-feedback-email.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
/* eslint no-console:0 */
const path = require('path')
const inquirer = require('inquirer')
const replace = require('replace-in-file')
const isCI = require('is-ci')
const spawn = require('cross-spawn')
const { EOL } = require('os')
if (isCI) {
console.log(`Not running autofill feedback as we're on CI`)
} else {
const prompt = inquirer.prompt([
{
name: 'email',
message: `what's your email address?`,
validate(val) {
if (!val) {
// they don't want to do this...
return true
} else if (!val.includes('@')) {
return 'email requires an @ sign...'
}
return true
},
},
])
const timeoutId = setTimeout(() => {
console.log(
`\n\nprompt timed out. No worries. Run \`node ./scripts/autofill-feedback-email.js\` if you'd like to try again`,
)
prompt.ui.close()
}, 15000)
prompt.then(({email} = {}) => {
clearTimeout(timeoutId)
if (!email) {
console.log(`Not autofilling email because none was provided`)
return
}
const options = {
files: [path.join(__dirname, '..', 'src/**/*.js')],
from: `&em=${EOL}`,
to: `&em=${email}${EOL}`,
}
replace(options).then(
changedFiles => {
console.log(`Updated ${changedFiles.length} with the email ${email}`)
console.log(
'committing changes for you so your jest watch mode works nicely',
)
spawn.sync('git', ['commit', '-am', 'email autofill', '--no-verify'], {
stdio: 'inherit',
})
},
error => {
console.error('Failed to update files')
console.error(error.stack)
},
)
})
}