Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

target_operations

Marcel Kloubert edited this page Jul 7, 2018 · 38 revisions

Home >> Targets >> Operations

Operations

This page describes the supported operation types, which can be defined with beforeDelete, beforeDeploy, beforePull, deleted, deployed, prepare and pulled properties inside a target.

Table of contents

Operations []

Name Description
if (JavaScript) Code, which checks if operation should be executed or not.
ignoreIfFail Continue if execution fails or not. Default: (false)
name The custom (display) name.
type The type. Default: open

chrome []

Executes a method for a DevTools compatible browser debugger, as implemented in Google Chrome.

For the following example, you have to start a Chrome instance with the following parameters:

chrome --remote-debugging-port=9222

Settings:

{    
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",

                "deployed": [
                    {
                        "type": "chrome",
                        "host": "localhost", "port": 9222,

                        "method": "Page.reload",
                        "parameters": {
                            "ignoreCache": true
                        }
                    }
                ]
            }
        ]
    }
}
Name Description
alwaysAskForPage Always ask for the browser page or not. Default: (false)
debug Debug results or not. Default: (true)
host The hostname, where the debugger runs. Default: 127.0.0.1
method The method to invoke (for more information s. Chrome DevTools Protocol Viewer). Default: Page.reload
pages A regular expression, which filters page by their title.
parameters Parameters for the method.
port The TCP port, where the debugger runs. Default: 9222

cleanup []

Cleanups a (local) directory.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "beforeDeploy": [
                    {
                        "type": "cleanup",
                        "dir": "./bin",
                        "include": [ "**" ],
                        "exclude": [ "**/*.log" ]
                    }
                ]
            }
        ]
    }
}
Name Description
dir* The directory to cleanup.
exclude One or more patterns of files to exclude.
include One or more patterns of files to include. Default: **
recursive Cleanup recursively or not. Default: (true)

* supports placeholders

command []

Executes a Visual Studio Code command.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "beforeDeploy": [
                    {
                        "type": "command",
                        "command": "workbench.action.tasks.build"
                    }
                ]
            }
        ]
    }
}
Name Description
arguments One or more optional argument for the execution.
command* The ID of the command to execute.

* supports placeholders

exec []

Executes a shell command inside the workspace.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "beforeDeploy": [
                    {
                        "type": "exec",
                        "command": "npm install"
                    }
                ]
            }
        ]
    }
}
Name Description
command* The (shell) command to execute.
cwd* The custom working directory for the execution. Relative paths will be mapped to the root directory of the underlying workspace.
maxBuffer Largest amount of data in bytes allowed on stdout or stderr. s. NodeJS exec()
noPlaceHolders Do not use placeholders in command property. Default: (false)
printOutput Print the result from stdout to output channel or not. Default: (true)
timeout Execution timeout. s. NodeJS exec()

* supports placeholders

http []

Does a HTTP request.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "sftp",
                "name": "My site",

                "host": "mysite.example.com",
                "user": "mkloubert", "password": "P@assword123!",

                "deployed": [
                    {
                        "type": "http",
                        
                        "url": "https://mysite.example.com/flush_cache.php",
                        "headers": {
                            "Authorization": "Basic bWtsb3ViZXJ0OlBhdWxpbmFaU3V4"
                        }
                    }
                ]
            }
        ]
    }
}
Name Description
body* The body or the path to a script that returns the body to send.
headers** The object that contains the request headers and their values by properties.
isBodyBase64 Is value in body property Base64 encoded or not. Default: (false)
isBodyScript Is value in body property the path to a script that returns the body to send or not. Default: (false)
method The HTTP request method. Default: GET
noPlaceholdersForTheseHeaders A list of one or more header names, where placeholders should not be applied to. This can also be a boolean value that indicates if the feature should be enabled for all headers or not. Default: (true)
options The value or object for the body script.
password The password for basic authentication.
url The URL to call.
username The username for basic authentication.

* supports placeholders, but only if script (isBodyScript = (true))
** supports placeholders

Body scripts []

A script file must have a public / exported getBody() function:

exports.getBody = async function(args) {
    // return a string or Buffer
}

The args parameter uses the HttpBodyModuleExecutionArguments interface.

Relative paths will be mapped to your home directory (.vscode-deploy-reloaded sub folder) or the .vscode folder.

open []

Opens a target, like an executable or a website.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "deployed": [
                    {
                        "type": "open",
                        "target": "https://github.com/mkloubert"
                    }
                ]
            }
        ]
    }
}
Name Description
target* The thing that should be opened. Can be a URL, file or executable.
wait Wait until execution has been finished or not. Default: (true)

* supports placeholders

Or shorter:

{
    "deploy.reloaded": {
        "targets": [
            {
                // ...

                "deployed": [
                    "https://github.com/mkloubert"
                ]
            }
        ]
    }
}

script []

Runs a script from a file.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "beforeDeploy": [
                    {
                        "type": "script",
                        
                        "script": "./my_beforeDeploy_script.js",
                        "options": 5979 
                    }
                ]
            }
        ]
    }
}
Name Description
options Additional options for the script execution.
script* The path to the script file. Relative paths will be mapped to your home directory (.vscode-deploy-reloaded sub folder) or the .vscode folder.

* supports placeholders

A script looks like that:

exports.execute = async function(args) {
    // do the MAGIC here

    // from the configuration example
    // above 'args.options' would contain
    // 5979 as value
}
args

s. ScriptTargetOperationExecutionArguments

slack []

Sends a notification to a one or more Slack channels.

{
    "deploy.reloaded": {
        "targets": [
            {
                "name": "My FTP target",                
                "type": "ftp",

                "deployed": [
                    {
                        "type": "slack",
                        
                        "channels": [ "<ID-OF-A-CHANNEL>" ],
                        "token": "<API-TOKEN>",
                        
                        "minimumNumberOfFiles": 2,
                        
                        "user": "mkloubert"
                    }
                ]
            }
        ]
    }
}
Name Description
channels* One or more channels to send notifications to.
minimumNumberOfFiles The minimum number of handled files before a notification is send. Default: 1
token* The API token.
user* The optional username that sends the notifications.

* supports placeholders

sql []

Executes SQL scripts.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "deployed": [
                    {
                        "type": "sql",
                        
                        "engine": "mysql",
                        "options": {
                            "host": "mysql.example.com",
                            "user": "dbUser",
                            "password": "P@assword123!", 
                            "database": "myDatabase"
                        },

                        "queries": [
                            "TRUNCATE TABLE `logs`"
                        ]
                    }
                ]
            }
        ]
    }
}
Name Description
engine The engine to use.
options The options for the connection.
queries One or more query to invoke.
engine []
Name Description
mysql MySQL
sql Microsoft SQL
options []
MySQL []
Name Description
database The database to connect to.
host The host. Default: 127.0.0.1
port The TCP port. Default: 3306
password The password.
rejectUnauthorized Reject untrusted SSL connections or not.
user The username. Default: root
SQL (Microsoft SQL) []
Name Description
database The database to connect to.
driver The driver to use (for more information s. mssql). Default: tedious
encrypt Encrypt the connection or not. Default: (false)
host The host. Default: 127.0.0.1
port The TCP port. Default: 1433
password The password.
user The username. Default: sa

wait []

Waits a number of milliseconds, before the next operation is executed.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",
                "name": "This is a test",

                "beforeDeploy": [
                    {
                        "type": "wait",
                        "time": 1000
                    }
                ]
            }
        ]
    }
}
Name Description
time The number of milliseconds to wait before next operation is invoked.

prepare []

Operations, which are stored in prepare setting of a target, are executed before the operations of beforeDeploy and even if no file is going to be handled.

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "test",

                "prepare": [
                    {
                        "type": "exec",
                        "command": "node install",

                        "onlyWhen": [ "deploy" ]
                    }
                ]
            }
        ]
    }
}
Name Description
onlyWhen A list of one or more deploy events the entry is executed when. Possible values are: delete, deploy or pull. Default: deploy
reloadFileList Reload list of files or not. Default: (true)