scattered

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2018 License: MIT Imports: 7 Imported by: 0

README

Scattered GoDoc

Scattered is a command line tool for asset hashing. (It would be called “scattered, covered, and smothered,” but that name is too long.) It is useful as a stand-alone tool for hashing web assets. Given a shell path or glob, for each file it makes an MD5 hash and copies the file to basename.HASH.ext. Finally, it returns a JSON object mapping input to output paths for use as a file manifest by some other tool.

Screenshots

$ scattered -h
Usage of scattered:

        scattered [options] <globs>...

Given a shell path or glob, for each file it makes an MD5 hash and
copies the file to basename.HASH.ext. Finally, it returns a JSON
object mapping input to output paths for use as a file manifest by
some other tool.

Options:

  -basepath string
        Base directory to process from (default ".")
  -dirpat string
        Regex for directories to process files in (default "^[^.].*")
  -dryrun
        Just create the JSON manifest; don't create files
  -link
        Use hardlinks instead of copying files
  -merge-existing
        Attempt to merge new manifest results into an existing file
  -output string
        File to save manifest (stdout if unset)
$ tree
.
|-- css
|   `-- site.css
|-- hello.txt
|-- img
|   `-- example.png
`-- js
    `-- menus.js

3 directories, 4 files
$ cat hello.txt
world
$ scattered *.txt
{
        "hello.txt": "hello.591785b794601e212b260e25925636fd.txt"
}
$ ls -1 hello*
hello.591785b794601e212b260e25925636fd.txt
hello.txt
$ scattered '*.css' '*.js' '*.png'
{
        "css/site.css": "css/site.d41d8cd98f00b204e9800998ecf8427e.css",
        "img/example.png": "img/example.d41d8cd98f00b204e9800998ecf8427e.png",
        "js/menus.js": "js/menus.d41d8cd98f00b204e9800998ecf8427e.js"
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIsDir = errors.New("Tried to hash the path of a directory")

ErrIsDir is returned by HashPath when attempting to hash a directory

Functions

func Copy

func Copy(srcBase, dstBase string, paths map[string]string) (err error)

Copy creates copies of the mapped resources.

func HashFileGlobs

func HashFileGlobs(basepath, dirpat string, filepats ...string) (map[string]string, error)

HashFileGlobs returns a map from filepaths to their HashPath equivalent for all files whoses parents match the dirpat regex and themselves match one of the filepat globs.

func HashPath

func HashPath(path string) (string, error)

HashPath opens the file at the provided filepath and returns a string containing the file's hash as part of its filename

func HashReader

func HashReader(r io.Reader) (string, error)

HashReader reads the provided io.Reader and returns its MD5 hash as a string or an error.

func IsHashedPath

func IsHashedPath(path string) bool

IsHashedPath returns true if a filepath matches the pattern path/name.HASH.ext, where HASH is an MD5 hash.

func Link(srcBase, destBase string, paths map[string]string) (err error)

Link creates hardlinks for the mapped resources.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL