Integrate app scans into main app list

This commit is contained in:
Sam Carlton 2021-03-04 20:46:39 -06:00
parent b725880da3
commit 9ee920d4f3

View file

@ -4,14 +4,20 @@ import MarkdownIt from 'markdown-it'
import slugify from 'slugify' import slugify from 'slugify'
import axios from 'axios' import axios from 'axios'
import statuses from './statuses' import statuses, { getStatusName } from './statuses'
import parseDate from './parse-date' import parseDate from './parse-date'
import { eitherMatches } from './matching.js'
import { getAppEndpoint } from './app-derived' import { getAppEndpoint } from './app-derived'
const md = new MarkdownIt() const md = new MarkdownIt()
const makeSlug = name => slugify(name, {
lower: true,
strict: true
})
const getTokenLinks = function ( childTokens ) { const getTokenLinks = function ( childTokens ) {
@ -108,6 +114,70 @@ export default async function () {
// await fs.writeFile('./commits-data.json', JSON.stringify(commits)) // await fs.writeFile('./commits-data.json', JSON.stringify(commits))
const scanListMap = new Map()
// Store app scans
await axios
.get(process.env.SCANS_SOURCE)
.then(function (response) {
response.data.appList.forEach( appScan => {
const appName = appScan.aliases[0]
// 'native' or 'unreported'
const statusName = getStatusName( appScan['Result'] )
const statusText = (statusName === 'native') ? `✅ Yes, Full Native Apple Silicon Support reported as of v${appScan['App Version']}` : '🔶 App has not yet been reported to be native to Apple Silicon'
const appSlug = makeSlug( appName )
// Skip empty slugs
if (appSlug.trim().length === 0) {
console.log('Empty slug', appScan)
return
}
const relatedLinks = []
// If downloadUrl is not empty then add it as the download link
if ( appScan['downloadUrl'] !== null ) {
relatedLinks.push({
href: appScan['downloadUrl'],
label: 'View',
})
}
// Add to scanned app list
scanListMap.set( appSlug, {
name: appName,
aliases: appScan['aliases'],
status: statusName,
lastUpdated: parseDate( appScan['Date'] ),
// url,
text: statusText,
slug: appSlug,
endpoint: getAppEndpoint({
category: {
slug: null
},
slug: appSlug
}),
category: {
slug: 'no-category'
},
relatedLinks
})
})
return
})
.catch(function (error) {
// handle error
console.warn(error)
})
// Parse markdown // Parse markdown
const result = md.parse(readmeContent) const result = md.parse(readmeContent)
@ -143,8 +213,6 @@ export default async function () {
// On heading close switch off heading mode // On heading close switch off heading mode
if (token.type.includes('paragraph_')) isParagraph = !isParagraph if (token.type.includes('paragraph_')) isParagraph = !isParagraph
if (isHeading && token.type === 'inline') { if (isHeading && token.type === 'inline') {
categoryTitle = token.content categoryTitle = token.content
categorySlug = slugify(token.content, { categorySlug = slugify(token.content, {
@ -157,17 +225,28 @@ export default async function () {
if ( isParagraph && token.type === 'inline' && token.content.includes(' - ') ) { if ( isParagraph && token.type === 'inline' && token.content.includes(' - ') ) {
const [ link, text ] = token.content.split(' - ').map(string => string.trim())
const relatedLinks = getTokenLinks(token.children) const [ link, text ] = token.content.split(' - ').map(string => string.trim())
const [ name, url ] = link.substring(1, link.length-1).split('](') const [ name, url ] = link.substring(1, link.length-1).split('](')
const appSlug = slugify(name, { // Search for this app in the scanList and remove duplicates
lower: true, scanListMap.forEach( ( scannedApp, key ) => {
strict: true
for ( const alias of scannedApp.aliases) {
// console.log( key, alias, name, eitherMatches(alias, name) )
if ( eitherMatches(alias, name) ) {
console.log(`Removing ${alias} from scanned apps`)
scanListMap.delete( key )
}
}
}) })
const relatedLinks = getTokenLinks(token.children)
const appSlug = makeSlug( name )
const endpoint = getAppEndpoint({ const endpoint = getAppEndpoint({
category: { category: {
slug: null slug: null
@ -219,7 +298,10 @@ export default async function () {
// console.log('appList', appList) // console.log('appList', appList)
return appList return [
...appList,
...Array.from( scanListMap, ([name, value]) => value )
]
// fs.readFile('../README.md', 'utf8') // fs.readFile('../README.md', 'utf8')
// .then((err, data) => { // .then((err, data) => {