1// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
2// license. Its contents can be found at:
3// http://creativecommons.org/publicdomain/zero/1.0/
4
5package bindata
6
7import (
8	"os"
9)
10
11// Translate reads assets from an input directory, converts them
12// to Go code and writes new files to the output specified
13// in the given configuration.
14func Translate(c *Config) (err error) {
15	c.cwd, err = os.Getwd()
16	if err != nil {
17		return ErrCWD
18	}
19
20	// Ensure our configuration has sane values.
21	err = c.validate()
22	if err != nil {
23		return
24	}
25
26	scanner := NewFSScanner(c)
27
28	assets := make([]Asset, 0)
29
30	// Locate all the assets.
31	for _, input := range c.Input {
32		err = scanner.Scan(input.Path, "", input.Recursive)
33		if err != nil {
34			return
35		}
36
37		assets = append(assets, scanner.assets...)
38
39		scanner.Reset()
40	}
41
42	if c.Split {
43		return translateToDir(c, assets)
44	}
45
46	return translateToFile(c, assets)
47}
48