From e0cf555d06901e8c83f5166b2731dab3a5f46072 Mon Sep 17 00:00:00 2001 From: Zara Zaimeche Date: Fri, 9 Jan 2015 13:38:39 +0000 Subject: Add npm to_lorry --- baserockimport/exts/npm.to_lorry | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 baserockimport/exts/npm.to_lorry 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); + } +}); + -- cgit v1.2.1