Skip to content

Commit

Permalink
fix(sasjs-cb): handled cases when dependency source is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
YuryShkoda committed Nov 3, 2020
1 parent 90211bb commit 97dfbe0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
23 changes: 14 additions & 9 deletions src/main.js
Expand Up @@ -155,16 +155,21 @@ export async function compileBuildServices(targetName) {
)
)
)
.catch((err) => {
const body = JSON.parse(err.body)
const message = body.message || ''

console.log(
chalk.redBright(
'An error has occurred when building services.',
message
.catch((error) => {
if (Array.isArray(error)) {
const nodeModulesErrors = error.find((err) =>
err.includes('node_modules/@sasjs/core')
)
)

if (nodeModulesErrors)
console.log(
chalk.yellowBright(
`Suggestion: @sasjs/core dependency is missing. Try running 'npm install @sasjs/core' command.`
)
)
} else {
displayResult(error, 'An error has occurred when building services.')
}
})
}

Expand Down
35 changes: 28 additions & 7 deletions src/sasjs-build/index.js
Expand Up @@ -75,41 +75,58 @@ export async function build(

async function compile(targetName) {
await copyFilesToBuildFolder()

const servicesToCompile = await getAllServices(
path.join(buildSourceFolder, 'sasjsconfig.json')
)

const serviceNamesToCompile = servicesToCompile.map((s) => s.split('/').pop())
const serviceNamesToCompileUniq = [...new Set(serviceNamesToCompile)]

const tgtMacros = targetToBuild ? targetToBuild.tgtMacros : []
const programFolders = await getProgramFolders(targetName)

const errors = []

await asyncForEach(serviceNamesToCompileUniq, async (buildFolder) => {
const folderPath = path.join(buildDestinationServ, buildFolder)
const subFolders = await getSubFoldersInFolder(folderPath)
const filesNamesInPath = await getFilesInFolder(folderPath)

await asyncForEach(filesNamesInPath, async (fileName) => {
const filePath = path.join(folderPath, fileName)

const dependencies = await loadDependencies(
filePath,
tgtMacros,
programFolders
)
await createFile(filePath, dependencies)
).catch((err) => {
errors.push(err)
})

if (dependencies) await createFile(filePath, dependencies)
})

await asyncForEach(subFolders, async (subFolder) => {
const fileNames = await getFilesInFolder(path.join(folderPath, subFolder))

await asyncForEach(fileNames, async (fileName) => {
const filePath = path.join(folderPath, subFolder, fileName)

const dependencies = await loadDependencies(
filePath,
tgtMacros,
programFolders
)
await createFile(filePath, dependencies)
).catch((err) => {
errors.push(err)
})

if (dependencies) await createFile(filePath, dependencies)
})
})
})

if (errors.length) throw errors
}

async function createFinalSasFiles() {
Expand Down Expand Up @@ -697,8 +714,10 @@ export async function getDependencyPaths(fileContent, tgtMacros = []) {
dependencies = [...dependencies, ...dependency]
count++
}

let dependencyPaths = []
const foundDependencies = []

await asyncForEach(sourcePaths, async (sourcePath) => {
if (await folderExists(sourcePath)) {
await asyncForEach(dependencies, async (dep) => {
Expand All @@ -713,9 +732,11 @@ export async function getDependencyPaths(fileContent, tgtMacros = []) {
dependencyPaths.push(...filePaths)
})
} else {
console.log(
chalk.redBright(`Source path ${sourcePath} does not exist.`)
)
const errorMessage = `Source path ${sourcePath} does not exist.`

console.log(chalk.redBright(errorMessage))

throw errorMessage
}
})

Expand Down

0 comments on commit 97dfbe0

Please sign in to comment.