Skip to content

Commit

Permalink
Fix lilconfig loader when no config file is being passed fix #690
Browse files Browse the repository at this point in the history
  • Loading branch information
karellm committed Nov 14, 2022
1 parent 81acff4 commit 1cfb14e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -45,7 +45,7 @@ Multiple globbing patterns are supported to specify complex file selections. You

**IMPORTANT NOTE**: If you pass the globs as CLI argument, they must be relative to where you run the command (aka relative to `process.cwd()`). If you pass the globs via the `input` option of the config file, they must be relative to the config file.

- **-c, --config <path>**: Path to the config file (default: i18next-parser.config.js).
- **-c, --config <path>**: Path to the config file (default: i18next-parser.config.{js,json,ts,yaml,yml}).
- **-o, --output <path>**: Path to the output directory (default: locales/$LOCALE/$NAMESPACE.json).
- **-s, --silent**: Disable logging to stdout.
- **--fail-on-warnings**: Exit with an exit code of 1 on warnings
Expand Down
12 changes: 10 additions & 2 deletions bin/cli.js
Expand Up @@ -53,7 +53,7 @@ import i18nTransform from '../dist/transform.js'

let config = {}
try {
const result = await lilconfig(pkg.name, {
const lilcongifOptions = {
searchPlaces: [
`${pkg.name}.config.js`,
`${pkg.name}.config.json`,
Expand All @@ -67,7 +67,15 @@ import i18nTransform from '../dist/transform.js'
'.yaml': yamlConfigLoader,
'.yml': yamlConfigLoader,
},
}).load(program.opts().config)
}
let result
if (program.opts().config) {
result = await lilconfig(pkg.name, lilcongifOptions).load(
program.opts().config
)
} else {
result = await lilconfig(pkg.name, lilcongifOptions).search()
}
config = result.config
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"scripts": {
"coverage": "c8 --all --include='src/**/*[.js|.jsx|.ts|.tsx]' --reporter=lcov --reporter=text yarn test",
"test": "mocha -r @babel/register -r @babel/polyfill --recursive test/*.test.js test/**/*.test.js",
"test:cli": "yarn -s build && ./bin/cli.js -c test/cli/i18next-parser.config.js && ./bin/cli.js -c test/cli/i18next-parser.config.ts && ./bin/cli.js -c test/cli/i18next-parser.config.yaml",
"test:cli": "yarn -s build && ./bin/cli.js '**/*.html' && ./bin/cli.js -c test/cli/i18next-parser.config.js && ./bin/cli.js -c test/cli/i18next-parser.config.ts && ./bin/cli.js -c test/cli/i18next-parser.config.yaml",
"watch": "babel src -d dist -w",
"prettify": "prettier --write \"{src,test}/**/*.js\"",
"build": "babel src -d dist",
Expand Down

0 comments on commit 1cfb14e

Please sign in to comment.