2020-08-09 05:08:30 +01:00
|
|
|
// +build mage
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/magefile/mage/mg"
|
|
|
|
"github.com/magefile/mage/sh"
|
2020-09-12 14:06:28 +01:00
|
|
|
"gitlab.com/dananglin/cv/helpers"
|
2020-08-09 05:08:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
aspellPersonalWordlist string = "./.aspell/.aspell.en.pws"
|
|
|
|
cvJsonDataFile string = "./data/cv.json"
|
2020-09-12 14:06:28 +01:00
|
|
|
cvOutputDir string = "./__output"
|
|
|
|
cvTemplateDir string = "./template/tex/"
|
|
|
|
cvOutputFileName string = "cv.tex"
|
2020-08-09 05:08:30 +01:00
|
|
|
dockerfile string = "./docker/Dockerfile"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Default sets the default target.
|
|
|
|
var Default = Pdf
|
|
|
|
|
|
|
|
// SpellCheck checks the CV JSON file for spelling errors. If there are any
|
|
|
|
// misspelt words found the function returns a list of those words in an error.
|
|
|
|
// Any error found while gathering the list is returned.
|
|
|
|
// This function depends on the aspell program.
|
|
|
|
func SpellCheck() error {
|
2020-09-13 14:24:29 +01:00
|
|
|
return helpers.SpellCheck(cvJsonDataFile, aspellPersonalWordlist)
|
2020-08-09 05:08:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tex takes the CV data file and generates the output tex file from
|
|
|
|
// template.
|
|
|
|
func Tex() error {
|
|
|
|
fmt.Println("Generating the tex file...")
|
2020-09-12 14:06:28 +01:00
|
|
|
|
2020-08-09 05:08:30 +01:00
|
|
|
mg.Deps(Clean)
|
|
|
|
|
2020-09-12 14:06:28 +01:00
|
|
|
return helpers.CreateCVTex(cvJsonDataFile, cvTemplateDir, cvOutputDir, cvOutputFileName)
|
2020-08-09 05:08:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pdf takes the output tex file generated by the Tex target and
|
|
|
|
// generates the output PDF file.
|
|
|
|
func Pdf() error {
|
|
|
|
mg.Deps(Tex)
|
|
|
|
|
2020-09-12 14:06:28 +01:00
|
|
|
pathArg := "--path=" + cvOutputDir
|
2020-08-09 05:08:30 +01:00
|
|
|
|
|
|
|
fmt.Println("Generating the PDF file...")
|
|
|
|
return sh.Run("mtxrun", pathArg, "--script", "context", "cv.tex")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Image builds the CV builder docker image.
|
|
|
|
func Image() error {
|
2020-09-12 14:06:28 +01:00
|
|
|
image := helpers.ImageName()
|
2020-08-09 05:08:30 +01:00
|
|
|
|
|
|
|
return sh.Run("docker", "build", "-f", dockerfile, "-t", image, ".")
|
|
|
|
}
|
|
|
|
|
|
|
|
// PublishImage publishes the CV builder docker image
|
|
|
|
// to the docker registry.
|
|
|
|
func PublishImage() error {
|
|
|
|
mg.Deps(Image)
|
|
|
|
|
2020-09-12 14:06:28 +01:00
|
|
|
image := helpers.ImageName()
|
2020-08-09 05:08:30 +01:00
|
|
|
return sh.Run("docker", "push", image)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean removes the directory where the output files
|
|
|
|
// are generated.
|
|
|
|
func Clean() error {
|
2020-09-12 14:06:28 +01:00
|
|
|
if err := sh.Rm(cvOutputDir); err != nil {
|
2020-08-09 05:08:30 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|