Pretty print settings file json

Summary: Making it a bit more human readable.

Reviewed By: passy

Differential Revision: D18271880

fbshipit-source-id: 10e8ba50957e9407b1436972f8a06915edf73dfb
This commit is contained in:
John Knox
2019-11-04 07:05:45 -08:00
committed by Facebook Github Bot
parent 6e69d20917
commit 61d4e0c6a5
2 changed files with 17 additions and 4 deletions

View File

@@ -1 +1,10 @@
{"androidHome":"/opt/android_sdk","something":{"else":4},"_persist":{"version":-1,"rehydrated":true}}
{
"androidHome": "/opt/android_sdk",
"something": {
"else": 4
},
"_persist": {
"version": -1,
"rehydrated": true
}
}

View File

@@ -35,7 +35,7 @@ export default class JsonFileStorage {
console.warn(
`Failed to read settings file: "${this.filepath}". ${e}. Replacing file with default settings.`,
);
return this.writeContents(JSON.stringify({})).then(() => ({}));
return this.writeContents(prettyStringify({})).then(() => ({}));
});
}
@@ -61,7 +61,7 @@ export default class JsonFileStorage {
}
removeItem(_key: string, callback?: () => any): Promise<void> {
return this.writeContents(JSON.stringify({}))
return this.writeContents(prettyStringify({}))
.then(_ => callback && callback())
.then(() => {});
}
@@ -73,7 +73,7 @@ export default class JsonFileStorage {
acc[cv[0]] = cv[1];
return acc;
}, {});
return JSON.stringify(reconstructedObject);
return prettyStringify(reconstructedObject);
}
deserializeValue(value: string): string {
@@ -95,3 +95,7 @@ export default class JsonFileStorage {
.then(() => promises.writeFile(this.filepath, content));
}
}
function prettyStringify(data: Object) {
return JSON.stringify(data, null, 2);
}