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:
16
src/api/viya/getFileStream.ts
Normal file
16
src/api/viya/getFileStream.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user