Create build dir to reduce mess

This commit is contained in:
ViViDboarder 2017-07-15 14:24:10 -07:00
parent 0be33639b0
commit 7aae9915f0
7 changed files with 75 additions and 39 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ syntax-highlighter.min.css
*.tgz *.tgz
# External Go dependencies # External Go dependencies
vendor/ vendor/
build/

View File

@ -19,36 +19,38 @@ run-combined: clean-index
package-apex: run-apex package-apex: run-apex
$(eval name = Apex) $(eval name = Apex)
$(eval package = Salesforce $(name).docset) $(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" mkdir -p "$(package)/Contents/Resources/Documents"
cp -r SFDashC/atlas.en-us.apexcode.meta "$(package)/Contents/Resources/Documents/" cp -r ./build/atlas.en-us.apexcode.meta "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.html "$(package)/Contents/Resources/Documents/" cp ./build/*.html "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.css "$(package)/Contents/Resources/Documents/" cp ./build/*.css "$(package)/Contents/Resources/Documents/"
cp SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" cp ./SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist"
cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/" cp ./build/docSet.dsidx "$(package)/Contents/Resources/"
@echo "Docset generated!" @echo "Docset generated!"
package-vf: run-vf package-vf: run-vf
$(eval name = Pages) $(eval name = Pages)
$(eval package = Salesforce $(name).docset) $(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" mkdir -p "$(package)/Contents/Resources/Documents"
cp -r SFDashC/atlas.en-us.pages.meta "$(package)/Contents/Resources/Documents/" cp -r ./build/atlas.en-us.pages.meta "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.html "$(package)/Contents/Resources/Documents/" cp ./build/*.html "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.css "$(package)/Contents/Resources/Documents/" cp ./build/*.css "$(package)/Contents/Resources/Documents/"
cp SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" cp ./SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist"
cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/" cp ./build/docSet.dsidx "$(package)/Contents/Resources/"
@echo "Docset generated!" @echo "Docset generated!"
package-combined: run-combined package-combined: run-combined
$(eval name = Combined) $(eval name = Combined)
$(eval package = Salesforce $(name).docset) $(eval package = Salesforce $(name).docset)
mkdir -p "$(package)/Contents/Resources/Documents" mkdir -p "$(package)/Contents/Resources/Documents"
cp -r SFDashC/*.meta "$(package)/Contents/Resources/Documents/" cp -r ./build/*.meta "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.html "$(package)/Contents/Resources/Documents/" cp ./build/*.html "$(package)/Contents/Resources/Documents/"
cp SFDashC/*.css "$(package)/Contents/Resources/Documents/" cp ./build/*.css "$(package)/Contents/Resources/Documents/"
cp SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist" cp ./SFDashC/Info-$(name).plist "$(package)/Contents/Info.plist"
cp SFDashC/docSet.dsidx "$(package)/Contents/Resources/" cp ./build/docSet.dsidx "$(package)/Contents/Resources/"
@echo "Docset generated!" @echo "Docset generated!"
archive: archive:
@ -56,10 +58,9 @@ archive:
@echo "Archives created!" @echo "Archives created!"
clean-index: clean-index:
rm -f SFDashC/docSet.dsidx rm -f ./build/docSet.dsidx
clean: clean-index clean: clean-index
rm -fr SFDashC/*.meta rm -fr ./build
rm -fr *.docset rm -fr *.docset
rm -f SFDashC/*.css
rm -f *.tgz rm -f *.tgz

View File

@ -4,12 +4,19 @@ import (
"database/sql" "database/sql"
"github.com/coopernurse/gorp" "github.com/coopernurse/gorp"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os"
"path/filepath"
) )
var dbmap *gorp.DbMap var dbmap *gorp.DbMap
var dbName = "docSet.dsidx"
func InitDb() *gorp.DbMap { func InitDb(buildDir string) *gorp.DbMap {
db, err := sql.Open("sqlite3", "docSet.dsidx") dbPath := filepath.Join(buildDir, dbName)
err := os.MkdirAll(filepath.Dir(dbPath), 0755)
ExitIfError(err)
db, err := sql.Open("sqlite3", dbPath)
ExitIfError(err) ExitIfError(err)
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}} dbmap := &gorp.DbMap{Db: db, Dialect: gorp.SqliteDialect{}}

View File

@ -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": []
}

15
SFDashC/docset-pages.json Normal file
View File

@ -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": []
}

View File

@ -1,5 +0,0 @@
<html>
<body>
This is a joint docset
</body>
</html>

View File

@ -13,8 +13,9 @@ import (
) )
// CSS Paths // 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 cssFiles = []string{"holygrail.min.css", "docs.min.css", "syntax-highlighter.min.css"}
var buildDir = "build"
var wg sync.WaitGroup var wg sync.WaitGroup
var throttle = make(chan int, maxConcurrency) var throttle = make(chan int, maxConcurrency)
@ -70,6 +71,8 @@ func printSuccess(toc *AtlasTOC) {
func saveMainContent(toc *AtlasTOC) { func saveMainContent(toc *AtlasTOC) {
filePath := fmt.Sprintf("%s.html", toc.Deliverable) filePath := fmt.Sprintf("%s.html", toc.Deliverable)
// Prepend build dir
filePath = filepath.Join(buildDir, filePath)
// Make sure file doesn't exist first // Make sure file doesn't exist first
if _, err := os.Stat(filePath); os.IsNotExist(err) { if _, err := os.Stat(filePath); os.IsNotExist(err) {
content := toc.Content content := toc.Content
@ -93,6 +96,8 @@ func saveMainContent(toc *AtlasTOC) {
func saveContentVersion(toc *AtlasTOC) { func saveContentVersion(toc *AtlasTOC) {
filePath := fmt.Sprintf("%s-version.txt", toc.Deliverable) filePath := fmt.Sprintf("%s-version.txt", toc.Deliverable)
// Prepend build dir
filePath = filepath.Join(buildDir, filePath)
err := os.MkdirAll(filepath.Dir(filePath), 0755) err := os.MkdirAll(filepath.Dir(filePath), 0755)
ExitIfError(err) ExitIfError(err)
@ -118,7 +123,7 @@ func main() {
} }
// Init the Sqlite db // Init the Sqlite db
dbmap = InitDb() dbmap = InitDb(buildDir)
err := dbmap.TruncateTables() err := dbmap.TruncateTables()
ExitIfError(err) ExitIfError(err)
@ -132,12 +137,6 @@ func main() {
saveContentVersion(toc) saveContentVersion(toc)
// Download each entry // Download each entry
/*
* topLevelEntryIDs := map[string]bool{
* "apex_dev_guide": true,
* "pages_compref": true,
* }
*/
for _, entry := range toc.TOCEntries { for _, entry := range toc.TOCEntries {
processChildReferences(entry, nil, toc) processChildReferences(entry, nil, toc)
} }
@ -203,6 +202,8 @@ func downloadContent(entry TOCEntry, toc *AtlasTOC, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
filePath := entry.GetContentFilepath(toc, true) filePath := entry.GetContentFilepath(toc, true)
// Prepend build dir
filePath = filepath.Join(buildDir, filePath)
// Make sure file doesn't exist first // Make sure file doesn't exist first
if _, err := os.Stat(filePath); os.IsNotExist(err) { if _, err := os.Stat(filePath); os.IsNotExist(err) {
content, err := entry.GetContent(toc) 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) { func downloadCSS(fileName string, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
if _, err := os.Stat(fileName); os.IsNotExist(err) { filePath := filepath.Join(buildDir, fileName)
err = os.MkdirAll(filepath.Dir(fileName), 0755) if _, err := os.Stat(filePath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(filePath), 0755)
ExitIfError(err) ExitIfError(err)
ofile, err := os.Create(fileName) ofile, err := os.Create(filePath)
ExitIfError(err) ExitIfError(err)
defer ofile.Close() defer ofile.Close()
cssURL := cssBasePath + "/" + fileName cssURL := cssBaseURL + "/" + fileName
response, err := http.Get(cssURL) response, err := http.Get(cssURL)
ExitIfError(err) ExitIfError(err)
defer response.Body.Close() defer response.Body.Close()