-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 857 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Generate Metadata for all images
const {
writeFileSync,
readdirSync,
rmSync,
existsSync,
mkdirSync,
} = require('fs')
const BASE_URL =
'https://gateway.pinata.cloud/ipfs/QmYDmEzA1Sb6zVvyRCRBiFHwjJKv5uXxvsaEUszTvNymoT'
function generateMetadata(url) {
const name = url.split('/').pop().split('.')[0]
const meta = {
name,
description: 'Welcome to the Dance Floor',
image: `${BASE_URL}/${encodeURIComponent(name.trim())}.png`,
attributes: [
{
trait_type: 'Item',
value: `${name}`,
},
],
}
writeFileSync(`./json/${name}.json`, JSON.stringify(meta))
}
// Create dir if not exists
if (!existsSync('./json')) {
mkdirSync('./json')
}
// Cleanup dir before each run
readdirSync('./json').forEach((f) => rmSync(`./json/${f}`))
const images = readdirSync('./images')
for (const image of images) {
generateMetadata(image)
}