Created
July 18, 2019 09:40
-
-
Save henrikhermansen/6fb6d9bd132eb1056cae7b712e7bf411 to your computer and use it in GitHub Desktop.
Run this postinstall to be able to compile Svelte using Parcel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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