Skip to content

Commit

Permalink
fix rename metadata json file to matchh upload name
Browse files Browse the repository at this point in the history
  • Loading branch information
ammanpashasc committed Jun 3, 2024
1 parent 9ac67d4 commit 9e5dc9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metadata-tool",
"version": "1.4.7",
"version": "1.4.8",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down Expand Up @@ -48,4 +48,4 @@
"singleQuote": true,
"printWidth": 120
}
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const main = async () => {

// Only build hashes if filetype is CSV - for JSON files we just need to verify schema
if (isCSV) {
ReportGenerator.add(`Building Hashes`, false);
ReportGenerator.add(`Building Hashes`, true);
const hashesNftData = await buildHashes<NFTData>(nftData, folderPath);

// Create generated media directory if it doesn't exist
Expand Down
23 changes: 17 additions & 6 deletions src/utils/outputJsonFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export async function outputJsonFiles(

if (data.defaultToken) {
// Don't include defaultToken.serialNumber when writing to file
ReportGenerator.add(`Writing defaultToken.json to file.`);
ReportGenerator.add(`Writing default token to file.`);
fs.writeFileSync(
paths.defaultToken,
JSON.stringify({ ...data.defaultToken, serialNumber: undefined }, null, 2)
);
}

// Don't include factory.tokenUriTemplate when writing to file
ReportGenerator.add(`Writing factory.json to file.`);
ReportGenerator.add(`Writing factory to file.`);
fs.writeFileSync(paths.factory, JSON.stringify({ ...data.factory, tokenUriTemplate: undefined }, null, 2));

let defaultToken: HashUrl | undefined = undefined;
Expand All @@ -68,6 +68,9 @@ export async function outputJsonFiles(
hash: defaultTokenHash,
url: defaultTokenUrl,
};

// Rename "defaultToken.json" to defaultTokenFileName
fs.renameSync(paths.defaultToken, normalizeUrl(path.join(workingDirectory, `/${defaultTokenFileName}`)));
}

const factoryHash = await HashGenerator.create(paths.factory);
Expand All @@ -76,24 +79,27 @@ export async function outputJsonFiles(
process.exit(1);
}

const factoryFileName = factoryHash + '.json';
const factory: HashUrl = {
hash: factoryHash,
url:
config.environmentUrl +
'/' +
encodeURIComponent(config.collectionName!.replace(/\s/g, '')) +
'/' +
factoryHash +
'.json',
factoryFileName,
};

// Rename "factory.json" to factoryFileName
fs.renameSync(paths.factory, normalizeUrl(path.join(workingDirectory, `/${factoryFileName}`)));

const tokens: Array<SerialHashUrl> = [];

for (let token of data.tokens) {
const tokenPath = normalizeUrl(path.join(workingDirectory, `/${token.serialNumber}.token.json`));
const tokenPath = normalizeUrl(path.join(workingDirectory, `/${token.serialNumber}.json`));

// Don't include token.serialNumber when writing to file
ReportGenerator.add(`Writing ${token.serialNumber}.token.json to file.`);
ReportGenerator.add(`Writing token ${token.serialNumber} to file.`);
fs.writeFileSync(tokenPath, JSON.stringify({ ...token, serialNumber: undefined }, null, 2));

const tokenHash = await HashGenerator.create(tokenPath);
Expand All @@ -112,6 +118,11 @@ export async function outputJsonFiles(
tokenFileName;

tokens.push({ serialNumber: token.serialNumber, hash: tokenHash, url: tokenUrl });

if (data.factory.tokenUriTemplate == '{hash}') {
// Rename `${token.serialNumber}.json` to tokenFileName
fs.renameSync(tokenPath, normalizeUrl(path.join(workingDirectory, `/${tokenFileName}`)));
}
}

return {
Expand Down

0 comments on commit 9e5dc9d

Please sign in to comment.