src/fs.js
function copyFiles(sourceDir, files, options = {}) {
	const { overwrite = true, errorOnExist } = options;

	_.castArray(files).forEach(file => {
		const sourcePath = path.resolve(sourceDir, file);
		if (!fs.existsSync(sourcePath)) {
			throw new MrmError(`copyFiles: source file not found: ${sourcePath}`);
		}

		const targetExist = fs.existsSync(file);
		if (targetExist && !overwrite) {
			if (errorOnExist) {
				throw new MrmError(`copyFiles: target file already exists: ${file}`);
			}
			return;
		}

		const content = read(sourcePath);

		// Skip copy if file contents are the same
		if (content === read(file)) {
			return;
		}

		updateFile(file, content, targetExist);
	});
}
function copyFiles(sourceDir, files, options = {}) {
	const { overwrite = true, errorOnExist } = options;

	_.castArray(files).forEach(file => {
		const sourcePath = path.resolve(sourceDir, file);
		if (!fs.existsSync(sourcePath)) {
			throw new MrmError(`copyFiles: source file not found: ${sourcePath}`);
		}

		const targetExist = fs.existsSync(file);
		if (targetExist && !overwrite) {
			if (errorOnExist) {
				throw new MrmError(`copyFiles: target file already exists: ${file}`);
			}
			return;
		}

		const content = read(sourcePath);

		// Skip copy if file contents are the same
		if (content === read(file)) {
			return;
		}

		updateFile(file, content, targetExist);
	});
}
function copyFiles ( sourceDir , files , options = { } ) { const { overwrite = true , errorOnExist } = options ; _ . castArray ( files ) . forEach ( file => { const sourcePath = path . resolve ( sourceDir , file ) ; if ( ! fs . existsSync ( sourcePath ) ) { throw new MrmError ( ` ${ sourcePath } ` ) ; } const targetExist = fs . existsSync ( file ) ; if ( targetExist && ! overwrite ) { if ( errorOnExist ) { throw new MrmError ( ` ${ file } ` ) ; } return ; } const content = read ( sourcePath ) ; // Skip copy if file contents are the same if ( content === read ( file ) ) { return ; } updateFile ( file , content , targetExist ) ; } ) ; }
Copy files from a given directory to the current working directory
Copy files from a given directory to the current working directory