@@ -4,13 +4,14 @@ 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'
7+ 'generate-lang-json' : {
8+ options : {
9+ langFileExt : '.json' ,
10+ src : {
11+ backend : 'routes/lang' ,
12+ frontend : 'frontend/src/**/lang'
13+ } ,
14+ dest : 'temp/lang'
1415 }
1516 } ,
1617 copy : {
@@ -269,6 +270,30 @@ module.exports = function(grunt) {
269270 done ( ) ;
270271 }
271272 } ) ;
273+ grunt . registerTask ( 'generate-lang-json' , function ( ) {
274+ const fs = require ( 'fs-extra' ) ;
275+ const path = require ( 'path' ) ;
276+
277+ const options = this . options ( ) ;
278+ const backendGlob = path . join ( options . src . backend , `*${ options . langFileExt } ` ) ;
279+ const dest = options . dest ;
280+ // load each route lang file
281+ /**
282+ * NOTE there must be a file in routes/lang for the language to be loaded,
283+ * won't work if you've only got lang files in frontend
284+ */
285+ grunt . file . expand ( { } , path . join ( backendGlob ) ) . forEach ( backendPath => {
286+ const basename = path . basename ( backendPath ) ;
287+ const frontendGlob = path . join ( options . src . frontend , basename ) ;
288+ let data = { ...fs . readJSONSync ( backendPath ) } ;
289+ // load all matching frontend lang files
290+ grunt . file . expand ( { } , frontendGlob ) . forEach ( frontendPath => {
291+ data = { ...data , ...fs . readJSONSync ( frontendPath ) } ;
292+ } ) ;
293+ fs . ensureDirSync ( dest ) ;
294+ fs . writeJSONSync ( path . join ( dest , basename ) , data , { spaces : 2 } ) ;
295+ } ) ;
296+ } ) ;
272297
273298 grunt . registerTask ( 'default' , [ 'build:dev' ] ) ;
274299 grunt . registerTask ( 'test' , [ 'mochaTest' ] ) ;
@@ -290,7 +315,7 @@ module.exports = function(grunt) {
290315 config . isProduction = isProduction ;
291316 grunt . file . write ( configFile , JSON . stringify ( config , null , 2 ) ) ;
292317 // run the task
293- grunt . task . run ( [ 'migration-conf' , 'requireBundle' , 'merge -json' , 'copy' , 'less:' + compilation , 'handlebars' , 'requirejs:' + compilation ] ) ;
318+ grunt . task . run ( [ 'migration-conf' , 'requireBundle' , 'generate-lang -json' , 'copy' , 'less:' + compilation , 'handlebars' , 'requirejs:' + compilation ] ) ;
294319
295320 } catch ( e ) {
296321 grunt . task . run ( [ 'requireBundle' , 'copy' , 'less:' + compilation , 'handlebars' , 'requirejs:' + compilation ] ) ;
0 commit comments