@@ -4,15 +4,6 @@ module.exports = function(grunt) {
44 // Project configuration.
55 grunt . initConfig ( {
66 pkg : grunt . file . readJSON ( 'package.json' ) ,
7- "merge-json" : {
8- en : {
9- src : [
10- 'routes/lang/en-application.json' ,
11- 'frontend/src/**/lang/en.json'
12- ] ,
13- dest : 'routes/lang/en.json'
14- }
15- } ,
167 copy : {
178 main : {
189 files : [
@@ -194,7 +185,7 @@ module.exports = function(grunt) {
194185 } ,
195186 lang : {
196187 files : [ 'routes/lang/*.json' ] ,
197- tasks : [ 'merge -json' ]
188+ tasks : [ 'generate-lang -json' ]
198189 }
199190 } ,
200191 mochaTest : {
@@ -251,7 +242,7 @@ module.exports = function(grunt) {
251242 grunt . file . write ( configFile , JSON . stringify ( config , null , 2 ) ) ;
252243 // run the tasks
253244 var compilation = ( config . isProduction ) ? 'compile' : 'dev' ;
254- grunt . task . run ( [ 'requireBundle' , 'merge -json' , 'copy' , 'less:' + compilation , 'handlebars' , 'requirejs:' + compilation ] ) ;
245+ grunt . task . run ( [ 'requireBundle' , 'generate-lang -json' , 'copy' , 'less:' + compilation , 'handlebars' , 'requirejs:' + compilation ] ) ;
255246 } ) ;
256247
257248 grunt . registerTask ( 'server' , "Running Server" , function ( ) {
@@ -346,7 +337,34 @@ module.exports = function(grunt) {
346337 done ( ) ;
347338 }
348339 } ) ;
340+ // TODO should probably have config up there ^
341+ grunt . registerTask ( 'generate-lang-json' , function ( ) {
342+ var _ = require ( 'underscore' ) ;
343+ var fs = require ( 'fs-extra' ) ;
344+ var path = require ( 'path' ) ;
345+
346+ var langFileExt = '.json' ;
347+ var backendSrc = path . join ( 'routes' , 'lang' , '*' + langFileExt ) ;
348+ var frontendSrc = path . join ( 'frontend' , 'src' , '**' , 'lang' ) ;
349+ var dest = path . join ( 'temp' , 'lang' ) ;
350+ // load each route lang file
351+ /**
352+ * NOTE there must be a file in routes/lang for the language to be loaded,
353+ * won't work if you've only got lang files in frontend
354+ */
355+ grunt . file . expand ( { } , backendSrc ) . forEach ( function ( filePath ) {
356+ var lang = path . basename ( filePath , langFileExt ) ;
357+ var data = _ . extend ( { } , fs . readJSONSync ( filePath ) ) ;
358+ // load all matching frontend lang files
359+ grunt . file . expand ( { } , path . join ( frontendSrc , lang + langFileExt ) ) . forEach ( function ( filePath2 ) {
360+ // TODO check for duplicates
361+ _ . extend ( data , fs . readJSONSync ( filePath2 ) ) ;
362+ } ) ;
363+ fs . ensureDirSync ( dest ) ;
364+ fs . writeJSONSync ( path . join ( dest , lang + langFileExt ) , data , { spaces : 2 } ) ;
365+ } ) ;
366+ } ) ;
349367
350368 grunt . registerTask ( 'test' , [ 'mochaTest' ] ) ;
351- grunt . registerTask ( 'default' , [ 'merge -json' , 'requireBundle' , 'less:dev' , 'handlebars' , 'watch' ] ) ;
369+ grunt . registerTask ( 'default' , [ 'generate-lang -json' , 'requireBundle' , 'less:dev' , 'handlebars' , 'watch' ] ) ;
352370} ;
0 commit comments