Skip to content

Instantly share code, notes, and snippets.

@framp
Created December 19, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save framp/9fdc0753c7a08a3048ca92c5ade1c3e5 to your computer and use it in GitHub Desktop.
Save framp/9fdc0753c7a08a3048ca92c5ade1c3e5 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const TARGET_FILE = './src/config.tsx';
const file = fs.readFileSync(TARGET_FILE).toString();
const lines = file.split('\n');
const start = lines.findIndex(l => l === '// KEYS');
const end = lines.findIndex(l => l === '// \\ KEYS');
const constants = lines.slice(start, end).map((l, i) => l.replace(/".*"/, `"${i.toString(36)}"`));
lines.splice(start, end-start, ...constants);
fs.writeFileSync(TARGET_FILE, lines.join('\n'));
/*
Take a file containing:
// KEYS
export const LOL = 'lol',
export const ASD = 'asd',
export const GIF = 'gif',
...
export const LMAO = 'lmao',
export const ROTFL = 'rotfl',
// \ KEYS
and replace the block with
// KEYS
export const LOL = '0',
export const ASD = '1',
export const GIF = '2',
...
export const LMAO = 'a',
export const ROTFL = 'b',
// \ KEYS
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment