-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcovenant.js
executable file
·39 lines (33 loc) · 1.2 KB
/
covenant.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
const bent = require('bent')
const fs = require('mz/fs')
const mkdirp = require('mkdirp')
const getDirName = require('path').dirname
async function writeFile (dest, content) {
await mkdirp(getDirName(dest)).then(async () => {
fs.writeFile(dest, content, 'utf8')
.catch((err) => console.log('Error writing file:', err))
.then(() => console.log(`Done! Created file ${dest}.`))
}).catch(err => {
console.log('Unable to creat directory for path.', err)
})
}
module.exports = async function download (email, dest) {
if (!email) {
throw new Error('An email address must be provided!')
}
const url = 'https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md'
dest = dest || 'CODE_OF_CONDUCT.md'
console.log('Downloading Contributors Covenant...')
const getString = bent('string')
const coc = await getString(url)
console.log('Replacing e-mail address...')
const content = coc.replace('[INSERT CONTACT METHOD]', email)
if (dest.split(',').length > 1) {
const destinations = dest.split(',')
for (let i = 0; i < destinations.length; i++) {
await writeFile(destinations[i], content)
}
} else {
await writeFile(dest, content)
}
}