<commit_before>#!/usr/bin/env node

const Promise = require('bluebird');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const program = require('commander');
const { red, green, blue, yellow } = require('chalk');

const i18nextConv = require('../lib');
const plurals = require('../lib/plurals');

const writeFileAsync = Promise.promisify(fs.writeFile);
const readFileAsync = Promise.promisify(fs.readFile);
const {
  gettextToI18next,
  i18nextToPo,
  i18nextToPot,
  i18nextToMo,
} = i18nextConv;

// test calls:

// gettext -> i18next
// node bin -l en -s ./test/_testfiles/en/translation.utf8.po -t ./test/_tmp/en.json
// node bin -l de -s ./test/_testfiles/de/translation.utf8.po -t ./test/_tmp/de.json
// node bin -l ru -s ./test/_testfiles/ru/translation.utf8.po -t ./test/_tmp/ru.json

// With filter:
// node bin -l en -s ./test/_testfiles/en/translation.utf8.po -t ./test/_tmp/en.json -f path/to/filter.js

// i18next -> gettext
// node bin -l de -s ./test/_testfiles/de/translation.utf8.json -t ./test/_tmp/de.po
// and back
// node bin -l de -s ./test/_tmp/de.po -t ./test/_tmp/de.json

// program
program
  .version(i18nextConv.version)
  .option('-b, --base [path]', 'Sepcify path for the base language file. only take effect with -K option', '')
  .option('-f, --filter [path]', 'Specify path to gettext filter')
  .option('-l, --language [domain]', 'Specify the language code, eg. \'en\'')
  .option('-p, --pot', 'Generate POT file.')
  .option('-s, --source [path]', 'Specify path to read from')
  .option('-t, --target [path]', 'Specify path to write to', '')
  .option('-K, --keyasareference', 'Deal with the reference comment as a key', false)
  .option('-ks, --keyseparator [path]', 'Specify keyseparator you want to use, defaults to ##', '##')
  .option('-P, --plurals [path]', 'Specify path to plural forms definitions')
  .option('--project', 'Specify the project-id-version when converting json to gettext')
  .option('--quiet', 'Silence output', false)
  .option('--skipUntranslated', 'Skip untranslated keys when converting into json', false)
  .option('--splitNewLine', 'Silence output', false)
  .option('--ctxSeparator [sep]', 'Specify the context separator', '_')
  .option('--ignorePlurals', 'Do not process the plurals')
  .parse(process.argv);

const {
  source,
  target,
  filter,
  ...options
} = program;

if (filter && fs.existsSync(filter)) {
  options.filter = require(filter); // eslint-disable-line global-require,import/no-dynamic-require
}

if (base && fs.existsSync(base)) {
  options.base = fs.readFileSync(base);
}

const {
  language,
  pot,
  base,
} = options;
<commit_msg>Fix cli project option<commit_after>#!/usr/bin/env node

const Promise = require('bluebird');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const program = require('commander');
const { red, green, blue, yellow } = require('chalk');

const i18nextConv = require('../lib');
const plurals = require('../lib/plurals');

const writeFileAsync = Promise.promisify(fs.writeFile);
const readFileAsync = Promise.promisify(fs.readFile);
const {
  gettextToI18next,
  i18nextToPo,
  i18nextToPot,
  i18nextToMo,
} = i18nextConv;

// test calls:

// gettext -> i18next
// node bin -l en -s ./test/_testfiles/en/translation.utf8.po -t ./test/_tmp/en.json
// node bin -l de -s ./test/_testfiles/de/translation.utf8.po -t ./test/_tmp/de.json
// node bin -l ru -s ./test/_testfiles/ru/translation.utf8.po -t ./test/_tmp/ru.json

// With filter:
// node bin -l en -s ./test/_testfiles/en/translation.utf8.po -t ./test/_tmp/en.json -f path/to/filter.js

// i18next -> gettext
// node bin -l de -s ./test/_testfiles/de/translation.utf8.json -t ./test/_tmp/de.po
// and back
// node bin -l de -s ./test/_tmp/de.po -t ./test/_tmp/de.json

// program
program
  .version(i18nextConv.version)
  .option('-b, --base [path]', 'Sepcify path for the base language file. only take effect with -K option', '')
  .option('-f, --filter [path]', 'Specify path to gettext filter')
  .option('-l, --language [domain]', 'Specify the language code, eg. \'en\'')
  .option('-p, --pot', 'Generate POT file.')
  .option('-s, --source [path]', 'Specify path to read from')
  .option('-t, --target [path]', 'Specify path to write to', '')
  .option('-K, --keyasareference', 'Deal with the reference comment as a key', false)
  .option('-ks, --keyseparator [path]', 'Specify keyseparator you want to use, defaults to ##', '##')
  .option('-P, --plurals [path]', 'Specify path to plural forms definitions')
  .option('--project [name]', 'Specify the project-id-version when converting json to gettext')
  .option('--quiet', 'Silence output', false)
  .option('--skipUntranslated', 'Skip untranslated keys when converting into json', false)
  .option('--splitNewLine', 'Silence output', false)
  .option('--ctxSeparator [sep]', 'Specify the context separator', '_')
  .option('--ignorePlurals', 'Do not process the plurals')
  .parse(process.argv);

const {
  source,
  target,
  filter,
  ...options
} = program;

if (filter && fs.existsSync(filter)) {
  options.filter = require(filter); // eslint-disable-line global-require,import/no-dynamic-require
}

if (base && fs.existsSync(base)) {
  options.base = fs.readFileSync(base);
}

const {
  language,
  pot,
  base,
} = options;

{'fraction_non_alphanumeric': 0.18362004487658937, 'fraction_numerical': 0.008601346297681375, 'mean_word_length': 3.544604927782498, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '758723', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1843, 'n_words': 506}