packages feed

g-npm 0.0.2 → 0.1.0

raw patch · 3 files changed

+35/−7 lines, 3 files

Files

g-npm.cabal view
@@ -1,5 +1,5 @@ Name:                g-npm-Version:             0.0.2+Version:             0.1.0 Description:         Generate Gentoo ebuilds from NodeJS/npm packages. License:             MIT License-file:        LICENSE
src/Main.hs view
@@ -5,7 +5,12 @@ import Control.Monad import System.Environment import System.Console.GetOpt+import System.Directory ++-- Default category+nodeCat :: String+nodeCat = "dev-nodejs" -- Flag type for Options data Flag = NoDeps          | PkgName String@@ -22,7 +27,7 @@  -- Default options startOptions = Options { optNoDeps = False-                , optOverlay = "" +                , optOverlay = "/tmp/node-overlay"                  , optPkgName = ""                 , optPkgVersion = "" }                 @@ -43,6 +48,20 @@         (_,_,errs) -> ioError (userError (concat errs ++ usageInfo header options))             where header = "Usage: g-npm [OPTION...]" +-- checkOverlay+-- Verifies if the Overlay path exists. Else, it creates it and +-- creates subfolders for dev-nodejs category.+checkOverlay :: FilePath -> IO ()+checkOverlay o = +        createDirectoryIfMissing True o++buildEbuildPath :: String -> String -> String -> FilePath+buildEbuildPath o n v =+    (o ++ "/" ++ nodeCat ++ "/" ++ n ++ "/" ++ (buildPkgName n v))++buildPkgName :: String -> String -> String+buildPkgName n v = n ++ "-" ++ v ++ ".ebuild"+ -- Main main :: IO () main = do@@ -50,10 +69,14 @@     (opts, non_opts) <- parseArgs args     opts' <- foldl (>>=) (return startOptions) opts -    pkg <- doGetNpm (optPkgName opts') (optPkgVersion opts')+    let n = (optPkgName opts')+    let v = (optPkgVersion opts')+    let o = (optOverlay opts') +    pkg <- doGetNpm n v+    checkOverlay (o ++ "/" ++ nodeCat ++ "/" ++ n)+     case pkg of-        Nothing -> ioError (userError ("Package " ++ (optPkgName opts') ++ +        Nothing -> ioError (userError ("Package " ++ n ++              " not found."))-        Just pkg -> putStrLn $ (showNpmEbuild pkg)-+        Just pkg -> writeFile (buildEbuildPath o n v) (showNpmEbuild pkg)
src/Npm.hs view
@@ -86,7 +86,12 @@ depStrings :: Npm -> String depStrings pkg = concat $                      intersperse "\n\t" $ -                        map (\(x, y) -> ">=dev-nodejs/" ++ x ++ "-" ++ (tail y)) $ dependencies pkg+                        map (\(x, y) -> ">=dev-nodejs/" ++ x ++ "-" ++ (cleanVersion y)) $ dependencies pkg+                where+                    cleanVersion :: String -> String+                    cleanVersion n +                            | head n == '~' = tail n+                            | otherwise = n  -- -- Converts the resulting JSON from querying the NPM Registry,