Created
February 20, 2019 18:48
-
-
Save bronzehedwick/c84d2bc3239f42156dca31c3db554f4c to your computer and use it in GitHub Desktop.
Small node script to generate a markdown file with every character mentioned in a .fountain script file
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
#!/usr/local/bin/node | |
/* eslint-env node, es6 */ | |
const fs = require('fs'); | |
const file = process.argv[2]; | |
const path = require('path'); | |
const lineReader = require('readline').createInterface({ | |
input: fs.createReadStream(file) | |
}); | |
let characters = new Map(); | |
function isUpperCase(str) { | |
return str === str.toUpperCase(); | |
} | |
function stripExtraTags(str) { | |
let newStr = str.replace('(O.S.)', ''); | |
newStr = newStr.replace('^', ''); | |
newStr = newStr.replace('(PHONE)', ''); | |
newStr = newStr.replace('\*', ''); | |
return newStr.trim(); | |
} | |
function isACharacter(str) { | |
if (!str) return false; | |
if (str.startsWith('INT.')) return false; | |
if (str.startsWith('EXT.')) return false; | |
if (str.startsWith('>')) return false; | |
if (str.startsWith('=')) return false; | |
if (str.indexOf('.') !== -1) return false; | |
if (str.indexOf('!') !== -1) return false; | |
if (str.indexOf('THEME') !== -1) return false; | |
if (str.indexOf('CREDITS') !== -1) return false; | |
return true; | |
} | |
lineReader.on('line', function readLine(line) { | |
if (isUpperCase(line) && isACharacter(line)) { | |
characters.set(stripExtraTags(line), stripExtraTags(line)); | |
} | |
}); | |
lineReader.on('close', function close() { | |
const fileDirectory = path.dirname(file); | |
let contents = '# Characters\n\n'; | |
let i = 1; | |
characters.forEach(item => { | |
contents += i + '. ' + item + '\n'; | |
i++; | |
}); | |
fs.writeFile(fileDirectory + '/Characters.md', contents, function writeFile(err) { | |
if (err) { | |
return console.error(err); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment