-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
63 lines (54 loc) · 1.71 KB
/
main.go
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
59
60
61
62
63
package main
import (
"flag"
"fmt"
"log"
"os"
)
func main() {
currentWd, e := os.Getwd()
if e != nil {
log.Fatal(e)
}
var defaultSpecTemplatePath = currentWd + "/templates/node2rpm.template"
var pkg, ver, exclude, wd, specTemplate string
var bundle bool
flag.StringVar(&pkg, "pkg", "", "the module needs to package.")
flag.StringVar(&ver, "ver", "latest", "the module's version.")
flag.BoolVar(&bundle, "bundle", true, "don't bundle dependencies.")
flag.StringVar(&exclude, "exclude", "", "the module to be excluded, in 'rimraf:1.0.0,mkdirp:1.0.1' format.")
flag.StringVar(&wd, "wd", currentWd, "the osc working directory")
flag.StringVar(&specTemplate, "st", defaultSpecTemplatePath, "the spec template file")
flag.Parse()
if len(pkg) == 0 {
log.Fatal("You must specify a module name to package.")
}
temp := NewTempData()
spec := NewSpecfile(pkg, wd, specTemplate)
if bundle {
if len(exclude) > 0 {
temp.Exclusion = parseExcludeString(exclude)
log.Println("These packages are set to be excluded:")
fmt.Println(temp.Exclusion.Inspect())
} else {
log.Println("No package to exclude, skipped.")
}
tree := Tree{}
parentTree := ParentTree{}
BuildDependencyTree(pkg, &ver, tree, parentTree, Parents{}, temp)
log.Printf("%s %s tree has been built:\n", pkg, ver)
fmt.Println(tree.Inspect(0))
tree.ToJson()
} else {
pkg1 := RegistryQuery(pkg, temp.ResponseCache)
if ver == "latest" {
ver = pkg1.Versions[0].String()
}
temp.Licenses.Append(pkg1.License)
temp.Tarballs.Append(pkg1.Json.Get(ver).Get("dist").Get("tarball").MustString())
}
temp.Tarballs.ToService(wd)
spec.Fill(pkg, ver, bundle, temp)
spec.Save()
log.Printf("Congrats! Module %s has been created/updated.", pkg)
}