Skip to content

Instantly share code, notes, and snippets.

@xNok
Created August 28, 2019 22:53
Show Gist options
  • Save xNok/b28fd575c87405baabed76fb127295cd to your computer and use it in GitHub Desktop.
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
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