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

target_pipeline

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

Home >> Targets >> pipeline

Pipeline

Pipes a list of sources files to a new destination, by using a script and sends the new file list to a target.

For example: You have PHP files that needs to be encrypted with optimizers, like Zend Optimizer, before they are uploaded. With a "pipe" script, you can encrypt them into a temporary directory and returns the list of that encrypted files, which will be processed by a "SFTP" based target, e.g.

{
    "deploy": {
        "targets": [
            {
                "type": "pipeline",
                "name": "My PHP encrypter",
                "description": "A script that encrypts source files",

                "script": "./encrypt-php.js",
                "options": {
                    "key": "P@assword123!"
                },
                "target": "My PHP server"
            },

            {
                "name": "My PHP server",
                "description": "A folder on my PHP server",
                "type": "sftp",

                "host": "host.example.com",
                "user": "tester", "password": "password",
            }
        ]
    }
}
Name Description
options Optional value for the execution.
script* The script file to exeute. Default: ./pipeline.js
target The name of the target that should be process the "piped" / new files.

* supports placeholders

Implement a pipe

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

// [REQUIRED]
// 
// do pipe the original files, you got from pipeline,
// to a new location, like a temporary directory, e.g.
exports.pipe = function(args) {
    // update "args.baseDirectory" with the new
    // target root directory, like a temporary folder
    // so the target will be able to resolve
    // relative file paths, e.g.

    var newFileList = [];
    for (var i = 0; i < args.files.length; i++) {
        if (args.context.isCancelling()) {
            // user started a "cancellation request"
            // so we stop here and tell that we
            // have canceled 

            return;
        }

        var originalFile = args.files[i];

        // do the MAGIC here
        // and process 'originalFile'
        // to a new file and
        // write its full path, that is inside "args.baseDirectory",
        // to 'newFileList'
    }

    // update the file list that will be
    // send by pipeline to defined target
    args.files = newFileList;

    // return a Promise
    // if you do the job
    // ASYNC
    // instead of nothing
}

// [OPTIONAL]
// 
// this will be invoked AFTER new files
// were processed by target
// 
// here you can do things like cleanups, e.g.
exports.onPipeCompleted = function(args, err) {
    // do the MAGIC here

    // return a Promise for
    // an ASYNC execution
    // instead of nothing
}

args parameters

s. PipeArguments

Clone this wiki locally