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

target_script

Marcel Kloubert edited this page Dec 9, 2017 · 8 revisions

Home >> Targets >> script

External Node.js based scripts

Deploys via a JS script.

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

                "script": "E:/test/deploy.js",
                "options": {
                    "TM": 5979,
                    "MK": "23979"
                }
            }
        ]
    }
}
Name Description
cache Load script from cache or not. Default: (false)
options Optional value for the execution.
script* The script file to exeute. Relative path will use the settings folder (like .vscode) or the home directory as scopes. Default: ./deploy.js

* supports placeholders

Implement own scripts

A script file has the following skeleton:

exports.execute = function(args) {
    if (0 == args.operation)
        // Delete files
        return deleteFiles(args);  // s. below

    if (1 == args.operation)
        // Deploy / upload
        return deployFiles(args);  // s. below

    if (2 == args.operation)
        // list directory
        return listDirectory(args);  // s. below

    if (3 == args.operation)
        // Pull / download
        return pullFiles(args);  // s. below

    throw new Error(`${args.operation} is not supported!`);
};


function deleteFiles(args) {
    for (let file of args.files) {
        if (args.isCancelling)
            break;  // user wants to cancel

        try {
            file.onBeforeDelete();  // tell that we are going to start the
                                    // delete operation for this file now
                                    // 
                                    // you can submit an optional string that
                                    // is displayed as 'destination' in the GUI

            // do the delete operation here

            file.onDeleteCompleted();  // tell that anything worked fine
        }
        catch (e) {
            file.onDeleteCompleted(e);  // submit the error
        }
    }
}

function deployFiles(args) {
    for (let file of args.files) {
        if (args.isCancelling)
            break;  // user wants to cancel

        try {
            file.onBeforeUpload();  // tell that we are going to start the
                                    // deploy operation for this file now
                                    // 
                                    // you can submit an optional string that
                                    // is displayed as 'destination' in the GUI

            // do the deploy operation here
            
            // reads the content of this file async
            let contentToDeploy = await file.read();

            file.onUploadCompleted();  // tell that anything worked fine
        }
        catch (e) {
            file.onUploadCompleted(e);  // submit the error
        }
    }
}

function listDirectory(args) {
    let result = {
        dirs[],   // DirectoryInfo
        files: [],  // FileInfo
        others: [],  // other FileSystemInfo objects
        target: args.target
    };

    // the directory to list is stored in
    // 'args.dir'

    // args.isCancelling provides if
    // user wants to cancel or not

    return result;
}

function pullFiles(args) {
    for (let file of args.files) {
        if (args.isCancelling)
            break;  // user wants to cancel

        try {
            file.onBeforeDownload();  // tell that we are going to start the
                                      // pull operation for this file now
                                      // 
                                      // you can submit an optional string that
                                      // is displayed as 'source' in the GUI

            // do the pull operation here
            // 
            // we store the data in 'downloadedData' var
            // for this example
            // 
            // recommed is to load the data as buffer
            // or readable NodeJS stream

            // tell that anything worked fine
            // and submit the data to write
            file.onDownloadCompleted(null, downloadedData);
        }
        catch (e) {
            file.onDownloadCompleted(e);  // submit the error
        }
    }
}
Clone this wiki locally