Skip to content

Commit

Permalink
provide single template name with better group name
Browse files Browse the repository at this point in the history
  • Loading branch information
denofevil committed Apr 9, 2017
1 parent 97ba1d2 commit b7b9643
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');

function printUsageAndExit() {
console.error("Usage: <input_dir>");
Expand Down Expand Up @@ -63,16 +64,14 @@ function convertSnippet(snippet, context) {
return templateText;
}
function convertFile(input, file) {
console.log(`converting ${file}`);
console.error(`converting ${file}`);
const snippets = JSON.parse(fs.readFileSync(`${input}/${file}`));
let templateSetText = `<templateSet group="${input}">`;
let templates = "";
for (const name of Object.keys(snippets).sort()) {
const snippet = snippets[name];
templateSetText += convertSnippet(snippet, file.substr(0, file.indexOf('.')));
templates += convertSnippet(snippet, file.substr(0, file.indexOf('.')));
}

templateSetText += "\n</templateSet>";
console.log(templateSetText);
return templates;
}

const input = process.argv[2];
Expand All @@ -82,7 +81,11 @@ if (!input) {
}

fs.readdir(input, (err, files) => {
let templateSetText = `<templateSet group="${path.basename(path.dirname(input))}">`;
files.forEach(file => {
convertFile(input, file)
templateSetText += convertFile(input, file)
});
templateSetText += "\n</templateSet>";

console.log(templateSetText);
});

0 comments on commit b7b9643

Please sign in to comment.