aboutsummaryrefslogtreecommitdiff
path: root/CLPM/Package.icl
blob: 06fae3f9c18abb4d6008ff259332003bc9c8fa45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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)