mirror of
https://github.com/hampusborgos/country-flags.git
synced 2025-12-25 01:03:23 -05:00
fix: change the script for building pngs to not skip the last svg file.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
var process = require('process')
|
var process = require('process')
|
||||||
var exec = require('child_process').exec
|
var exec = require('child_process').exec
|
||||||
|
var execSync = require('child_process').execSync
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
|
||||||
var help_message = "You must pass one argument to build-pngs. It should be target dimension in the format `200:` for width 200px, or `:200` for height 200px."
|
var help_message = "You must pass one argument to build-pngs. It should be target dimension in the format `200:` for width 200px, or `:200` for height 200px."
|
||||||
@@ -84,47 +85,40 @@ function get_all_svgs(callback) {
|
|||||||
}, (error) => {})
|
}, (error) => {})
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert_and_compress_svg(path_to_svg, callback) {
|
function convert_and_compress_svg(path_to_svg) {
|
||||||
var path_to_tmp_png = path_to_svg.substring(0, path_to_svg.length - 4) + '.png'
|
var path_to_tmp_png = path_to_svg.substring(0, path_to_svg.length - 4) + '.png'
|
||||||
|
|
||||||
var svgexport_command = "svgexport " + path_to_svg + " " + path_to_tmp_png + " pad " + get_output_dimensions()
|
var svgexport_command = "svgexport " + path_to_svg + " " + path_to_tmp_png + " pad " + get_output_dimensions()
|
||||||
console.log(svgexport_command)
|
console.log(svgexport_command)
|
||||||
exec(svgexport_command, (error, stdout, stderr) => {
|
execSync(svgexport_command, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("Failed to convert SVG: " + path_to_svg)
|
console.log("Failed to convert SVG: " + path_to_svg)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var image_min_command = "imagemin " + path_to_tmp_png + " --out-dir=" + get_output_directory()
|
var image_min_command = "imagemin " + path_to_tmp_png + " --out-dir=" + get_output_directory()
|
||||||
console.log(image_min_command)
|
console.log(image_min_command)
|
||||||
exec(image_min_command, (error, stdout, stderr) => {
|
execSync(image_min_command, (error, stdout, stderr) => {
|
||||||
// Always remove temp file
|
|
||||||
fs.unlink(path_to_tmp_png, (error) => {})
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("Failed to convert SVG: " + path_to_svg)
|
console.log("Failed to convert SVG: " + path_to_svg)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Always remove temp file
|
||||||
|
fs.unlink(path_to_tmp_png, (error) => {
|
||||||
|
console.log(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert_all_files(svgs, callback) {
|
function convert_all_files(svgs, callback) {
|
||||||
var i = 0
|
for (let i = 0; i < svgs.length; i++) {
|
||||||
|
|
||||||
function do_next_file() {
|
|
||||||
console.log("Converting [" + (i + 1) + "/" + svgs.length + "] " + svgs[i])
|
console.log("Converting [" + (i + 1) + "/" + svgs.length + "] " + svgs[i])
|
||||||
convert_and_compress_svg(svg_directory + svgs[i], do_next_file)
|
convert_and_compress_svg(svg_directory + svgs[i])
|
||||||
|
}
|
||||||
|
|
||||||
++i
|
|
||||||
if (i >= svgs.length) {
|
|
||||||
callback()
|
callback()
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do_next_file()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the program
|
// Run the program
|
||||||
|
|||||||
Reference in New Issue
Block a user