Merge branch 'master' into feat/tv

This commit is contained in:
Sam Carlton 2020-12-26 12:13:31 -06:00
commit 426bf9d1a4
7 changed files with 1341 additions and 1280 deletions

View file

@ -203,7 +203,7 @@ export default async function () {
// url,
text,
slug: appSlug,
// endpoint,
endpoint,
category,
// content: token.content,
relatedLinks

View file

@ -4,7 +4,7 @@ import slugify from 'slugify'
import axios from 'axios'
// import { statuses } from './build-app-list'
// import { getAppEndpoint } from './app-derived'
import { getAppEndpoint } from './app-derived'
// console.log('process.env.GAMES_SOURCE', process.env.GAMES_SOURCE)
@ -140,10 +140,10 @@ export default async function () {
// url: `https://rawg.io/search?query=${encodeURIComponent(game.Games)}`,
text: getStatusText(game),
slug,
// endpoint: getAppEndpoint({
// slug,
// category
// }),//`/game/${slug}`,
endpoint: getAppEndpoint({
slug,
category
}),//`/game/${slug}`,
category,
content: '',
// relatedLinks: [],

View file

@ -10,7 +10,7 @@ import axios from 'axios'
const marked = require('marked')
const HTMLParser = require(`node-html-parser`)
// import { getAppEndpoint } from './app-derived'
import { getAppEndpoint } from './app-derived'
const statusesTranslations = {
@ -42,140 +42,222 @@ const statusesMessages = {
'': '🔶 Unknown, more info needed'
}
function getStatusText(formula) {
// Match status to Sheet Status
return statusesMessages[formula.status]
}
function parseStatus(formulae) {
// Match status to Sheet Status
return statusesTranslations[formulae.status]
class MakeHomebrewList {
constructor() {
// Data from the issue
this.issueTableRowData = null
// Data from the official Homebrew API
this.allFormulaeArray = null
this.allFormulae = null
}
getStatusText (formula) {
// Match status to Sheet Status
return statusesMessages[formula.status]
}
searchFormulaeForName (name) {
for (const formula of this.allFormulaeArray) {
// Check normal name
if (formula.name === name) return formula
// Check normal oldname
if (formula.oldname === name) return formula
// Check aliases
if ((formula.aliases !== undefined) && formula.aliases.includes(name)) return formula
}
return null
}
formulaIsNative (formulae) {
const formulaData = this.allFormulae[formulae.fullName] || this.searchFormulaeForName(formulae.name)
// If this formula doesn't exist
// then return false
if (formulaData !== Object(formulaData)) {
return false
}
console.log('formulaData', formulaData)
console.log('formulae', formulae)
// Check the official list first since it's data is newer and more frequently updated
const hasStableFormula = (formulaData.bottle.stable !== undefined)
const hasArm64Formula = hasStableFormula && (formulaData.bottle.stable.files['arm64_big_sur'] !== undefined)
return hasArm64Formula
}
parseStatus (formulae) {
// If an ARM 64 formula exists then it's native
if (this.formulaIsNative(formulae)) {
return 'native'
}
// Match status to Sheet Status
return statusesTranslations[formulae.status]
}
async make () {
// Fetch Gihub Issue List
const [
issueResponse,
allFormulaeResponse
] = await Promise.all([
// Fetch Gihub Issue List
axios.get(process.env.HOMEBREW_SOURCE),
// Fetch Official Homebrew Formulae List
axios.get('https://formulae.brew.sh/api/formula.json')
])
// Extract commit from response data
const issueMarkdown = issueResponse.data.data.repository.issue.body
// Parse markdown
const issueHTML = marked(issueMarkdown)
// Parse Markdown HTML into a dom
const dom = HTMLParser.parse(issueHTML)
// Store the original array
this.allFormulaeArray = allFormulaeResponse.data
// Extract list from allFormulaeResponse and map into an object for easy access
this.allFormulae = Object.fromEntries(allFormulaeResponse.data.map(formula => {
return [
formula.full_name,
formula
]
}))
// console.log('allFormulae', allFormulae)
// Map table Headings
// [ 'Formula', 'Works1on 11.0', 'Comments' ]
// const tableHeadings = dom.querySelectorAll('thead th').map(th => th.rawText)
const headings = [
'fullName',
'status',
'comments'
]
// Map Formulae List within table
const tableRows = dom.querySelectorAll('table tr')
// Remove the first row (Headings)
tableRows.shift()
this.issueTableRowData = tableRows.map( tr => {
// Map Table Cells
const cellsData = tr.querySelectorAll('td').map((td, i) => {
const column = headings[i]
if (td.childNodes.length === 0) return ''
if (column === 'comments') return td.innerHTML
return td.rawText
})
const formulaeRow = Object.fromEntries(cellsData.map( (cellData, i) => {
return [ headings[i], cellData ]
}))
formulaeRow.name = formulaeRow.fullName.split(' ')[0]
formulaeRow.links = tr.querySelectorAll('a').map( a => {
const href = a.getAttribute('href')
return {
href,
label: a.rawText,
// a
}
})
// if (formulaeRow.links.length !== 0) console.log('formulaeRow', formulaeRow.links)
return formulaeRow
})
// console.log('dom', dom.length)
// console.log('issueHTML', issueHTML)
// console.log('formulaeWithStatus', formulaeWithStatus)
const formulaeList = []
for (const formulae of this.issueTableRowData) {
// If this formulae status is empty
// then skip this formulae
// if (formulae.status.length === 0) continue
// If this formulae emoji status is not in statusesTranslations
// then skip this formulae
if (!statusesTranslations.hasOwnProperty(formulae.status)) continue
// Generate slug
const slug = formulae.name
// slugify(formulae.name, {
// lower: true,
// strict: true
// })
const category = {
slug: 'homebrew'
}
formulaeList.push({
name: formulae.name,
status: this.parseStatus(formulae),
// url: `https://formulae.brew.sh/formula/${formulae.name}`,
text: this.getStatusText(formulae),
slug,
endpoint: getAppEndpoint({
slug,
category
}),//`/formula/${slug}`,
category,
content: formulae.comments,
relatedLinks: [
{
href: `https://formulae.brew.sh/formula/${formulae.name}`,
label: formulae.name,
// a
},
...formulae.links
],
// reports: [
// formulae
// ]
})
}
// console.log('formulaeList', formulaeList)
return formulaeList
}
}
export default async function () {
const maker = new MakeHomebrewList()
// Fetch Homebrew
const response = await axios.get(process.env.HOMEBREW_SOURCE)
// Extract commit from response data
const issueMarkdown = response.data.data.repository.issue.body
// Parse markdown
const issueHTML = marked(issueMarkdown)
// Parse Markdown HTML into a dom
const dom = HTMLParser.parse(issueHTML)
// Map table Headings
// [ 'Formula', 'Works1on 11.0', 'Comments' ]
// const tableHeadings = dom.querySelectorAll('thead th').map(th => th.rawText)
const headings = [
'fullName',
'status',
'comments'
]
// Map Formulae List within table
const tableRows = dom.querySelectorAll('table tr')
// Remove the first row (Headings)
tableRows.shift()
const tableRowData = tableRows.map( tr => {
// Map Table Cells
const cellsData = tr.querySelectorAll('td').map((td, i) => {
const column = headings[i]
if (td.childNodes.length === 0) return ''
if (column === 'comments') return td.innerHTML
return td.rawText
})
const formulaeRow = Object.fromEntries(cellsData.map( (cellData, i) => {
return [ headings[i], cellData ]
}))
formulaeRow.name = formulaeRow.fullName.split(' ')[0]
formulaeRow.links = tr.querySelectorAll('a').map( a => {
const href = a.getAttribute('href')
return {
href,
label: a.rawText,
// a
}
})
// if (formulaeRow.links.length !== 0) console.log('formulaeRow', formulaeRow.links)
return formulaeRow
})
// console.log('dom', dom.length)
// console.log('issueHTML', issueHTML)
// console.log('formulaeWithStatus', formulaeWithStatus)
const formulaeList = []
for (const formulae of tableRowData) {
// If this formulae status is empty
// then skip this formulae
// if (formulae.status.length === 0) continue
// If this formulae emoji status is not in statusesTranslations
// then skip this formulae
if (!statusesTranslations.hasOwnProperty(formulae.status)) continue
// Generate slug
const slug = formulae.name
// slugify(formulae.name, {
// lower: true,
// strict: true
// })
const category = {
slug: 'homebrew'
}
formulaeList.push({
name: formulae.name,
status: parseStatus(formulae),
// url: `https://formulae.brew.sh/formula/${formulae.name}`,
text: getStatusText(formulae),
slug,
// endpoint: getAppEndpoint({
// slug,
// category
// }),//`/formula/${slug}`,
category,
content: formulae.comments,
relatedLinks: [
{
href: `https://formulae.brew.sh/formula/${formulae.name}`,
label: formulae.name,
// a
},
...formulae.links
],
// reports: [
// formulae
// ]
})
}
// console.log('formulaeList', formulaeList)
return formulaeList
return await maker.make()
}

View file

@ -65,6 +65,12 @@ export const categories = {
pluralLabel: '3D and Architecture Applications',
slug: '3d-and-architecture',
},
'vpns-security-and-privacy': {
...categoryTemplate,
label: 'VPNs, Security, and Privacy',
pluralLabel: 'VPN, Security, and Privacy Applications',
slug: 'vpns-security-and-privacy',
},
// Special Lists
'games': {