Skip to content

Commit

Permalink
Merge pull request #24 from HashLips/dev
Browse files Browse the repository at this point in the history
Added update baseUri feature
  • Loading branch information
HashLips authored Sep 17, 2021
2 parents e4c2fe4 + b4308bb commit cb4b737
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
Binary file modified .DS_Store
Binary file not shown.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const MODE = {
};
```

When you are all ready, run the following command and your outputted art will be in the `build` directory:
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:

```sh
npm run build
Expand All @@ -167,7 +167,7 @@ or
node index.js
```

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:
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:

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

That's it, you're done.

### Updating baseUri for IPFS

You might possibly want to update the baseUri after you have ran your collection. To update the baseUri simply run:

```sh
node utils/updateBaseUri.js
```

### Printing rarity data (Experimental feature)

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

```sh
node rarityData.js
node utils/rarityData.js
```

The output will look something like this:
Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { MODE } = require("./blendMode.js");
const description =
"This is the description of your NFT project, remember to replace this";
const baseUri = "https://hashlips/nft";
const baseUri = "ipfs://QmNfPMWLPTEbFpBtPFy4wkYEHRVWcz8dzjziTcPbebzF53";

const layerConfigurations = [
{
growEditionSizeTo: 5,
growEditionSizeTo: 20,
layersOrder: [
{ name: "Background" },
{ name: "Eyeball" },
Expand Down
8 changes: 5 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const buildSetup = () => {
fs.rmdirSync(buildDir, { recursive: true });
}
fs.mkdirSync(buildDir);
fs.mkdirSync(`${buildDir}/json`);
fs.mkdirSync(`${buildDir}/images`);
};

const getRarityWeight = (_str) => {
Expand Down Expand Up @@ -80,7 +82,7 @@ const layersSetup = (layersOrder) => {

const saveImage = (_editionCount) => {
fs.writeFileSync(
`${buildDir}/${_editionCount}.png`,
`${buildDir}/images/${_editionCount}.png`,
canvas.toBuffer("image/png")
);
};
Expand Down Expand Up @@ -177,12 +179,12 @@ const createDna = (_layers) => {
};

const writeMetaData = (_data) => {
fs.writeFileSync(`${buildDir}/_metadata.json`, _data);
fs.writeFileSync(`${buildDir}/json/_metadata.json`, _data);
};

const saveMetaDataSingleFile = (_editionCount) => {
fs.writeFileSync(
`${buildDir}/${_editionCount}.json`,
`${buildDir}/json/${_editionCount}.json`,
JSON.stringify(
metadataList.find((meta) => meta.edition == _editionCount),
null,
Expand Down
6 changes: 3 additions & 3 deletions rarityData.js → utils/rarityData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const isLocal = typeof process.pkg === "undefined";
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);
const layersDir = `${basePath}/layers`;

const { layerConfigurations } = require("./src/config.js");
const { layerConfigurations } = require("../src/config.js");

const { getElements } = require("./src/main.js");
const { getElements } = require("../src/main.js");

// read json data
let rawdata = fs.readFileSync("build/_metadata.json");
let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`);
let data = JSON.parse(rawdata);
let editionSize = data.length;

Expand Down
27 changes: 27 additions & 0 deletions utils/updateBaseUri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

const fs = require("fs");
const path = require("path");
const isLocal = typeof process.pkg === "undefined";
const basePath = isLocal ? process.cwd() : path.dirname(process.execPath);

const { baseUri } = require("../src/config.js");

// read json data
let rawdata = fs.readFileSync(`${basePath}/build/json/_metadata.json`);
let data = JSON.parse(rawdata);

data.forEach((item) => {
item.image = `${baseUri}/${item.edition}.png`;
fs.writeFileSync(
`${basePath}/build/json/${item.edition}.json`,
JSON.stringify(item, null, 2)
);
});

fs.writeFileSync(
`${basePath}/build/json/_metadata.json`,
JSON.stringify(data, null, 2)
);

console.log(`Updated baseUri for images to ===> ${baseUri}`);

0 comments on commit cb4b737

Please sign in to comment.