atm3-deploy-http-push
Advanced tools
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再上传 | ||
}) | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7414
124
22
2
1
+ Addedarchiver@^1.0.0
+ Addedrequest@^2.72.0
+ Addedajv@6.12.6(transitive)
+ Addedarchiver@1.3.0(transitive)
+ Addedarchiver-utils@1.3.0(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbl@1.2.3(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedbuffer-alloc@1.2.0(transitive)
+ Addedbuffer-alloc-unsafe@1.1.0(transitive)
+ Addedbuffer-crc32@0.2.13(transitive)
+ Addedbuffer-fill@1.0.0(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcompress-commons@1.2.2(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addedcrc@3.8.0(transitive)
+ Addedcrc32-stream@2.0.0(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlazystream@1.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtar-stream@1.6.2(transitive)
+ Addedto-buffer@1.1.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwalkdir@0.0.11(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
+ Addedzip-stream@1.2.0(transitive)