Last active
August 29, 2015 14:08
-
-
Save d48/f163e6508ca5d2883984 to your computer and use it in GitHub Desktop.
Creating bundles for culture files via Node.js
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
// get native file system object | |
var fs = require('fs') | |
// get a template | |
, template = fs.readFileSync('./template.txt', 'utf8') | |
// read files from a directory called '/cultures' for file names, specifically language tag, e.g., 'en-US' or 'fr-FR' | |
, filesInDir = fs.readdirSync('./cultures/') | |
// create file handle to output to | |
, stream = fs.createWriteStream('./bundles.txt') | |
, tempBundle | |
, value | |
, reg | |
; | |
stream.once('open', function(fd) { | |
// iterate through each file found in the directory | |
filesInDir.map(function(val, key) { | |
// extract just the language tag from file, .e.g 'atlas.culture.en-US.js', just gets 'en-US' | |
value = val.replace('atlas.culture.','').replace('.js',''); | |
// replace string 'languageTag' | |
reg = new RegExp("languageTag", "g") | |
// with value | |
tempBundle = template.replace(reg, value); | |
// output to file | |
stream.write(tempBundle); | |
}); | |
stream.end(); | |
}); |
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
<ScriptBundle> | |
<VirtualPath>~/bundles/libs/atlas/cultures/languageTag/js</VirtualPath> | |
<FilePath>\assets\global\libs\atlas\js\cultures\atlas.culture.languageTag.js</FilePath> | |
<Includes> | |
<Include> | |
<VirtualPath>~/assets/global/libs/atlas/js/cultures/atlas.culture.languageTag.js</VirtualPath> | |
</Include> | |
</Includes> | |
</ScriptBundle> |
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
// sample ScriptBundle block, but 385 of these for each culture file | |
<ScriptBundle> | |
<VirtualPath>~/bundles/libs/atlas/cultures/af-ZA/js</VirtualPath> | |
<FilePath>\assets\global\libs\atlas\js\cultures\atlas.culture.af-ZA.js</FilePath> | |
<Includes> | |
<Include> | |
<VirtualPath>~/assets/global/libs/atlas/js/cultures/atlas.culture.af-ZA.js</VirtualPath> | |
</Include> | |
</Includes> | |
</ScriptBundle> | |
<ScriptBundle> | |
<VirtualPath>~/bundles/libs/atlas/cultures/af/js</VirtualPath> | |
<FilePath>\assets\global\libs\atlas\js\cultures\atlas.culture.af.js</FilePath> | |
<Includes> | |
<Include> | |
<VirtualPath>~/assets/global/libs/atlas/js/cultures/atlas.culture.af.js</VirtualPath> | |
</Include> | |
</Includes> | |
</ScriptBundle> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where culture directory looks like this for 385 files: