From 2e61dcecd4ccbc22d51854f062e509a9bb79fd83 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 10 Jul 2021 22:56:10 -0500 Subject: [PATCH] Add App Bundles section to app template --- pages-eleventy/app.11ty.js | 149 ++++++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-) diff --git a/pages-eleventy/app.11ty.js b/pages-eleventy/app.11ty.js index ceba932..b177c6a 100644 --- a/pages-eleventy/app.11ty.js +++ b/pages-eleventy/app.11ty.js @@ -4,7 +4,8 @@ import config from '../nuxt.config.js' import { getAppType, getRouteType } from '../helpers/app-derived.js' import { deviceSupportsApp } from '../helpers/devices.js' -import { makeLastUpdatedFriendly } from '../helpers/parse-date' +import { makeLastUpdatedFriendly } from '../helpers/parse-date.js' +import { getStatusOfScan } from '../helpers/statuses.js' import VideoRow from '../components-eleventy/video/row.js' @@ -15,6 +16,10 @@ import VideoRow from '../components-eleventy/video/row.js' // Setup dotenv dotenv.config() +function isString( maybeString ) { + return (typeof maybeString === 'string' || maybeString instanceof String) +} + export const makeTitle = function ( app ) { return `Does ${app.name} work on Apple Silicon? - ${ config.head.title }` } @@ -56,6 +61,57 @@ export function renderPageLinksHtml ( links ) { } ).join('') } +export function supportedArchitectures ( appScan ) { + // if ( Array.isArray(appScan['Macho Meta']) ) { + // return appScan['Macho Meta'].map( architecture => architecture.processorType) + // } + + // console.log('meta', appScan['Macho Meta']) + + if ( appScan['Macho Meta'].architectures === undefined ) return [] + + return appScan['Macho Meta'].architectures + .map( architecture => architecture.processorType) + .filter(processorType => Number(processorType) !== 0) +} + +function renderBundleDataLevel ( bundleLevelData, depth = 0 ) { + + const levelContainerClassses = 'border rounded-lg bg-black bg-opacity-10 space-y-4 p-4 mt-4' + const maxDepth = 2 + + if ( isString(bundleLevelData) ) { + return bundleLevelData + } + + if ( depth >= maxDepth ) { + return /* html */`
${ JSON.stringify(bundleLevelData, undefined, 2) }
` + } + + if ( Array.isArray( bundleLevelData ) ) { + const htmlList = bundleLevelData.map( ( bundleLevel ) => { + return /* html */`
  • ${ renderBundleDataLevel( bundleLevel, depth + 1 ) }
  • ` + } ).join('') + + return /* html */`` + } + + if ( Object(bundleLevelData) === bundleLevelData ) { + const htmlList = Object.entries(bundleLevelData).map( ( [key, bundleLevel] ) => { + return /* html */`
  • ${key} : ${ renderBundleDataLevel( bundleLevel, depth + 1 ) }
  • ` + } ).join('') + + return /* html */` +
    + Details + +
    + ` + } + + return /* html */`${ JSON.stringify(bundleLevelData) }` +} + export class AppTemplate { // or `async data() {` // or `get data() {` @@ -102,9 +158,13 @@ export class AppTemplate { const { app: { payload: { app, relatedVideos = [] } }, - 'device-list': deviceList + 'device-list': deviceList, + // 'app-bundles': appBundlesFromFile } = data + + // console.log('appBundlesFromFile', appBundlesFromFile) + const hasRelatedVideos = relatedVideos.length > 0 // console.log('deviceList', deviceList) @@ -113,6 +173,8 @@ export class AppTemplate { const hasMultipleAliases = !!app.aliases && app.aliases.length > 1 + const hasBundleIdentifiers = !!app.bundleIds && app.bundleIds.length > 0 + const appDeviceSupport = deviceList.map( device => { const supportsApp = deviceSupportsApp( device, app ) return { @@ -129,6 +191,16 @@ export class AppTemplate { const relatedVideosRowHtml = hasRelatedVideos ? await this.boundComponent(VideoRow)( relatedVideos ) : null + const appBundles = [] //hasBundleIdentifiers ? app.bundleIds.map( bundleId => this.getAppBundles() ) : null + + if ( hasBundleIdentifiers ) { + for ( const bundleIdentifier of app.bundleIds ) { + const versions = await this.getAppVersions( bundleIdentifier ) + appBundles.push( [bundleIdentifier, versions] ) + } + } + + return /* html */`
    @@ -188,6 +260,79 @@ export class AppTemplate { ` : '' } + + ${ hasBundleIdentifiers ? /* html */` +
    + +

    + App Bundles +

    + +
    + +
    + + ${ appBundles.map( ( [bundleIdentifier, versions] ) => /* html */` + + `).join('') } + +
    + + +
    + ${ appBundles.map( ( [bundleIdentifier, versions] ) => /* html */` +
    +

    ${ bundleIdentifier }

    + +
    + +
    + + ${ Object.entries(versions).sort((a, b) => new Date(b[1]['Date']) - new Date(a[1]['Date'])).map( ( [ version, report ] ) => /* html */` +
    +
    v${ version }
    +
    +
    + ${ getStatusOfScan( report, false ) } +
    +
    + 🖥 Supported Architectures ${ supportedArchitectures( report ).join(', ') } +
    +
    +
    + Full Info Plist +
    ${ JSON.stringify(report['Info Plist'], undefined, 2) }
    +
    +
    + Full Meta Details +
    ${ JSON.stringify(report['Macho Meta'], undefined, 2) }
    +
    +
    + `).join('') } + +
    + +
    +
    + `).join('') } +
    + +
    + + +
    + ` : '' } +
    ${ lastUpdatedFriendly !== null ? /* html */`