4 * Generate cache file with information about apps
7 * - www/api/rest/connect/stick/stick/generate.php
9 require_once __DIR__ . '/functions.php';
10 require_once __DIR__ . '/../config.php';
12 $cacheDir = dirname(__FILE__, 2) . '/cache/';
13 if (!is_dir($cacheDir)) {
14 if (!mkdir($cacheDir)) {
15 fwrite(STDERR, "Failed to create cache dir: $cacheDir\n");
20 if (!isset($argv[1])) {
21 fwrite(STDERR, "Pass the path to a directory with game data json files\n");
25 if (!is_dir($gamesDir)) {
26 fwrite(STDERR, 'Given path is not a directory: ' . $gamesDir . "\n");
30 $appsCacheFile = $cacheDir . 'connect-apps.min.json';
31 $featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json';
34 $games = loadGames($gamesDir);
35 loadConfigFeaturedFile();
36 loadConfigPopularTxtFile();
37 //make it "package name => number"
38 array_unshift($GLOBALS['popular'], 'dummy');
39 $GLOBALS['popular'] = array_flip($GLOBALS['popular']);
40 unset($GLOBALS['popular']['dummy']);
44 foreach ($games as $gameData) {
45 $connectGames[] = convertGameDataForConnect($gameData, $GLOBALS['popular']);
49 json_encode($connectGames, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
53 $featuredMenu = buildFeaturedMenu($GLOBALS['featured'], $games);
55 $featuredAgesCacheFile,
56 json_encode($featuredMenu, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)