#364 - Honour file ending rules in data files

This commit is contained in:
Elio Struyf
2022-06-28 09:04:38 +02:00
parent 8f4fe45d9e
commit a78d9c5906
2 changed files with 11 additions and 2 deletions
+1
View File
@@ -20,6 +20,7 @@
- [#348](https://github.com/estruyf/vscode-front-matter/issues/348): Fix media dashboard breadcrumb when multiple page folders are in use
- [#356](https://github.com/estruyf/vscode-front-matter/issues/356): Re-introduce the `labelField` to the `frontMatter.taxonomy.fieldGroups` setting
- [#358](https://github.com/estruyf/vscode-front-matter/issues/358): Fix for relative path of the public folder
- [#364](https://github.com/estruyf/vscode-front-matter/issues/364): Honour file ending rules in data files
## [7.3.4] - 2022-06-13
+10 -2
View File
@@ -1,3 +1,4 @@
import { workspace } from 'vscode';
import { DataFile } from './../../models/DataFile';
import { DashboardMessage } from "../../dashboardWebView/DashboardMessage";
import { BaseListener } from "./BaseListener";
@@ -30,6 +31,10 @@ export class DataListener extends BaseListener {
}
}
/**
* Process the data update
* @param msgData
*/
private static processDataUpdate(msgData: any) {
const { file, fileType, entries } = msgData as { file: string, fileType: string, entries: any[] };
@@ -41,11 +46,14 @@ export class DataListener extends BaseListener {
}
}
const insertFinalNewLine = workspace.getConfiguration().get('files.insertFinalNewline');
if (fileType === 'yaml') {
const yamlData = yaml.safeDump(entries);
writeFileSync(absPath, yamlData, 'utf8');
writeFileSync(absPath, insertFinalNewLine ? `${yamlData}\n` : yamlData, 'utf8');
} else {
writeFileSync(absPath, JSON.stringify(entries, null, 2));
const jsonData = JSON.stringify(entries, null, 2);
writeFileSync(absPath, insertFinalNewLine ? `${jsonData}\n` : jsonData, 'utf8');
}
this.processDataFile(msgData);