Skip to content

Commit

Permalink
Allow path arguments for tusk install
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Robinson committed Oct 27, 2009
1 parent 1af6366 commit abf5be6
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/narwhal/tusk/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,27 @@ exports.install = function (options, names) {

// validate the requested names against those
// in the catalog of downloadable packages.
var names = names.filter(function (name) {
var localPackagePath = localSourcePath.join(name, "package.json");
if (util.has(catalog.packages, name)) {
} else if (localPackagePath.isFile()) {
catalog.packages[name] = json.decode(localPackagePath.read({charset: 'utf-8'}));
} else {
parser.print("ERROR: Package not found: " + util.enquote(name));
return false;
var names = names.map(function (name) {
var localPath = fs.path(fs.absolute(name).replace(/\/$/, "")); // FIXME: basename/dirname broken with trailing slash
var localPackagePath = localPath.join(name, "package.json");
if (localPackagePath.isFile()) {
var packageData = json.decode(localPackagePath.read({charset: 'utf-8'}));
print(packageData.name +","+ localPath.basename()+","+localPath)
var packageName = packageData.name || localPath.basename();

packageData.location = "file://" + localPath;
packageData.type = "directory";

catalog.packages[packageName] = packageData;
return packageName;
} else if (util.has(catalog.packages, name)) {
// nothing to do.
return name;
}
return true;
});

parser.print("ERROR: Package not found: " + util.enquote(name));
return null;
}).filter(function(name) { print(name); return !!name; });

// load the notes on user-requested and dependency packages
// for book keeping.
Expand Down Expand Up @@ -119,7 +129,7 @@ exports.install = function (options, names) {
zipsDirectory.mkdirs();

missing.forEach(function (name) {
if (localSourcePath.join(name, "package.json").isFile()) {
if (/^file:\/\//.test(catalog.packages[name].location)) {
print('Local package: ' + name);
return;
}
Expand All @@ -146,12 +156,14 @@ exports.install = function (options, names) {
try {
var targetPath = tusk.getDirectory().join('packages', name);

if (localSourcePath.join(name, "package.json").isFile()) {
var components = catalog.packages[name].location.match(/^file:\/\/(.*)$/);
if (components) {
var sourcePath = components[1];
print('Copying: ' + sourcePath);
if (options.simulate)
return;

fs.copyTree(localSourcePath.join(name), targetPath);
fs.copyTree(sourcePath, targetPath);

var files = targetPath.listTree().filter(function(f) { return targetPath.join(f).isFile(); });
print(files.join("\n"));
Expand Down

0 comments on commit abf5be6

Please sign in to comment.