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

target_script

Marcel Kloubert edited this page Apr 15, 2017 · 50 revisions

Home >> Targets >> script

External Node.js based scripts

Deploys via a JS script.

{
    "deploy": {
        "targets": [
            {
                "type": "script",
                "name": "My script",
                "description": "A deploy script",

                "script": "E:/test/deploy.js",
                "options": {
                    "TM": 5979,
                    "MK": "23979"
                }
            }
        ]
    }
}
Name Description
options Optional value for the execution.
script* The script file to exeute. Default: ./deploy.js

* supports placeholders

Implement own scripts

A script file has the following skeleton (s. ScriptModule):

// this function is REQUIRED
exports.deployFile = function(args) {
    if (args.canceled) {
        return;
    }

    // use this to tell the extension that
    // we begin to deploy the file
    args.onBeforeDeploy('Name of the destination, like a path or URL');

    //TODO: do the MAGIC here
    // 
    //      check for 'args.canceled' == (true)
    //      in each of your "important" code parts
    //      where deployment can be cancelled

    // return NOTHING to indicate that
    // this is a SYNC execution
}

// this function is OPTIONAL
//
// by default the 'deployFile' is called for
// each file that is submitted to this function
exports.deployWorkspace = function(args) {
    return new Promise(function(resolve, reject) {
        // tell extension that whole operation
        // has been completed
        var onCompleted = function(err) {
            if (err) {
                reject(err);
            }
            else {
                resolve(args);  // send input arguments
                                // back to the extension
            }
        };

        args.context.once('deploy.cancel', function() {
            args.canceled = true;
        });

        // use this to tell the extension that
        // we begin to deploy a file
        // from the 
        var onBeforeDeployFile = function(fileToDeploy) {
            if (args.deployOptions.onBeforeDeployFile) {
                args.deployOptions.onBeforeDeployFile(args.sender, {
                    file: fileToDeploy,
                    target: args.target
                });
            }
        };

        // tell extension that a file operation
        // has been completed
        var onFileCompleted = function(deployedFile, err) {
            if (args.deployOptions.onFileCompleted) {
                args.deployOptions.onFileCompleted(args.sender, {
                    error: err,
                    file: deployedFile,
                    target: args.target
                });
            }
        };

        try {
            // iterate over the file list
            // of 'args.files' property...
            for (var i = 0; i < args.files.length; i++) {
                if (args.canceled) {
                    onCompleted();  // cancellation request
                    return;
                }

                var fileToDeploy = args.files[i];

                try {
                    onBeforeDeployFile(fileToDeploy);

                    //TODO: do the MAGIC here

                    onFileCompleted(fileToDeploy);
                }
                catch (e) {
                    onFileCompleted(fileToDeploy, e);
                }
            }

            onCompleted();
        }
        catch (e) {
            onCompleted(e);
        }
    });
}

// [OPTIONAL]
// this is for the logic of
// PULLING A FILE
// 
// if not defined: deployFile() is used
exports.pullFile = function(args) {
    // your code to pull file
    // similar to 'deployFile()'
}

// [OPTIONAL]
// this is for the logic of
// PULLING FILES OF A PACKAGE
// 
// if not defined: deployWorkspace() is used
exports.pullWorkspace = function(args) {
    // your code to pull package
    // similar to 'deployWorkspace()'
}

args parameters

deployFile(), pullFile()

s. DeployFileArguments

deployWorkspace(), pullWorkspace()

s. DeployWorkspaceArguments

Clone this wiki locally