ts: only read .json files when parsing IDLs (#1214)

This commit is contained in:
John Rees 2021-12-31 01:26:11 +00:00 committed by GitHub
parent b6cbdb257e
commit 69299fb723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

View File

@ -47,19 +47,21 @@ const workspace = new Proxy({} as any, {
} }
const idlMap = new Map<string, Idl>(); const idlMap = new Map<string, Idl>();
fs.readdirSync(idlFolder).forEach((file) => { fs.readdirSync(idlFolder)
const filePath = `${idlFolder}/${file}`; .filter((file) => file.endsWith(".json"))
const idlStr = fs.readFileSync(filePath); .forEach((file) => {
const idl = JSON.parse(idlStr); const filePath = `${idlFolder}/${file}`;
idlMap.set(idl.name, idl); const idlStr = fs.readFileSync(filePath);
const name = camelCase(idl.name, { pascalCase: true }); const idl = JSON.parse(idlStr);
if (idl.metadata && idl.metadata.address) { idlMap.set(idl.name, idl);
workspaceCache[name] = new Program( const name = camelCase(idl.name, { pascalCase: true });
idl, if (idl.metadata && idl.metadata.address) {
new PublicKey(idl.metadata.address) workspaceCache[name] = new Program(
); idl,
} new PublicKey(idl.metadata.address)
}); );
}
});
// Override the workspace programs if the user put them in the config. // Override the workspace programs if the user put them in the config.
const anchorToml = toml.parse( const anchorToml = toml.parse(