summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZara Zaimeche <zara.zaimeche@codethink.co.uk>2015-01-09 13:38:39 +0000
committerZara Zaimeche <zara.zaimeche@codethink.co.uk>2015-01-09 15:00:27 +0000
commite0cf555d06901e8c83f5166b2731dab3a5f46072 (patch)
tree3402b26fa0939782153090ad1d169b0073bf3122
parent7440829b18a04f678449ad0f021a5a0f6d6cb526 (diff)
downloadimport-e0cf555d06901e8c83f5166b2731dab3a5f46072.tar.gz
Add npm to_lorry
-rwxr-xr-xbaserockimport/exts/npm.to_lorry51
1 files changed, 51 insertions, 0 deletions
diff --git a/baserockimport/exts/npm.to_lorry b/baserockimport/exts/npm.to_lorry
new file mode 100755
index 0000000..ba0f442
--- /dev/null
+++ b/baserockimport/exts/npm.to_lorry
@@ -0,0 +1,51 @@
+#!/usr/bin/env node
+//
+// Copyright (C) 2014 Codethink Limited
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+npm = require("npm");
+
+base = require("./importer_base");
+
+npm.load(function(er, npm) {
+ if (process.argv.length === 3)
+ packageName = process.argv[2];
+ else
+ throw ("Error! Too many command line arguments! Usage: " +
+ "./npm.to_lorry PACKAGENAME");
+ if (er) throw er;
+
+ npm.commands.view([packageName], "silent", getRepo);
+
+ function getRepo(er, packageInfo){
+ if (er) throw er;
+
+ package = base.getFirstItem(packageInfo);
+
+ repoInfo = package.repository;
+ pathWithPkgName = "npm/" + packageName;
+
+ lorry = {};
+ lorry[pathWithPkgName] = {
+ "url": repoInfo["url"],
+ "type": repoInfo["type"],
+ "x-products-npm": [packageName]
+ };
+
+ outputText=JSON.stringify(lorry, null, 4);
+ console.log(outputText);
+ }
+});
+