From 2201b4ee15c0f8f9bc80ab8cdf20c404173e0f71 Mon Sep 17 00:00:00 2001 From: Mihajlo Medjedovic Date: Tue, 1 Dec 2020 12:08:40 +0100 Subject: [PATCH] fix: sasjs run default contextName, removed `localRcFile` functions --- src/commands/run.js | 5 ++--- src/utils/config-utils.js | 14 -------------- src/utils/utils.js | 31 ++++--------------------------- 3 files changed, 6 insertions(+), 44 deletions(-) diff --git a/src/commands/run.js b/src/commands/run.js index f5c70cf6a..a33565b7b 100644 --- a/src/commands/run.js +++ b/src/commands/run.js @@ -50,12 +50,11 @@ async function executeOnSasViya(filePath, buildTarget, linesToExecute) { serverType: buildTarget.serverType, debug: true }) + const contextName = await getVariable('contextName', buildTarget) if (!contextName) { - throw new Error( - 'Compute Context Name is required for SAS Viya deployments.\n Please ensure that `contextName` is present in your build target configuration or in your .env file, and try again.\n' - ) + contextName = sasjs.getSasjsConfig().contextName } const accessToken = await getAccessToken(buildTarget) diff --git a/src/utils/config-utils.js b/src/utils/config-utils.js index 330c04548..09479ee01 100644 --- a/src/utils/config-utils.js +++ b/src/utils/config-utils.js @@ -151,15 +151,6 @@ export async function getGlobalRcFile() { : sasjsRcFileContent } -export async function getLocalRcFile() { - const projectRoot = await getProjectRoot() - if (!projectRoot) { - return null - } - const config = await getConfiguration(path.join(projectRoot, '.sasjsrc')) - return config -} - export async function saveGlobalRcFile(content) { const homeDir = require('os').homedir() const rcFilePath = path.join(homeDir, '.sasjsrc') @@ -169,11 +160,6 @@ export async function saveGlobalRcFile(content) { console.log(chalk.greenBright(`Config saved to '${rcFilePath}'.`)) } -export async function saveLocalRcFile(content) { - const projectRoot = await getProjectRoot() - await createFile(path.join(projectRoot, '.sasjsrc'), content) -} - export async function getFolders(sasOnly = false) { const configPath = sasOnly ? '../config-sasonly.json' : '../config.json' const config = await readFile(path.join(__dirname, configPath)) diff --git a/src/utils/utils.js b/src/utils/utils.js index f2d9a8194..14890c513 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -3,7 +3,6 @@ import chalk from 'chalk' import path from 'path' import ora from 'ora' import { fileExists, createFile, readFile } from './file-utils' -import { getLocalRcFile } from './config-utils' async function inExistingProject(folderPath) { const packageJsonExists = await fileExists( @@ -180,44 +179,22 @@ export function chunk(text, maxLength = 220) { export async function getVariable(name, target) { let value = process.env[name] + if (value) { return value } + value = target && target.tgtDeployVars ? target.tgtDeployVars[name] : null if (value) { return value } + value = target && target.tgtBuildVars ? target.tgtBuildVars[name] : null if (value) { return value } - const localRcFile = await getLocalRcFile() - if (localRcFile && localRcFile.targets) { - const currentTarget = localRcFile.targets.find( - (t) => t.name === target.name - ) - if (currentTarget) { - value = - currentTarget && currentTarget.tgtDeployVars - ? currentTarget.tgtDeployVars[name] - : null - if (value) { - return value - } - value = - currentTarget && currentTarget.tgtBuildVars - ? currentTarget.tgtBuildVars[name] - : null - if (value) { - return value - } - return currentTarget && currentTarget.authInfo - ? currentTarget.authInfo[name] - : null - } - return null - } + return null } /**