Skip to content

Commit

Permalink
fix(constants): used getNodeModulePath for macroCorePath
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Apr 13, 2022
1 parent a811a53 commit 567e076
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { parse } from './types/command/parse'

export async function cli(args: string[]) {
await setProjectDir(args)
await instantiateLogger()
await setConstants()
await loadProjectEnvVariables()
await instantiateLogger()

const command = parse(args)
const returnCode = await command.execute()
Expand Down
37 changes: 10 additions & 27 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 { folderExists, getAbsolutePath } from '@sasjs/utils'
import { getNodeModulePath } from './utils'
import { getAbsolutePath } from '@sasjs/utils'

export const contextName = 'sasjs cli compute context'

Expand All @@ -20,21 +20,6 @@ export const setConstants = async () => {
(isLocal ? 'sasjsresults' : '.sasjs/sasjsresults')
const homeDir = require('os').homedir()

const getMacroCoreGlobalPath = async () => {
try {
const sasjsPath = await getInstalledPath('@sasjs/cli')
const macroCoreGlobal = path.join(
sasjsPath,
'node_modules',
'@sasjs',
'core'
)
return macroCoreGlobal
} catch (e) {
throw 'Please install SASjs cli `npm i -g @sasjs/cli`'
}
}

const buildSourceFolder = path.join(isLocal ? process.projectDir : homeDir)
const buildSourceDbFolder = path.join(
isLocal ? process.projectDir : homeDir,
Expand All @@ -53,16 +38,14 @@ 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
? (await folderExists(buildSourceCorePath))
? buildSourceCorePath
: await getMacroCoreGlobalPath()
: await getMacroCoreGlobalPath()
const macroCorePath = await getNodeModulePath('@sasjs/core')

if (!macroCorePath) {
process.logger?.warn(
`Couldn't locate @sasjs/core path. Please run 'npm install @sasjs/core@latest' to install it locally or 'npm install -g @sasjs/core@latest' to install it globally.`
)
}

const buildDestinationResultsFolder = getAbsolutePath(
buildResultsFolder,
isLocal ? process.projectDir : homeDir
Expand Down
8 changes: 6 additions & 2 deletions src/utils/spec/setConstants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('setConstants', () => {
})

test('should set constants inside appFolder', async () => {
const appFolder = ['some', 'app', 'folder'].join(path.sep)
process.projectDir = appFolder

jest
.spyOn(configUtils, 'getLocalOrGlobalConfig')
.mockImplementation(async () =>
Expand All @@ -23,12 +26,12 @@ describe('setConstants', () => {
})
)

jest.spyOn(process, 'cwd').mockImplementation(() => appFolder)

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

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

await setConstants()

verifySasjsConstants(process.projectDir)
Expand Down Expand Up @@ -83,6 +86,7 @@ const verifySasjsConstants = (appFolder?: string) => {
expect(sasjsConstants.buildDestinationTestFolder).toEqual(
[prefixAppFolder, 'sasjsbuild', 'tests'].join(path.sep)
)

if (appFolder) {
expect(sasjsConstants.macroCorePath).toEqual(
[prefixAppFolder, 'node_modules', '@sasjs', 'core'].join(path.sep)
Expand Down

0 comments on commit 567e076

Please sign in to comment.