tideliftcli/manifests.go

144 lines
2.6 KiB
Go
Raw Normal View History

2019-05-14 03:26:13 +00:00
package main
2019-05-14 21:16:59 +00:00
import (
"fmt"
"log"
2019-05-15 02:09:14 +00:00
"os"
2019-05-14 21:16:59 +00:00
"github.com/bmatcuk/doublestar"
)
2019-05-15 02:40:51 +00:00
var (
/*
When adding new manifest types, for new package managers
add a new entry here. If it's a new platform/package manager, please
update the comments with the platform name for organization sense
*/
manifestGlobs = []string{
// Hackage
"*.cabal",
// npm
"package.json",
"package-lock.json",
"npm-shrinkwrap.json",
"yarn.lock",
// Maven
"pom.xml",
"ivy.xml",
"build.gradle",
// RubyGems
"Gemfile",
"Gemfile.lock",
"gems.rb",
"gems.locked",
"*.gemspec",
// Packagist
"composer.json",
"composer.lock",
// PyPi
"setup.py",
"req*.txt",
"req*.pip",
"requirements/*.txt",
"requirements/*.pip",
"Pipfile",
"Pipfile.lock",
// Nuget
"packages.config",
"Project.json",
"Project.lock.json",
"*.nuspec",
"paket.lock",
"*.csproj",
// Bower
"bower.json",
// CPAN
"META.json",
"META.yml",
// CocoaPods
"Podfile",
"Podfile.lock",
"*.podspec",
// Clojars
"project.clj",
// Meteor
"versions.json",
// CRAN
"DESCRIPTION",
// Cargo
"Cargo.toml",
"Cargo.lock",
// Hex
"mix.exs",
"mix.lock",
// Swift
"Package.swift",
// Pub
"pubspec.yaml",
"pubspec.lock",
// Carthage
"Cartfile",
"Cartfile.private",
"Cartfile.resolved",
// Dub
"dub.json",
"dub.sdl",
// Julia
"REQUIRE",
// Shards
"shard.yml",
"shard.lock",
// Go
"glide.yaml",
"glide.lock",
"Godeps",
"Godeps/Godeps.json",
"vendor/manifest",
"vendor/vendor.json",
"Gopkg.toml",
"Gopkg.lock",
// Elm
"elm-package.json",
"elm_dependencies.json",
"elm-stuff/exact-dependencies.json",
// Haxelib
"haxelib.json",
// Hackage
"*.cabal",
"cabal.config",
}
)
2019-05-14 21:16:59 +00:00
2019-05-15 02:40:51 +00:00
// getListOfManifestFilenames: Given a directory, changes directory to that directory,
// then loops through all of the support manifest file patterns, and
// gets all matching instances
//
// returns string[] of filenames relative to the directory passed in.
2019-05-14 21:26:22 +00:00
func getListOfManifestFilenames(directory string) []string {
2019-05-15 02:09:14 +00:00
os.Chdir(directory)
2019-05-14 21:16:59 +00:00
matchingFiles := make([]string, 0)
2019-05-15 02:40:51 +00:00
for _, glob := range manifestGlobs {
files := getListOfGlobMatches(glob)
2019-05-14 21:16:59 +00:00
if len(files) > 0 {
matchingFiles = append(matchingFiles, files...)
}
}
return matchingFiles
}
2019-05-15 02:40:51 +00:00
// getListOfGlobMatches uses doublestar's Glob function to expand and find
// all instances of a manifest file pattern, in your given directory
//
// returns string[] of all matching file patterns
2019-05-14 21:26:22 +00:00
func getListOfGlobMatches(glob string) []string {
2019-05-15 02:40:51 +00:00
pathGlob := fmt.Sprintf("**/%s", glob)
files, err := doublestar.Glob(pathGlob)
2019-05-14 21:16:59 +00:00
if err != nil {
log.Fatal(err)
}
return files
}