Skip to content

Instantly share code, notes, and snippets.

@rofe
Created May 21, 2024 14:06
Show Gist options
  • Save rofe/4c859fc6caee0d60668e50712f7b5396 to your computer and use it in GitHub Desktop.
Save rofe/4c859fc6caee0d60668e50712f7b5396 to your computer and use it in GitHub Desktop.
filter mountpoints in inventory.json
/* eslint-disable no-console, header/header, import/no-extraneous-dependencies */
import fs from 'fs-extra';
function filter(filters) {
return (mp) => filters.every((f) => {
if (f.startsWith('-')) {
return !mp.includes(f.substring(1));
} else {
return mp.includes(f);
}
});
}
async function listMountPoints() {
const json = await fs.readJson('inventory.json');
const og = Object.values(json.entries);
const mps = og
.map((project) => project.contentSourceUrl)
.filter(filter(process.argv.slice(2)));
mps.forEach((mp) => console.log(mp));
console.log(`Returned ${mps.length} of ${og.length} mountpoints`);
}
listMountPoints();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment