mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-08-04 05:33:10 +00:00
refactor(files) read, readPipe
This commit is contained in:
parent
76d32ab80f
commit
052613a522
2 changed files with 34 additions and 28 deletions
17
cloudcmd.js
17
cloudcmd.js
|
|
@ -157,9 +157,15 @@
|
|||
filesList.push(KEY, CERT);
|
||||
|
||||
files.read(filesList, 'utf-8', function(errors, files) {
|
||||
if (errors)
|
||||
var status, name, msg,
|
||||
namesStr = '';
|
||||
|
||||
if (errors) {
|
||||
status = 'error';
|
||||
Util.log(errors);
|
||||
else {
|
||||
} else {
|
||||
status = 'ok';
|
||||
|
||||
FileTemplate = files[FILE_TMPL];
|
||||
PanelTemplate = files[PANEL_TMPL];
|
||||
PathTemplate = files[PATH_TMPL];
|
||||
|
|
@ -171,6 +177,13 @@
|
|||
cert : files[CERT]
|
||||
};
|
||||
|
||||
namesStr = filesList.map(function(name) {
|
||||
return path.basename(name);
|
||||
});
|
||||
|
||||
msg = CloudFunc.formatMsg('read', namesStr, status);
|
||||
Util.log(msg);
|
||||
|
||||
server.start(params);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,31 +19,19 @@
|
|||
object.read = function(files, options, callback) {
|
||||
var done = [],
|
||||
errors,
|
||||
i, n,
|
||||
name,
|
||||
readFiles = {},
|
||||
doneFunc = function (name, error, data) {
|
||||
var msg, status;
|
||||
|
||||
done.pop();
|
||||
|
||||
if (error) {
|
||||
status = 'error';
|
||||
|
||||
if (!error)
|
||||
readFiles[name] = data;
|
||||
else {
|
||||
if (!errors)
|
||||
errors = {};
|
||||
|
||||
errors[name] = error;
|
||||
}
|
||||
else {
|
||||
status = 'ok';
|
||||
readFiles[name] = data;
|
||||
}
|
||||
|
||||
name = path.basename(name);
|
||||
msg = CloudFunc.formatMsg('read', name, status);
|
||||
|
||||
Util.log(msg);
|
||||
|
||||
if (!done.length)
|
||||
Util.exec(callback, errors, readFiles);
|
||||
|
|
@ -54,23 +42,24 @@
|
|||
options = null;
|
||||
}
|
||||
|
||||
n = files && files.length;
|
||||
for (i = 0; i < n; i++) {
|
||||
name = files.pop();
|
||||
done.push(name);
|
||||
|
||||
done = files.map(function(name) {
|
||||
fs.readFile(name, options, doneFunc.bind(null, name));
|
||||
}
|
||||
return name;
|
||||
});
|
||||
};
|
||||
|
||||
object.readPipe = readPipe;
|
||||
|
||||
function readPipe(params) {
|
||||
var name,
|
||||
p = params,
|
||||
length = p.names && p.names.length;
|
||||
var name, lenght,
|
||||
p = params;
|
||||
|
||||
if (!length) {
|
||||
if (p.names) {
|
||||
names = p.names.slice();
|
||||
lenght = p.names.length;
|
||||
}
|
||||
|
||||
if (!lenght) {
|
||||
p.write.end();
|
||||
Util.exec(p.callback);
|
||||
} else {
|
||||
|
|
@ -85,7 +74,11 @@
|
|||
if (error)
|
||||
Util.exec(p.callback, error);
|
||||
else
|
||||
readPipe(params);
|
||||
readPipe({
|
||||
names : names,
|
||||
write : p.write,
|
||||
gzip : p.gzip
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue