Stryke CodeThe Stryke Code extension allows you to work with your Stryke source code from your local VSC instance. Once you install Stryke Code, you will be able to retrieve and save scripts and templates as well as execute scripts and renter templates of any of your Stryke applications via VSC commands. To configure which app instance the extension should connect to and setup any other parameters, you can use the Stryke settings found under user and workspace configurations Write codeScripts are written in plain JavaScript (ECMAScript 2017) and run on a controlled Node environment. This environment provides a secure and fast way for your scripts to execute, with some handy Node features such as the ability to require some built in Node modules as well as some external ones. For a list of supported modules please check the Stryke Library reference. Interacting with Stryke is done via the Stryke Library. Through the Stryke Library you can retrieve the current user, the record in context, perform CRUD and query operations. Documentation for the library can be found here: Stryke Library reference. Resolve and Error functionsAll scripts written for Stryke must be terminated via the execution of either a When Alternatively, calling Develop TemplatesTemplates are used to render the output of scripts (JSON) as rich HTML documents. Templates represent the HTML document in which the script result is injected. The JSON data returned by a script is injected in an HTML template via {{ }} syntax and follows the Mustache protocol. Using Stryke Code you can develop the HTML templates for your application and render them locally to preview your work. The template that is being rendered locally can be injected with mock data following the data mocking process described below. CommandsStryke code offers the following set of commands which can be executed via the VSC command palette LoginThis command authenticates you with Stryke using the username in the VSC configuration. When executed, it will prompt for a password in order to log in to Stryke. This command must be run before any other commands that interact with Stryke. It will maintain an open session with Stryke until the logout command is run. LogoutCloses an open session with Stryke if the user has previously logged in. Retrieve all CodeRetrieves all scripts and templates for the configured app instance (in the workspace configuration). Files will be named after the record's name (eg: script name). If any files with the same names as any of the retrieved scripts exist in the local folder, they will be overwritten with the content coming from the server. Retrieve Active FileRetrieves from Stryke the latest source code for the script or template in the active window. The content of the source code will be overwritten with the content from the server. Save CodeSaves the current (active in the VSC editor) script or template under the configured application instance in Stryke. Script source code files are assumed to have a The name of the local file will be used to identify the source code in Stryke (matching the name field). In order to create a new script in Stryke, simply create a new file with a Similarly, to create a new template from VSC, create a new file with a If the file already exists in Stryke, its content will be updated with the one in the local file. Note that HTML templates are sanitized when saved to Stryke. The sanitized output will replace the content of the HTML template in the editor as soon as a template file is successfully saved in Stryke. Execute Active ScriptExecutes the current (active in the VC editor) script in Stryke. The script will be executed remotely on Stryke. The script record must exist in Stryke in order for it to be executed. The script's result, execution times and log output can be viewed in the VSC output panel. Render Active TemplateRenders the current (active in the VC editor) HTML template locally. Stryke code will open a new window next to the HTML source code showing the HTML rendered. If a mock file is provided, the values from the mock data are injected where appropriate. Once the command is executed, the template will be re-rendered everytime it is saved locally. This is independent from the autosave configuration, which if enabled will save the template file to Stryke when it is saved locally. User impersonationIt is possible to execute a script on behalf of a specific user of the app instance. In order to do this, the username of this user needs to be set in the Stryke's configuration under the parameter "runas". Once the "runas" parameter is set, all scripts executed by the extension will be executed as if that user was running them. Code such as 'stryk.user' will return the details of the user being impersonated. Mocking data for executionWhen executing a script from VSC, it is possible to mock some of the data that is provided to the script at execution time. Things such as the record in context to the script execution can be mocked by creating a mock data file in the same folder as the script file for which data is being mocked. The mock data file must have the following naming:
The mock data file must contain a JSON with the following format
Mocking options
It is possible to specify an arbitrary record (which must exist in the app instance) that will be provided to the script at execution time as the record in context (through:
API and stand alone scripts can be passed JSON data in the request's payload when they are executed.
This data is accessed via the Stryke library through: Using the mockData, it is possible to provide this JSON data using the "requestData" field using the following format:
Render TemplateRenders the HTML template that is currently active in the VSC editor in a side panel. The rendering is done locally and is refreshed everytime the HTML file is saved. Mock data can be injected in the template when it is rendered by defining a mock file as described below. Mocking template dataSimilarly to mocking data when executing a script, it is possible to mock data to be injected in a template that is rendered locally. The mock data must be contained in a file with the following naming:
The format of the mock data must match the format of the JSON object that is returned by the script that is generating the data for the template. The content of the mock file should follow this format:
ConfigurationStryke Code requires setting of some configuration parameters. It is possible to set these parameters at both the User and Workspace level in VSC ( It is assumed that a workspace contains files of a single app instance. It is possible to keep source code of multiple app instances in the same folder/workspace. However, only one app instance can be configured at a time for script CRUD and execution. Trying to retrieve, modify or execute a script that belongs to a different app instance than the one currently configured in the workspace settings will cause an error. The following parameters are to be configured before starting to work with scripts.
Stryke DocumentationFor more details and full documentation on how to develop scripts and templates, please visit the Stryke Docs page. |