Skip to content

Instantly share code, notes, and snippets.

@henrikhermansen
Created July 18, 2019 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrikhermansen/6fb6d9bd132eb1056cae7b712e7bf411 to your computer and use it in GitHub Desktop.
Save henrikhermansen/6fb6d9bd132eb1056cae7b712e7bf411 to your computer and use it in GitHub Desktop.
Run this postinstall to be able to compile Svelte using Parcel
const fs = require('fs').promises;
const svelteDir = 'node_modules/svelte';
const extname = path => path.split('.').pop();
const filename = path => {
const arr = path.split('.');
arr.pop();
return arr.join('.');
};
const handleFile = async path => {
if (extname(path) === 'mjs') {
try {
await fs.unlink(`${filename(path)}.js`);
console.log('Deleted JS counterpart', path);
} catch {
console.warn('No JS counterpart to delete', path);
}
}
};
const checkFile = async path => {
const stat = await fs.lstat(path);
if (stat.isFile()) {
handleFile(path);
}
if (stat.isDirectory()) {
traverseDir(path)
}
};
const traverseDir = async dir => {
const files = await fs.readdir(dir);
files.forEach(file => checkFile(`${dir}/${file}`));
};
traverseDir(svelteDir);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment