mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
feature(patch) add from npm
This commit is contained in:
parent
d03196aa96
commit
e5f4e48471
3 changed files with 2 additions and 56 deletions
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
Util = require(DIR_LIB + 'util'),
|
||||
CloudFunc = require(DIR_LIB + 'cloudfunc'),
|
||||
patch = require(DIR_SERVER + 'patch'),
|
||||
patch = require('patchfile'),
|
||||
ashify = require('ashify'),
|
||||
|
||||
mellow = require('mellow');
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
|
||||
check = require('checkup'),
|
||||
diff = require('daffy'),
|
||||
flop = require('flop'),
|
||||
exec = require('execon'),
|
||||
|
||||
ERROR_MSG = 'File is to big. ' +
|
||||
'Could not patch files ' +
|
||||
'bigger then ';
|
||||
|
||||
module.exports = function(name, patch, options, callback) {
|
||||
check(arguments, ['name', 'patch', 'callback']);
|
||||
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
flop.read(name, 'size raw', function(error, size) {
|
||||
if (!error)
|
||||
if (isNaN(options.size) || size < options.size)
|
||||
patchFile(name, patch, callback);
|
||||
else
|
||||
error = {
|
||||
message: ERROR_MSG + options.size
|
||||
};
|
||||
|
||||
if (error)
|
||||
callback(error);
|
||||
});
|
||||
};
|
||||
|
||||
function patchFile(name, patch, callback) {
|
||||
fs.readFile(name, 'utf8', function read(error, data) {
|
||||
var diffResult;
|
||||
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
error = exec.try(function() {
|
||||
diffResult = diff.applyPatch(data, patch);
|
||||
});
|
||||
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
fs.writeFile(name, diffResult, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
@ -43,6 +43,7 @@
|
|||
"minify": "~1.4.0",
|
||||
"minimist": "~1.1.0",
|
||||
"mollify": "~1.0.0",
|
||||
"patchfile": "~1.0.0",
|
||||
"pipe-io": "~1.1.1",
|
||||
"ponse": "~1.3.0",
|
||||
"rendy": "~1.0.2",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue