aboutsummaryrefslogtreecommitdiff
path: root/CLPM/Package.icl
diff options
context:
space:
mode:
Diffstat (limited to 'CLPM/Package.icl')
-rw-r--r--CLPM/Package.icl58
1 files changed, 58 insertions, 0 deletions
diff --git a/CLPM/Package.icl b/CLPM/Package.icl
new file mode 100644
index 0000000..06fae3f
--- /dev/null
+++ b/CLPM/Package.icl
@@ -0,0 +1,58 @@
+implementation module CLPM.Package
+
+import _SystemArray
+import StdFile
+import StdList
+
+import Control.Applicative
+from Data.Func import $
+from Text import class Text(indexOf,subString),
+ instance Text String, instance + String
+import Text.JSON
+
+derive JSONEncode StoredPackage
+derive JSONDecode StoredPackage
+
+toPackage :: StoredPackage -> Package
+toPackage spkg
+ = { Package
+ | name = fromJust $ spkg.StoredPackage.name <|> Just DEFAULT_NAME
+ , desc = fromJust $ spkg.StoredPackage.desc <|> Just DEFAULT_DESC
+ , author = fromJust $ spkg.StoredPackage.author <|> Just DEFAULT_AUTHOR
+ , url = fromJust $ spkg.StoredPackage.url <|> Just DEFAULT_URL
+ , depends = map toDep $ fromJust $ spkg.StoredPackage.depends <|> Just []
+ }
+where
+ toDep :: StoredDependency -> Dependency
+ toDep (name, src)
+ = { dep_name = name, dep_source = toPackSource src }
+
+ toPackSource :: StoredPackageSource -> PackageSource
+ toPackSource sps = GitHub owner repo Latest
+ where
+ owner = subString 0 slash sps
+ repo = subString (slash + 1) (size sps - 1) sps
+ slash = indexOf "/" sps
+
+toStoredPackage :: Package -> StoredPackage
+toStoredPackage pkg
+ = { StoredPackage
+ | name = Just pkg.Package.name
+ , desc = Just pkg.Package.desc
+ , author = Just pkg.Package.author
+ , url = Just pkg.Package.url
+ , depends = case map toStoredDep pkg.Package.depends of
+ [] = Nothing
+ ds = Just ds
+ }
+where
+ toStoredDep :: Dependency -> StoredDependency
+ toStoredDep d = (d.dep_name, toStoredPackSource d.dep_source)
+
+ toStoredPackSource :: PackageSource -> StoredPackageSource
+ toStoredPackSource (GitHub o r t) = o + "/" + r
+ // TODO
+
+instance <<< Package
+where
+ (<<<) f p = f <<< (jsonPrettyPrint $ toJSON $ toStoredPackage p)