tettusud / merge-jsons-webpack-plugin

This plugin is used to merge json files into single json file,using glob or file names
https://npmjs.com/package/merge-jsons-webpack-plugin
Apache License 2.0
36 stars 20 forks source link

Deep merge with file path #47

Open loginov-rocks opened 5 years ago

loginov-rocks commented 5 years ago

Hello!

Is it possible to do like so:

Your application structure:

/src/app/
|-- catalog
|   |-- catalogItem
|   |   |-- locales
|   |   |   |-- en.json
|   |   |   `-- ru.json
|   |   `-- catalogItem.component.js
|   |-- locales
|   |   |-- en.json
|   |   `-- ru.json
|   `-- catalog.component.js
`-- user
    |-- locales
    |   |-- de.json 
    |   |-- en.json
    |   `-- ru.json
    `-- user.component.js

After using the above gulpfile.js:

/dist/locales/
|-- de.json
|-- en.json
`-- ru.json

The en.json file will look like this:

{
  "catalog": {
    "catalogItem": {
      // contents of `/src/app/catalog/catalogItem/locales/en.json`
    },
    // contents of `/src/app/catalog/locales/en.json`
  },
  "user": {
    // contents of `/src/app/user/locales/en.json`
  }
}

So you can obtain values using dot notation, catalog.catalogItem.headline for example.

Gulp example: https://github.com/loginov-rocks/gulp-locales-bundler/blob/master/src/gulpLocalesBundler.js

loginov-rocks commented 5 years ago

Made a straightforward function FYI: https://github.com/loginov-rocks/locales-bundler/blob/master/src/localesBundler.js#L15-L42

tettusud commented 5 years ago

@loginov-rocks apologies, I was little away from this repo, I will check this .By the way thanks for dropping the suggestion

tettusud commented 5 years ago

@loginov-rocks , a new package 0.0.19 was published, is that something that could help you?