Created
January 19, 2022 15:39
-
-
Save deanrad/8ce70868279291f93aca45ece5fe3e0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Omnibus } = require("omnibus-rxjs"); | |
const fs = require("fs"); | |
const { join } = require("path"); | |
const bus = new Omnibus(); | |
bus.spy(({ type, payload }) => console.log(type, payload)); | |
const dirPath = "./"; | |
const jsonMaker = bus.filter( | |
({ type }) => type === "png", | |
({ payload: { idx } }) => { | |
const pngFile = `${idx}.png`; | |
const jsonFile = `${idx}.json`; | |
const jsonObj = { | |
name: `My Numbered NFT: ${idx}`, | |
image: pngFile, | |
attributes: [ | |
{ trait_type: "Layer-1", value: "0" }, | |
{ trait_type: "Layer-2", value: "0" }, | |
{ trait_type: "Layer-3", value: "0" }, | |
{ trait_type: "Layer-4", value: "1" }, | |
], | |
properties: { | |
files: [{ uri: pngFile, type: "image/png" }], | |
}, | |
collection: { name: "numbers", family: "numbers" }, | |
}; | |
fs.writeFileSync(join(dirPath, jsonFile), JSON.stringify(jsonObj, null, 2)); | |
} | |
); | |
const files = fs.readdirSync(dirPath); | |
for (const file of files) { | |
if (file.endsWith(".png")) { | |
const idx = Number(file.replace(".png", "")); | |
bus.trigger({ type: "png", payload: { idx } }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment