Mustache-based translations
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
const fs = require('fs'); | |
var exec = require('child_process').exec; | |
const DATA = 'data/'; | |
const TEMPLATES = 'templates/'; | |
const OUTPUT = 'build/'; | |
// Retrieve language from args | |
const args = process.argv.slice(2); | |
const lang = args[0]; | |
if (!lang || lang == "") { | |
console.error('No language specified'); | |
process.exit(1); | |
} | |
// Check for corresponding data file | |
const dataFile = DATA + lang + '.json'; | |
if (!fs.existsSync(dataFile)) { | |
console.error('Data file for "' + lang + '" not found in data directory'); | |
process.exit(1); | |
} | |
// Run mustache for perform replacements | |
// Once per file in the templates directory | |
fs.readdir(TEMPLATES, (err, files) => { | |
if (err) { | |
console.error("Unable to access data directory", err); | |
process.exit(1); | |
} | |
files.forEach((file, index) => { | |
const templateFile = TEMPLATES + file; | |
const outputFile = OUTPUT + file; | |
exec(`mustache ${dataFile} ${templateFile} > ${outputFile}`, (err) => { | |
if (err) { | |
console.error('Unable to run mustache on template', err); | |
process.exit(1); | |
} | |
console.log(`Processed ${templateFile} to ${outputFile}`); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment