Created
August 30, 2018 15:13
-
-
Save sebastianbenz/905d7cb5dd8db9b30110c5acda7b5ce4 to your computer and use it in GitHub Desktop.
Fetches a list of AMP components.
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 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