-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetaDataGenerator.js
More file actions
161 lines (149 loc) · 4.44 KB
/
metaDataGenerator.js
File metadata and controls
161 lines (149 loc) · 4.44 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const fs = require("fs");
const prompt = require("prompt-sync")();
const Jimp = require("jimp");
const emoji = require("node-emoji");
async function createJsonFiles(
numFiles,
collectionName,
collectionSymbol,
collectionDescription,
royaltiesPercentage,
imageFile,
traits,
creators,
externalUrl
) {
if (!fs.existsSync("images")) {
fs.mkdirSync("images");
}
if (!fs.existsSync("json_files")) {
fs.mkdirSync("json_files");
}
const failedFiles = [];
for (let i = 0; i < numFiles; i++) {
const fileName = `${i}.png`;
try {
const img = await Jimp.read(imageFile);
await img.writeAsync(`images/${fileName}`);
} catch (e) {
console.log(`${emoji.get("x")} Error creating image ${fileName}: ${e}`);
failedFiles.push(i);
continue;
}
const data = {
name: `${collectionName} #${i}`,
symbol: collectionSymbol,
description: collectionDescription,
seller_fee_basis_points: parseInt(royaltiesPercentage * 100),
image: `${fileName}`,
external_url: externalUrl,
attributes: traits,
properties: {
files: [
{
uri: `${fileName}`,
type: "image/png",
},
],
category: "image",
creators: creators,
},
};
try {
fs.writeFileSync(`json_files/${i}.json`, JSON.stringify(data, null, 4));
console.log(
`${emoji.get("white_check_mark")} ${i}.json created successfully`
);
} catch (e) {
console.log(`${emoji.get("x")} Error creating JSON file ${i}.json: ${e}`);
failedFiles.push(i);
}
}
if (failedFiles.length > 0) {
console.log(
`${emoji.get("hourglass_flowing_sand")} Retrying ${
failedFiles.length
} failed files...`
);
for (let i of failedFiles) {
const fileName = `${i}.png`;
const data = {
name: `${collectionName} #${i}`,
symbol: collectionSymbol,
description: collectionDescription,
seller_fee_basis_points: parseInt(royaltiesPercentage * 100),
image: `${fileName}`,
external_url: externalUrl,
attributes: traits,
properties: {
files: [
{
uri: `${fileName}`,
type: "image/png",
},
],
category: "image",
creators: creators,
},
};
try {
fs.writeFileSync(`json_files/${i}.json`, JSON.stringify(data, null, 4));
console.log(
`${emoji.get("white_check_mark")} ${i}.json created successfully`
);
} catch (e) {
console.log(
`${emoji.get("x")} Error creating JSON file ${i}.json: ${e}`
);
}
}
}
console.log(`${emoji.get("rocket")} All files created successfully!`);
process.exit();
}
try {
const numFiles = parseInt(prompt("Enter the collection size: "));
const collectionName = prompt("Enter collection name: ");
const collectionSymbol = prompt("Enter collection symbol: ");
const collectionDescription = prompt("Enter collection description: ");
const royaltiesPercentage =
parseFloat(prompt("Enter the percentage of royalties (1-10): ")) / 1;
const imageFile = prompt("Enter the location of the image file: ");
const externalUrl = prompt("Enter an external URL (optional): ");
// get traits
const numTraits = parseInt(prompt("Enter the number of traits: "));
const traits = [];
for (let i = 0; i < numTraits; i++) {
const traitType = prompt(`Trait ${i + 1} type: `);
const value = prompt(`Trait ${i + 1} value: `);
traits.push({
trait_type: traitType,
value: value,
});
}
const creators = [];
const numCreators = parseInt(prompt("Enter the number of creators: "));
for (let i = 0; i < numCreators; i++) {
const creatorAddress = prompt(`Enter the address of creator ${i + 1}: `);
const creatorShare = parseInt(
prompt(`Enter the percentage of royalties for creator ${i + 1}: `)
);
creators.push({
address: creatorAddress,
share: creatorShare,
});
}
createJsonFiles(
numFiles,
collectionName,
collectionSymbol,
collectionDescription,
royaltiesPercentage,
imageFile,
traits,
creators,
externalUrl
);
} catch (e) {
console.log(`${emoji.get("x")} Error: ${e}. Please try again later.`);
}