From 7aae9915f024ffb186ed853ff363a8fd3a14482d Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Sat, 15 Jul 2017 14:24:10 -0700 Subject: [PATCH] Create build dir to reduce mess --- .gitignore | 1 + Makefile | 41 ++++++++++++++++++------------------ SFDashC/database.go | 11 ++++++++-- SFDashC/docset-apexcode.json | 15 +++++++++++++ SFDashC/docset-pages.json | 15 +++++++++++++ SFDashC/index.htm | 5 ----- SFDashC/main.go | 26 ++++++++++++----------- 7 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 SFDashC/docset-apexcode.json create mode 100644 SFDashC/docset-pages.json delete mode 100644 SFDashC/index.htm diff --git a/.gitignore b/.gitignore index 4ae2b6c..da1b3e7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ syntax-highlighter.min.css *.tgz # External Go dependencies vendor/ +build/ diff --git a/Makefile b/Makefile index 72ead07..8ef7cb8 100644 --- a/Makefile +++ b/Makefile @@ -19,36 +19,38 @@ run-combined: clean-index package-apex: run-apex $(eval name = Apex) $(eval package = Salesforce $(name).docset) - $(eval version = $(shell cat SFDashC/apexcode-version.txt)) + $(eval version = $(shell cat ./build/apexcode-version.txt)) + cat ./SFDashC/docset-apexcode.json | sed s/VERSION/$(version)/ > ./build/docset-apexcode.json mkdir -p "$(package)/Contents/Resources/Documents" - cp -r SFDashC/atlas.en-us.apexcode.meta "$(package)/Contents/Resources/Documents/" - cp SFDashC/*.html "$(package)/Contents/Resources/Documents/" - cp SFDashC/*.css "$(package)/Contents/Resources/Documents/" - cp SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" - cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/" + cp -r ./build/atlas.en-us.apexcode.meta "$(package)/Contents/Resources/Documents/" + cp ./build/*.html "$(package)/Contents/Resources/Documents/" + cp ./build/*.css "$(package)/Contents/Resources/Documents/" + cp ./SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" + cp ./build/docSet.dsidx "$(package)/Contents/Resources/" @echo "Docset generated!" package-vf: run-vf $(eval name = Pages) $(eval package = Salesforce $(name).docset) - $(eval version = $(shell cat SFDashC/pages-version.txt)) + $(eval version = $(shell cat ./build/pages-version.txt)) + cat ./SFDashC/docset-pages.json | sed s/VERSION/$(version)/ > ./build/docset-pages.json mkdir -p "$(package)/Contents/Resources/Documents" - cp -r SFDashC/atlas.en-us.pages.meta "$(package)/Contents/Resources/Documents/" - cp SFDashC/*.html "$(package)/Contents/Resources/Documents/" - cp SFDashC/*.css "$(package)/Contents/Resources/Documents/" - cp SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" - cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/" + cp -r ./build/atlas.en-us.pages.meta "$(package)/Contents/Resources/Documents/" + cp ./build/*.html "$(package)/Contents/Resources/Documents/" + cp ./build/*.css "$(package)/Contents/Resources/Documents/" + cp ./SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" + cp ./build/docSet.dsidx "$(package)/Contents/Resources/" @echo "Docset generated!" package-combined: run-combined $(eval name = Combined) $(eval package = Salesforce $(name).docset) mkdir -p "$(package)/Contents/Resources/Documents" - cp -r SFDashC/*.meta "$(package)/Contents/Resources/Documents/" - cp SFDashC/*.html "$(package)/Contents/Resources/Documents/" - cp SFDashC/*.css "$(package)/Contents/Resources/Documents/" - cp SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" - cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/" + cp -r ./build/*.meta "$(package)/Contents/Resources/Documents/" + cp ./build/*.html "$(package)/Contents/Resources/Documents/" + cp ./build/*.css "$(package)/Contents/Resources/Documents/" + cp ./SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" + cp ./build/docSet.dsidx "$(package)/Contents/Resources/" @echo "Docset generated!" archive: @@ -56,10 +58,9 @@ archive: @echo "Archives created!" clean-index: - rm -f SFDashC/docSet.dsidx + rm -f ./build/docSet.dsidx clean: clean-index - rm -fr SFDashC/*.meta + rm -fr ./build rm -fr *.docset - rm -f SFDashC/*.css rm -f *.tgz diff --git a/SFDashC/database.go b/SFDashC/database.go index c22a1b4..7de9e39 100644 --- a/SFDashC/database.go +++ b/SFDashC/database.go @@ -4,12 +4,19 @@ import ( "database/sql" "github.com/coopernurse/gorp" _ "github.com/mattn/go-sqlite3" + "os" + "path/filepath" ) var dbmap *gorp.DbMap +var dbName = "docSet.dsidx" -func InitDb() *gorp.DbMap { - db, err := sql.Open("sqlite3", "docSet.dsidx") +func InitDb(buildDir string) *gorp.DbMap { + dbPath := filepath.Join(buildDir, dbName) + err := os.MkdirAll(filepath.Dir(dbPath), 0755) + ExitIfError(err) + + db, err := sql.Open("sqlite3", dbPath) ExitIfError(err) dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}} diff --git a/SFDashC/docset-apexcode.json b/SFDashC/docset-apexcode.json new file mode 100644 index 0000000..a08f473 --- /dev/null +++ b/SFDashC/docset-apexcode.json @@ -0,0 +1,15 @@ +{ + "name": "Salesforce Apex", + "version": "VERSION", + "archive": "Salesforce_Apex.tgz", + "author": { + "name": "ViViDboarder", + "link": "https://github.com/ViViDboarder" + }, + "aliases": [ + "apex", + "salesforce", + "sfdc" + ], + "specific_versions": [] +} diff --git a/SFDashC/docset-pages.json b/SFDashC/docset-pages.json new file mode 100644 index 0000000..195e209 --- /dev/null +++ b/SFDashC/docset-pages.json @@ -0,0 +1,15 @@ +{ + "name": "Salesforce Visualforce", + "version": "VERSION", + "archive": "Salesforce_Pages.tgz", + "author": { + "name": "ViViDboarder", + "link": "https://github.com/ViViDboarder" + }, + "aliases": [ + "visualforce", + "salesforce", + "sfdc" + ], + "specific_versions": [] +} diff --git a/SFDashC/index.htm b/SFDashC/index.htm deleted file mode 100644 index d3106c1..0000000 --- a/SFDashC/index.htm +++ /dev/null @@ -1,5 +0,0 @@ - - - This is a joint docset - - diff --git a/SFDashC/main.go b/SFDashC/main.go index 76425ab..917f83e 100644 --- a/SFDashC/main.go +++ b/SFDashC/main.go @@ -13,8 +13,9 @@ import ( ) // CSS Paths -var cssBasePath = "https://developer.salesforce.com/resource/stylesheets" +var cssBaseURL = "https://developer.salesforce.com/resource/stylesheets" var cssFiles = []string{"holygrail.min.css", "docs.min.css", "syntax-highlighter.min.css"} +var buildDir = "build" var wg sync.WaitGroup var throttle = make(chan int, maxConcurrency) @@ -70,6 +71,8 @@ func printSuccess(toc *AtlasTOC) { func saveMainContent(toc *AtlasTOC) { filePath := fmt.Sprintf("%s.html", toc.Deliverable) + // Prepend build dir + filePath = filepath.Join(buildDir, filePath) // Make sure file doesn't exist first if _, err := os.Stat(filePath); os.IsNotExist(err) { content := toc.Content @@ -93,6 +96,8 @@ func saveMainContent(toc *AtlasTOC) { func saveContentVersion(toc *AtlasTOC) { filePath := fmt.Sprintf("%s-version.txt", toc.Deliverable) + // Prepend build dir + filePath = filepath.Join(buildDir, filePath) err := os.MkdirAll(filepath.Dir(filePath), 0755) ExitIfError(err) @@ -118,7 +123,7 @@ func main() { } // Init the Sqlite db - dbmap = InitDb() + dbmap = InitDb(buildDir) err := dbmap.TruncateTables() ExitIfError(err) @@ -132,12 +137,6 @@ func main() { saveContentVersion(toc) // Download each entry - /* - * topLevelEntryIDs := map[string]bool{ - * "apex_dev_guide": true, - * "pages_compref": true, - * } - */ for _, entry := range toc.TOCEntries { processChildReferences(entry, nil, toc) } @@ -203,6 +202,8 @@ func downloadContent(entry TOCEntry, toc *AtlasTOC, wg *sync.WaitGroup) { defer wg.Done() filePath := entry.GetContentFilepath(toc, true) + // Prepend build dir + filePath = filepath.Join(buildDir, filePath) // Make sure file doesn't exist first if _, err := os.Stat(filePath); os.IsNotExist(err) { content, err := entry.GetContent(toc) @@ -235,15 +236,16 @@ func downloadContent(entry TOCEntry, toc *AtlasTOC, wg *sync.WaitGroup) { func downloadCSS(fileName string, wg *sync.WaitGroup) { defer wg.Done() - if _, err := os.Stat(fileName); os.IsNotExist(err) { - err = os.MkdirAll(filepath.Dir(fileName), 0755) + filePath := filepath.Join(buildDir, fileName) + if _, err := os.Stat(filePath); os.IsNotExist(err) { + err = os.MkdirAll(filepath.Dir(filePath), 0755) ExitIfError(err) - ofile, err := os.Create(fileName) + ofile, err := os.Create(filePath) ExitIfError(err) defer ofile.Close() - cssURL := cssBasePath + "/" + fileName + cssURL := cssBaseURL + "/" + fileName response, err := http.Get(cssURL) ExitIfError(err) defer response.Body.Close()