Exemple #1
0
func Install(c *cli.Context) {

	lockFile := "composer.lock"
	if _, found := os.Stat(lockFile); os.IsNotExist(found) {
		Update(c)
		return
	}

	fmt.Println("Reading lock")
	lock, err := gomposer.ReadLock(lockFile)
	if err != nil {
		panic(err)
	}
	Download(lock.Packages)
}
Exemple #2
0
func Update(c *cli.Context) {
	r := gomposer.PackageReader{}
	actual, _ := r.Read("composer.json")

	fmt.Println("Solving dependencies")
	d := gomposer.ToDependency(actual)

	hc, _ := gomposer.NewHttpClient("https://packagist.org/packages/")
	pr := gomposer.PackageRepository{Client: hc}

	repo := dependency.GetNewRepo(pr)

	ads := dependency.GetPackageNames(d)
	repo.GetAll(ads)

	s := dependency.NewSolver(repo.Dependencies, repo.Replaces)
	required, err := s.Solve(d)

	if err != nil {
		fmt.Println(err)
		return
	}

	lockGenerator := gomposer.LockGenerator{
		PackageRepo: pr,
	}
	newLock, err := lockGenerator.Generate(required)

	if err != nil {
		panic(err)
	}

	lockFile := "composer.lock"

	oldLock, err := gomposer.ReadLock(lockFile)
	if err != nil {
		panic(err)
	}

	diff := gomposer.DiffLock(newLock, oldLock)

	if len(diff["removed"]) != 0 {
		Remove(diff["removed"])
	}
	_, found := os.Stat("vendors")

	var packages []gomposer.ComposerPackage

	if os.IsNotExist(found) {
		packages = newLock.Packages
	} else {
		packages = diff["added"]
	}

	if len(packages) == 0 {
		fmt.Println("Nothing to update")
		return
	}

	Download(packages)
	gomposer.WriteLock(newLock)
}