Skip to content

Commit

Permalink
Support uploads without HTML Files
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Feb 10, 2015
1 parent 80125cc commit 8250b4f
Showing 1 changed file with 74 additions and 64 deletions.
138 changes: 74 additions & 64 deletions src/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,103 +453,113 @@ func Deploy(options Options) {
files := listFiles(options)

htmlFileRefs := filesWithExtension(files, ".html")
var htmlFiles []HTMLFile
var id string

if len(htmlFileRefs) == 0 {
panic("Error: No HTML files found")
}
log.Println("No HTML files found")
} else {
inclFiles := make(map[string]*FileRef)
htmlFiles = make([]HTMLFile, len(htmlFileRefs))
for i, file := range htmlFileRefs {
dir := filepath.Dir(file.LocalPath)

rel, err := filepath.Rel(options.Root, dir)
if err != nil {
panic(err)
}

inclFiles := make(map[string]*FileRef)
htmlFiles := make([]HTMLFile, len(htmlFileRefs))
for i, file := range htmlFileRefs {
dir := filepath.Dir(file.LocalPath)
paths, base := parseHTML(options, file.LocalPath)

rel, err := filepath.Rel(options.Root, dir)
if err != nil {
panic(err)
}
if strings.HasPrefix(strings.ToLower(base), "http") || strings.HasPrefix(base, "//") {
panic("Absolute base tags are not supported")
}

paths, base := parseHTML(options, file.LocalPath)
htmlFiles[i] = HTMLFile{
File: *file,
Deps: make([]FileInst, len(paths)),
Base: base,
}

if strings.HasPrefix(strings.ToLower(base), "http") || strings.HasPrefix(base, "//") {
panic("Absolute base tags are not supported")
}
for j, path := range paths {
local := filepath.Join(options.Root, rel, base, path)
remote := filepath.Join(options.Dest, rel, base, path)

htmlFiles[i] = HTMLFile{
File: *file,
Deps: make([]FileInst, len(paths)),
Base: base,
}
ref, ok := inclFiles[local]
if !ok {
ref = &FileRef{
LocalPath: local,
RemotePath: remote,

for j, path := range paths {
local := filepath.Join(options.Root, rel, base, path)
remote := filepath.Join(options.Dest, rel, base, path)
// Filled in after the deploy:
UploadedPath: "",
}

ref, ok := inclFiles[local]
if !ok {
ref = &FileRef{
LocalPath: local,
RemotePath: remote,
inclFiles[local] = ref
}

// Filled in after the deploy:
UploadedPath: "",
use := FileInst{
File: ref,
InstPath: path,
}

inclFiles[local] = ref
htmlFiles[i].Deps[j] = use
}
}

use := FileInst{
File: ref,
InstPath: path,
}
inclFileList := make([]*FileRef, len(inclFiles))
i := 0
for _, ref := range inclFiles {
inclFileList[i] = ref
i++
}

htmlFiles[i].Deps[j] = use
hashPaths := make([]string, 0)
for _, item := range inclFileList {
hashPaths = append(hashPaths, item.LocalPath)
}
for _, item := range htmlFiles {
hashPaths = append(hashPaths, item.File.LocalPath)
}
}

inclFileList := make([]*FileRef, len(inclFiles))
i := 0
for _, ref := range inclFiles {
inclFileList[i] = ref
i++
}
hash := hashFiles(hashPaths)
id = hash[:12]

hashPaths := make([]string, 0)
for _, item := range inclFileList {
hashPaths = append(hashPaths, item.LocalPath)
}
for _, item := range htmlFiles {
hashPaths = append(hashPaths, item.File.LocalPath)
deployFiles(options, true, inclFileList)
}

hash := hashFiles(hashPaths)
id := hash[:12]

deployFiles(options, true, inclFileList)
deployFiles(options, false, ignoreFiles(files, htmlFileRefs))

// Ensure that the new files exist in s3
// Time based on "Eventual Consistency: How soon is eventual?"
time.Sleep(1500 * time.Millisecond)
if len(htmlFileRefs) != 0 {
// Ensure that the new files exist in s3
// Time based on "Eventual Consistency: How soon is eventual?"
time.Sleep(1500 * time.Millisecond)

wg := sync.WaitGroup{}
for _, file := range htmlFiles {
wg.Add(1)
wg := sync.WaitGroup{}
for _, file := range htmlFiles {
wg.Add(1)

go func(file HTMLFile) {
defer wg.Done()
deployHTML(options, id, file)
}(file)
}

go func(file HTMLFile) {
defer wg.Done()
deployHTML(options, id, file)
}(file)
wg.Wait()
}

wg.Wait()
visId := id
if id == "" {
visId = "0 HTML Files"
}

color.Printf(`
+------------------------------------+
| @{g}Deploy Successful!@{|} |
| |
| Deploy ID: @{?}%s@{|} |
+------------------------------------+
`, id)
`, visId)

}

Expand Down

0 comments on commit 8250b4f

Please sign in to comment.