Skip to content

Commit

Permalink
restructure project
Browse files Browse the repository at this point in the history
  • Loading branch information
Tch1b0 committed Sep 17, 2023
1 parent 4a08641 commit 8766d74
Show file tree
Hide file tree
Showing 20 changed files with 319 additions and 310 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build
coverage
ppm
.DS_Store
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
module github.com/Glow-Project/ppm

go 1.19
go 1.21

require (
github.com/go-git/go-git/v5 v5.6.1
github.com/go-git/go-git/v5 v5.9.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.25.0
github.com/urfave/cli/v2 v2.25.7
)

require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230321155629-9a39f2531310 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.2 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
117 changes: 53 additions & 64 deletions go.sum

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions internal/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ import (
"fmt"
"path"

"github.com/Glow-Project/ppm/internal/paths"
"github.com/Glow-Project/ppm/internal/pm"
"github.com/Glow-Project/ppm/internal/utility"
"github.com/urfave/cli/v2"
)

func initialize(ctx *cli.Context) error {
paths, err := utility.CreatePathsFromCwd()
pth, err := paths.CreatePathsFromCwd()
if err != nil {
return err
}

if _, err := utility.CreatePpmConfig(paths.Root); err != nil {
if _, err := pm.CreateConfig(pth.Root); err != nil {
return fmt.Errorf("error creating ppm.json config-file: %w", err)
}

utility.ColorPrintln("{GRN}new ppm.json config-file generated")

if ok, _ := utility.DoesPathExist(path.Join(paths.Root, ".git")); ok {
if ok, _ := utility.DoesPathExist(path.Join(pth.Root, ".git")); ok {
utility.ColorPrintln("{YLW}when using ppm it is recommended to add the addons direcotry to your .gitignore file")
}

Expand Down
22 changes: 12 additions & 10 deletions internal/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,53 @@ package commands

import (
"github.com/Glow-Project/ppm/internal/fetch"
"github.com/Glow-Project/ppm/internal/paths"
"github.com/Glow-Project/ppm/internal/pm"
"github.com/Glow-Project/ppm/internal/utility"
"github.com/go-git/go-git/v5"
"github.com/urfave/cli/v2"
)

func install(ctx *cli.Context) error {
paths, config, err := utility.GetPathsAndConfig()
pth, config, err := pm.GetPathsAndConfig()
if err != nil {
return err
}

utility.CheckOrCreateDir(paths.Addons)
utility.CheckOrCreateDir(pth.Addons)

dependencies := ctx.Args()
if dependencies.Len() == 0 {
installAllDependencies(&config, paths)
installAllDependencies(&config, pth)
}

for _, dep := range dependencies.Slice() {
if err = installDependency(&config, paths, utility.DependencyFromString(dep), false); err != nil {
if err = installDependency(&config, pth, pm.DependencyFromString(dep), false); err != nil {
return err
}
}

return nil
}

func installAllDependencies(config *utility.PpmConfig, paths utility.Paths) error {
func installAllDependencies(config *pm.Config, pth paths.Paths) error {
for _, dependency := range config.Dependencies {
if err := installDependency(config, paths, dependency, false); err != nil {
if err := installDependency(config, pth, dependency, false); err != nil {
return err
}
}
return nil
}

func installDependency(config *utility.PpmConfig, paths utility.Paths, dependency utility.Dependency, isSubDependency bool) error {
func installDependency(config *pm.Config, pth paths.Paths, dependency pm.Dependency, isSubDependency bool) error {
if !isSubDependency {
utility.ColorPrintln("\rinstalling {YLW}%s", dependency.Identifier)
} else {
utility.ColorPrintln("\t -> installing {YLW}%s", dependency.Identifier)
}
loadAnim := utility.StartLoading()

err := fetch.InstallDependency(dependency, paths)
err := fetch.InstallDependency(dependency, pth)
loadAnim.Stop()

switch err := err.(type) {
Expand Down Expand Up @@ -77,7 +79,7 @@ func installDependency(config *utility.PpmConfig, paths utility.Paths, dependenc
config.AddDependency(dependency)
}

subConfig, err := utility.GetPluginConfig(paths, dependency)
subConfig, err := pm.GetPluginConfig(pth, dependency)
if err != nil {
if !isSubDependency {
utility.PrintDone()
Expand All @@ -88,7 +90,7 @@ func installDependency(config *utility.PpmConfig, paths utility.Paths, dependenc
// iterate over dependencies and install them if needed
for _, dep := range subConfig.Dependencies {
if !config.HasSubDependency(dep) {
installDependency(config, paths, dep, true)
installDependency(config, pth, dep, true)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/commands/reinstall.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package commands

import (
"github.com/Glow-Project/ppm/internal/utility"
"github.com/Glow-Project/ppm/internal/pm"
"github.com/urfave/cli/v2"
)

func reinstall(ctx *cli.Context) error {
paths, config, err := utility.GetPathsAndConfig()
paths, config, err := pm.GetPathsAndConfig()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/show.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package commands

import (
"github.com/Glow-Project/ppm/internal/utility"
"github.com/Glow-Project/ppm/internal/pm"
"github.com/urfave/cli/v2"
)

func showConfig(ctx *cli.Context) error {
_, config, err := utility.GetPathsAndConfig()
_, config, err := pm.GetPathsAndConfig()
if err != nil {
return err
}
Expand Down
16 changes: 9 additions & 7 deletions internal/commands/tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import (
"encoding/json"
"os"

"github.com/Glow-Project/ppm/internal/utility"
"github.com/Glow-Project/ppm/internal/paths"
"github.com/Glow-Project/ppm/internal/pm"

"github.com/urfave/cli/v2"
)

func tidy(ctx *cli.Context) error {
paths, err := utility.CreatePathsFromCwd()
pth, err := paths.CreatePathsFromCwd()
if err != nil {
return err
}

content, err := os.ReadFile(paths.ConfigFile)
content, err := os.ReadFile(pth.ConfigFile)
if err != nil {
return err
}
Expand All @@ -29,23 +31,23 @@ func tidy(ctx *cli.Context) error {
return nil
}

deps := []utility.Dependency{}
deps := []pm.Dependency{}
for _, dep := range strDeps {
str, ok := dep.(string)
if !ok {
return nil
}
deps = append(deps, utility.DependencyFromString(str))
deps = append(deps, pm.DependencyFromString(str))
}

jsonContent["dependencies"] = deps
jsonData, err := json.MarshalIndent(jsonContent, "", "\t")
if err != nil {
return err
}
os.WriteFile(paths.ConfigFile, jsonData, 0644)
os.WriteFile(pth.ConfigFile, jsonData, 0644)

config, err := utility.ParsePpmConfig(paths.ConfigFile)
config, err := pm.ParseConfig(pth.ConfigFile)
if err != nil {
return err
}
Expand Down
22 changes: 12 additions & 10 deletions internal/commands/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import (
"os"
"path"

"github.com/Glow-Project/ppm/internal/paths"
"github.com/Glow-Project/ppm/internal/pm"
"github.com/Glow-Project/ppm/internal/utility"
"github.com/urfave/cli/v2"
)

func uninstall(ctx *cli.Context) error {
paths, config, err := utility.GetPathsAndConfig()
pth, config, err := pm.GetPathsAndConfig()
if err != nil {
return err
}

dependencies := ctx.Args()
if len(dependencies.First()) == 0 {
uninstallAllDependencies(&config, paths, ctx.Bool("hard"))
uninstallAllDependencies(&config, pth, ctx.Bool("hard"))
return nil
}

for i := 0; i < dependencies.Len(); i++ {
dep := utility.DependencyFromString(dependencies.Get(i))
dep := pm.DependencyFromString(dependencies.Get(i))
if config.HasDependency(dep) && !config.HasSubDependency(dep) {
uninstallDependency(&config, paths, dep, false)
uninstallDependency(&config, pth, dep, false)
} else if config.HasSubDependency(dep) {
utility.ColorPrintln("{RED}the plugin {YLW}%s {RED}is a sub-dependency and can only be uninstalled by uninstalling its parent", dep.Identifier)
} else {
Expand All @@ -34,10 +36,10 @@ func uninstall(ctx *cli.Context) error {
return nil
}

func uninstallAllDependencies(config *utility.PpmConfig, paths utility.Paths, hard bool) error {
func uninstallAllDependencies(config *pm.Config, pth paths.Paths, hard bool) error {
loadAnim := utility.StartLoading()

if err := os.RemoveAll(paths.Addons); err != nil {
if err := os.RemoveAll(pth.Addons); err != nil {
return err
}

Expand All @@ -50,24 +52,24 @@ func uninstallAllDependencies(config *utility.PpmConfig, paths utility.Paths, ha
return nil
}

func uninstallDependency(config *utility.PpmConfig, paths utility.Paths, dependency utility.Dependency, isSubDependency bool) error {
func uninstallDependency(config *pm.Config, pth paths.Paths, dependency pm.Dependency, isSubDependency bool) error {
if !isSubDependency {
utility.ColorPrintln("\runinstalling {YLW}%s", dependency.Identifier)
} else {
utility.ColorPrintln("\t -> uninstalling {YLW}%s", dependency.Identifier)
}
loadAnim := utility.StartLoading()

subConfig, err := utility.GetPluginConfig(paths, dependency)
subConfig, err := pm.GetPluginConfig(pth, dependency)
for i := 0; err == nil && i < len(subConfig.Dependencies); i++ {
dep := subConfig.Dependencies[i]
if !config.HasDependency(dep) {
uninstallDependency(config, paths, dep, true)
uninstallDependency(config, pth, dep, true)
}
}

// path: root/addons/dependency
err = os.RemoveAll(path.Join(paths.Addons, dependency.Identifier))
err = os.RemoveAll(path.Join(pth.Addons, dependency.Identifier))
loadAnim.Stop()
if err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions internal/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package commands
import (
"path/filepath"

"github.com/Glow-Project/ppm/internal/paths"
"github.com/Glow-Project/ppm/internal/pm"
"github.com/Glow-Project/ppm/internal/utility"
"github.com/urfave/cli/v2"
)

// the update method is called by the cli
// it updates all dependencies
func update(ctx *cli.Context) error {
paths, config, err := utility.GetPathsAndConfig()
paths, config, err := pm.GetPathsAndConfig()
if err != nil {
return err
}
Expand All @@ -26,13 +28,13 @@ func update(ctx *cli.Context) error {
return nil
}

func updateAllDependencies(config *utility.PpmConfig, paths *utility.Paths) error {
func updateAllDependencies(config *pm.Config, pth *paths.Paths) error {
for _, dependency := range config.Dependencies {
if dependency.Type != utility.GithubAsset {
if dependency.Type != pm.GithubAsset {
continue
}

if err := utility.UpdateGithubRepo(filepath.Join(paths.Addons, dependency.Identifier)); err != nil {
if err := utility.UpdateGithubRepo(filepath.Join(pth.Addons, dependency.Identifier)); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit 8766d74

Please sign in to comment.