Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

atm3-deploy-http-push

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atm3-deploy-http-push - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

184

index.js
/**
* fis.baidu.com
*/
var fs = require('fs');
var archive = require('archiver')('zip');
var request = require('request');
var _ = fis.util;
function upload(receiver, to, release, content, file, callback) {
var subpath = file.subpath;
fis.util.upload(
//url, request options, post data, file
receiver, null, {
to: to + release
}, content, subpath,
function (err, res) {
if (err || res.trim() != '0') {
callback('upload file [' + subpath + '] to [' + to +
'] by receiver [' + receiver + '] error [' + (err || res) + ']');
} else {
var time = '[' + fis.log.now(true) + ']';
process.stdout.write(
' - '.green.bold +
time.grey + ' ' +
subpath.replace(/^\//, '') +
' >> '.yellow.bold +
to + release +
'\n'
);
callback();
}
var subpath = file.subpath;
fis.util.upload(
//url, request options, post data, file
receiver, null, {
to: to + release
}, content, subpath,
function(err, res) {
if (err || res.trim() != '0') {
callback('upload file [' + subpath + '] to [' + to +
'] by receiver [' + receiver + '] error [' + (err || res) + ']');
} else {
var time = '[' + fis.log.now(true) + ']';
process.stdout.write(
' - '.green.bold +
time.grey + ' ' +
subpath.replace(/^\//, '') +
' >> '.yellow.bold +
to + release +
'\n'
);
callback();
}
}
);
}
function normalizePath(to, root) {
var cwd = process.cwd();
if (!to) {
to = '/';
} else if (to[0] === '.') {
to = fis.util(cwd + '/' + to);
} else if (/^output\b/.test(to)) {
to = fis.util(root + '/' + to);
} else {
to = fis.util(to);
}
);
return to;
}
module.exports = function (options, modified, total, callback) {
if (!options.to) {
throw new Error('options.to is required!');
} else if (!options.receiver) {
throw new Error('options.receiver is required!');
}
module.exports = function(options, modified, total, callback) {
if (!options.to) {
throw new Error('options.to is required!');
} else if (!options.receiver) {
throw new Error('options.receiver is required!');
}
var to = options.to;
var receiver = options.receiver;
var to = options.to,
type = options.type,
reTryCount = options.retry,
zipFile = options.file || "publish/publish.zip";
var receiver = options.receiver;
var steps = [];
var steps = [];
var realModified = modified.filter(function (file) {
return !file._fromCache;
});
if (!realModified.length) {
return fis.log.info('nothing need to upload!');
}
modified.forEach(function (file) {
var reTryCount = options.retry;
var realModified = modified.filter(function(file) {
return !file._fromCache;
});
if (!realModified.length) {
return fis.log.info('nothing need to upload!');
}
steps.push(function (next) {
var _upload = arguments.callee;
upload(receiver, to, file.getHashRelease(), file.getContent(), file, function (error) {
if (error) {
if (!--reTryCount) {
throw new Error(error);
} else {
_upload();
}
} else {
next();
if (type === "zip") {
var targetPath = normalizePath(zipFile, fis.project.getProjectPath());
if (!fis.util.exists(targetPath)) {
fis.util.mkdir(fis.util.pathinfo(targetPath).dirname);
}
});
});
});
var output = fs.createWriteStream(targetPath);
output.on('close', function() {
fis.log.debug('\nzip end!');
process.stdout.write("\nUpload start!\n");
var path = fis.project.getProjectPath() + "/" + zipFile;
var formData = {
to: to,
type: type,
file: fs.createReadStream(path)
};
request.post({url:receiver, formData: formData}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
fs.unlink(path);
process.stdout.write("Upload successful!");
});
});
_.reduceRight(steps, function (next, current) {
return function () {
current(next);
};
}, callback)();
archive.pipe(output);
modified.forEach(function(file) {
if (!file.release) {
fis.log.error('unable to get release path of file[' + file.realpath + ']: Maybe this file is neither in current project or releasable');
}
archive.append(file.getContent(), {
name: file.getHashRelease()
});
});
archive.finalize();
} else {
modified.forEach(function(file) {
steps.push(function(next) {
var _upload = arguments.callee;
upload(receiver, to, file.getHashRelease(), file.getContent(), file, function(error) {
if (error) {
if (!--reTryCount) {
throw new Error(error);
} else {
_upload();
}
} else {
next();
}
});
});
});
}
_.reduceRight(steps, function(next, current) {
return function() {
current(next);
};
}, callback)();
};
module.exports.options = {
// 允许重试两次。
retry: 2
};
// 允许重试两次。
retry: 2
};
{
"name": "atm3-deploy-http-push",
"version": "1.0.2",
"version": "1.0.3",
"description": "atm3 deploy http-push plugin",

@@ -28,24 +28,28 @@ "main": "index.js",

"homepage": "https://github.com/fex-team/atm3-deploy-http-push",
"_id": "atm3-deploy-http-push@1.0.1",
"_shasum": "5eac819ea647e4cc49c3b8ce9a97015b4ae8346b",
"_from": "atm3-deploy-http-push@1.0.1",
"_npmVersion": "2.7.4",
"_nodeVersion": "0.12.2",
"_id": "atm3-deploy-http-push@1.0.3",
"_shasum": "fcf899277be52d78a0bdd2eb70021e0b3d452a57",
"_from": "atm3-deploy-http-push@*",
"_npmVersion": "2.14.7",
"_nodeVersion": "4.2.2",
"_npmUser": {
"name": "fansekey",
"email": "fansekey@gmail.com"
"name": "googleyufei",
"email": "googleyufei@qq.com"
},
"dist": {
"shasum": "5eac819ea647e4cc49c3b8ce9a97015b4ae8346b",
"tarball": "http://registry.npmjs.org/atm3-deploy-http-push/-/atm3-deploy-http-push-1.0.1.tgz"
"shasum": "fcf899277be52d78a0bdd2eb70021e0b3d452a57",
"tarball": "https://registry.npmjs.org/atm3-deploy-http-push/-/atm3-deploy-http-push-1.0.2.tgz"
},
"maintainers": [
{
"name": "fansekey",
"email": "fansekey@gmail.com"
"name": "googleyufei",
"email": "googleyufei@qq.com"
}
],
"directories": {},
"_resolved": "http://registry.npmjs.org/atm3-deploy-http-push/-/atm3-deploy-http-push-1.0.1.tgz",
"readme": "ERROR: No README data found!"
"_resolved": "https://registry.npmjs.org/atm3-deploy-http-push/-/atm3-deploy-http-push-1.0.2.tgz",
"readme": "ERROR: No README data found!",
"dependencies": {
"archiver": "^1.0.0",
"request": "^2.72.0"
}
}

@@ -17,5 +17,6 @@ # fis3-deploy-http-push

//这个参数会跟随post请求一起发送
to: '/home/fis/www'
to: '/home/fis/www',
type: 'zip'//将文件打包成zip再上传
})
})
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc