Skip to content

Commit

Permalink
build: update cries updater script
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Mar 2, 2024
1 parent 7a7b39b commit 723fb11
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"au:abilities": "yarn tsx ./scripts/data-gen-scripts/scripted-updaters/asset-updaters/abilities-updater.ts",
"au:items": "yarn tsx ./scripts/data-gen-scripts/scripted-updaters/asset-updaters/items-updater.ts",
"au:moves": "yarn tsx ./scripts/data-gen-scripts/scripted-updaters/asset-updaters/moves-updater.ts",
"au:cries": "yarn tsx ./scripts/data-gen-scripts/scripted-updaters/asset-updaters/cry-updater.ts"
"au:cries": "yarn tsx ./scripts/data-gen-scripts/scripted-updaters/cries-updater/cry-updater.ts"
},
"dependencies": {
"graphql": "^16.8.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const logFile = new URL('./output.log', import.meta.url);

export const MegaSpriteRegex = /^(.+)-(x|y)$/g;

export const baseUrl = 'https://play.pokemonshowdown.com/audio/cries' as const;
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import { pokedex } from '#assets/pokedex.js';
import { FetchResultTypes, fetch } from '@sapphire/fetch';
import { eachLimit } from 'async';
import { bold, green } from 'colorette';
import { green, yellow } from 'colorette';
import { toLowerSingleWordCase } from '../../../../src/lib/utils/utils';
import { inspectData, replaceEnumLikeValues, writeDataToFileAndPrettify } from '../../../utils';
import { generations } from '../classification-updater/constants';
import { getModulePathForGeneration, getPokemonGenerationForDexNumber } from '../classification-updater/utils';
import { pokedexAppendContent, pokedexPrependContent } from '../utils/pokedex-constants';

const MegaSpriteRegex = /^(.+)-(x|y)$/g;
const baseUrl = 'https://play.pokemonshowdown.com/audio/cries' as const;
import { MegaSpriteRegex, baseUrl } from './constants';
import { log } from './log-wrapper';

await eachLimit(pokedex.values(), 10, async (pokemon) => {
const logPrefix = `${pokemon.species} (${pokemon.num}${pokemon.forme ?? ''}) - `;

await log({ msg: `${logPrefix}Started processing`, color: yellow, isBold: false, isIndent: true, bypassCiCheck: true });

let nameToUse = pokemon.baseSpecies ? pokemon.species : toLowerSingleWordCase(pokemon.species);

if (nameToUse.match(MegaSpriteRegex)) {
nameToUse = nameToUse.replace(MegaSpriteRegex, '$1$2');
}

const urlToFetch = `${baseUrl}/${nameToUse}.mp3` as const;
await log({ msg: `${logPrefix}Fetching URL ${urlToFetch}`, color: yellow, isBold: false, isIndent: true });

const mapEntry = pokedex.get(pokemon.key);
try {
const result = await fetch(urlToFetch, FetchResultTypes.Result);
if (result.status === 200) {
mapEntry.cry = urlToFetch;
await log({ msg: `${logPrefix}Set cry on the map object`, color: yellow, isBold: false, isIndent: true });
}
} catch {
// Ignore entry
Expand All @@ -43,4 +48,5 @@ for (const generation of generations) {
await writeDataToFileAndPrettify(pokedexPrependContent + content + pokedexAppendContent, getModulePathForGeneration(generation));
}

console.log(bold(green('Done writing to disk')));
await log({ msg: 'Done writing to disk', color: green, isBold: true, isIndent: false });
process.exit(0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { log as baseLog, type LogParamaters } from '../utils/append-to-log.js';
import { logFile } from './constants.js';

export async function log(params: Omit<LogParamaters, 'logFile'>) {
return baseLog({ ...params, logFile });
}

0 comments on commit 723fb11

Please sign in to comment.