From b005b9ff13194804205f58fd1071b621689cf158 Mon Sep 17 00:00:00 2001 From: kurokeita Date: Wed, 26 Jun 2024 10:47:44 +0700 Subject: [PATCH 1/2] properly construct the generated data with same structure as the source data --- cli/build/index.js | 6 ++++++ cli/sync/index.js | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/build/index.js b/cli/build/index.js index 589b80a..0d4ddcd 100755 --- a/cli/build/index.js +++ b/cli/build/index.js @@ -60,6 +60,12 @@ run(async () => { // @type { quotes: Quote[], authors: Author[], tags: Tag[] } const db = parseDataFiles(DEST) + Object.keys(src).forEach(key => { + if (typeof db.key === 'undefined') { + db[key] = [] + } + }) + // Apply transforms to the source data to create the generated data files // This will add computed properties that are not included in the source // data files. diff --git a/cli/sync/index.js b/cli/sync/index.js index a8f28fd..2cbb83b 100644 --- a/cli/sync/index.js +++ b/cli/sync/index.js @@ -33,7 +33,8 @@ try { await testConnection() log.newLine() - const dataFiles = parseDataFiles(dataDir.generated) + const dataSrc = args.d || args.dest || dataDir.generated + const dataFiles = parseDataFiles(dataSrc) // Connect to the database await client.connect() From 0b0cdd471a94626398cbb61d4634e100811c014c Mon Sep 17 00:00:00 2001 From: kurokeita Date: Wed, 26 Jun 2024 10:51:21 +0700 Subject: [PATCH 2/2] update the README for `sync` module to reflect the correct command --- cli/sync/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/sync/README.md b/cli/sync/README.md index 091e8d3..75ebf2f 100644 --- a/cli/sync/README.md +++ b/cli/sync/README.md @@ -14,7 +14,7 @@ Before running this command, make sure you run the build command to create / upd ## Usage ```sh -$ node cli/syncData [] [..options] +$ node cli/sync [] [..options] ``` ## Options