ctagz.js
function findCTagsFile(searchPath, tagFilePattern = '{.,}tags') {
    const ctagsFinder = function ctagsFinder(tagPath) {
        console.error(`ctagz: Searching ${tagPath}`)
        return fs.readdirAsync(tagPath).then(files => {
            const matched = files.filter(minimatch.filter(tagFilePattern)).sort()
            const ret = !matched ? Promise.resolve(null) :
                Promise.reduce(matched, (acc, match) => {
                    if (acc) {
                        return acc
                    }
                    const matchPath = path.join(tagPath, match)
                    return fs.statAsync(matchPath).then(stats => {
                        if (!stats.isFile()) {
                            return null
                        }

                        return fs.openAsync(matchPath, 'r').then(fd => new CTags(matchPath, fd))
                            .catch(() => null)
                    })
                }, null)

            return ret.then(result => {
                const newTagPath = path.dirname(tagPath)
                if (!result && newTagPath !== tagPath) {
                    return ctagsFinder(newTagPath)
                }
                return result
            })
        })
    }

    let tagPath = path.resolve(searchPath)
    return fs.statAsync(tagPath).then(stats => {
        if (stats.isFile()) {
            tagPath = path.dirname(tagPath)
        }
        return ctagsFinder(tagPath)
    })
}
function findCTagsFile(searchPath, tagFilePattern = '{.,}tags') {
    const ctagsFinder = function ctagsFinder(tagPath) {
        console.error(`ctagz: Searching ${tagPath}`)
        return fs.readdirAsync(tagPath).then(files => {
            const matched = files.filter(minimatch.filter(tagFilePattern)).sort()
            const ret = !matched ? Promise.resolve(null) :
                Promise.reduce(matched, (acc, match) => {
                    if (acc) {
                        return acc
                    }
                    const matchPath = path.join(tagPath, match)
                    return fs.statAsync(matchPath).then(stats => {
                        if (!stats.isFile()) {
                            return null
                        }

                        return fs.openAsync(matchPath, 'r').then(fd => new CTags(matchPath, fd))
                            .catch(() => null)
                    })
                }, null)

            return ret.then(result => {
                const newTagPath = path.dirname(tagPath)
                if (!result && newTagPath !== tagPath) {
                    return ctagsFinder(newTagPath)
                }
                return result
            })
        })
    }

    let tagPath = path.resolve(searchPath)
    return fs.statAsync(tagPath).then(stats => {
        if (stats.isFile()) {
            tagPath = path.dirname(tagPath)
        }
        return ctagsFinder(tagPath)
    })
}
function findCTagsFile ( searchPath , tagFilePattern = '{.,}tags' ) { const ctagsFinder = function ctagsFinder ( tagPath ) { console . error ( ` ${ tagPath } ` ) return fs . readdirAsync ( tagPath ) . then ( files => { const matched = files . filter ( minimatch . filter ( tagFilePattern ) ) . sort ( ) const ret = ! matched ? Promise . resolve ( null ) : Promise . reduce ( matched , ( acc , match ) => { if ( acc ) { return acc } const matchPath = path . join ( tagPath , match ) return fs . statAsync ( matchPath ) . then ( stats => { if ( ! stats . isFile ( ) ) { return null } return fs . openAsync ( matchPath , 'r' ) . then ( fd => new CTags ( matchPath , fd ) ) . catch ( ( ) => null ) } ) } , null ) return ret . then ( result => { const newTagPath = path . dirname ( tagPath ) if ( ! result && newTagPath !== tagPath ) { return ctagsFinder ( newTagPath ) } return result } ) } ) } let tagPath = path . resolve ( searchPath ) return fs . statAsync ( tagPath ) . then ( stats => { if ( stats . isFile ( ) ) { tagPath = path . dirname ( tagPath ) } return ctagsFinder ( tagPath ) } ) }
Finds the CTags file from the specified search path and pattern
@param {string} searchPath The path to search. This may either be a
file or directory. If a file is passed,
its directory is searched. If the tag file
is not found, its parent directories are
then searched.
@param {string} tagFilePattern The search pattern to use when searching
for the tag file. This pattern can be
anything that the minimatch package
supports. However, if more than one file
matches, the results are sorted, and only
the first file is used as the tag file.
@return {any[]} An new CTags instance.
The caller call destroy() when finished with it.
Finds the CTags file from the specified search path and pattern