-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add reactor management commands (#17)
- use new reactor `code` field - deprecate formulas
- Loading branch information
1 parent
dcc0916
commit 67c668a
Showing
10 changed files
with
321 additions
and
11 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
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,52 @@ | ||
import { BaseCommand } from '../../base'; | ||
import { createReactor } from '../../reactors/management'; | ||
import { createModelFromFlags, REACTOR_FLAGS } from '../../reactors/utils'; | ||
import { promptStringIfUndefined } from '../../utils'; | ||
|
||
export default class Create extends BaseCommand { | ||
public static description = | ||
'Creates a new Reactor. Requires `reactor:create` Management Application permission'; | ||
|
||
public static examples = ['<%= config.bin %> <%= command.id %> ']; | ||
|
||
public static flags = { | ||
...REACTOR_FLAGS, | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const { flags, bt } = await this.parse(Create); | ||
|
||
const name = await promptStringIfUndefined(flags.name, { | ||
message: 'What is the Reactor name?', | ||
validate: (value) => Boolean(value), | ||
}); | ||
|
||
const code = await promptStringIfUndefined(flags['code'], { | ||
message: 'Enter the Reactor code file path:', | ||
validate: (value) => Boolean(value), | ||
}); | ||
|
||
const applicationId = await promptStringIfUndefined( | ||
flags['application-id'], | ||
{ | ||
message: '(Optional) Enter the Application ID to use in the Reactor:', | ||
} | ||
); | ||
|
||
const configuration = await promptStringIfUndefined(flags.configuration, { | ||
message: '(Optional) Enter the configuration file path (.env format):', | ||
}); | ||
|
||
const model = createModelFromFlags({ | ||
name, | ||
code, | ||
applicationId, | ||
configuration, | ||
}); | ||
|
||
const { id } = await createReactor(bt, model); | ||
|
||
this.log('Reactor created successfully!'); | ||
this.log(`id: ${id}`); | ||
} | ||
} |
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,40 @@ | ||
import { Args, Flags } from '@oclif/core'; | ||
import { BaseCommand } from '../../base'; | ||
import { deleteReactor } from '../../reactors/management'; | ||
|
||
export default class Delete extends BaseCommand { | ||
public static description = | ||
'Deletes a Reactor. Requires `reactor:delete` and `reactor:read` Management Application permissions'; | ||
|
||
public static examples = [ | ||
'<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca', | ||
]; | ||
|
||
public static args = { | ||
id: Args.string({ | ||
description: 'Reactor id to delete', | ||
required: true, | ||
}), | ||
}; | ||
|
||
public static flags = { | ||
yes: Flags.boolean({ | ||
char: 'y', | ||
description: 'auto confirm the operation', | ||
default: false, | ||
allowNo: false, | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const { | ||
bt, | ||
flags: { yes }, | ||
args: { id }, | ||
} = await this.parse(Delete); | ||
|
||
if (await deleteReactor(bt, id, yes)) { | ||
this.log('Reactor deleted successfully!'); | ||
} | ||
} | ||
} |
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,100 @@ | ||
import { Args, Flags, ux } from '@oclif/core'; | ||
import { BaseCommand } from '../../base'; | ||
import { watchForChanges } from '../../files'; | ||
import { showReactorLogs } from '../../logs'; | ||
import { patchReactor } from '../../reactors/management'; | ||
import { createModelFromFlags, REACTOR_FLAGS } from '../../reactors/utils'; | ||
|
||
export default class Update extends BaseCommand { | ||
public static description = | ||
'Updates an existing Reactor. Requires `reactor:update` Management Application permission'; | ||
|
||
public static examples = [ | ||
'<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca', | ||
'<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca --code ./reactor.js', | ||
'<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca --configuration ./.env.reactor', | ||
]; | ||
|
||
public static flags = { | ||
...REACTOR_FLAGS, | ||
watch: Flags.boolean({ | ||
char: 'w', | ||
description: 'Watch for changes in informed files', | ||
default: false, | ||
required: false, | ||
}), | ||
logs: Flags.boolean({ | ||
char: 'l', | ||
description: 'Start logs server after update', | ||
default: false, | ||
required: false, | ||
}), | ||
}; | ||
|
||
public static args = { | ||
id: Args.string({ | ||
description: 'Reactor id to update', | ||
required: true, | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const { | ||
bt, | ||
args: { id }, | ||
flags: { | ||
name, | ||
code, | ||
'application-id': applicationId, | ||
configuration, | ||
watch, | ||
logs, | ||
}, | ||
} = await this.parse(Update); | ||
|
||
const model = createModelFromFlags({ | ||
name, | ||
code, | ||
applicationId, | ||
configuration, | ||
}); | ||
|
||
await patchReactor(bt, id, model); | ||
|
||
this.log('Reactor updated successfully!'); | ||
|
||
if (logs) { | ||
await showReactorLogs(bt, id); | ||
} | ||
|
||
if (watch) { | ||
const entries = Object.entries({ | ||
code, | ||
configuration, | ||
}).filter(([, value]) => Boolean(value)) as [string, string][]; | ||
|
||
const files = entries.reduce( | ||
(arr, [, file]) => [...arr, file], | ||
[] as string[] | ||
); | ||
|
||
if (files.length) { | ||
this.log(`Watching files for changes: ${files.join(', ')} `); | ||
} | ||
|
||
entries.forEach(([prop, file]) => { | ||
watchForChanges(file, async () => { | ||
ux.action.start(`Detected change in ${file}. Pushing changes`); | ||
await patchReactor( | ||
bt, | ||
id, | ||
createModelFromFlags({ | ||
[prop]: file, | ||
}) | ||
); | ||
ux.action.stop('✅\t'); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.