2021-09-17 00:26:18 -04:00
|
|
|
import loconfig from '../../loconfig.json';
|
|
|
|
|
import glob from '../utils/glob.js';
|
|
|
|
|
import message from '../utils/message.js';
|
|
|
|
|
import notification from '../utils/notification.js';
|
|
|
|
|
import template from '../utils/template.js';
|
|
|
|
|
import concat from 'concat';
|
|
|
|
|
import { basename } from 'node:path';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Concatenates groups of files.
|
2021-09-21 16:01:47 -04:00
|
|
|
*
|
2021-09-21 17:33:32 -04:00
|
|
|
* @todo Add support for minification.
|
|
|
|
|
*
|
2021-09-21 16:01:47 -04:00
|
|
|
* @async
|
|
|
|
|
* @return {Promise}
|
2021-09-17 00:26:18 -04:00
|
|
|
*/
|
2021-09-21 16:01:47 -04:00
|
|
|
export default async function concatFiles() {
|
2021-09-17 00:26:18 -04:00
|
|
|
loconfig.tasks.concats.forEach(async ({
|
|
|
|
|
includes,
|
|
|
|
|
outfile
|
|
|
|
|
}) => {
|
|
|
|
|
const filename = basename(outfile || 'undefined');
|
|
|
|
|
|
|
|
|
|
const timeLabel = `${filename} concatenated in`;
|
|
|
|
|
console.time(timeLabel);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
includes = includes.map((path) => template(path));
|
|
|
|
|
outfile = template(outfile);
|
|
|
|
|
|
|
|
|
|
const files = await glob(includes);
|
|
|
|
|
|
|
|
|
|
await concat(files, outfile);
|
|
|
|
|
|
|
|
|
|
if (files.length) {
|
|
|
|
|
message(`${filename} concatenated`, 'success', timeLabel);
|
|
|
|
|
} else {
|
|
|
|
|
message(`${filename} is empty`, 'notice', timeLabel);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
message(`Error concatenating ${filename}`, 'error');
|
|
|
|
|
message(err);
|
|
|
|
|
|
|
|
|
|
notification({
|
|
|
|
|
title: `${filename} concatenation failed 🚨`,
|
|
|
|
|
message: `${err.name}: ${err.message}`
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|