Skip to content

Commit

Permalink
basic support for sassDir, subdirectories are missed on build output
Browse files Browse the repository at this point in the history
  • Loading branch information
drewwells committed Dec 21, 2016
1 parent fc8f480 commit 88c334a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
46 changes: 43 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ type BuildArgs struct {
// BuildDir is the base build directory used. When recursive
// file matching is involved, this directory will be used as the
// parent.
BuildDir string
Includes []string
BuildDir string
Includes []string
// Project is the source for Sass files and is searched
// recursively for those files
Project string
Font string
Gen string
Style int
Expand Down Expand Up @@ -77,6 +80,7 @@ type Build struct {
status chan error
queue chan work

proj string
paths []string
bArgs *BuildArgs
partialMap *SafePartialMap
Expand All @@ -99,6 +103,7 @@ func NewBuild(args *BuildArgs, pMap *SafePartialMap) *Build {
queue: make(chan work),
closing: make(chan struct{}),

proj: args.Project,
paths: args.Paths(),
bArgs: args,
partialMap: pMap,
Expand Down Expand Up @@ -127,8 +132,43 @@ func (b *Build) Run() error {
return <-b.done
}

func (b *Build) findFiles() ([]string, error) {
// no project given just use path arguments
if len(b.proj) == 0 {
return pathsToFiles(b.paths, true), nil
}

if len(b.paths) == 0 {
return pathsToFiles([]string{b.proj}, true), nil
}

var absPaths []string
for _, path := range b.paths {
abs, err := filepath.Abs(path)
if err != nil {
return nil, err
}
absPaths = append(absPaths, abs)
}

// Project and paths passed, throw error if path outside of
// project path
for _, file := range absPaths {
fmt.Println(b.proj, "|", file)
if !strings.HasPrefix(file, b.proj) {
fmt.Println("exited out")
return nil, fmt.Errorf("%s not found in project path %s",
file, b.proj)
}
}
return pathsToFiles(b.paths, true), nil
}

func (b *Build) loadWork() {
files := pathsToFiles(b.paths, true)
files, err := b.findFiles()
if err != nil {
b.done <- err
}
for _, file := range files {
b.queue <- work{file: file}
}
Expand Down
16 changes: 11 additions & 5 deletions wt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ func flags(set *pflag.FlagSet) {
set.MarkDeprecated("generated-images-path", "Use --gen instead")
set.StringVar(&gen, "gen", ".", "Path to place generated images")

set.StringSliceVar(&includes, "sass-dir", nil,
"Compass backwards compat, use --proj instead")
set.MarkDeprecated("sass-dir", "recursive paths can be passed as argument ie. wt compile sass")

set.StringVarP(&proj, "proj", "p", "",
"Path to directory containing Sass stylesheets")
"Project root which is searched recursively for [^_]file.sass files to build")
set.MarkDeprecated("proj", "recursive paths can be passed as argument ie. wt compile sass")

set.BoolVar(&nothingb, "no-line-comments", false, "UNSUPPORTED: Disable line comments, use comments")
set.MarkDeprecated("no-line-comments", "Use --comments instead")
set.BoolVar(&relativeAssets, "relative-assets", false, "UNSUPPORTED: Make compass asset helpers generate relative urls to assets.")
Expand Down Expand Up @@ -109,8 +115,6 @@ func flags(set *pflag.FlagSet) {
set.MarkDeprecated("css-dir", "Use -b instead")
set.StringVar(&jsDir, "javascripts-dir", "", "")
set.MarkDeprecated("javascripts-dir", "Compass backwards compat, ignored")
set.StringSliceVar(&includes, "sass-dir", nil,
"Compass backwards compat, use --includes instead")
set.StringVarP(&config, "config", "c", "",
"Temporarily disabled: Location of the config file")

Expand Down Expand Up @@ -235,10 +239,11 @@ func parseBuildArgs(paths []string) *wt.BuildArgs {
gba := &wt.BuildArgs{
ImageDir: dir,
BuildDir: buildDir,
Includes: append([]string{proj}, incs...),
Includes: incs,
Font: font,
Style: style,
Gen: gen,
Project: proj,
Comments: comments,
CacheBust: cachebust,
SourceMap: sourceMap,
Expand Down Expand Up @@ -291,6 +296,7 @@ func globalRun(paths []string) (*wt.SafePartialMap, *wt.BuildArgs) {
log.Printf(" Image Dir: %s\n", gba.ImageDir)
log.Printf(" Build Dir: %s\n", gba.BuildDir)
log.Printf("Build Image Dir: %s\n", gba.Gen)
log.Printf(" Project Dir: %s\n", gba.Project)
log.Printf(" Include Dir(s): %s\n", gba.Includes)
log.Println("===================================")
}
Expand Down Expand Up @@ -379,7 +385,7 @@ func Compile(cmd *cobra.Command, paths []string) {
func run(pMap *wt.SafePartialMap, gba *wt.BuildArgs) {

// No paths given, read from stdin and wait
if len(gba.Paths()) == 0 {
if len(gba.Paths()) == 0 && len(gba.Project) == 0 {

log.Println("Reading from stdin, -h for help")
out := os.Stdout
Expand Down

0 comments on commit 88c334a

Please sign in to comment.