3
3
@Grab (' org.apache.xmlgraphics:batik-transcoder:1.16' )
4
4
@Grab (' org.apache.xmlgraphics:batik-codec:1.16' )
5
5
6
- import java.util.logging.Logger
7
6
import groovy.cli.commons.CliBuilder
8
7
import groovy.json.JsonSlurper
9
8
import net.sourceforge.plantuml.klimt.sprite.SpriteGrayLevel
@@ -26,7 +25,6 @@ final PNGS_DIR = new File('pngs')
26
25
PNGS_DIR . mkdirs()
27
26
final SPRITES_LISTING = new SpritesListing (new File (' sprites-list.md' ), PNGS_DIR )
28
27
29
- def log = Logger . getLogger(" script" )
30
28
def cli = new CliBuilder (usage : " ${ this.class.getSimpleName()} .groovy [options] <svgs URL>" , stopAtNonOption : false , footer : " Usage example: ./${ this.class.getSimpleName()} .groovy https://github.com/gilbarbara/logos/tree/master/logos" )
31
29
cli. s(longOpt : ' scale' , args : 1 , argName : ' scale' , " Scale (eg: 0.5 to reduce size to half) of generated sprites. Default value: $DEFAULT_SCALE " )
32
30
cli. c(longOpt : ' use-cache' , " When specified, already downloaded files are not re-downloaded" )
@@ -46,25 +44,24 @@ def svgsUrl = options.arguments()[0]
46
44
def scaleFactor = options. s ?: DEFAULT_SCALE
47
45
def useCache = options. c
48
46
49
- listSvgsUrls(svgsUrl, log )
47
+ listSvgsUrls(svgsUrl)
50
48
.collect {
51
- downloadFile(it, TMP_DIR , useCache, log )
49
+ downloadFile(it, TMP_DIR , useCache)
52
50
}
53
51
.collect {
54
- svg2Png(it, PNGS_DIR , log )
52
+ svg2Png(it, PNGS_DIR )
55
53
}
56
54
.collect {
57
55
scaleImage(it, scaleFactor)
58
56
}
59
57
.collect {
60
- png2PlantUmlSprite(it, SPRITES_DIR , log )
58
+ png2PlantUmlSprite(it, SPRITES_DIR )
61
59
}
62
60
.each {
63
61
SPRITES_LISTING . addSprite(it)
64
62
}
65
63
66
- static def listSvgsUrls (baseUrl , log ) {
67
- log. info(" Getting SVGs list ..." )
64
+ static def listSvgsUrls (baseUrl ) {
68
65
def matcher = baseUrl =~ / ^https:\/\/ github.com\/ ([^\/ ]+)\/ ([^\/ ]+)\/ tree\/ (.*)$/
69
66
if (! matcher. matches()) {
70
67
throw new IllegalArgumentException (" Provided URL is not a GitHub folder URL" )
@@ -96,8 +93,8 @@ static def getUrlJson(url) {
96
93
.parseText(new URL (url). text)
97
94
}
98
95
99
- static def downloadFile (url , workDir , useCache , log ) {
100
- log . info (" Downloading ${ url} ..." )
96
+ static def downloadFile (url , workDir , useCache ) {
97
+ println (" Downloading ${ url} ..." )
101
98
def fileName = Paths . get(new URI (url). path). fileName
102
99
def svgFile = new File (" $workDir /${ fileName} " )
103
100
if (useCache && svgFile. exists()) {
@@ -108,8 +105,8 @@ static def downloadFile(url, workDir, useCache, log) {
108
105
return svgFile
109
106
}
110
107
111
- static def svg2Png (svg , workDir , log ) {
112
- log . info (" Converting ${ svg} to png ..." )
108
+ static def svg2Png (svg , workDir ) {
109
+ println (" Converting ${ svg} to png ..." )
113
110
def fileName = svg. name. replace(" .svg" ," .png" )
114
111
def pngFile = new File (" $workDir /$fileName " )
115
112
pngFile. delete()
@@ -135,8 +132,8 @@ static def scaleImage(png, scaleFactor) {
135
132
return png
136
133
}
137
134
138
- static def png2PlantUmlSprite (png , outputDir , log ) {
139
- log . info (" Converting ${ png} to puml ..." )
135
+ static def png2PlantUmlSprite (png , outputDir ) {
136
+ println (" Converting ${ png} to puml ..." )
140
137
BufferedImage im = ImageIO . read(png)
141
138
removeAlpha(im)
142
139
String spriteName = png. name. replace(" .png" ," " )
0 commit comments