Skip to content

Commit

Permalink
feat: Enable SAS_PACKAGES in SASjs Server
Browse files Browse the repository at this point in the history
  • Loading branch information
sabhas committed Oct 3, 2022
1 parent 69ddf31 commit 424f0fc
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 9 deletions.
147 changes: 147 additions & 0 deletions api/package-lock.json

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

13 changes: 8 additions & 5 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Api of SASjs server",
"main": "./src/server.ts",
"scripts": {
"initial": "npm run swagger && npm run compileSysInit && npm run copySASjsCore",
"initial": "npm run swagger && npm run compileSysInit && npm run copySASjsCore && npm run downloadMacros",
"prestart": "npm run initial",
"prebuild": "npm run initial",
"start": "NODE_ENV=development nodemon ./src/server.ts",
Expand All @@ -17,20 +17,21 @@
"lint:fix": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
"lint": "npx prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
"exe": "npm run build && pkg .",
"copy:files": "npm run public:copy && npm run sasjsbuild:copy && npm run sasjscore:copy && npm run web:copy",
"copy:files": "npm run public:copy && npm run sasjsbuild:copy && npm run sas: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/",
"sas:copy": "cp -r ./sas/ ./build/sas/",
"web:copy": "rimraf web && mkdir web && cp -r ../web/build/ ./web/build/",
"compileSysInit": "ts-node ./scripts/compileSysInit.ts",
"copySASjsCore": "ts-node ./scripts/copySASjsCore.ts"
"copySASjsCore": "ts-node ./scripts/copySASjsCore.ts",
"downloadMacros": "ts-node ./scripts/downloadMacros.ts"
},
"bin": "./build/src/server.js",
"pkg": {
"assets": [
"./build/public/**/*",
"./build/sasjsbuild/**/*",
"./build/sasjscore/**/*",
"./build/sas/**/*",
"./web/build/**/*"
],
"targets": [
Expand Down Expand Up @@ -84,11 +85,13 @@
"@types/swagger-ui-express": "^4.1.3",
"@types/unzipper": "^0.10.5",
"adm-zip": "^0.5.9",
"axios": "0.27.2",
"csrf": "^3.1.0",
"dotenv": "^10.0.0",
"http-headers-validation": "^0.0.1",
"jest": "^27.0.6",
"mongodb-memory-server": "^8.0.0",
"nodejs-file-downloader": "4.10.2",
"nodemon": "^2.0.7",
"pkg": "5.6.0",
"prettier": "^2.3.1",
Expand Down
39 changes: 39 additions & 0 deletions api/scripts/downloadMacros.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import axios from 'axios'
import Downloader from 'nodejs-file-downloader'
import { createFile, listFilesInFolder } from '@sasjs/utils'

import { sasJSCoreMacros, sasJSCoreMacrosInfo } from '../src/utils/file'

export const downloadMacros = async () => {
const url =
'https://api.github.com/repos/yabwon/SAS_PACKAGES/contents/SPF/Macros'

console.info(`Downloading macros from ${url}`)

await axios
.get(url)
.then(async (res) => {
await downloadFiles(res.data)
})
.catch((err) => {
throw new Error(err)
})
}

const downloadFiles = async function (fileList: any) {
for (const file of fileList) {
const downloader = new Downloader({
url: file.download_url,
directory: sasJSCoreMacros,
fileName: file.path.replace(/^SPF\/Macros/, ''),
cloneFiles: false
})
await downloader.download()
}

const fileNames = await listFilesInFolder(sasJSCoreMacros)

await createFile(sasJSCoreMacrosInfo, fileNames.join('\n'))
}

downloadMacros()
4 changes: 3 additions & 1 deletion api/src/controllers/internal/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Session } from '../../types'
import { promisify } from 'util'
import { execFile } from 'child_process'
import {
getPackagesFolder,
getSessionsFolder,
generateUniqueFileName,
sysInitCompiledPath,
Expand Down Expand Up @@ -104,7 +105,8 @@ export class SASSessionController extends SessionController {

// the autoexec file is executed on SAS startup
const autoExecPath = path.join(sessionFolder, 'autoexec.sas')
const contentForAutoExec = `/* compiled systemInit */
const contentForAutoExec = `filename packages "${getPackagesFolder()}";
/* compiled systemInit */
${compiledSystemInitContent}
/* autoexec */
${autoExecContent}`
Expand Down
7 changes: 5 additions & 2 deletions api/src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const sysInitCompiledPath = path.join(
'systemInitCompiled.sas'
)

export const sasJSCoreMacros = path.join(apiRoot, 'sasjscore')
export const sasJSCoreMacros = path.join(apiRoot, 'sas', 'sasautos')
export const sasJSCoreMacrosInfo = path.join(sasJSCoreMacros, '.macrolist')

export const getWebBuildFolder = () => path.join(codebaseRoot, 'web', 'build')
Expand All @@ -28,7 +28,10 @@ export const getAppStreamConfigPath = () =>
path.join(getSasjsRootFolder(), 'appStreamConfig.json')

export const getMacrosFolder = () =>
path.join(getSasjsRootFolder(), 'sasjscore')
path.join(getSasjsRootFolder(), 'sas', 'sasautos')

export const getPackagesFolder = () =>
path.join(getSasjsRootFolder(), 'sas', 'sas_packages')

export const getUploadsFolder = () => path.join(getSasjsRootFolder(), 'uploads')

Expand Down
7 changes: 6 additions & 1 deletion api/src/utils/setupFolders.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { createFile, createFolder, fileExists } from '@sasjs/utils'
import { getDesktopUserAutoExecPath, getFilesFolder } from './file'
import {
getDesktopUserAutoExecPath,
getFilesFolder,
getPackagesFolder
} from './file'
import { ModeType } from './verifyEnvVariables'

export const setupFolders = async () => {
const drivePath = getFilesFolder()
await createFolder(drivePath)
await createFolder(getPackagesFolder())

if (process.env.MODE === ModeType.Desktop) {
if (!(await fileExists(getDesktopUserAutoExecPath()))) {
Expand Down

0 comments on commit 424f0fc

Please sign in to comment.