/* eslint-disable no-console */
const path = require('path');
const fse = require('fs-extra');
const glob = require('fast-glob');

async function typescriptCopy({ from, to }) {
	if (!(await fse.pathExists(to))) {
		console.warn(`path ${to} does not exists`);
		return [];
	}

	const files = await glob(['**/*.png', '**/*.svg', '**/*.css'], { cwd: from });

	const cmds = files.map((file) =>
		fse.copy(path.resolve(from, file), path.resolve(to, file)),
	);

	return Promise.all(cmds);
}

async function run() {
	try {
		await typescriptCopy({ from: './src', to: './lib' });
	} catch (err) {
		console.error(err);
		process.exit(1);
	}
}

run();