Skip to content

Commit

Permalink
Merge pull request #204 from devangel/master
Browse files Browse the repository at this point in the history
fix package fetch and push
  • Loading branch information
dcarroll committed Oct 9, 2015
2 parents 98ac1d2 + 18ce1f4 commit 34f6bb9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
5 changes: 2 additions & 3 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var cmdFetch = &Command{
-n, -name # name of specific metadata to retrieve (must be used with -type)
-d, -directory # override the default target directory
-u, -unpack # unpack any zipped static resources (ignored if type is not StaticResource)
-p, -preserve # preserve the zip file
-p, -preserve # preserve the zip file
Export specified artifact(s) to a local directory. Use "package" type to retrieve an unmanaged package.
Expand Down Expand Up @@ -137,8 +137,7 @@ func persistBundles(bundles AuraDefinitionBundleResult, definitions AuraDefiniti
if err := os.MkdirAll(root, 0755); err != nil {
ErrorAndExit(err.Error())
}
var wd, _ = os.Getwd()
fmt.Println("Working Dir: ", wd)

for key, value := range bundleMap {
if err := os.MkdirAll(filepath.Join(root, value), 0755); err != nil {
ErrorAndExit(err.Error())
Expand Down
53 changes: 46 additions & 7 deletions push.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ func contains(s []string, e string) bool {

func pushPackage() {
if len(resourcepath) == 0 {
ErrorAndExit(fmt.Sprintf("No resource path sepcified."))
var packageFolder = findPackageFolder(metadataName[0])
zipResource(packageFolder, metadataName[0])
resourcepath.Set(packageFolder + ".resource")
//var dir, _ = os.Getwd();
//ErrorAndExit(fmt.Sprintf("No resource path sepcified. %s, %s", metadataName[0], dir))
}
deployPackage()
}
Expand Down Expand Up @@ -255,6 +259,41 @@ func findMetadataTypeFolder(mdtype string, root string) (folder string) {
return
}

func findPackageFolder(packageName string) (folder string) {
var wd, _ = os.Getwd()
// We need to start at the metadata folder, go down first
folder = findMetadataFolder(wd)
if len(folder) == 0 {
// Didn't find it, error out
fmt.Println("Could not find metadata folder.")
}
if _, err := os.Stat(filepath.Join(folder, packageName)); err == nil {
folder = filepath.Join(folder, packageName)
}
return
}

func findMetadataFolder(dir string) (folderPath string) {
filepath.Walk(dir, func(path string, f os.FileInfo, err error) error {
if filepath.Base(path) == "metadata" {
folderPath = path
return errors.New("walk cancelled")
}
return nil
})
if len(folderPath) == 0 {
// not down, so, go up
for dir != string(os.PathSeparator) {
dir = filepath.Dir(dir)
if filepath.Base(dir) == "metadata" {
folderPath = dir
return
}
}
}
return
}

// This method will use the type that is passed to the -type flag to find all
// metadata that matches that type. It will also filter on the metadata
// name(s) passed on the -name flag(s). This method also looks for unpacked
Expand All @@ -274,13 +313,13 @@ func pushByMetadataType() {
// Check to see if any names where specified in the -name flag
if len(metadataName) == 0 {
// Take all
zipResource(path)
zipResource(path, "")
} else {
for _, name := range metadataName {
fname := filepath.Base(path)
// Check to see if the resource name matches the one of the ones passed on the -name flag
if fname == name {
zipResource(path)
zipResource(path, "")
}
}
}
Expand Down Expand Up @@ -317,7 +356,7 @@ func pushByMetadataType() {
}

// Just zip up what ever is in the path
func zipResource(path string) {
func zipResource(path string, topLevelFolder string) {
zipfile := new(bytes.Buffer)
zipper := zip.NewWriter(zipfile)
startPath := path + "/"
Expand All @@ -329,7 +368,7 @@ func zipResource(path string) {
if err != nil {
return err
}
fl, err := zipper.Create(strings.Replace(path, startPath, "", -1))
fl, err := zipper.Create(filepath.Join(topLevelFolder, strings.Replace(path, startPath, "", -1)))
if err != nil {
ErrorAndExit(err.Error())
}
Expand Down Expand Up @@ -362,7 +401,7 @@ func pushByName() {
// Check to see if any names where specified in the -name flag
if len(metadataName) == 0 {
// Take all
zipResource(path)
zipResource(path, "")
} else {
for _, name := range metadataName {
fname := filepath.Base(path)
Expand All @@ -372,7 +411,7 @@ func pushByName() {
if metadataType == "staticresources" {
metadataType = "StaticResource"
}
zipResource(path)
zipResource(path, "")
}
}
}
Expand Down

0 comments on commit 34f6bb9

Please sign in to comment.