Last active
March 15, 2024 08:59
-
-
Save lostPixels/630dbe4f4fc9e5da549fb85e08b7e896 to your computer and use it in GitHub Desktop.
Automatically make an Artblocks features.json file from features.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 1. Create a features.js script that has one method function calculateFeatures(tokenData) {...}. You will need this for Artblocks anywayz. | |
2. Add this line to the bottom: export default calculateFeatures; | |
3. Copy the contents of this gist into generate-features-json.js | |
4. In your terminal, run node generate-features-json.js. | |
5. The script will take a minute to generate 2,000 outcomes and compile all of the different traits. | |
6. Tada. features.json can be uploaded to Artblocks. | |
**/ | |
import fs from 'fs'; | |
import calculateFeatures from './features.js' | |
const featuresFilename = 'features.json'; | |
console.log('Calculating features...'); | |
let keys = null; | |
let res = [] | |
const indexes = {}; | |
for (let i = 0; i < 2_000; i++) { | |
//random 64 char hex string. | |
const hash = Math.random().toString(16).substr(2, 16) | |
const features = calculateFeatures({ hash }) | |
if (!keys) { | |
keys = Object.keys(features); | |
keys.forEach((key) => { | |
indexes[key] = res.length; | |
res.push({ id: "", name: key, type: "enum", options: [] }); | |
}); | |
} | |
keys.forEach(key => { | |
if (!res[indexes[key]].options.includes(features[key])) { | |
res[indexes[key]].options.push(features[key]); | |
} | |
}); | |
} | |
res = res.map(feature => { | |
if (feature.options.includes(true) && feature.options.includes(false)) { | |
feature.type = "boolean"; | |
} | |
return feature; | |
}); | |
//Save as JSON file | |
fs.writeFileSync(featuresFilename, JSON.stringify(res, null, 2)); | |
console.log(`Saved as ${featuresFilename}.`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment