Skip to content

Commit

Permalink
Different handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopic committed Dec 24, 2024
1 parent 02fedba commit aec5ee6
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions scripts/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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`),
Expand All @@ -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 )
]
}));

Expand Down

0 comments on commit aec5ee6

Please sign in to comment.