Created
January 31, 2018 00:55
-
-
Save Fallenstedt/987d24504578567075ebeec6ca10b8e3 to your computer and use it in GitHub Desktop.
generate n .xlsx files from a source template using a list of names
This file contains hidden or 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
var fs = require('fs'); | |
var XLSX = require('xlsx'); | |
console.log('app starting') | |
const SOURCE = './source/listOfFilesYouWantToGenerate.xlsx'; | |
const QUESTIONS = './source/sourceFileThatNeedsToBeCopiesManyTimes.xlsx'; | |
const TARGET = './vendors'; | |
const sourceFile = XLSX.readFile(SOURCE); | |
const fileNames = Object.keys(sourceFile.Sheets.Approved) | |
.filter((key) => doesStringContainCharacter(key, 'D')) | |
.map(item => { | |
let newFileName = sourceFile.Sheets.Approved[item].v; | |
newFileName = newFileName.replace(/\./g, '-').toLowerCase() | |
newFileName = newFileName.replace('((https://serverless-com/))','') | |
return newFileName | |
}) | |
// TODO check if target directory is empty before copying so you don't fuck up your work | |
// .map(item => copyFile(item)) | |
function copyFile(name) { | |
fs.createReadStream(QUESTIONS).pipe(fs.createWriteStream(TARGET + "/" + name + '.xlsx')); | |
} | |
function doesStringContainCharacter(key, char) { | |
return key.indexOf(char) > -1 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment