import dotenv from 'dotenv' 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.js' import { getStatusOfScan } from '../helpers/statuses.js' import { isString } from '../helpers/check-types.js' import VideoRow from '../components-eleventy/video/row.js' // import VideoRow from '../components-eleventy/video/row.js' // import { isVideo } from '../helpers/app-derived' // Setup dotenv dotenv.config() export const makeTitle = function ( app ) { return `Does ${app.name} work on Apple Silicon? - ${ config.head.title }` } export const makeDescription = function ( app ) { return `Latest reported support status of ${ app.name } on Apple Silicon and Apple M1 Pro and M1 Max Processors.` } // https://stackoverflow.com/a/15069646/1397641 function makeEnglishList ( array, conjunction = 'and' ) { const total = array.length if ( total < 3 ) return array.join(` ${conjunction} `) array = array.slice() // Prepend conjunction to final part array[ total-1 ] = `${ conjunction } ${ array[ total-1 ] }` return array.join(', ') } export function renderPageLinksHtml ( links ) { return links.map( (link, i) => { const notAppTestLink = !link.label.includes('๐Ÿงช') const isMainLink = (i === 0) && notAppTestLink return /* html */` ${ isMainLink ? 'View' : link.label } ` } ).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() {` data () { return { layout: 'default.11ty.js', pagination: { data: 'eleventy-endpoints', size: 1, alias: 'app', before: function( data ) { return data.filter( entry => { // const [ _, routeType ] = entry.route.split('/') const routeType = getRouteType( entry.route ) return routeType === 'app' }) } }, eleventyComputed: { title: ({ app: { payload: { app } } }) => { // console.log('data', data) return makeTitle( app ) }, description: ({ app: { payload: { app } } }) => { return makeDescription( app ) }, mainHeading: ({ app: { payload: { app } } }) => { return `Does ${ app.name } work on Apple Silicon?` }, }, permalink: ({ app }) => { // console.log('payload', app.payload) return app.route.substring(1) + '/' } } } async render( data ) { const { app: { payload: { app, relatedVideos = [] } }, 'device-list': deviceList, // 'app-bundles': appBundlesFromFile } = data // console.log('appBundlesFromFile', appBundlesFromFile) const hasRelatedVideos = relatedVideos.length > 0 // console.log('deviceList', deviceList) // console.log('video.payload', Object.keys(video.payload)) 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 { ...device, emoji: supportsApp ? 'โœ…' : '๐Ÿšซ', ariaLabel: `${app.name} has ${ supportsApp ? '' : 'not' } been reported to work on ${device.name}` } }) const lastUpdatedFriendly = makeLastUpdatedFriendly( app.lastUpdated ) const relatedLinksHtml = renderPageLinksHtml( app.relatedLinks ) 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 */`

    ${ data.mainHeading }

    ${ app.text }

    ${ hasMultipleAliases ? /* html */` May also be known as ${ makeEnglishList( app.aliases, 'or' ) } ` : '' }

    Device Support

    ${ appDeviceSupport.map( device => /* html */` `).join('') }
    ${ hasRelatedVideos ? /* html */` ` : '' } ${ 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 */`
    ` : '' } Report Update
    ` } } module.exports = AppTemplate