Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
Marcel Kloubert edited this page Dec 30, 2017 · 4 revisions

Home >> if

if

Many settings like shell commands, packages or targets support an if property, which contains JavaScript code which indicates if a setting is currently available/usable or not.

{
    "deploy.reloaded": {
        "executeOnStartup": [
            {
                "command": "npm install",
                "if": " !require('fs').existsSync( $v['workspaceroot'] + '/node_modules' ) "
            }
        ]
    }
}

The upper shell command is only executed, if NO node_modules folder is found in the root directory of the underlying workspace.

Constants

$ctx

A special object of the underlying setting / object.

$v

An object that stores all placeholders, which are available in that context as object.

The values can be accessed by their names in lower case format.

{
    "deploy.reloaded": {
        "executeOnStartup": [
            {
                "command": "npm install",
                "if": " require('fs').existsSync( $v['workspaceroot'] + '/package.json' ) "
            }
        ]
    }
}

Functions

$e

Short version of JavaScript's eval.

{
    "deploy.reloaded": {
        "executeOnStartup": [
            {
                "command": "npm install",
                "if": " $e( \" $r('fs').existsSync( $v['workspaceroot'] + '/composer.json' \" ) "
            }
        ]
    }
}

$r

Short version of NodeJS's require, which includes a module the same way, as you are working as extension code. This makes extension modules and modules from package.json also available for you.

{
    "deploy.reloaded": {
        "executeOnStartup": [
            {
                "command": "npm install",
                "if": " $r('fs').existsSync( $v['workspaceroot'] + '/composer.json' ) "
            }
        ]
    }
}

Modules

$h

The helper module of that extension.

{
    "deploy.reloaded": {
        "executeOnStartup": [
            {
                "command": "npm install",
                "if": " 'my_project' === $h.normalizeString( $v['workspace'] ) "
            }
        ]
    }
}
Clone this wiki locally