mirror of
https://github.com/zhigang1992/replace-in-file.git
synced 2026-04-29 05:05:33 +08:00
30 lines
632 B
JavaScript
30 lines
632 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Dependencies
|
|
*/
|
|
const glob = require('glob');
|
|
|
|
/**
|
|
* Async wrapper for glob
|
|
*/
|
|
module.exports = function globAsync(pattern, ignore, allowEmptyPaths) {
|
|
return new Promise((resolve, reject) => {
|
|
glob(pattern, {ignore, nodir: true}, (error, files) => {
|
|
|
|
//istanbul ignore if: hard to make glob error
|
|
if (error) {
|
|
return reject(error);
|
|
}
|
|
|
|
//Error if no files match, unless allowed
|
|
if (!allowEmptyPaths && files.length === 0) {
|
|
return reject(new Error('No files match the pattern: ' + pattern));
|
|
}
|
|
|
|
//Resolve
|
|
resolve(files);
|
|
});
|
|
});
|
|
};
|