Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/main.go
  • Loading branch information
snakeice committed Oct 3, 2018
2 parents 6579afc + 7cb092a commit 61263c2
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ Use "boss [command] --help" for more information about a command.
+ Sample:
+ `boss install github.com/HashLoad/horse`
+ `boss install github.com/HashLoad/horse:1.0.0`


### For use yor project in boss create a tag with [semantic version](https://semver.org/)
11 changes: 6 additions & 5 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package cmd
import (
"bufio"
"fmt"
"github.com/hashload/boss/models"
"github.com/spf13/cobra"
"os"
"path/filepath"
"regexp"

"github.com/hashload/boss/models"
"github.com/spf13/cobra"
)

var initCmd = &cobra.Command{
Expand All @@ -27,7 +28,7 @@ var initCmd = &cobra.Command{
}

pkgJson.Name = getParamOrDef("package name: ("+folderName+")", folderName)
pkgJson.Homepage = getParamOrDef("homepage:", "")
pkgJson.Homepage = getParamOrDef("homepage", "")
pkgJson.Version = getParamOrDef("version: (1.0.0)", "1.0.0")
pkgJson.Description = getParamOrDef("description", "")
pkgJson.MainSrc = getParamOrDef("source folder: (src/)", "src/")
Expand Down Expand Up @@ -55,11 +56,11 @@ func getParamOrDef(msg string, def string) string {

func printHead() {
println(`
This utility will walk you through creating a package.json file.
This utility will walk you through creating a boss.json file.
It only covers the most common items, and tries to guess sensible defaults.
Use 'boss install <pkg>' afterwards to install a package and
save it as a dependency in the package.json file.
save it as a dependency in the boss.json file.
Press ^C at any time to quit.
{like npm @_@ }`)
Expand Down
8 changes: 5 additions & 3 deletions cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package cmd

import (
"strings"

"github.com/hashload/boss/core"
"github.com/hashload/boss/core/gb"
"github.com/hashload/boss/core/paths"
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils"
"github.com/spf13/cobra"
"strings"
)

var dev bool
Expand All @@ -28,7 +29,7 @@ var installCmd = &cobra.Command{
split := strings.Split(dependency, ":")
var ver string
if len(split) == 1 {
ver = "^1"
ver = "x"
} else {
ver = split[1]
}
Expand All @@ -42,10 +43,11 @@ var installCmd = &cobra.Command{
if loadPackage.IsNew && len(args) == 0 {
return
}
loadPackage.Save()
paths.EnsureModulesDir()
msg.Info("Installing modules in project patch")
core.EnsureDependencies(loadPackage)
utils.UpdateLibraryPath()
loadPackage.Save()
gb.RunGB()
},
}
Expand Down
48 changes: 25 additions & 23 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,36 @@ func contains(a []string, x string) bool {
}

func processOthers() {
if len(processed) > processedOld {
processedOld = len(processed)
infos, e := ioutil.ReadDir(env.GetModulesDir())
if e != nil {
msg.Err("Error on try load dir of modules: %s", e)
}
infos, e := ioutil.ReadDir(env.GetModulesDir())
if e != nil {
msg.Err("Error on try load dir of modules: %s", e)
}

for _, info := range infos {
if !info.IsDir() {
continue
}
if contains(processed, info.Name()) {
continue
}
msg.Info("Processing module: %s", info.Name())
for _, info := range infos {
if !info.IsDir() {
continue
}
if contains(processed, info.Name()) {
continue
} else {
processed = append(processed, info.Name())
}
msg.Info("Processing module: %s", info.Name())

fileName := filepath.Join(env.GetModulesDir(), info.Name(), "boss.json")
fileName := filepath.Join(env.GetModulesDir(), info.Name(), "boss.json")

_, i := os.Stat(fileName)
if os.IsNotExist(i) {
msg.Warn("boss.json not exists in %s", info.Name())
}
_, i := os.Stat(fileName)
if os.IsNotExist(i) {
msg.Warn("\tboss.json not exists in %s", info.Name())
}

if packageOther, e := models.LoadPackageOther(fileName); e != nil {
msg.Err("Error on try load package %s: %s", fileName, e)
} else {
EnsureDependencies(packageOther)
if packageOther, e := models.LoadPackageOther(fileName); e != nil {
if os.IsNotExist(e) {
continue
}
msg.Err("\tError on try load package %s: %s", fileName, e)
} else {
EnsureDependencies(packageOther)
}

}
Expand Down
3 changes: 2 additions & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion models/dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package models
import (
"crypto/md5"
"encoding/hex"
"github.com/hashload/boss/msg"
"io"
"regexp"
"strings"

"github.com/hashload/boss/msg"
)

type Dependency struct {
Expand Down Expand Up @@ -57,6 +58,9 @@ func ParseDependency(repo string, info string) Dependency {
dependency := Dependency{}
dependency.Repository = repo
dependency.version = parsed[0]
if dependency.version == "x" {
dependency.version = "> 0.0.0"
}
if re.MatchString(dependency.version) {
msg.Warn("Current version for %s is not semantic (x.y.z), for comparation using %s -> %s",
dependency.Repository, dependency.version, dependency.version+".0")
Expand Down
7 changes: 0 additions & 7 deletions models/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package models
import (
"encoding/json"
. "io/ioutil"
"time"

"github.com/hashload/boss/consts"
)
Expand All @@ -19,18 +18,12 @@ type Package struct {
MainSrc string `json:"mainsrc"`
Supported string `json:"supported"`
DprojName string `json:"dprojFile"`
ModifyedAt time.Time `json:"modifyedAt"`
Scripts interface{} `json:"scripts,omitempty"`
Dependencies interface{} `json:"dependencies,omitempty"`
DevDependencies interface{} `json:"devDependencies,omitempty"`
}

func (p *Package) updateTime() {
p.ModifyedAt = time.Now()
}

func (p *Package) Save() {
p.updateTime()
marshal, _ := json.MarshalIndent(p, "", "\t")
WriteFile(p.fileName, marshal, 664)
}
Expand Down

0 comments on commit 61263c2

Please sign in to comment.