40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import settle from 'p-settle'
|
|
import { promisify } from 'util'
|
|
import { readFile } from 'fs'
|
|
import path from 'path'
|
|
const read = promisify(readFile)
|
|
|
|
// A helper function to return a list of paths to ignore from .npmignore, .gitignore, .rcignore
|
|
function ignore (repoPath,files) {
|
|
// console.log('additional files', files)
|
|
let ignoreList = []
|
|
let ignoreFiles = ['.npmignore','.gitignore','.rcignore']
|
|
if (Array.isArray(files)) {
|
|
ignoreFiles=[...ignoreFiles,...files]
|
|
} else {
|
|
if (files) ignoreFiles.push(files)
|
|
}
|
|
|
|
// each set in an the array is new line delimited set of ignore patterns
|
|
return settle(ignoreFiles.map(file => {
|
|
// console.log('directory',path.dirname(file))
|
|
if (path.dirname(file)==='.') file = repoPath+'/'+file
|
|
// console.log('file', file)
|
|
return read(file)
|
|
}))
|
|
.then((sets) => {
|
|
sets.forEach( set => {
|
|
if (set.isFulfilled) ignoreList.push(...set.value.toString().match(/.+/g))
|
|
else console.log('READ ERROR=> ',set.reason.Error)
|
|
})
|
|
// console.log('built list=====================', ignoreList)
|
|
return Promise.resolve(ignoreList)
|
|
})
|
|
.catch((err) => {
|
|
// only returned when something horrible is wrong
|
|
return Promise.reject(err)
|
|
})
|
|
}
|
|
|
|
export default ignore
|