1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-09 21:30:05 +00:00

fix(node): only create and write file stream if running in node

This commit is contained in:
Krishna Acondy
2021-07-23 22:24:41 +01:00
parent 15d5f9ec91
commit 281a145bef
2 changed files with 32 additions and 28 deletions

View File

@@ -0,0 +1,16 @@
import { isFolder } from '@sasjs/utils/file'
import { generateTimestamp } from '@sasjs/utils/time'
import { Job } from '../../types'
export const getFileStream = async (job: Job, filePath?: string) => {
const { createWriteStream } = require('@sasjs/utils/file')
const logPath = filePath || process.cwd()
const isFolderPath = await isFolder(logPath)
if (isFolderPath) {
const logFileName = `${job.name || 'job'}-${generateTimestamp()}.log`
const logFilePath = `${filePath || process.cwd()}/${logFileName}`
return await createWriteStream(logFilePath)
} else {
return await createWriteStream(logPath)
}
}