Skip to content

Commit

Permalink
fix(writeFile): get app root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sarabveer committed Dec 4, 2023
1 parent 97c9371 commit 7830cfb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/writeFile.js
Original file line number Diff line number Diff line change
@@ -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' },
)
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7830cfb

Please sign in to comment.