-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new activate and deploy LWC command for datapacks of type OmniScript
- Loading branch information
Showing
18 changed files
with
353 additions
and
127 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
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
54 changes: 0 additions & 54 deletions
54
packages/vscode-extension/src/commands/datapacks/generateLwc.ts
This file was deleted.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
packages/vscode-extension/src/commands/datapacks/omniScriptActivate.ts
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,82 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { OmniScriptActivationOptions, OmniScriptActivator, OmniScriptDefinitionGenerator, OmniScriptSpecification, VlocityDatapack } from '@vlocode/vlocity-deploy'; | ||
import { VlocodeCommand } from '../../constants'; | ||
import { vscodeCommand } from '../../lib/commandRouter'; | ||
import { DatapackCommand } from './datapackCommand'; | ||
import { container } from '@vlocode/core'; | ||
import { ActivityProgress } from '../../lib/vlocodeActivity'; | ||
|
||
@vscodeCommand(VlocodeCommand.omniScriptActivate, { focusLog: true, showProductionWarning: true }) | ||
export default class ActivateOmniScriptCommand extends DatapackCommand { | ||
|
||
public execute(...args: any[]) : Promise<void> { | ||
return this.executeWithSelection(args[1] || [args[0] || this.currentOpenDocument]); | ||
} | ||
|
||
protected async executeWithSelection(selectedFiles: vscode.Uri[]) : Promise<void> { | ||
const datapacks = await this.loadDatapacks(selectedFiles); | ||
const options = { | ||
toolingApi: true, | ||
remoteActivation: false, | ||
reactivateDependentScripts: false | ||
}; | ||
|
||
if (datapacks.length === 0) { | ||
throw new Error('Selected file is not a Vlocity OmniScript DataPack'); | ||
} | ||
|
||
const hasReusableScripts = datapacks.some(datapack => datapack.IsReusable__c); | ||
if (hasReusableScripts && await this.promptDependencyReactivation()) { | ||
options.reactivateDependentScripts = true; | ||
} | ||
|
||
return this.vlocode.withActivity('OmniScript', (progress) => this.activateScripts(datapacks, options, progress)); | ||
} | ||
|
||
protected async activateScripts( | ||
datapacks: VlocityDatapack[], | ||
options: OmniScriptActivationOptions, | ||
progress: ActivityProgress | ||
) : Promise<void> { | ||
const activated = new Array<OmniScriptSpecification>(); | ||
const failed = new Array<OmniScriptSpecification & { error: unknown }>(); | ||
|
||
for (const datapack of datapacks) { | ||
const omniScriptSpec = { | ||
type: datapack.Type__c, | ||
subType: datapack.SubType__c, | ||
language: datapack.Language__c | ||
}; | ||
|
||
if (!omniScriptSpec.subType || !omniScriptSpec.type) { | ||
throw new Error(`Datapack is not of type OmniScript: ${datapack.headerFile}`); | ||
} | ||
|
||
progress.report({ message: `Activating ${omniScriptSpec.type}/${omniScriptSpec.subType}...` }); | ||
|
||
try { | ||
await container.get(OmniScriptActivator).activate(omniScriptSpec, options); | ||
activated.push(omniScriptSpec); | ||
} catch (error) { | ||
failed.push({...omniScriptSpec, error }); | ||
this.logger.error(`Failed to activate ${omniScriptSpec.type}/${omniScriptSpec.subType}: ${error.message}`); | ||
} | ||
} | ||
|
||
void vscode.window.showInformationMessage(`Activated ${activated.length} OmniScript(s)`); | ||
} | ||
|
||
private async promptDependencyReactivation() : Promise<boolean> { | ||
const outcome = await vscode.window.showQuickPick([ | ||
{ value: true, label: 'Yes', description: 'Reactivate scripts that use this script as dependency' }, | ||
{ value: false, label: 'No', description: 'Only reactivate this script and do not refresh any scripts embedding this script as dependency' } | ||
], { | ||
placeHolder: 'Reactivate dependent scripts?' | ||
}); | ||
if (!outcome) { | ||
throw new Error('User cancelled operation'); | ||
} | ||
return outcome.value; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/vscode-extension/src/commands/datapacks/omniScriptDeployLwc.ts
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,53 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { OmniScriptActivator, OmniScriptDefinitionGenerator, VlocityDatapack } from '@vlocode/vlocity-deploy'; | ||
import { VlocodeCommand } from '../../constants'; | ||
import { vscodeCommand } from '../../lib/commandRouter'; | ||
import { DatapackCommand } from './datapackCommand'; | ||
import { container } from '@vlocode/core'; | ||
import { ActivityProgress } from '../../lib/vlocodeActivity'; | ||
|
||
@vscodeCommand(VlocodeCommand.omniScriptDeployLwc, { focusLog: true, showProductionWarning: true }) | ||
export default class DeployLwcCommand extends DatapackCommand { | ||
|
||
public execute(...args: any[]) : Promise<void> { | ||
return this.executeWithSelection(args[1] || [args[0] || this.currentOpenDocument]); | ||
} | ||
|
||
protected async executeWithSelection(selectedFiles: vscode.Uri[]) : Promise<void> { | ||
const datapacks = await this.loadDatapacks(selectedFiles) | ||
|
||
if (datapacks.length === 0) { | ||
throw new Error('Selected file is not a Vlocity OmniScript DataPack'); | ||
} | ||
|
||
const notLwcEnabled = datapacks.some(datapack => !datapack.IsLwcEnabled__c); | ||
if (notLwcEnabled) { | ||
const notLwcWarningResult = await vscode.window.showWarningMessage( | ||
'Not all selected OmniScripts are LWC enabled. Only LWC enabled OmniScripts can be deployed as LWC components. ' + | ||
'Deploying non-LWC enabled OmniScripts can result in errors during deployment.', | ||
'Continue', 'Cancel' | ||
); | ||
if (notLwcWarningResult !== 'Continue') { | ||
return; | ||
} | ||
} | ||
|
||
return this.vlocode.withActivity('OmniScript', (progress) => this.deployLwc(datapacks, progress)); | ||
} | ||
|
||
protected async deployLwc(datapacks: VlocityDatapack[], progress: ActivityProgress) : Promise<void> { | ||
for (const datapack of datapacks) { | ||
progress.report({ message: `Generating ${datapack.name} definitions...`, total: datapacks.length, increment: 1 }); | ||
const definition = await container.get(OmniScriptDefinitionGenerator).getScriptDefinitionFromDatapack(datapack); | ||
|
||
progress.report({ message: `Deploying ${datapack.name} LWC...` }); | ||
await container.get(OmniScriptActivator).deployLwc(definition, { | ||
toolingApi: true, | ||
remoteActivation: false, | ||
reactivateDependentScripts: true | ||
}); | ||
} | ||
void vscode.window.showInformationMessage(`Deployed LWC components for ${datapacks.length} OmniScript(s)`); | ||
} | ||
} |
Oops, something went wrong.