Skip to content

Commit

Permalink
allow relative paths in .json "include" directives
Browse files Browse the repository at this point in the history
  • Loading branch information
valette committed Feb 12, 2013
1 parent 1b9ce3b commit 21ff101
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
51 changes: 29 additions & 22 deletions cl-rpc.js
Expand Up @@ -135,21 +135,21 @@ exports.includeActions=function (file, callback) {
};

includeActionsJSON = function (file, callback) {
var actionsObject;
var actionsObject;
var libraryName = libpath.basename(file, '.json');

fs.readFile(file, function (err, data) {
try {
actionsObject = JSON.parse(data);
}
catch (error) {
console.log('error importing ' + file);
actions['import_error_' + libraryName] = {lib : libraryName};
if ( typeof(callback) === 'function' ) {
callback();
}
return;
}
fs.readFile(file, function (err, data) {
try {
actionsObject = JSON.parse(data);
}
catch (error) {
console.log('error importing ' + file);
actions['import_error_' + libraryName] = {lib : libraryName};
if ( typeof(callback) === 'function' ) {
callback();
}
return;
}
var localActions = actionsObject.actions || [];
var path = fs.realpathSync(libpath.dirname(file));
var actionsArray = Object.keys(localActions);
Expand All @@ -175,14 +175,21 @@ includeActionsJSON = function (file, callback) {
actions[actionsArray[i]] = action;
}

var dirs = actionsObject.dataDirs || {};
var keys = Object.keys(dirs);
for (i = 0; i != keys.length ; i++) {
var key = keys[i];
dataDirs[key] = dirs[key];
}

var includes = actionsObject.include || [];
var dirs = actionsObject.dataDirs || {};
var keys = Object.keys(dirs);
for (i = 0; i != keys.length ; i++) {
var key = keys[i];
dataDirs[key] = dirs[key];
}

var includes = actionsObject.include || [];
for (i = 0; i != includes.length; i++) {
var include = includes[i];
if (include.charAt(0) != '/') {
// the path is relative. Prepend directory
includes[i] = libpath.dirname(file) + '/' + include;
}
}
exports.includeActions(includes, function () {
if ( typeof(callback) === 'function' ) {
callback();
Expand Down Expand Up @@ -696,4 +703,4 @@ exports.getDirectoryContent = function (path, callback) {
}
);
};
exports.includeActions(__dirname + '/base.json');
exports.addDirectory(__dirname + '/lib/');
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cl-rpc",
"version": "0.1.1",
"version": "0.1.3",
"description": "A simple rpc module that launches command-line programms",
"main": "cl-rpc.js",
"scripts": {
Expand Down

0 comments on commit 21ff101

Please sign in to comment.