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 Jan 20, 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

Implement own scripts

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

// this function is REQUIRED
function deployFile(args) {
    return new Promise(function(resolve, reject) {
        // tell extension that whole operation
        // has been completed
        var hasCancelled = false;
        var onCompleted = function(err) {
            args.canceled = hasCancelled;

            if (err) {
                reject(err);
            }
            else {
                resolve(args);  // send input arguments
                                // back to the extension
            }
        };

        // [HINT for version 5.x+]
        // this is the replacement for
        // 'isCancelling()' method
        me.context.once('deploy.cancel', function() {
            hasCancelled = true;
        });

        if (hasCancelled) {
            onCompleted();  // cancellation request
            return;
        }

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

        try {
            onBeforeDeploy();

            //TODO: do the MAGIC here

            onCompleted();
        }
        catch (e) {
            onCompleted(e);
        }
    });
}
exports.deployFile = deployFile;

// this function is OPTIONAL
//
// by default the 'deployFile' is called for
// each file that is submitted to this function
function deployWorkspace(args) {
    return new Promise(function(resolve, reject) {
        // tell extension that whole operation
        // has been completed
        var hasCancelled = false;
        var onCompleted = function(err, hasCancelled) {
            args.canceled = hasCancelled;

            if (err) {
                reject(err);
            }
            else {
                resolve(args);  // send input arguments
                                // back to the extension
            }
        };

        // [HINT for version 5.x+]
        // this is the replacement for
        // 'isCancelling()' method
        me.context.once('deploy.cancel', function() {
            hasCancelled = 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 (hasCancelled) {
                    onCompleted(null, true);  // 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);
        }
    });
}
exports.deployWorkspace = deployWorkspace;

args parameters

deployFile()

s. DeployFileArguments

deployWorkspace()

s. DeployWorkspaceArguments

Clone this wiki locally