Update scripts

This commit is contained in:
Michael Jackson
2019-02-01 17:54:21 -08:00
parent 3424643488
commit 8f11d84428
7 changed files with 207 additions and 76 deletions

22
scripts/utils/unpkg.js Normal file
View File

@ -0,0 +1,22 @@
const fetch = require('isomorphic-fetch');
function getMetadata(packageName, version) {
return fetch(`https://unpkg.com/${packageName}@${version}/?meta`, {
method: 'GET'
}).then(res => res.json());
}
function collectFiles(directory) {
return directory.files.reduce((memo, file) => {
return memo.concat(file.type === 'directory' ? collectFiles(file) : file);
}, []);
}
function getFiles(packageName, version) {
return getMetadata(packageName, version).then(collectFiles);
}
module.exports = {
getMetadata,
getFiles
};