Skip to content

Commit

Permalink
fix(compile): fixed macroCorePath sasjs constant
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 11, 2022
1 parent 2139402 commit fdaec26
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
20 changes: 9 additions & 11 deletions src/commands/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,35 +205,33 @@ ${buildConfig}
}

async function getCreateWebServiceScript(serverType: ServerType) {
const macroCorePath = getMacroCorePath()

switch (serverType) {
case ServerType.SasViya:
return await readFile(
`${getMacroCorePath()}/viya/mv_createwebservice.sas`
)
return await readFile(`${macroCorePath}/viya/mv_createwebservice.sas`)

case ServerType.Sas9:
return await readFile(
`${getMacroCorePath()}/meta/mm_createwebservice.sas`
)
return await readFile(`${macroCorePath}/meta/mm_createwebservice.sas`)

// FIXME: use sasjs/mv_createwebservice.sas ones created
case ServerType.Sasjs:
return await readFile(
`${getMacroCorePath()}/viya/mv_createwebservice.sas`
)
return await readFile(`${macroCorePath}/viya/mv_createwebservice.sas`)

default:
throw new ServerTypeError()
}
}

async function getCreateFileScript(serverType: ServerType) {
const macroCorePath = getMacroCorePath()

switch (serverType) {
case ServerType.SasViya:
return await readFile(`${getMacroCorePath()}/viya/mv_createfile.sas`)
return await readFile(`${macroCorePath}/viya/mv_createfile.sas`)
// FIXME: use sasjs/mv_createfile.sas ones created
case ServerType.Sasjs:
return await readFile(`${getMacroCorePath()}/viya/mv_createfile.sas`)
return await readFile(`${macroCorePath}/viya/mv_createfile.sas`)

default:
throw new ServerTypeError([ServerType.SasViya, ServerType.Sasjs])
Expand Down
11 changes: 9 additions & 2 deletions src/utils/setConstants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import { getInstalledPath } from 'get-installed-path'
import { getLocalOrGlobalConfig } from './config'
import { getAbsolutePath } from '@sasjs/utils'
import { folderExists, getAbsolutePath } from '@sasjs/utils'

export const contextName = 'sasjs cli compute context'

Expand Down Expand Up @@ -52,8 +52,15 @@ export const setConstants = async () => {
const buildDestinationJobsFolder = path.join(buildDestinationFolder, 'jobs')
const buildDestinationDbFolder = path.join(buildDestinationFolder, 'db')
const buildDestinationDocsFolder = path.join(buildDestinationFolder, 'docs')
const buildSourceCorePath = path.join(
buildSourceFolder,
'node_modules',
'@sasjs/core'
)
const macroCorePath = isLocal
? path.join(buildSourceFolder, 'node_modules', '@sasjs/core')
? (await folderExists(buildSourceCorePath))
? buildSourceCorePath
: await getMacroCoreGlobalPath()
: await getMacroCoreGlobalPath()
const buildDestinationResultsFolder = getAbsolutePath(
buildResultsFolder,
Expand Down
19 changes: 13 additions & 6 deletions src/utils/spec/setConstants.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Configuration, readFile, ServerType, Target } from '@sasjs/utils'
import { Configuration } from '@sasjs/utils'
import path from 'path'
import * as configUtils from '../config'
import { setConstants } from '../setConstants'
import * as fileModule from '@sasjs/utils/file'

describe('setConstants', () => {
let config: Configuration

beforeAll(async () => {
;({ config } = JSON.parse(
await readFile(path.join(__dirname, '..', '..', 'config.json'))
await fileModule.readFile(path.join(__dirname, '..', '..', 'config.json'))
))
})

test('should set contants inside appFolder', async () => {
test('should set constants inside appFolder', async () => {
jest
.spyOn(configUtils, 'getLocalOrGlobalConfig')
.mockImplementation(async () =>
Expand All @@ -21,14 +22,19 @@ describe('setConstants', () => {
isLocal: true
})
)

jest
.spyOn(fileModule, 'folderExists')
.mockImplementation(() => Promise.resolve(true))

process.projectDir = ['some', 'app', 'folder'].join(path.sep)

await setConstants()

verifySasjsConstants(process.projectDir)
})

test('should set contants outside appFolder', async () => {
test('should set constants outside appFolder', async () => {
jest
.spyOn(configUtils, 'getLocalOrGlobalConfig')
.mockImplementation(async () =>
Expand Down Expand Up @@ -77,11 +83,11 @@ const verifySasjsConstants = (appFolder?: string) => {
expect(sasjsConstants.buildDestinationTestFolder).toEqual(
[prefixAppFolder, 'sasjsbuild', 'tests'].join(path.sep)
)
if (appFolder)
if (appFolder) {
expect(sasjsConstants.macroCorePath).toEqual(
[prefixAppFolder, 'node_modules', '@sasjs', 'core'].join(path.sep)
)
else
} else {
expect(sasjsConstants.macroCorePath).toEqual(
expect.toEndWith(
[
Expand All @@ -94,4 +100,5 @@ const verifySasjsConstants = (appFolder?: string) => {
].join(path.sep)
)
)
}
}

0 comments on commit fdaec26

Please sign in to comment.