Skip to content

Commit

Permalink
fix: fix shared resource types
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Feb 6, 2024
1 parent 25eca9d commit 9613963
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/patches/provisioning.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@

import { clText } from "@commercelayer/cli-core"
import { CommerceLayerProvisioningStatic } from "@commercelayer/provisioning-sdk"


export const checkProvisioningCommand = (argv: string[]): string[] => {
const provisioningCommands = ['retrieve', 'list', 'create', 'update', 'delete', 'get', 'relationship', 'fetch']


const provisioningResources = CommerceLayerProvisioningStatic.resources()
export const checkProvisioningCommand = (argv: string[]): string[] => {

const cmdIdx = process.argv.findIndex(a => !a.startsWith('/'))
const cmd = process.argv[cmdIdx]
const res = process.argv.find(a => !a.startsWith('/') && (a !== cmd))

if (res && ['retrieve', 'list', 'create', 'update', 'delete', 'get', 'relationship', 'fetch'].includes(cmd) && provisioningResources.includes(res)) {
process.argv[cmdIdx] = `provisioning:${cmd}`
}
// Check provisioning command
if (provisioningCommands.includes(cmd)) {

const res = process.argv.find(a => !a.startsWith('/') && (a !== cmd))

// Check provisioning resource
if (res) {

const provisioningResources = [ ...CommerceLayerProvisioningStatic.resources() ]
provisioningResources.splice(provisioningResources.indexOf('organizations'), 1)
provisioningResources.splice(provisioningResources.indexOf('versions'), 1)

const provisioningResource = provisioningResources.includes(res) || (provisioningResources.includes(clText.pluralize(res)))
if (provisioningResource) process.argv[cmdIdx] = `provisioning:${cmd}`

}

}

return argv

Expand Down

0 comments on commit 9613963

Please sign in to comment.