From 323abcae629e094ed0929bab47386832c64d17e5 Mon Sep 17 00:00:00 2001 From: sareyko Date: Mon, 1 Oct 2018 16:05:23 +0200 Subject: [PATCH] Make `--files-from` work like in gettext Fixes #74 --- index.js | 8 ++++++++ test/cli.js | 20 ++++++++++++++++++++ test/fixtures/list-crlf.txt | 1 + test/fixtures/list-ht.txt | 1 + 4 files changed, 30 insertions(+) create mode 100644 test/fixtures/list-crlf.txt create mode 100644 test/fixtures/list-ht.txt diff --git a/index.js b/index.js index e195dfd..1f455e3 100644 --- a/index.js +++ b/index.js @@ -195,6 +195,14 @@ function xgettext(input, options, cb) { if (options['files-from']) { input = fs.readFileSync(options['files-from'], options['from-code']) .split('\n') + .map(function (line) { + return line.split('').reduceRight(function(acc, c) { + if (' \t\r'.indexOf(c) === -1 || acc.length > 0) { + return c + acc; + } + return acc; + }, ''); + }) .filter(function (line) { return line.trim().length > 0; }); diff --git a/test/cli.js b/test/cli.js index 7b65f73..e8a6c4c 100644 --- a/test/cli.js +++ b/test/cli.js @@ -87,6 +87,26 @@ describe('CLI', function () { }); }); + it('should read input from a CR LF delimited file', function (done) { + run(['--output=-', '--files-from=fixtures/list-crlf.txt'], function (err) { + throw new Error(err); + }, function (code, data) { + assert.equal(0, code); + assert(data.match('This is a fixed sentence')); + done(); + }); + }); + + it('should read input from a HT delimited file', function (done) { + run(['--output=-', '--files-from=fixtures/list-ht.txt'], function (err) { + throw new Error(err); + }, function (code, data) { + assert.equal(0, code); + assert(data.match('This is a fixed sentence')); + done(); + }); + }); + it('should handle stdin input', function (done) { var child = run(['--output=-', '--language=Handlebars', '--from-code=utf8', '-'], function (err) { throw new Error(err); diff --git a/test/fixtures/list-crlf.txt b/test/fixtures/list-crlf.txt new file mode 100644 index 0000000..f996372 --- /dev/null +++ b/test/fixtures/list-crlf.txt @@ -0,0 +1 @@ +fixtures/template.hbs diff --git a/test/fixtures/list-ht.txt b/test/fixtures/list-ht.txt new file mode 100644 index 0000000..ecc3760 --- /dev/null +++ b/test/fixtures/list-ht.txt @@ -0,0 +1 @@ +fixtures/template.hbs \ No newline at end of file