Skip to content

Commit

Permalink
feat: deploy zipped file to sasjs server if available (#1288)
Browse files Browse the repository at this point in the history
* feat: deploy zipped file to sasjs server if available intead of json content

* chore: spec fix
  • Loading branch information
sabhas authored Dec 8, 2022
1 parent ae84587 commit 0364c90
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 19 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"access": "public"
},
"dependencies": {
"@sasjs/adapter": "4.0.1",
"@sasjs/adapter": "4.1.0",
"@sasjs/core": "4.45.2",
"@sasjs/lint": "1.15.0",
"@sasjs/utils": "2.51.1",
Expand Down
38 changes: 27 additions & 11 deletions src/commands/deploy/internal/deployToSASJSWithServicePack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { SASjsApiClient, SasjsRequestClient } from '@sasjs/adapter/node'
import { getAuthConfig } from '../../../utils/config'
import { isSasJsServerInServerMode } from '../../../utils/utils'
import { readFile, Target, StreamConfig, ServicePackSASjs } from '@sasjs/utils'
import {
readFile,
Target,
StreamConfig,
ServicePackSASjs,
fileExists
} from '@sasjs/utils'

/**
* Deploys app to `SASJS` server.
Expand All @@ -13,22 +19,32 @@ export async function deployToSasjsWithServicePack(
target: Target,
streamConfig?: StreamConfig
) {
const jsonContent = await readFile(jsonFilePath)
const payload: ServicePackSASjs = JSON.parse(jsonContent)
const sasjsApiClient = new SASjsApiClient(
new SasjsRequestClient(target.serverUrl, target.httpsAgentOptions)
)

const authConfig = (await isSasJsServerInServerMode(target))
? await getAuthConfig(target)
: undefined

const sasjsApiClient = new SASjsApiClient(
new SasjsRequestClient(target.serverUrl, target.httpsAgentOptions)
)
let result
const zipFilePath = jsonFilePath + '.zip'
if (await fileExists(zipFilePath)) {
result = await sasjsApiClient
.deployZipFile(zipFilePath, authConfig)
.catch((err) => {
process.logger?.error('deployToSASjs Error', err)
})
} else {
const jsonContent = await readFile(jsonFilePath)
const payload: ServicePackSASjs = JSON.parse(jsonContent)

const result = await sasjsApiClient
.deploy(payload, target.appLoc, authConfig)
.catch((err) => {
process.logger?.error('deployToSASjs Error', err)
})
result = await sasjsApiClient
.deploy(payload, target.appLoc, authConfig)
.catch((err) => {
process.logger?.error('deployToSASjs Error', err)
})
}

if (result?.status === 'failure') {
process.logger?.error(result.message)
Expand Down
7 changes: 7 additions & 0 deletions src/commands/deploy/spec/cbd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ServiceConfig,
removeHeader
} from '@sasjs/utils'
import * as fileModule from '@sasjs/utils/file'
import {
createTestMinimalApp,
removeTestApp,
Expand Down Expand Up @@ -39,6 +40,12 @@ describe('sasjs cbd with server type SASJS', () => {
})

it(`should deploy compile and build to sasjs/server`, async () => {
jest.spyOn(fileModule, 'fileExists').mockImplementation((filePath) => {
if (filePath.endsWith('.zip')) return Promise.resolve(false)

return Promise.resolve(true)
})

const deployMock = jest
.spyOn(SASjsApiClient.prototype, 'deploy')
.mockImplementation(() =>
Expand Down

0 comments on commit 0364c90

Please sign in to comment.