mirror of
https://github.com/zhigang1992/replace-in-file.git
synced 2026-06-15 10:37:52 +08:00
* Bump dependencies * [feature] #38 Count number of matches * Update make-replacements.js * [feature] #42 Differentiate number of matches and number of replacements * [enhance] #56 Support for CWD parameter * Default config value * [enhance] #63 Add --quiet flag to supress console output in CLI * Update success-handler.js * Update readme and add change log
43 lines
825 B
JavaScript
43 lines
825 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Dependencies
|
|
*/
|
|
const glob = require('glob');
|
|
|
|
/**
|
|
* Get paths (sync)
|
|
*/
|
|
module.exports = function getPathsSync(patterns, config) {
|
|
|
|
//Extract relevant config
|
|
const {ignore, disableGlobs, glob: globConfig, cwd} = config;
|
|
|
|
//Not using globs?
|
|
if (disableGlobs) {
|
|
return patterns;
|
|
}
|
|
|
|
//Prepare glob config
|
|
const cfg = Object.assign({ignore}, globConfig, {nodir: true});
|
|
|
|
//Append CWD configuration if given (#56)
|
|
//istanbul ignore if
|
|
if (cwd) {
|
|
cfg.cwd = cwd;
|
|
}
|
|
|
|
//Get paths
|
|
const paths = patterns.map(pattern => glob.sync(pattern, cfg));
|
|
const flattened = [].concat.apply([], paths);
|
|
|
|
//Prefix each path with CWD if given (#56)
|
|
//istanbul ignore if
|
|
if (cwd) {
|
|
return flattened.map(path => `${cwd}${path}`);
|
|
}
|
|
|
|
//Return flattened
|
|
return flattened;
|
|
};
|