diff --git a/scripts/sync.js b/scripts/sync.js index b82f0e137..e14fecb16 100644 --- a/scripts/sync.js +++ b/scripts/sync.js @@ -3,16 +3,23 @@ const fs = require("fs"); const fsprom = require("fs/promises"); require('dotenv').config() -async function copyFileIgnoreMissing(source, destination) { - try { - await fsprom.copyFile(source, destination); - } catch (err) { - if (err.code === 'ENOENT') { - // ignore missing source files - } else { - // everything else - throw err; - } + +function missingIndexTsHandler(err){ + if (err.code === 'ENOENT') { + // Just give some advice to the user + console.error('./build/index.d.ts not found. You have to generate it with "yarn definitions"'); + } + + // Keep the chain failed + throw err; +} + +function ignoreFileNotFound(err){ + if (err.code === 'ENOENT') { + // Ignore file not found + } else { + // Keep the chain failed + throw err; } } @@ -21,7 +28,7 @@ async function run(ARKHAM_CARDS){ const exists = fs.existsSync(ARKHAM_CARDS); if (exists === true){ await Promise.all([ - fsprom.copyFile('./build/index.d.ts', `${ARKHAM_CARDS}/src/data/scenario/types.d.ts`), + fsprom.copyFile('./build/index.d.ts', `${ARKHAM_CARDS}/src/data/scenario/types.d.ts`).catch( missingIndexTsHandler ), fsprom.copyFile('./build/standalone.json', `${ARKHAM_CARDS}/assets/generated/standaloneScenarios.json`), fsprom.copyFile('./build/allCampaigns.json', `${ARKHAM_CARDS}/assets/generated/allCampaigns.json`), fsprom.copyFile('./build/scenarioNames.json', `${ARKHAM_CARDS}/assets/generated/scenarioNames.json`), @@ -32,17 +39,17 @@ async function run(ARKHAM_CARDS){ fsprom.copyFile('./chaos_tokens.json', `${ARKHAM_CARDS}/assets/generated/chaosOdds.json`), fsprom.copyFile('./rules/en/rules.json', `${ARKHAM_CARDS}/assets/generated/rules.json`) ]); - + // I18n files const langs=['es', 'ko', 'it', 'fr', 'ru', 'de', 'zh', 'pt', 'pl', 'vi', 'cs', 'zh-cn']; await Promise.allSettled( langs.flatMap(async (lang)=>{ return [ - copyFileIgnoreMissing(`./build/allCampaigns_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/allCampaigns_${lang}.json`), - copyFileIgnoreMissing(`./build/scenarioNames_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/scenarioNames_${lang}.json`), - copyFileIgnoreMissing(`./build/campaignLogs_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/campaignLogs_${lang}.json`), - copyFileIgnoreMissing(`./build/encounterSets_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/encounterSets_${lang}.json`), - copyFileIgnoreMissing(`./errata/${lang}/errata.json`, `${ARKHAM_CARDS}/assets/generated/campaignErrata_${lang}.json`), - copyFileIgnoreMissing(`./rules/${lang}/rules.json`, `${ARKHAM_CARDS}/assets/generated/rules_${lang}.json`) + fsprom.copyFile(`./build/allCampaigns_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/allCampaigns_${lang}.json`).catch( ignoreFileNotFound ), + fsprom.copyFile(`./build/scenarioNames_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/scenarioNames_${lang}.json`).catch( ignoreFileNotFound ), + fsprom.copyFile(`./build/campaignLogs_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/campaignLogs_${lang}.json`).catch( ignoreFileNotFound ), + fsprom.copyFile(`./build/encounterSets_${lang}.json`, `${ARKHAM_CARDS}/assets/generated/encounterSets_${lang}.json`).catch( ignoreFileNotFound ), + fsprom.copyFile(`./errata/${lang}/errata.json`, `${ARKHAM_CARDS}/assets/generated/campaignErrata_${lang}.json`).catch( ignoreFileNotFound ), + fsprom.copyFile(`./rules/${lang}/rules.json`, `${ARKHAM_CARDS}/assets/generated/rules_${lang}.json`).catch( ignoreFileNotFound ) ] }));