Make app export append a trailing newline to the app.json files so that we match prettier.

This commit is contained in:
Cory McWilliams 2024-02-24 11:12:35 -05:00
parent d5267be38c
commit 70a3e7fc7d
2 changed files with 8 additions and 4 deletions

View File

@ -11,12 +11,16 @@
#include <stdlib.h>
#include <string.h>
static void _write_file(const char* path, const void* blob, size_t size)
static void _write_file(const char* path, const void* blob, size_t size, bool force_add_trailing_newline)
{
FILE* file = fopen(path, "wb");
if (file)
{
fwrite(blob, 1, size, file);
if (force_add_trailing_newline)
{
fputc('\n', file);
}
fclose(file);
}
else
@ -147,7 +151,7 @@ void tf_ssb_export(tf_ssb_t* ssb, const char* key)
if (tf_ssb_db_blob_get(ssb, blob_id, &file_blob, &file_size))
{
snprintf(file_path, sizeof(file_path), "apps/%s/%s", path, file_name);
_write_file(file_path, file_blob, file_size);
_write_file(file_path, file_blob, file_size, false);
tf_free(file_blob);
}
@ -177,7 +181,7 @@ void tf_ssb_export(tf_ssb_t* ssb, const char* key)
size_t length = 0;
const char* string = JS_ToCStringLen(context, &length, json);
snprintf(file_path, sizeof(file_path), "apps/%s.json", path);
_write_file(file_path, string, length);
_write_file(file_path, string, length, true);
JS_FreeCString(context, string);
JS_FreeValue(context, json);