next-translate-scanner
Version:
Scan next-translate code for translations and update json files.
65 lines (64 loc) • 2.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __importDefault(require("./logger"));
const commander_1 = require("commander");
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const getMergedConfig = () => {
let config = {
input: [],
locales: ['en'],
pseudoLocale: null,
keySeparator: '.',
nsSeparator: ':',
defaultNS: undefined,
sort: true,
keepRemoved: true,
output: './locales/$LOCALE/$NAMESPACE.json',
defaultValue: () => null,
indentation: 2,
replaceDefaults: false,
failOnWarnings: false
};
logger_1.default.setSilent(commander_1.program.opts().silent);
try {
config = {
...config,
...require(path_1.default.resolve(commander_1.program.opts().config))
};
}
catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
commander_1.program.error(chalk_1.default.red(`Config file does not exist: ${commander_1.program.opts().config}`));
}
else {
throw err;
}
}
config.output = commander_1.program.opts().output || config.output;
const args = commander_1.program.args || [];
let inputs = [];
// prefer globs specified in the cli
if (args.length) {
inputs = args;
}
else if (config.input) {
if (!Array.isArray(config.input)) {
if (typeof config.input === 'string') {
config.input = [config.input];
}
else {
logger_1.default.error(`'input' must be an array when specified in the config`, true);
}
}
inputs = config.input;
}
if (!inputs.length) {
logger_1.default.error(`no file paths specified`, true);
}
return { config, inputs };
};
exports.default = getMergedConfig;