This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
100 lines (93 loc) · 2.22 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"time"
"github.com/rhygg/buck/cache"
"github.com/rhygg/buck/cmds"
"github.com/rhygg/buck/utils"
"github.com/urfave/cli/v2"
)
func DeleteModCache(dir string, mcache cache.ModuleCache) bool {
files, _ := ioutil.ReadDir(dir)
for _, f := range files {
fi, err := os.Stat(filepath.Join(dir, f.Name()))
if err != nil {
fmt.Println(err)
}
currTime := time.Now()
fTime := fi.ModTime()
if fTime.Sub(currTime).Hours() >= 1 {
fmt.Println("[BUCK] cache: removing " + f.Name() + " from cache.")
err := os.Remove(filepath.Join(dir, f.Name()))
if err != nil {
return false
}
del := mcache.Cache.Remove(f.Name())
return del == true
}
}
return false
}
func main() {
cwd, err := os.Getwd()
if err != nil {
utils.LogError(err.Error())
}
current, err := user.Current()
if err != nil {
fmt.Print("[BUCK] main: Could not find home directory location, exiting...")
}
homedir := current.HomeDir
cacheR := cache.Newrdc(50)
cacheM := cache.Newmc(100, homedir, "buck-cache")
pos := DeleteModCache(filepath.Join(homedir, "buck-cache"), cacheM)
if !pos {
fmt.Print("[BUCK] cache: could not delete outdated cache.")
}
app := &cli.App{
Name: "Buck",
Copyright: "(c) 2022 Adonis Tremblay",
HelpName: "Buck",
Version: "0.0.1",
Usage: "A NodeJS package manager, built for speed",
UsageText: "buck [global options] command [command options] [arguments...]",
Commands: []*cli.Command{
{
Name: "add",
Aliases: []string{"install", "a", "i"},
Usage: "Install a/multiple package(s)",
Action: func(c *cli.Context) error {
cmds.Add(cmds.AddConfig{
CWD: cwd,
Packages: c.Args().Slice(),
HomeDir: homedir,
}, cacheR, cacheM)
return nil
},
},
{
Name: "remove",
Aliases: []string{"uninstall", "r", "u"},
Usage: "Remove a/multiple package(s)",
Action: func(c *cli.Context) error {
fmt.Println("uninstall")
return nil
},
},
{
Name: "update",
Aliases: []string{"u"},
Usage: "Update a package",
Action: func(c *cli.Context) error {
fmt.Println("update")
return nil
},
},
},
}
app.Run(os.Args)
}