Skip to content

Commit

Permalink
Remove top-level GetEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 4, 2020
1 parent 94072ea commit aa79553
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
17 changes: 5 additions & 12 deletions cmd/checker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ func main() {
}

if subcommand == "lint" {
names := flag.Args()[1:]
runAllChecks := len(names) == 1

for _, name := range names {
lintPackage(runAllChecks, name)
}
lintPackage(flag.Arg(1))

if validationErrorCount > 0 {
fmt.Printf("%d linting error(s)\n", validationErrorCount)
Expand All @@ -42,7 +37,7 @@ func main() {
panic("unknown subcommand")
}

func lintPackage(runAllChecks bool, path string) {
func lintPackage(path string) {
ctx := util.ContextWithName(path)

util.Debugf(ctx, "Linting %s...\n", path)
Expand Down Expand Up @@ -85,11 +80,9 @@ func lintPackage(runAllChecks bool, path string) {
if !npm.Exists(pckg.Autoupdate.Target) {
err(ctx, "package doesn't exists on npm")
} else {
if runAllChecks {
counts := npm.GetMonthlyDownload(pckg.Autoupdate.Target)
if counts.Downloads < 800 {
err(ctx, "package download per month on npm is under 800")
}
counts := npm.GetMonthlyDownload(pckg.Autoupdate.Target)
if counts.Downloads < 800 {
err(ctx, "package download per month on npm is under 800")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/packages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
}

if subcommand == "generate" {
files, err := filepath.Glob(path.Join(packages.CDNJS_PACKAGES_PATH, "*", "package.json"))
files, err := filepath.Glob(path.Join(util.GetCDNJSPackages(), "*", "package.json"))
util.Check(err)

out := make([]outputPackage, 0)
Expand Down
8 changes: 1 addition & 7 deletions packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import (
"github.com/cdnjs/tools/util"
)

var (
BASE_PATH = util.GetEnv("BOT_BASE_PATH")
CDNJS_PATH = path.Join(BASE_PATH, "cdnjs")
CDNJS_PACKAGES_PATH = path.Join(BASE_PATH, "cdnjs", "ajax", "libs")
)

type Repository struct {
Repotype string `json:"type"`
Url string `json:"url"`
Expand Down Expand Up @@ -78,7 +72,7 @@ func stringInObject(key string, object map[string]interface{}) string {

// Location of the package in the cdnjs repo
func (p *Package) Path() string {
return path.Join(CDNJS_PACKAGES_PATH, p.Name)
return path.Join(util.GetCDNJSPackages(), p.Name)
}

func (p *Package) Versions() (versions []string) {
Expand Down
13 changes: 13 additions & 0 deletions util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"fmt"
"os"
"path"
)

const (
Expand All @@ -20,3 +21,15 @@ func GetEnv(name string) string {
func IsDebug() bool {
return os.Getenv("DEBUG") != ""
}

func GetBotBasePath() string {
return GetEnv("BOT_BASE_PATH")
}

func GetCDNJSPath() string {
return path.Join(GetBotBasePath(), "cdnjs")
}

func GetCDNJSPackages() string {
return path.Join(GetBotBasePath(), "cdnjs", "ajax", "libs")
}
6 changes: 1 addition & 5 deletions util/fileglob.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"strings"
)

var (
GLOB_EXECUTABLE = path.Join(GetEnv("BOT_BASE_PATH"), "glob", "index.js")
)

func ListFilesGlob(base string, pattern string) []string {
if _, err := os.Stat(base); os.IsNotExist(err) {
fmt.Println("match", pattern, "in", base, "but doesn't exists")
Expand All @@ -21,7 +17,7 @@ func ListFilesGlob(base string, pattern string) []string {

fmt.Println("match", pattern, "in", base)

cmd := exec.Command(GLOB_EXECUTABLE, pattern)
cmd := exec.Command(path.Join(GetBotBasePath(), "glob", "index.js"), pattern)
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
Expand Down

0 comments on commit aa79553

Please sign in to comment.