From 85de6a2dab5a83d6409ed8643cb03f800fae6435 Mon Sep 17 00:00:00 2001 From: Jan Brecka Date: Wed, 24 Feb 2016 19:44:36 +0100 Subject: [PATCH] assignInFile can write to different file --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 42d4010..dec68cb 100644 --- a/src/index.js +++ b/src/index.js @@ -37,9 +37,12 @@ function assign(template, assigns, keyMaker, valueMaker) { } function assignInFile(file, assigns, keyMaker, valueMaker) { - return fs.readFileAsync(file, encoding) + const input = Array.isArray(file) ? file[0] : file; + const output = Array.isArray(file) ? file[1] : file; + + return fs.readFileAsync(input, encoding) .then((content) => assign(content, assigns, keyMaker, valueMaker)) - .then((content) => fs.writeFileAsync(file, content, encoding)); + .then((content) => fs.writeFileAsync(output, content, encoding)); } function md5FileHash(file) {