diff --git a/CHANGELOG.md b/CHANGELOG.md index ab18dada..fe1113cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/listeners/dashboard/DataListener.ts b/src/listeners/dashboard/DataListener.ts index 4497e0ac..969beef3 100644 --- a/src/listeners/dashboard/DataListener.ts +++ b/src/listeners/dashboard/DataListener.ts @@ -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);