Created
August 28, 2019 22:53
-
-
Save xNok/b28fd575c87405baabed76fb127295cd to your computer and use it in GitHub Desktop.
prepare json file to configure slideshow from all the png in a folder
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
var fs = require('fs'); | |
// command usage validation | |
if (process.argv.length <= 3) { | |
console.log("Usage: " + __filename + " path/to/directory path/to/output"); | |
process.exit(-1); | |
} | |
var path = process.argv[2]; | |
var output = process.argv[3]; | |
var panels = { | |
list: [] | |
}; | |
fs.readdir(path, function(err, items) { | |
// list all file in folder | |
for (var i=0; i<items.length; i++) { | |
console.log(items[i]) | |
panels.list.push({ name: items[i] }) | |
} | |
// create json | |
var json = JSON.stringify(panels, null, 4); | |
// print json to output | |
fs.writeFile(output, json, (err) => { | |
if (err) throw err; | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment