mirror of
https://github.com/sasjs/server.git
synced 2026-01-12 00:30:06 +00:00
feat(execute): add macroVars to job execution
This commit is contained in:
@@ -3,14 +3,15 @@ import {
|
||||
readFile,
|
||||
generateTimestamp,
|
||||
deleteFile,
|
||||
fileExists
|
||||
fileExists,
|
||||
createFile
|
||||
} from '@sasjs/utils'
|
||||
import path from 'path'
|
||||
import { ExecutionResult, ExecutionQuery } from '../types'
|
||||
import {
|
||||
getTmpFolderPath,
|
||||
getTmpFilesFolderPath,
|
||||
getTmpLogFolderPath
|
||||
getTmpLogFolderPath,
|
||||
getTmpWeboutFolderPath
|
||||
} from '../utils'
|
||||
import { configuration } from '../../package.json'
|
||||
|
||||
@@ -27,11 +28,36 @@ export const processSas = async (
|
||||
|
||||
const sasFile: string = sasCodePath.split(path.sep).pop() || 'default'
|
||||
|
||||
const sasWeboutPath = path.join(
|
||||
getTmpWeboutFolderPath(),
|
||||
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.json'].join(
|
||||
''
|
||||
)
|
||||
)
|
||||
|
||||
let sasCode = await readFile(sasCodePath)
|
||||
const originalSasCode = sasCode
|
||||
|
||||
if (query.macroVars) {
|
||||
const macroVars = query.macroVars.macroVars
|
||||
|
||||
Object.keys(macroVars).forEach(
|
||||
(key: string) =>
|
||||
(sasCode = `%let ${key}=${macroVars[key]};\n${sasCode}`)
|
||||
)
|
||||
}
|
||||
|
||||
sasCode = `filename _webout "${sasWeboutPath}";\n${sasCode}`
|
||||
|
||||
await createFile(sasCodePath, sasCode)
|
||||
|
||||
const sasLogPath = path.join(
|
||||
getTmpLogFolderPath(),
|
||||
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.log'].join('')
|
||||
)
|
||||
|
||||
await createFile(sasLogPath, '')
|
||||
|
||||
execFile(
|
||||
configuration.sasPath,
|
||||
['-SYSIN', sasCodePath, '-log', sasLogPath, '-nosplash'],
|
||||
@@ -41,7 +67,9 @@ export const processSas = async (
|
||||
|
||||
const log = await readFile(sasLogPath)
|
||||
|
||||
// deleteFile(sasLogPath)
|
||||
deleteFile(sasLogPath)
|
||||
|
||||
await createFile(sasCodePath, originalSasCode)
|
||||
|
||||
resolve({ log: log, logPath: sasLogPath })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user