Skip to content

Commit

Permalink
fix: merge script
Browse files Browse the repository at this point in the history
Signed-off-by: Mirko Mollik <[email protected]>
  • Loading branch information
cre8 committed Aug 25, 2024
1 parent 74dd8a8 commit f49195a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions viewer/scripts/merge-wallets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@ import { readdirSync, readFileSync, writeFileSync } from 'fs';
// url for the folder containing the wallet files in the GitHub repo
const commitHistoryBase = 'https://github.com/openwallet-foundation/digital-wallet-and-agent-overviews-sig/commits/main/wallets/'


const dependenciesFiles = readdirSync('../dependencies');

const dependencies = dependenciesFiles.map(file => {
const json = JSON.parse(readFileSync(`../dependencies/${file}`));
json['$schema'] = undefined;
return json;
});


// function to merge all the individual wallet files into a single file
const files = readdirSync('../wallets');
const wallets = []

const wallets = [];
for (const file of files) {
try {
const json = JSON.parse(readFileSync(`../wallets/${file}`));
json.commitHistory = commitHistoryBase + file;
// for now we insert the dependencies instead of just referencing them
if(json.dependencies) {
json.dependencies = json.dependencies.map(dependencies => {
try {
const content = JSON.parse(readFileSync(`../dependencies/${dependencies}.json`));
content['$schema'] = undefined;
return content;
}
catch(e) {
console.warn(`Error parsing ${dependencies}.json: ${e}`)
return dependencies;
json.dependencies = json.dependencies.map(dependency => {
const found = dependencies.find(d => d.name === dependency);
if(found) {
return found;
}
console.warn(`Could not find dependency ${dependency} for wallet ${json.name}`);
return dependency;
});
}
wallets.push(json)
Expand All @@ -30,4 +38,5 @@ for (const file of files) {
console.warn(`Error parsing ${file}: ${e}`)
}
}
writeFileSync('src/assets/wallets.json', JSON.stringify(wallets));
writeFileSync('src/assets/wallets.json', JSON.stringify(wallets, null, 2));
console.log(`Merged ${files.length} wallet files into src/assets/wallets.json`);

0 comments on commit f49195a

Please sign in to comment.