From 2cca34a689d5a56fd3a5112fd23430dbdcd173c7 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Fri, 11 Jun 2021 16:30:53 -0500 Subject: [PATCH] Generate app variations with fake list --- build-lists.js | 2 +- helpers/app-store/genres.js | 8 +- helpers/build-fake-app-list.js | 137 ++++++++++++++++++++++++--------- helpers/categories.js | 12 +++ 4 files changed, 119 insertions(+), 40 deletions(-) diff --git a/build-lists.js b/build-lists.js index fbed236..8efd94e 100644 --- a/build-lists.js +++ b/build-lists.js @@ -55,7 +55,7 @@ class BuildLists { name: 'app', path: '/static/app-list.json', buildMethod: async () => (await Promise.all([ - buildFakeList({ totalApps: !isProduction ? 500 : 0 }), + !isProduction && buildFakeList(), buildAppList() ])).flat(1) }, diff --git a/helpers/app-store/genres.js b/helpers/app-store/genres.js index 2e8210a..f4d5588 100644 --- a/helpers/app-store/genres.js +++ b/helpers/app-store/genres.js @@ -1,5 +1,5 @@ // Source 1: https://42matters.com/docs/app-market-data/ios/apps/appstore-genres -export default { +const genresByID = { '0': ['Mobile Software Application'], '6018': ['Book'], '6000': ['Business'], @@ -75,3 +75,9 @@ export default { '13029': ['Newsstand', 'Travel & Regional'], '13030': ['Newsstand', 'Women\'s Interest'], } + +export const allGenres = Array.from( new Set( Object.values(genresByID).map( genreId => genreId.flat(1) ) )) + + + +export default genresByID diff --git a/helpers/build-fake-app-list.js b/helpers/build-fake-app-list.js index c8dea50..a2af957 100644 --- a/helpers/build-fake-app-list.js +++ b/helpers/build-fake-app-list.js @@ -2,8 +2,8 @@ import { v4 as uuid } from 'uuid' // import statuses, { getStatusName } from './statuses' -// import appStoreGenres from './app-store/genres.js' -// import { findCategoryForTagsSet } from './categories.js' +import { allGenres } from './app-store/genres.js' +import { categories, appCategories } from './categories.js' import parseDate from './parse-date.js' // import { eitherMatches } from './matching.js' import { getAppEndpoint } from './app-derived' @@ -11,54 +11,115 @@ import { makeSlug } from './slug.js' +export const statusMessages = [ + '✅ Yes, Full Native Apple Silicon Support', + '✳️ Yes, works via Translation or Virtualization', + '⏹ No, not working at all but support is in development', + '🚫 No, not yet supported only works on Intel-based Macs', + '🔶 App has not yet been reported to be native to Apple Silicon', + '🔶 Unknown, more info needed', +] + +function makeAppVariation ( variationOptions ) { + const [ + // Statuses + statusMessage, + + // Category Slugs + categorySlug, + + // Tags + tagOne, + ] = variationOptions + + const fakeAppId = uuid() + + const name = `Fake App ${fakeAppId}` + const slug = makeSlug( name ) + + const category = { + label: 'Developer Tools', + slug: 'developer-tools' + } + + return { + name, + aliases: [], + status: '', + bundleId: '', + lastUpdated: parseDate( '2021-02-07T03:20:42.086Z' ), + // url, + text: statusMessage, + slug, + endpoint: getAppEndpoint({ + category: { + slug: null + }, + slug: slug + }), + category: categories[categorySlug], + tags: [ + tagOne, + 'fake' + ], + // content: token.content, + relatedLinks: [ + { + label: 'Website', + href: 'https://doesitarm.com/apple-silicon-app-test/', + } + ], + } +} + export default async function ( options = {} ) { const { totalApps = 100 } = options + + const appOptions = [ + // Statuses + statusMessages, + + // Category Slugs + Object.keys( appCategories ), + + // Tags + [ + '', + // ...allGenres + ] + ] + + let appVariations = appOptions[0].map(function(item) { return [item]; }); + + // https://stackoverflow.com/a/35004005/1397641 + for (var k = 1; k < appOptions.length; k++) { + var next = []; + appVariations.forEach(function(item) { + appOptions[k].forEach(function(word) { + const line = item.slice(0) + line.push(word) + next.push(line) + }) + }); + appVariations = next + } + + console.log('Total variations', appVariations.length) + const appList = [] - for (let i=0; i { + return !nonAppCategorySlugs.includes( slug ) + }) +) + export const categoriesById = Object.fromEntries( Object.entries( categories ).map( ([ key, category ]) => [category.id, { ...category, key } ] ) )