#!/usr/bin/env bash

# This bash script automates part of the process when creating a new icon.
# It only can be executed after adding the new icon information into essentialIconsMap.json,
# and after adding the PDF and SVG icon's versions into the respective folders.


# stop if any command returns error
set -e
# log the commands into terminal
set -x

# rename filenames in PDFs and SVGs directories with 'my-' at the beginning, if they don't have it
node scripts/lint-svgs.js
node scripts/lint-pdfs.js

# zip new PDFs file and save it into the root directory
zip -r PDFs.zip ./PDFs/*

# create JS file from essentialIconsMap.json file
node scripts/generate-essentialIconsMap.js > essentialIconsMap.js

# install customised fork of an open-source app called, 'svg-sprite-generator', if it's not installed yet,
# then execute it to create sprite.svg file
which svg-sprite-generate || npm install -g git+https://git@github.com/antman888/svg-sprite-generator
svg-sprite-generate -d ./SVGs -o ./sprite.svg