Skip to content

Instantly share code, notes, and snippets.

@sebastianbenz
Created August 30, 2018 15:13
Show Gist options
  • Save sebastianbenz/905d7cb5dd8db9b30110c5acda7b5ce4 to your computer and use it in GitHub Desktop.
Save sebastianbenz/905d7cb5dd8db9b30110c5acda7b5ce4 to your computer and use it in GitHub Desktop.
Fetches a list of AMP components.
const fetch = require('node-fetch');
const REGEX_EXTENSION_DIR = /extensions\/(amp-[^\/]+)$/;
const GITHUB_AMPHTML_TREE_URL = 'https://api.github.com/repos/ampproject/amphtml/git/trees/master?recursive=1';
const fetchComponentList = async () => {
const response = await fetch(GITHUB_AMPHTML_TREE_URL);
const data = await response.json();
return data.tree.map((item) => item.path.match(REGEX_EXTENSION_DIR))
.filter((match) => match && !match[1].endsWith('impl'))
.map((match) => match[1]);
};
fetchComponentList().then((components) => console.log(components));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment