-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix plugin install/uninstall commands
- Loading branch information
Showing
7 changed files
with
116 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
#!/usr/bin/env node_modules/.bin/ts-node | ||
|
||
const PROVISIONING = true; | ||
const OCLIF_PATCH = true | ||
const COMMAND_PATCH_ENABLED = true | ||
|
||
// eslint-disable-next-line node/shebang, unicorn/prefer-top-level-await | ||
; (async () => { | ||
|
||
const oclif = await import('@oclif/core') | ||
const oclif = OCLIF_PATCH ? require('../src/patches/oclif/execute') : await import('@oclif/core') | ||
|
||
// Check Provisioning commands | ||
if (PROVISIONING) require('../src/patches/provisioning').checkProvisioningCommand(process.argv) | ||
if (COMMAND_PATCH_ENABLED) require('../src/patches/command').patchCommand(process.argv) | ||
|
||
await oclif.execute({ development: true, dir: __dirname }) | ||
.then(oclif.flush(60000)) | ||
.catch(error => { | ||
if (error.code === 'EEXIT' && error.oclif.exit === 0) { /* command exit (quit) */ } | ||
else | ||
if (error.message === 'HOOK_EXIT') { /* hook exit */ } | ||
else | ||
return oclif.Errors.handle(error) | ||
}) | ||
|
||
})() | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
#!/usr/bin/env node | ||
|
||
const PROVISIONING = true; | ||
const OCLIF_PATCH = true | ||
const COMMAND_PATCH_ENABLED = true | ||
|
||
// eslint-disable-next-line unicorn/prefer-top-level-await | ||
(async () => { | ||
; (async () => { | ||
|
||
const oclif = await import('@oclif/core') | ||
const oclif = OCLIF_PATCH ? require('../lib/patches/oclif/execute') : await import('@oclif/core') | ||
|
||
// Check Provisioning commands | ||
if (PROVISIONING) require('../lib/patches/provisioning').checkProvisioningCommand(process.argv) | ||
if (COMMAND_PATCH_ENABLED) require('../lib/patches/command').patchCommand(process.argv) | ||
|
||
await oclif.execute({ development: false, dir: __dirname }) | ||
.then(oclif.flush(60000)) | ||
.catch(error => { | ||
if (error.code === 'EEXIT' && error.oclif.exit === 0) { /* command exit (quit) */ } | ||
else | ||
if (error.message === 'HOOK_EXIT') { /* hook exit */ } | ||
else | ||
return oclif.Errors.handle(error) | ||
}) | ||
|
||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
import { clText } from "@commercelayer/cli-core" | ||
import { CommerceLayerProvisioningStatic } from "@commercelayer/provisioning-sdk" | ||
|
||
|
||
const PROVISIONING = true | ||
const provisioningCommands = ['retrieve', 'list', 'create', 'update', 'delete', 'get', 'relationship', 'fetch'] | ||
|
||
|
||
export const patchCommand = (argv: string[]): string[] => { | ||
|
||
const cmdIdx = process.argv.findIndex(a => !a.startsWith('/')) | ||
const cmd = process.argv[cmdIdx] | ||
|
||
// Check provisioning command | ||
if (PROVISIONING && provisioningCommands.includes(cmd)) return checkProvisioningCommand(cmd, cmdIdx, argv) | ||
|
||
// Check plugins command | ||
if (['install', 'uninstall'].includes(cmd)) argv[cmdIdx] = `plugins:${cmd}` | ||
|
||
|
||
return argv | ||
|
||
} | ||
|
||
|
||
export const checkProvisioningCommand = (cmd: string, cmdIdx: number, argv: string[]): string[] => { | ||
|
||
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { run, handle, flush, settings} from '@oclif/core' | ||
import type { LoadOptions } from '@oclif/core/lib/interfaces' | ||
|
||
|
||
export async function execute(options: { | ||
args?: string[] | ||
development?: boolean | ||
dir: string | ||
loadOptions?: LoadOptions | ||
}): Promise<unknown> { | ||
|
||
if (options.development) { | ||
process.env.NODE_ENV = 'development' | ||
settings.debug = true | ||
} | ||
|
||
return run(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir) | ||
.then(async (result) => { | ||
await flush(60000) | ||
return result | ||
}) | ||
.catch(async (error) => { | ||
if (error.code === 'EEXIT' && error.oclif.exit === 0) { /* command exit (quit) */ } | ||
else | ||
if (error.message === 'HOOK_EXIT') { /* hook exit */ } | ||
else return handle(error as Error) | ||
}) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.