4 Commits

Author SHA1 Message Date
38f0ad345b Updated readme
Added changelog
2020-03-07 11:00:54 -06:00
2cd90c7b99 Added config support for specifying the output file prefix
This was hardcoded to "app-" because that's what I wanted mine to use. No real reason it has to be that way, though. Only offering a prefix is still pretty limiting, but better than hardcoding.
2020-03-07 10:55:44 -06:00
332d48dd33 Documented config properties 2020-03-07 10:54:59 -06:00
0e4c6557ca Return errors if told to output to a directory and writing a file fails 2020-03-07 10:54:21 -06:00
4 changed files with 26 additions and 5 deletions

10
CHANGELOG.md Normal file
View File

@ -0,0 +1,10 @@
# v1.1.0
## Added
* Ability to specify a prefix to use when outputting files via the OutputDir config property.
* Documented all config properties to explain their usage.
## Changed
* If no FilePrefix is specified in the config, files will now be written as (hash).min.(extension) (no `app-` prefix as was hardcoded into previous releases).
# v1.0.0
Initial release

View File

@ -35,6 +35,7 @@ func main() {
},
Minify: true,
OutputDir: "assets/",
FilePrefix: "app-",
})
}
```
@ -46,6 +47,7 @@ Config key | Use
Files | An array of strings representing paths to files you want compiled
Minify | Bool, optionally minify the files with https://github.com/tdewolff/minify
OutputDir | String, the directory you'd like to write the compiled files to (with trailing slash)
FilePrefix | String, what, if anything, should be prefixed onto the output filenames
Note that if an output dir is specified, "css" and "js" subdirectories will be used/created to hold the resulting files. Leaving it blank will cause it to not write any files to disk.

View File

@ -100,10 +100,14 @@ func finalize(config Config, buf map[FileType]*bytes.Buffer) (map[FileType]*Comp
}
dir := filepath.Join(config.OutputDir, string(key))
os.MkdirAll(dir, 0755)
if err := os.MkdirAll(dir, 0755); err != nil {
return nil, err
}
destFile := filepath.Join(dir, "app-"+ret[key].Hash+ext)
ioutil.WriteFile(destFile, bytes, 0644)
destFile := filepath.Join(dir, config.FilePrefix+ret[key].Hash+ext)
if err := ioutil.WriteFile(destFile, bytes, 0644); err != nil {
return nil, err
}
ret[key].OutputPath = destFile
}
}

View File

@ -2,7 +2,12 @@ package precompiler
// Config holds information on how to run the compiler
type Config struct {
// Files is a list of files to precompile together
Files []string
// Minify specifies whether minification should happen along with concatenation
Minify bool
// OutputDir if specified will cause the result to be written to this directory
OutputDir string
// FilePrefix is a string that will be prefixed on the files if OutputDir is specified
FilePrefix string
}