From 7830cfb1dd9b4fcf7eba17c7a79e1e3a2854e0f2 Mon Sep 17 00:00:00 2001 From: Sarabveer Singh Date: Mon, 4 Dec 2023 00:54:31 -0500 Subject: [PATCH] fix(writeFile): get app root directory --- lib/writeFile.js | 5 +++-- package-lock.json | 9 +++++++++ package.json | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/writeFile.js b/lib/writeFile.js index 110e0a5..8ce2d3c 100644 --- a/lib/writeFile.js +++ b/lib/writeFile.js @@ -1,16 +1,17 @@ import { mkdirSync, writeFileSync } from 'fs' +import appRoot from 'app-root-path' const writeFile = ( { date: dateStr, ids, sttmIds } ) => { const date = dateStr.split( '-' ) // Create folder if not exists - mkdirSync( `./archive/${date[ 0 ]}/${date[ 1 ]}`, { recursive: true } ) + mkdirSync( `${appRoot}/archive/${date[ 0 ]}/${date[ 1 ]}`, { recursive: true } ) // Write file // Error if already exists try { writeFileSync( - `./archive/${date[ 0 ]}/${date[ 1 ]}/${date[ 2 ]}.json`, + `${appRoot}/archive/${date[ 0 ]}/${date[ 1 ]}/${date[ 2 ]}.json`, `${JSON.stringify( { sttm2_ids: sttmIds, shabad_ids: ids }, null, 2 )}\n`, { flag: 'wx' }, ) diff --git a/package-lock.json b/package-lock.json index 931f8b4..6cf7c2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@gurbaninow/database": "^5.0.0-beta", + "app-root-path": "^3.1.0", "date-fns": "^2.30.0", "date-fns-tz": "^2.0.0", "fast-xml-parser": "^4.3.2", @@ -1814,6 +1815,14 @@ "node": ">=5.0.0" } }, + "node_modules/app-root-path": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.1.0.tgz", + "integrity": "sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", diff --git a/package.json b/package.json index 326f98a..0fca73e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "homepage": "https://github.com/gurbaninow/hukamnama-archive#readme", "dependencies": { "@gurbaninow/database": "^5.0.0-beta", + "app-root-path": "^3.1.0", "date-fns": "^2.30.0", "date-fns-tz": "^2.0.0", "fast-xml-parser": "^4.3.2",