Skip to content

Commit cb4b737

Browse files
authored
Merge pull request #24 from HashLips/dev
Added update baseUri feature
2 parents e4c2fe4 + b4308bb commit cb4b737

6 files changed

Lines changed: 48 additions & 11 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const MODE = {
155155
};
156156
```
157157

158-
When you are all ready, run the following command and your outputted art will be in the `build` directory:
158+
When you are all ready, run the following command and your outputted art will be in the `build/images` directory and the json in the `build/json` directory:
159159

160160
```sh
161161
npm run build
@@ -167,7 +167,7 @@ or
167167
node index.js
168168
```
169169

170-
The program will output all the images in the `build` directory along with the metadata files. Each collection will have a `_metadata.json` file that consists of all the metadata in the collection inside the `build` folder. The `build` folder also will contain all the images as well as single json files that represent each image file. The single json file of a image will look something like this:
170+
The program will output all the images in the `build/images` directory along with the metadata files in the `build/json` directory. Each collection will have a `_metadata.json` file that consists of all the metadata in the collection inside the `build/json` directory. The `build/json` folder also will contain all the single json files that represent each image file. The single json file of a image will look something like this:
171171

172172
```json
173173
{
@@ -192,12 +192,20 @@ The program will output all the images in the `build` directory along with the m
192192

193193
That's it, you're done.
194194

195+
### Updating baseUri for IPFS
196+
197+
You might possibly want to update the baseUri after you have ran your collection. To update the baseUri simply run:
198+
199+
```sh
200+
node utils/updateBaseUri.js
201+
```
202+
195203
### Printing rarity data (Experimental feature)
196204

197205
To see the percentages of each attribute across your collection, run:
198206

199207
```sh
200-
node rarityData.js
208+
node utils/rarityData.js
201209
```
202210

203211
The output will look something like this:

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const { MODE } = require("./blendMode.js");
22
const description =
33
"This is the description of your NFT project, remember to replace this";
4-
const baseUri = "https://hashlips/nft";
4+
const baseUri = "ipfs://QmNfPMWLPTEbFpBtPFy4wkYEHRVWcz8dzjziTcPbebzF53";
55

66
const layerConfigurations = [
77
{
8-
growEditionSizeTo: 5,
8+
growEditionSizeTo: 20,
99
layersOrder: [
1010
{ name: "Background" },
1111
{ name: "Eyeball" },

src/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const buildSetup = () => {
2727
fs.rmdirSync(buildDir, { recursive: true });
2828
}
2929
fs.mkdirSync(buildDir);
30+
fs.mkdirSync(`${buildDir}/json`);
31+
fs.mkdirSync(`${buildDir}/images`);
3032
};
3133

3234
const getRarityWeight = (_str) => {
@@ -80,7 +82,7 @@ const layersSetup = (layersOrder) => {
8082

8183
const saveImage = (_editionCount) => {
8284
fs.writeFileSync(
83-
`${buildDir}/${_editionCount}.png`,
85+
`${buildDir}/images/${_editionCount}.png`,
8486
canvas.toBuffer("image/png")
8587
);
8688
};
@@ -177,12 +179,12 @@ const createDna = (_layers) => {
177179
};
178180

179181
const writeMetaData = (_data) => {
180-
fs.writeFileSync(`${buildDir}/_metadata.json`, _data);
182+
fs.writeFileSync(`${buildDir}/json/_metadata.json`, _data);
181183
};
182184

183185
const saveMetaDataSingleFile = (_editionCount) => {
184186
fs.writeFileSync(
185-
`${buildDir}/${_editionCount}.json`,
187+
`${buildDir}/json/${_editionCount}.json`,
186188
JSON.stringify(
187189
metadataList.find((meta) => meta.edition == _editionCount),
188190
null,

rarityData.js renamed to utils/rarityData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const isLocal = typeof process.pkg === "undefined";
66
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
77
const layersDir = `${basePath}/layers`;
88

9-
const { layerConfigurations } = require("./src/config.js");
9+
const { layerConfigurations } = require("../src/config.js");
1010

11-
const { getElements } = require("./src/main.js");
11+
const { getElements } = require("../src/main.js");
1212

1313
// read json data
14-
let rawdata = fs.readFileSync("build/_metadata.json");
14+
let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`);
1515
let data = JSON.parse(rawdata);
1616
let editionSize = data.length;
1717

utils/updateBaseUri.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
const isLocal = typeof process.pkg === "undefined";
6+
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
7+
8+
const { baseUri } = require("../src/config.js");
9+
10+
// read json data
11+
let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`);
12+
let data = JSON.parse(rawdata);
13+
14+
data.forEach((item) => {
15+
item.image = `${baseUri}/${item.edition}.png`;
16+
fs.writeFileSync(
17+
`${basePath}/build/json/${item.edition}.json`,
18+
JSON.stringify(item, null, 2)
19+
);
20+
});
21+
22+
fs.writeFileSync(
23+
`${basePath}/build/json/_metadata.json`,
24+
JSON.stringify(data, null, 2)
25+
);
26+
27+
console.log(`Updated baseUri for images to ===> ${baseUri}`);

0 commit comments

Comments
 (0)