-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.go
86 lines (75 loc) · 3.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
"io/ioutil"
"os"
)
var VERSION string
var shouldInit = kingpin.Flag("init", "Initialize a Bladefile").Bool()
var contentsTemplate = kingpin.Flag("template", "Contents json template to generate for.").Short('t').Default("Contents.json").String()
var interpolation = kingpin.Flag("interpolation", "Interpolation: l2, l3 (Lanczos 2 and 3), n (nearest neighbor), bc (bicubic), bl (bilinear), mn (Mitchell-Netravali)").Short('i').Default("l3").String()
var source = kingpin.Flag("source", "Source image to use. For optimal results supply a highest size PNG.").Short('s').String()
var out = kingpin.Flag("out", "Out folder. Use current folder if none given.").Short('o').String()
var includeContents = kingpin.Flag("catalog", "Include generation of a new image catalog Contents.json").Short('c').Bool()
var dryRun = kingpin.Flag("dryrun", "Do a dry run, don't write out anything").Short('d').Bool()
var mount = kingpin.Flag("mount", "Mount on an existing image catalog (take its Contents.json and output images to it)").Short('m').String()
var verbose = kingpin.Flag("verbose", "Verbose output").Bool()
var version = kingpin.Flag("version", "Current version").Short('v').Bool()
var BLADEFILE = `#
# Uncomment below to specify your own resources.
# See https://github.com/jondot/blade for more information.
#
blades:
- source: assets/icon-1024x1024.png # this image should be the only image, and the biggest image you can use (typically for icons, 1024x1024)
mount: project_name/Assets.xcassets/AppIcon.appiconset
contents: true # use 'false' if you want to only update existing catalog, 'true' if you want to generate a full catalog every time
# - source: spaceship.png
# mount: project_name/Images.xcassets/Spaceship.imageset # you can also generate regular image sets, not just app icons
# - source: iTunesArtwork@2x.png
# template: templates/iphone-appicon.json # use a template if you want to batch build catalogs regardless of an xcode project (e.g. as part of a CI process)
# out: out/newiphone
# contents: true
`
func init() {
log.SetLevel(log.FatalLevel)
}
func main() {
kingpin.Parse()
if *version {
println(VERSION)
os.Exit(0)
}
if *shouldInit {
ioutil.WriteFile("Bladefile", []byte(BLADEFILE), 0644)
fmt.Println("Wrote Bladefile.\nYou have 1 blade set up with recommended settings, please review that it matches your project.")
os.Exit(0)
}
if *verbose {
log.SetLevel(log.InfoLevel)
}
bladefile := Bladefile{}
if bladefile.Exists() {
log.Infof("Found a local Bladefile.")
err := bladefile.Load()
if err != nil {
log.Fatalf("Cannot load bladefile (%s)", err)
}
log.Infof("Bladefile contains %d blade defs.", len(bladefile.Blades))
for _, blade := range bladefile.Blades {
blade.Run()
}
} else {
blade := Blade{
Template: *contentsTemplate,
Interpolation: *interpolation,
Source: *source,
Out: *out,
IncludeContents: *includeContents,
DryRun: *dryRun,
Mount: *mount,
}
blade.Run()
}
}