2021-09-17 00:26:18 -04:00
|
|
|
import loconfig from '../../loconfig.json';
|
2021-09-17 00:04:56 -04:00
|
|
|
import message from '../utils/message.js';
|
|
|
|
|
import notification from '../utils/notification.js';
|
2021-09-17 00:26:18 -04:00
|
|
|
import template from '../utils/template.js';
|
|
|
|
|
import { basename } from 'node:path';
|
2021-09-16 14:22:20 -04:00
|
|
|
import mixer from 'svg-mixer';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates and transforms SVG spritesheets.
|
2021-09-21 16:01:47 -04:00
|
|
|
*
|
|
|
|
|
* @async
|
|
|
|
|
* @return {Promise}
|
2021-09-16 14:22:20 -04:00
|
|
|
*/
|
2021-09-21 16:01:47 -04:00
|
|
|
export default async function compileSVGs() {
|
2021-09-17 00:26:18 -04:00
|
|
|
loconfig.tasks.svgs.forEach(async ({
|
2021-09-16 14:22:20 -04:00
|
|
|
includes,
|
2021-09-17 00:26:18 -04:00
|
|
|
outfile
|
2021-09-16 14:22:20 -04:00
|
|
|
}) => {
|
2021-09-17 00:26:18 -04:00
|
|
|
const filename = basename(outfile || 'undefined');
|
2021-09-16 14:22:20 -04:00
|
|
|
|
|
|
|
|
const timeLabel = `${filename} compiled in`;
|
|
|
|
|
console.time(timeLabel);
|
2020-11-27 16:01:54 -05:00
|
|
|
|
2021-09-17 00:26:18 -04:00
|
|
|
try {
|
|
|
|
|
includes = includes.map((path) => template(path));
|
|
|
|
|
outfile = template(outfile);
|
|
|
|
|
|
|
|
|
|
const result = await mixer(includes, {
|
|
|
|
|
spriteConfig: {
|
|
|
|
|
usages: false
|
|
|
|
|
}
|
2021-09-16 14:22:20 -04:00
|
|
|
});
|
2021-09-17 00:26:18 -04:00
|
|
|
|
|
|
|
|
await result.write(outfile);
|
|
|
|
|
|
|
|
|
|
message(`${filename} compiled`, 'success', timeLabel);
|
|
|
|
|
} catch (err) {
|
2021-09-16 14:22:20 -04:00
|
|
|
message(`Error compiling ${filename}`, 'error');
|
|
|
|
|
message(err);
|
2020-12-11 10:41:07 -05:00
|
|
|
|
2021-09-16 14:22:20 -04:00
|
|
|
notification({
|
|
|
|
|
title: `${filename} compilation failed 🚨`,
|
|
|
|
|
message: `${err.name}: ${err.message}`
|
|
|
|
|
});
|
2021-09-17 00:26:18 -04:00
|
|
|
}
|
2020-11-27 16:01:54 -05:00
|
|
|
});
|
2021-09-15 17:24:33 -04:00
|
|
|
};
|