Skip to content

Commit

Permalink
update yaml dependency and fix the handling of empty ns
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Jan 19, 2021
1 parent 7a39a57 commit 419f202
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
Project versioning adheres to [Semantic Versioning](http://semver.org/).
Change log format is based on [Keep a Changelog](http://keepachangelog.com/).

## [7.6.9](https://github.com/locize/locize-cli/compare/v7.6.8...v7.6.9) - 2021-01-19

- update yaml dependency and fix the handling of empty ns


## [7.6.8](https://github.com/locize/locize-cli/compare/v7.6.7...v7.6.8) - 2020-12-11

- fix edge-case in unflatten function
Expand Down
10 changes: 7 additions & 3 deletions convertToDesiredFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const convertToDesiredFormat = (
cb
) => {
opt.getNamespace = opt.getNamespace || getRemoteNamespace;
const isEmpty = !data || Object.keys(data).length === 0;
try {
if (opt.format === 'json') {
try {
Expand Down Expand Up @@ -129,18 +130,21 @@ const convertToDesiredFormat = (
return;
}
if (opt.format === 'yaml') {
cb(null, jsyaml.safeDump(flatten(data)));
if (isEmpty) return cb(null, '');
cb(null, jsyaml.dump(flatten(data)));
return;
}
if (opt.format === 'yaml-nested') {
cb(null, jsyaml.safeDump(shouldUnflatten(data) ? unflatten(data) : data));
if (isEmpty) return cb(null, '');
cb(null, jsyaml.dump(shouldUnflatten(data) ? unflatten(data) : data));
return;
}
if (opt.format === 'yaml-rails') {
if (isEmpty) return cb(null, '');
var newData = {};
newData[lng] = {};
newData[lng][namespace] = shouldUnflatten(data) ? unflatten(data) : data;
cb(null, jsyaml.safeDump(removeUndefinedFromArrays(newData)));
cb(null, jsyaml.dump(removeUndefinedFromArrays(newData)));
return;
}
if (opt.format === 'android') {
Expand Down
12 changes: 9 additions & 3 deletions convertToFlatFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ const convertToFlatFormat = (opt, data, lng, cb) => {
return;
}
if (opt.format === 'yaml') {
cb(null, flatten(jsyaml.safeLoad(data)));
const d = data.toString();
if (!d || d === '') return cb(null, {});
cb(null, flatten(jsyaml.load(d)));
return;
}
if (opt.format === 'yaml-nested') {
cb(null, flatten(jsyaml.safeLoad(data)));
const d = data.toString();
if (!d || d === '') return cb(null, {});
cb(null, flatten(jsyaml.load(d)));
return;
}
if (opt.format === 'yaml-rails') {
const jsObj = jsyaml.safeLoad(data);
const d = data.toString();
if (!d || d === '') return cb(null, {});
const jsObj = jsyaml.load(d);
cb(
null,
flatten(
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"colors": "1.4.0",
"commander": "6.2.0",
"csvjson": "5.1.0",
"diff": "4.0.2",
"diff": "5.0.0",
"flat": "5.0.2",
"fluent_conv": "3.0.1",
"gettext-converter": "1.0.6",
"ini": "1.3.7",
"js-yaml": "3.14.1",
"ini": "2.0.0",
"js-yaml": "4.0.0",
"laravelphp": "2.0.3",
"lodash.clonedeep": "4.5.0",
"mkdirp": "1.0.4",
Expand All @@ -31,7 +31,7 @@
"xlsx": "0.16.9"
},
"devDependencies": {
"eslint": "7.15.0",
"eslint": "7.18.0",
"gh-release": "4.0.4",
"pkg": "4.4.9"
},
Expand Down

0 comments on commit 419f202

Please sign in to comment.