Skip to content

Instantly share code, notes, and snippets.

@lostPixels
Last active October 7, 2022 21:45
Show Gist options
  • Save lostPixels/04eb5edec444e346168989be3f1a8513 to your computer and use it in GitHub Desktop.
Save lostPixels/04eb5edec444e346168989be3f1a8513 to your computer and use it in GitHub Desktop.
const replace = require('replace-in-file');
let files = 'dist/main.js'; //Add your sketch file here.
let from = [ //Add your keywords that you want to replace here!
/grainHigh/g,
/grainLow/g,
/shadowColor/g,
]
const alpha = Array.from(Array(26)).map((e, i) => i + 65);
const alphabet = alpha.map((x) => String.fromCharCode(x));
let to = [];
let letterCount = 0;
let letterStep = 0;
for (let i = 0; i < from.length; i++) {
let lt = alphabet[letterStep] + letterCount;
to.push(lt);
letterCount++;
if (letterCount > 9) {
letterCount = 0;
letterStep++;
}
}
const options = {
files,
from,
to,
};
replace(options)
.then(results => {
console.log('Replacement results:', results);
})
.catch(error => {
console.error('Error occurred:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment