in src/FileUpdater.js [225:281]
function mergeAndUpdateDir (sourceDirs, targetDir, options, log) {
if (sourceDirs && typeof sourceDirs === 'string') {
sourceDirs = [sourceDirs];
} else if (!Array.isArray(sourceDirs)) {
throw new Error('A source directory path or array of paths is required.');
}
if (!targetDir || typeof targetDir !== 'string') {
throw new Error('A target directory path is required.');
}
const rootDir = (options && options.rootDir) || '';
let include = (options && options.include) || ['**'];
if (typeof include === 'string') {
include = [include];
} else if (!Array.isArray(include)) {
throw new Error('Include parameter must be a glob string or array of glob strings.');
}
let exclude = (options && options.exclude) || [];
if (typeof exclude === 'string') {
exclude = [exclude];
} else if (!Array.isArray(exclude)) {
throw new Error('Exclude parameter must be a glob string or array of glob strings.');
}
// Scan the files in each of the source directories.
const sourceMaps = sourceDirs.map(sourceDir => {
const sourcePath = path.join(rootDir, sourceDir);
if (!fs.existsSync(sourcePath)) {
throw new Error(`Source directory does not exist: ${sourcePath}`);
}
return mapDirectory(rootDir, sourceDir, include, exclude);
});
// Scan the files in the target directory, if it exists.
const targetFullPath = path.join(rootDir, targetDir);
const targetMap = fs.existsSync(targetFullPath)
? mapDirectory(rootDir, targetDir, include, exclude)
: {};
const pathMap = mergePathMaps(sourceMaps, targetMap, targetDir);
// Iterate in sorted order for nicer logs
return Object.keys(pathMap).sort().map(subPath => {
const entry = pathMap[subPath];
return updatePathWithStats(
entry.sourcePath,
entry.sourceStats,
entry.targetPath,
entry.targetStats,
options,
log
);
}).some(updated => updated);
}