Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing and refactor code #1023

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
77d42ec
add linter
ramses429 Mar 18, 2022
daa7e45
add function getAbstractedIndexes
ramses429 Mar 18, 2022
d967375
resolve import
ramses429 Mar 18, 2022
609484a
add more configurations
ramses429 Mar 18, 2022
0f8efd9
add testing function
ramses429 Mar 24, 2022
b1048c5
Merge pull request #1 from ramses429/refactor-code
ramses429 Mar 24, 2022
5838de8
add function testing
ramses429 Mar 25, 2022
c52ed19
add test functions getRarityWeight, cleanDna and removeQueryStrings
andrexfenix Mar 25, 2022
b85e451
Merge pull request #2 from ramses429/continue-with-refactor-add-test-…
ramses429 Mar 26, 2022
6a44df8
add testing function cleanName, getElements
andrexfenix Mar 26, 2022
ea94e54
merged and resolve conflict in main.js
andrexfenix Mar 26, 2022
3968a79
modified rooted of functions addMetadata, genColor, drawBackground, s…
andrexfenix Mar 29, 2022
7d0622b
Merge pull request #3 from ramses429/factor-function-testing-297
ramses429 Mar 30, 2022
66e5a6f
Revert "Factor function testing 297"
ramses429 Mar 30, 2022
505eebb
Merge pull request #4 from ramses429/revert-3-factor-function-testing…
ramses429 Mar 30, 2022
1f29ab4
add testin function: cleanDna, cleanName, getElements, getRarityWeigh…
andrexfenix Mar 30, 2022
824e140
fix state function addMetadata and drawBackground
andrexfenix Mar 30, 2022
5b4fde1
Merge 'main' into refactor-function-testing-298
andrexfenix Mar 31, 2022
8c1fae6
refactor drawElement , addAttributes and addText
andrexfenix Mar 31, 2022
18c8e4e
Merge pull request #5 from ramses429/refactor-function-testing-298
ramses429 Apr 1, 2022
ef16983
add husky configuration
ramses429 Apr 1, 2022
9df28f9
Merge pull request #6 from ramses429/add-husky-actions-349851
ramses429 Apr 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add husky configuration
ramses429 committed Apr 1, 2022
commit ef16983ad8b0904f0562de8fc003e956af88d59c
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@ module.exports = {
jest: true
},
extends: [
"standard"
"standard",
"prettier"
],
parserOptions: {
ecmaVersion: "latest"
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@
"update_info": "node utils/update_info.js",
"preview_gif": "node utils/preview_gif.js",
"generate_metadata": "node utils/generate_metadata.js",
"test":"jest"
"test": "jest",
"lint": "eslint src/**",
"lint:fix": "eslint src/** --fix"
},
"author": "Daniel Eugene Botha (HashLips)",
"license": "MIT",
@@ -32,11 +34,19 @@
"devDependencies": {
"@types/jest": "^27.4.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.2.0",
"jest": "^27.5.1"
"husky": "^7.0.4",
"jest": "^27.5.1",
"lint-staged": "^12.3.7"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run test"
}
}
}
85 changes: 42 additions & 43 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
const basePath = process.cwd();
const { MODE } = require(`${basePath}/constants/blend_mode.js`);
const { NETWORK } = require(`${basePath}/constants/network.js`);

const network = NETWORK.eth;

// General metadata for Ethereum
const namePrefix = 'Your Collection';
const description = 'Remember to replace this description';
const baseUri = 'ipfs://NewUriToReplace';
const namePrefix = "Your Collection";
const description = "Remember to replace this description";
const baseUri = "ipfs://NewUriToReplace";

const solanaMetadata = {
symbol: 'YC',
symbol: "YC",
seller_fee_basis_points: 1000, // Define how much % you want from secondary market sales 1000 = 10%
external_url: 'https://www.youtube.com/c/hashlipsnft',
external_url: "https://www.youtube.com/c/hashlipsnft",
creators: [
{
address: '7fXNuer5sbZtaTEPhtJ5g5gNtuyRoKkvxdjEjEnPN4mC',
share: 100,
},
],
address: "7fXNuer5sbZtaTEPhtJ5g5gNtuyRoKkvxdjEjEnPN4mC",
share: 100
}
]
};

// If you have selected Solana then the collection starts from 0 automatically
const layerConfigurations = [
{
growEditionSizeTo: 5,
layersOrder: [
{ name: 'Background' },
{ name: 'Eyeball' },
{ name: 'Iris' },
{ name: 'Shine' },
{ name: 'Bottom lid' },
{ name: 'Top lid' },
],
{ name: "Background" },
{ name: "Eyeball" },
{ name: "Iris" },
{ name: "Shine" },
{ name: "Bottom lid" },
{ name: "Top lid" }
]
},
{
growEditionSizeTo: 25,
layersOrder: [
{ name: 'Background' },
{ name: 'Eyeball' },
{ name: 'Eye color' },
{ name: 'Iris' },
{ name: 'Shine' },
{ name: 'Bottom lid' },
{ name: 'Top lid' },
],
},
{ name: "Background" },
{ name: "Eyeball" },
{ name: "Eye color" },
{ name: "Iris" },
{ name: "Shine" },
{ name: "Bottom lid" },
{ name: "Top lid" }
]
}
];

const shuffleLayerConfigurations = false;
@@ -55,60 +54,60 @@ const debugLogs = false;
const format = {
width: 512,
height: 512,
smoothing: false,
smoothing: false
};

const gif = {
export: false,
repeat: 0,
quality: 100,
delay: 500,
delay: 500
};

const text = {
only: false,
color: '#ffffff',
color: "#ffffff",
size: 20,
xGap: 40,
yGap: 40,
align: 'left',
baseline: 'top',
weight: 'regular',
family: 'Courier',
spacer: ' => ',
align: "left",
baseline: "top",
weight: "regular",
family: "Courier",
spacer: " => "
};

const pixelFormat = {
ratio: 2 / 128,
ratio: 2 / 128
};

const background = {
generate: true,
brightness: '80%',
brightness: "80%",
static: false,
default: '#000000',
default: "#000000"
};

const extraMetadata = {};

const rarityDelimiter = '#';
const rarityDelimiter = "#";

const uniqueDnaTorrance = 10000;

const preview = {
thumbPerRow: 5,
thumbWidth: 50,
imageRatio: format.height / format.width,
imageName: 'preview.png',
imageName: "preview.png"
};

const preview_gif = {
const previewGif = {
numberOfImages: 5,
order: 'ASC', // ASC, DESC, MIXED
order: "ASC", // ASC, DESC, MIXED
repeat: 0,
quality: 100,
delay: 500,
imageName: 'preview.gif',
imageName: "preview.gif"
};

module.exports = {
@@ -129,5 +128,5 @@ module.exports = {
network,
solanaMetadata,
gif,
preview_gif,
previewGif
};
16 changes: 8 additions & 8 deletions src/functions/addMetadata/index.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ const {
extraMetadata,
namePrefix,
network,
solanaMetadata,
solanaMetadata
} = require(`${basePath}/src/config.js`);
const { NETWORK } = require(`${basePath}/constants/network.js`);
const sha1 = require(`${basePath}/node_modules/sha1`);
@@ -21,7 +21,7 @@ const addMetadata = (_dna, _edition, metadataList, attributesList) => {
date: dateTime,
...extraMetadata,
attributes: attributesList,
compiler: 'HashLips Art Engine',
compiler: "HashLips Art Engine"
};
if (network === NETWORK.sol) {
tempMetadata = {
@@ -41,16 +41,16 @@ const addMetadata = (_dna, _edition, metadataList, attributesList) => {
files: [
{
uri: `${_edition}.png`,
type: 'image/png',
},
type: "image/png"
}
],
category: 'image',
creators: solanaMetadata.creators,
},
category: "image",
creators: solanaMetadata.creators
}
};
}
metadataList.push(tempMetadata);
//console.log('metadatalist:', metadataList);
// console.log('metadatalist:', metadataList);
attributesList = [];
return { metadataList, attributesList };
};
2 changes: 1 addition & 1 deletion src/functions/cleanDna/index.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ const removeQueryStrings = require(`${basePath}/src/functions/removeQueryStrings

const cleanDna = (_str) => {
const withoutOptions = removeQueryStrings(_str);
const dna = Number(withoutOptions.split(':').shift());
const dna = Number(withoutOptions.split(":").shift());
return dna;
};

8 changes: 4 additions & 4 deletions src/functions/cleanDna/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const getAbstractedIndexes = require('./index');
const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const getAbstractedIndexes = require("./index");
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

describe('cleanDna cero', () => {
test('cleanDna', () => {
describe("cleanDna cero", () => {
test("cleanDna", () => {
const resultInputFalse = getAbstractedIndexes(mockDataInput);
expect(resultInputFalse).toStrictEqual(mockDataOutput);
});
2 changes: 1 addition & 1 deletion src/functions/cleanDna/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mockDataInput = '0:Black#1.png';
const mockDataInput = "0:Black#1.png";
const mockDataOutput = 0;
module.exports.mockDataInput = mockDataInput;
module.exports.mockDataOutput = mockDataOutput;
8 changes: 4 additions & 4 deletions src/functions/cleanName/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const cleanName = require('./index');
const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const cleanName = require("./index");
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

describe('cleanName cero', () => {
test('cleanName', () => {
describe("cleanName cero", () => {
test("cleanName", () => {
const resultNameWithoutExtension = cleanName(mockDataInput);
expect(resultNameWithoutExtension).toStrictEqual(mockDataOutput);
});
4 changes: 2 additions & 2 deletions src/functions/cleanName/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mockDataInput = '0:Black#1.png';
const mockDataOutput = '0:Black';
const mockDataInput = "0:Black#1.png";
const mockDataOutput = "0:Black";
module.exports.mockDataInput = mockDataInput;
module.exports.mockDataOutput = mockDataOutput;
9 changes: 0 additions & 9 deletions src/functions/createDna/index.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/functions/drawBackground/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const basePath = process.cwd();
const { background, format } = require(`${basePath}/src/config.js`);
const genColor = require('../genColor');
const genColor = require("../genColor");

const drawBackground = (ctx) => {
ctx.fillStyle = background.static ? background.default : genColor();
2 changes: 1 addition & 1 deletion src/functions/drawElement/function/addAttributes/index.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ const addAttributes = (_element, attributesList) => {
const selectedElement = _element.layer.selectedElement;
attributesList.push({
trait_type: _element.layer.name,
value: selectedElement.name,
value: selectedElement.name
});
return attributesList;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const addAttributes = require('./index');
const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const addAttributes = require("./index");
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

describe('addAttributes cero', () => {
test('addAttributes', () => {
describe("addAttributes cero", () => {
test("addAttributes", () => {
const resultNewDataAttribute = addAttributes(
mockDataInput._element,
mockDataInput.attributesList
30 changes: 15 additions & 15 deletions src/functions/drawElement/function/addAttributes/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -3,32 +3,32 @@ const basePath = process.cwd();
const mockDataInput = {
_element: {
layer: {
name: 'Top lid',
blend: 'source-over',
name: "Top lid",
blend: "source-over",
opacity: 1,
selectedElement: {
id: 1,
name: 'Low',
filename: 'Low#20.png',
name: "Low",
filename: "Low#20.png",
path: `${basePath}/layers/Top lid/Low#20.png`,
weight: 20,
},
weight: 20
}
},
loadedImage: {
onload: null,
onerror: null,
},
onerror: null
}
},
attributesList: [
{ trait_type: 'Eyeball', value: 'White' },
{ trait_type: 'Eye color', value: 'Yellow' },
{ trait_type: 'Iris', value: 'Large' },
{ trait_type: 'Shine', value: 'Shapes' },
{ trait_type: 'Bottom lid', value: 'Low' },
],
{ trait_type: "Eyeball", value: "White" },
{ trait_type: "Eye color", value: "Yellow" },
{ trait_type: "Iris", value: "Large" },
{ trait_type: "Shine", value: "Shapes" },
{ trait_type: "Bottom lid", value: "Low" }
]
};

const mockDataOutput = { trait_type: 'Top lid', value: 'Low' };
const mockDataOutput = { trait_type: "Top lid", value: "Low" };

module.exports.mockDataInput = mockDataInput;
module.exports.mockDataOutput = mockDataOutput;
4 changes: 2 additions & 2 deletions src/functions/drawElement/function/addText/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const addText = (_sig, ctx, x, y, size, text) => {
//console.log({ _sig, ctx, x, y, size, text });
// console.log({ _sig, ctx, x, y, size, text });
ctx.fillStyle = text.color;
ctx.font = `${text.weight} ${size}pt ${text.family}`;
ctx.textBaseline = text.baseline;
ctx.textAlign = text.align;
ctx.fillText(_sig, x, y);
//console.log({ ctx });
// console.log({ ctx });
return ctx;
};

22 changes: 11 additions & 11 deletions src/functions/drawElement/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const basePath = process.cwd();
const { format } = require(`${basePath}/src/config.js`);
const addText = require(`./function/addText`);
const addAttributes = require(`./function/addAttributes`);
const addText = require("./function/addText");
const addAttributes = require("./function/addAttributes");

const drawElement = (
_renderObject,
@@ -21,17 +21,17 @@ const drawElement = (
text.yGap * (_index + 1),
text.size,
text
)
)
: ctx.drawImage(
_renderObject.loadedImage,
0,
0,
format.width,
format.height
);
_renderObject.loadedImage,
0,
0,
format.width,
format.height
);

var attributesList = addAttributes(_renderObject, attributesList);
return { newCtx: ctx, newAttributesList: attributesList };
const newAttributesList = addAttributes(_renderObject, attributesList);
return { newCtx: ctx, newAttributesList };
};

module.exports = drawElement;
12 changes: 6 additions & 6 deletions src/functions/getElements/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const fs = require('fs');
const getRarityWeight = require('../getRarityWeight');
const cleanName = require('../cleanName');
const fs = require("fs");
const getRarityWeight = require("../getRarityWeight");
const cleanName = require("../cleanName");

const getElements = (path) => {
return fs
.readdirSync(path)
.filter((item) => !/(^|\/)\.[^\/\.]/g.test(item))
.filter((item) => !/(^|\/)\.[^/.]/g.test(item))
.map((i, index) => {
if (i.includes('-')) {
if (i.includes("-")) {
throw new Error(`layer name can not contain dashes, please fix: ${i}`);
}
return {
id: index,
name: cleanName(i),
filename: i,
path: `${path}${i}`,
weight: getRarityWeight(i),
weight: getRarityWeight(i)
};
});
};
8 changes: 4 additions & 4 deletions src/functions/getElements/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const getElements = require('./index');
const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const getElements = require("./index");
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

describe('getElements cero', () => {
test('getElements', () => {
describe("getElements cero", () => {
test("getElements", () => {
const resultObjectFile = getElements(mockDataInput.path);
expect(resultObjectFile).toEqual([expect.objectContaining(mockDataOutput)]);
});
10 changes: 5 additions & 5 deletions src/functions/getElements/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const basePath = process.cwd();

const mockDataInput = {
path: basePath + '/layers/Background/',
path: basePath + "/layers/Background/"
};

const mockDataOutput = {
id: 0,
name: 'Black',
filename: 'Black#1.png',
path: basePath + `/layers/Background/Black#1.png`,
weight: 1,
name: "Black",
filename: "Black#1.png",
path: basePath + "/layers/Background/Black#1.png",
weight: 1
};

module.exports.mockDataInput = mockDataInput;
2 changes: 1 addition & 1 deletion src/functions/getRarityWeight/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const basePath = process.cwd();
const { rarityDelimiter } = require(`${basePath}/src/config.js`);

function getRarityWeight(_str) {
function getRarityWeight (_str) {
const nameWithoutExtension = _str.slice(0, -4);
let nameWithoutWeight = Number(
nameWithoutExtension.split(rarityDelimiter).pop()
12 changes: 4 additions & 8 deletions src/functions/getRarityWeight/index.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const basePath = process.cwd();
const buildDir = `${basePath}/build`;
const fs = require('fs');
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const getRarityWeight = require("./index");

const getRarityWeight = require('./index');

describe('getRarityWeight cero', () => {
test('getRarityWeight', () => {
describe("getRarityWeight cero", () => {
test("getRarityWeight", () => {
const resultNameWithoutWeightAndExtension = getRarityWeight(mockDataInput);
expect(resultNameWithoutWeightAndExtension).toStrictEqual(mockDataOutput);
});
2 changes: 1 addition & 1 deletion src/functions/getRarityWeight/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mockDataInput = 'High#30.png';
const mockDataInput = "High#30.png";
const mockDataOutput = 30;
module.exports.mockDataInput = mockDataInput;
module.exports.mockDataOutput = mockDataOutput;
6 changes: 3 additions & 3 deletions src/functions/layersSetup/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const basePath = process.cwd();
const getElements = require('../getElements');
const getElements = require("../getElements");
const layersDir = `${basePath}/layers`;

const layersSetup = (layersOrder) => {
@@ -13,13 +13,13 @@ const layersSetup = (layersOrder) => {
blend:
layerObj.options?.blend !== undefined
? layerObj.options?.blend
: 'source-over',
: "source-over",
opacity:
layerObj.options?.opacity !== undefined ? layerObj.options?.opacity : 1,
bypassDNA:
layerObj.options?.bypassDNA !== undefined
? layerObj.options?.bypassDNA
: false,
: false
}));
return layers;
};
8 changes: 4 additions & 4 deletions src/functions/layersSetup/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const layerSetup = require('./index');
const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const layerSetup = require("./index");
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

describe('layerSetup cero', () => {
test('layerSetup', () => {
describe("layerSetup cero", () => {
test("layerSetup", () => {
const resultObjectFile = layerSetup(mockDataInput);
expect(resultObjectFile).toEqual(mockDataOutput);
});
186 changes: 93 additions & 93 deletions src/functions/layersSetup/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const basePath = process.cwd();

const mockDataInput = [
{ name: 'Background' },
{ name: 'Eyeball' },
{ name: 'Eye color' },
{ name: 'Iris' },
{ name: 'Shine' },
{ name: 'Bottom lid' },
{ name: 'Top lid' },
{ name: "Background" },
{ name: "Eyeball" },
{ name: "Eye color" },
{ name: "Iris" },
{ name: "Shine" },
{ name: "Bottom lid" },
{ name: "Top lid" }
];

const mockDataOutput = [
@@ -16,197 +16,197 @@ const mockDataOutput = [
elements: [
{
id: 0,
name: 'Black',
filename: 'Black#1.png',
name: "Black",
filename: "Black#1.png",
path: `${basePath}/layers/Background/Black#1.png`,
weight: 1,
},
weight: 1
}
],
name: 'Background',
blend: 'source-over',
name: "Background",
blend: "source-over",
opacity: 1,
bypassDNA: false,
bypassDNA: false
},
{
id: 1,
elements: [
{
id: 0,
name: 'Red',
filename: 'Red#50.png',
name: "Red",
filename: "Red#50.png",
path: `${basePath}/layers/Eyeball/Red#50.png`,
weight: 50,
weight: 50
},
{
id: 1,
name: 'White',
filename: 'White#50.png',
name: "White",
filename: "White#50.png",
path: `${basePath}/layers/Eyeball/White#50.png`,
weight: 50,
},
weight: 50
}
],
name: 'Eyeball',
blend: 'source-over',
name: "Eyeball",
blend: "source-over",
opacity: 1,
bypassDNA: false,
bypassDNA: false
},
{
id: 2,
elements: [
{
id: 0,
name: 'Cyan',
filename: 'Cyan#1.png',
name: "Cyan",
filename: "Cyan#1.png",
path: `${basePath}/layers/Eye color/Cyan#1.png`,
weight: 1,
weight: 1
},
{
id: 1,
name: 'Green',
filename: 'Green#1.png',
name: "Green",
filename: "Green#1.png",
path: `${basePath}/layers/Eye color/Green#1.png`,
weight: 1,
weight: 1
},
{
id: 2,
name: 'Pink',
filename: 'Pink#1.png',
name: "Pink",
filename: "Pink#1.png",
path: `${basePath}/layers/Eye color/Pink#1.png`,
weight: 1,
weight: 1
},
{
id: 3,
name: 'Purple',
filename: 'Purple#1.png',
name: "Purple",
filename: "Purple#1.png",
path: `${basePath}/layers/Eye color/Purple#1.png`,
weight: 1,
weight: 1
},
{
id: 4,
name: 'Red',
filename: 'Red#1.png',
name: "Red",
filename: "Red#1.png",
path: `${basePath}/layers/Eye color/Red#1.png`,
weight: 1,
weight: 1
},
{
id: 5,
name: 'Yellow',
filename: 'Yellow#10.png',
name: "Yellow",
filename: "Yellow#10.png",
path: `${basePath}/layers/Eye color/Yellow#10.png`,
weight: 10,
},
weight: 10
}
],
name: 'Eye color',
blend: 'source-over',
name: "Eye color",
blend: "source-over",
opacity: 1,
bypassDNA: false,
bypassDNA: false
},
{
id: 3,
elements: [
{
id: 0,
name: 'Large',
filename: 'Large#20.png',
name: "Large",
filename: "Large#20.png",
path: `${basePath}/layers/Iris/Large#20.png`,
weight: 20,
weight: 20
},
{
id: 1,
name: 'Medium',
filename: 'Medium#20.png',
name: "Medium",
filename: "Medium#20.png",
path: `${basePath}/layers/Iris/Medium#20.png`,
weight: 20,
weight: 20
},
{
id: 2,
name: 'Small',
filename: 'Small#60.png',
name: "Small",
filename: "Small#60.png",
path: `${basePath}/layers/Iris/Small#60.png`,
weight: 60,
},
weight: 60
}
],
name: 'Iris',
blend: 'source-over',
name: "Iris",
blend: "source-over",
opacity: 1,
bypassDNA: false,
bypassDNA: false
},
{
id: 4,
elements: [
{
id: 0,
name: 'Shapes',
filename: 'Shapes#100.png',
name: "Shapes",
filename: "Shapes#100.png",
path: `${basePath}/layers/Shine/Shapes#100.png`,
weight: 100,
},
weight: 100
}
],
name: 'Shine',
blend: 'source-over',
name: "Shine",
blend: "source-over",
opacity: 1,
bypassDNA: false,
bypassDNA: false
},
{
id: 5,
elements: [
{
id: 0,
name: 'High',
filename: 'High#20.png',
name: "High",
filename: "High#20.png",
path: `${basePath}/layers/Bottom lid/High#20.png`,
weight: 20,
weight: 20
},
{
id: 1,
name: 'Low',
filename: 'Low#40.png',
name: "Low",
filename: "Low#40.png",
path: `${basePath}/layers/Bottom lid/Low#40.png`,
weight: 40,
weight: 40
},
{
id: 2,
name: 'Middle',
filename: 'Middle#40.png',
name: "Middle",
filename: "Middle#40.png",
path: `${basePath}/layers/Bottom lid/Middle#40.png`,
weight: 40,
},
weight: 40
}
],
name: 'Bottom lid',
blend: 'source-over',
name: "Bottom lid",
blend: "source-over",
opacity: 1,
bypassDNA: false,
bypassDNA: false
},
{
id: 6,
elements: [
{
id: 0,
name: 'High',
filename: 'High#30.png',
name: "High",
filename: "High#30.png",
path: `${basePath}/layers/Top lid/High#30.png`,
weight: 30,
weight: 30
},
{
id: 1,
name: 'Low',
filename: 'Low#20.png',
name: "Low",
filename: "Low#20.png",
path: `${basePath}/layers/Top lid/Low#20.png`,
weight: 20,
weight: 20
},
{
id: 2,
name: 'Middle',
filename: 'Middle#50.png',
name: "Middle",
filename: "Middle#50.png",
path: `${basePath}/layers/Top lid/Middle#50.png`,
weight: 50,
},
weight: 50
}
],
name: 'Top lid',
blend: 'source-over',
name: "Top lid",
blend: "source-over",
opacity: 1,
bypassDNA: false,
},
bypassDNA: false
}
];

module.exports.mockDataInput = mockDataInput;
2 changes: 1 addition & 1 deletion src/functions/removeQueryStrings/index.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
*/
const removeQueryStrings = (_dna) => {
const query = /(\?.*$)/;
return _dna.replace(query, '');
return _dna.replace(query, "");
};

module.exports = removeQueryStrings;
12 changes: 4 additions & 8 deletions src/functions/removeQueryStrings/index.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const basePath = process.cwd();
const buildDir = `${basePath}/build`;
const fs = require('fs');
const { mockDataInput, mockDataOutput } = require("./inputOutputData.js");

const { mockDataInput, mockDataOutput } = require('./inputOutputData.js');
const removeQueryString = require("./index");

const removeQueryString = require('./index');

describe('removeQueryString cero', () => {
test('removeQueryString', () => {
describe("removeQueryString cero", () => {
test("removeQueryString", () => {
const resultFileNameWithoutOptions = removeQueryString(mockDataInput);
expect(resultFileNameWithoutOptions).toStrictEqual(mockDataOutput);
});
4 changes: 2 additions & 2 deletions src/functions/removeQueryStrings/inputOutputData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mockDataInput = '0:Black#1.png?setting=value';
const mockDataOutput = '0:Black#1.png';
const mockDataInput = "0:Black#1.png?setting=value";
const mockDataOutput = "0:Black#1.png";
module.exports.mockDataInput = mockDataInput;
module.exports.mockDataOutput = mockDataOutput;
4 changes: 2 additions & 2 deletions src/functions/saveImage/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const basePath = process.cwd();
const buildDir = `${basePath}/build`;
const fs = require('fs');
const fs = require("fs");

const saveImage = (_editionCount, canvas) => {
fs.writeFileSync(
`${buildDir}/images/${_editionCount}.png`,
canvas.toBuffer('image/png')
canvas.toBuffer("image/png")
);
};

9 changes: 0 additions & 9 deletions src/functions/shuffle/index.test.js

This file was deleted.

22 changes: 10 additions & 12 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const basePath = process.cwd();
const { NETWORK } = require(`${basePath}/constants/network.js`);
const fs = require('fs');
const fs = require("fs");
const sha1 = require(`${basePath}/node_modules/sha1`);
const { createCanvas, loadImage } = require(`${basePath}/node_modules/canvas`);
const buildDir = `${basePath}/build`;
const layersDir = `${basePath}/layers`;

// functions
const getAbstractedIndexes = require(`${basePath}/src/functions/getAbstractedIndexes`);
@@ -30,18 +29,17 @@ const {
debugLogs,
text,
network,
gif,
gif
} = require(`${basePath}/src/config.js`);
const HashlipsGiffer = require(`${basePath}/modules/HashlipsGiffer.js`);

const canvas = createCanvas(format.width, format.height);
const ctx = canvas.getContext('2d');
const ctx = canvas.getContext("2d");
ctx.imageSmoothingEnabled = format.smoothing;

const metadataList = [];
let attributesList = [];
const attributesList = [];
const dnaList = new Set();
const DNA_DELIMITER = '-';

let hashlipsGiffer = null;

@@ -62,11 +60,11 @@ const loadLayerImg = async (_layer) => {
const image = await loadImage(`${_layer.selectedElement.path}`);
return { layer: _layer, loadedImage: image };
} catch (error) {
console.error('Error loading image:', error);
console.error("Error loading image:", error);
}
};

const isDnaUnique = (_DnaList = new Set(), _dna = '') => {
const isDnaUnique = (_DnaList = new Set(), _dna = "") => {
const _filteredDNA = filterDNAOptions(_dna);
return !_DnaList.has(_filteredDNA);
};
@@ -95,7 +93,7 @@ const startCreating = async () => {
abstractedIndexes = shuffle(abstractedIndexes);
}

debugLogs && console.log('Editions left to create: ', abstractedIndexes);
debugLogs && console.log("Editions left to create: ", abstractedIndexes);

while (layerConfigIndex < layerConfigurations.length) {
const layers = layersSetup(
@@ -117,7 +115,7 @@ const startCreating = async () => {
});

await Promise.all(loadedElements).then((renderObjectArray) => {
debugLogs && console.log('Clearing canvas');
debugLogs && console.log("Clearing canvas");
ctx.clearRect(0, 0, format.width, format.height);
if (gif.export) {
hashlipsGiffer = new HashlipsGiffer(
@@ -158,7 +156,7 @@ const startCreating = async () => {
hashlipsGiffer.add();
}
debugLogs &&
console.log('Editions left to create: ', abstractedIndexes);
console.log("Editions left to create: ", abstractedIndexes);
saveImage(abstractedIndexes[0], canvas);
const copyMetadaList = metadataList;
const copyAttributesList = attributesList;
@@ -183,7 +181,7 @@ const startCreating = async () => {
editionCount++;
abstractedIndexes.shift();
} else {
console.log('DNA exists!');
console.log("DNA exists!");
failedCount++;
if (failedCount >= uniqueDnaTorrance) {
console.log(