lib/cache.js
function(config){
    if (!_fs.exist(config.output)){
        return abortProcess(
            config,'no package to be uploaded'
        );
    }
    _logger.info('begin build upload form ...');
    var form = new FormData();
    var ex = _util.merge(
        {
            version: '0.1',
            platform: 'ios&android'
        },
        config.extension
    );
    // build form
    Object.keys(ex).forEach(function(name){
        form.append(name,ex[name]);
    });
    form.append('token',config.token);
    form.append('resID',config.appid);
    form.append('appID',config.nativeId);
    form.append('userData',JSON.stringify({domains:config.domains}));
    form.append('zip',fs.createReadStream(config.output));
    // submit form
    _logger.info('begin upload package to web cache server ...');
    form.submit(config.api,function(err,res){
        if (err){
            return abortProcess(
                config,'upload failed for reason:\n%s',err.stack
            );
        }
        // chunk response data
        var arr = [];
        res.on('data',function(chunk){
            arr.push(chunk);
        });
        // parse response result
        res.on('end',function(){
            var ret = null,
                txt = arr.join('');
            try{
                ret = JSON.parse(txt);
            }catch(ex){
                // result error
                return abortProcess(
                    config,'[%s] %s\n%s',
                    res.statusCode,txt,ex.stack
                );
            }
            if (!!ret&&ret.code==0){
                clearTemp(config);
                _logger.info('package upload success');
                config.ondone();
            }else{
                return abortProcess(
                    config,'package upload failed for reason: [%s] %s',
                    res.statusCode,txt
                );
            }
        });
        res.resume();
    });
}
function(config){
    if (!_fs.exist(config.output)){
        return abortProcess(
            config,'no package to be uploaded'
        );
    }
    _logger.info('begin build upload form ...');
    var form = new FormData();
    var ex = _util.merge(
        {
            version: '0.1',
            platform: 'ios&android'
        },
        config.extension
    );
    // build form
    Object.keys(ex).forEach(function(name){
        form.append(name,ex[name]);
    });
    form.append('token',config.token);
    form.append('resID',config.appid);
    form.append('appID',config.nativeId);
    form.append('userData',JSON.stringify({domains:config.domains}));
    form.append('zip',fs.createReadStream(config.output));
    // submit form
    _logger.info('begin upload package to web cache server ...');
    form.submit(config.api,function(err,res){
        if (err){
            return abortProcess(
                config,'upload failed for reason:\n%s',err.stack
            );
        }
        // chunk response data
        var arr = [];
        res.on('data',function(chunk){
            arr.push(chunk);
        });
        // parse response result
        res.on('end',function(){
            var ret = null,
                txt = arr.join('');
            try{
                ret = JSON.parse(txt);
            }catch(ex){
                // result error
                return abortProcess(
                    config,'[%s] %s\n%s',
                    res.statusCode,txt,ex.stack
                );
            }
            if (!!ret&&ret.code==0){
                clearTemp(config);
                _logger.info('package upload success');
                config.ondone();
            }else{
                return abortProcess(
                    config,'package upload failed for reason: [%s] %s',
                    res.statusCode,txt
                );
            }
        });
        res.resume();
    });
}
upload package to web cache server
@param  {Object} config - config object
@return {Void}