From 95843fa4c711aa695ee63ad265b8def4ba56360d Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Sun, 6 Mar 2022 01:57:14 +0500 Subject: [PATCH] fix: macros are available Sessions with SASAUTOS --- .gitignore | 1 + api/package.json | 8 +++++--- api/scripts/compileSysInit.ts | 1 - api/scripts/copySASjsCore.ts | 25 +++++++++++++++++++++++ api/src/controllers/internal/Execution.ts | 5 ++++- api/src/controllers/internal/Session.ts | 5 ++++- api/src/utils/file.ts | 2 ++ 7 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 api/scripts/copySASjsCore.ts diff --git a/.gitignore b/.gitignore index 3d08c5d..00a8877 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ sas/ tmp/ build/ sasjsbuild/ +sasjscore/ certificates/ executables/ .env diff --git a/api/package.json b/api/package.json index 02ba0b2..b08c4f5 100644 --- a/api/package.json +++ b/api/package.json @@ -4,7 +4,7 @@ "description": "Api of SASjs server", "main": "./src/server.ts", "scripts": { - "initial": "npm run swagger && npm run compileSysInit", + "initial": "npm run swagger && npm run compileSysInit && npm run copySASjsCore", "prestart": "npm run initial", "prebuild": "npm run initial", "start": "nodemon ./src/server.ts", @@ -16,11 +16,13 @@ "lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"", "package:lib": "npm run build && cp ./package.json build && cp README.md build && cd build && npm version \"5.0.0\" && npm pack", "exe": "npm run build && npm run exe:copy && pkg .", - "exe:copy": "npm run public:copy && npm run sasjsbuild:copy && npm run web:copy", + "exe:copy": "npm run public:copy && npm run sasjsbuild:copy && npm run sasjscore:copy && npm run web:copy", "public:copy": "cp -r ./public/ ./build/public/", "sasjsbuild:copy": "cp -r ./sasjsbuild/ ./build/sasjsbuild/", + "sasjscore:copy": "cp -r ./sasjscore/ ./build/sasjscore/", "web:copy": "rimraf web && mkdir web && cp -r ../web/build/ ./web/build/", - "compileSysInit": "ts-node ./scripts/compileSysInit.ts" + "compileSysInit": "ts-node ./scripts/compileSysInit.ts", + "copySASjsCore": "ts-node ./scripts/copySASjsCore.ts" }, "bin": "./build/src/server.js", "pkg": { diff --git a/api/scripts/compileSysInit.ts b/api/scripts/compileSysInit.ts index 2aa5443..58438e7 100644 --- a/api/scripts/compileSysInit.ts +++ b/api/scripts/compileSysInit.ts @@ -21,7 +21,6 @@ const compiledSystemInit = async (systemInit: string) => })) const createSysInitFile = async () => { - console.log('macroCorePath', macroCorePath) const systemInitContent = await readFile( path.join(__dirname, 'systemInit.sas') ) diff --git a/api/scripts/copySASjsCore.ts b/api/scripts/copySASjsCore.ts new file mode 100644 index 0000000..a6f5d70 --- /dev/null +++ b/api/scripts/copySASjsCore.ts @@ -0,0 +1,25 @@ +import path from 'path' +import { asyncForEach, copy, createFolder, deleteFolder } from '@sasjs/utils' + +import { apiRoot, sasJSCoreMacros } from '../src/utils' + +const macroCorePath = path.join(apiRoot, 'node_modules', '@sasjs', 'core') + +export const copySASjsCore = async () => { + await deleteFolder(sasJSCoreMacros) + await createFolder(sasJSCoreMacros) + + console.log('Copying SASjs Core Macros...') + + const foldersToCopy = ['base', 'ddl', 'fcmp', 'lua', 'server'] + + await asyncForEach(foldersToCopy, async (coreSubFolder) => { + const coreSubFolderPath = path.join(macroCorePath, coreSubFolder) + + await copy(coreSubFolderPath, sasJSCoreMacros) + }) + + console.log('Macros available at: ', sasJSCoreMacros) +} + +copySASjsCore() diff --git a/api/src/controllers/internal/Execution.ts b/api/src/controllers/internal/Execution.ts index f3eebf1..3e60a9d 100644 --- a/api/src/controllers/internal/Execution.ts +++ b/api/src/controllers/internal/Execution.ts @@ -13,7 +13,8 @@ import { extractHeaders, generateFileUploadSasCode, getTmpFilesFolderPath, - HTTPHeaders + HTTPHeaders, + sasJSCoreMacros } from '../../utils' export interface ExecutionVars { @@ -104,6 +105,8 @@ export class ExecutionController { ` program = ` +options insert=(SASAUTOS="${sasJSCoreMacros}"); + /* runtime vars */ ${varStatments} filename _webout "${weboutPath}" mod; diff --git a/api/src/controllers/internal/Session.ts b/api/src/controllers/internal/Session.ts index 5921a25..5fe8f2d 100644 --- a/api/src/controllers/internal/Session.ts +++ b/api/src/controllers/internal/Session.ts @@ -67,7 +67,10 @@ export class SessionController { // the autoexec file is executed on SAS startup const autoExecPath = path.join(sessionFolder, 'autoexec.sas') - const contentForAutoExec = `/* compiled systemInit */\n${compiledSystemInitContent}\n/* autoexec */\n${autoExecContent}` + const contentForAutoExec = `/* compiled systemInit */ +${compiledSystemInitContent} +/* autoexec */ +${autoExecContent}` await createFile(autoExecPath, contentForAutoExec) // create empty code.sas as SAS will not start without a SYSIN diff --git a/api/src/utils/file.ts b/api/src/utils/file.ts index 5072bb9..7907959 100644 --- a/api/src/utils/file.ts +++ b/api/src/utils/file.ts @@ -8,6 +8,8 @@ export const sysInitCompiledPath = path.join( 'systemInitCompiled.sas' ) +export const sasJSCoreMacros = path.join(apiRoot, 'sasjscore') + export const getWebBuildFolderPath = () => path.join(codebaseRoot, 'web', 'build')