_input.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const fs = require('fs')
  2. const treeUri = './json/tree.json'
  3. const modelUri = './json/request.json'
  4. const inputUri = './json/input.json'
  5. const _done = () => {
  6. const model = _getModelObj()
  7. const tree = _getConfigTree()
  8. const DATA = _converObj(model['DATA'], tree['DATA'])
  9. const input = {
  10. DATA
  11. }
  12. fs.writeFileSync(inputUri, JSON.stringify(input))
  13. }
  14. const _getConfigTree = () => {
  15. return JSON.parse(fs.readFileSync(treeUri))
  16. }
  17. const _getModelObj = () => {
  18. return JSON.parse(fs.readFileSync(modelUri))
  19. }
  20. const _converObj = (model, tree) => {
  21. const tmp = {}
  22. for(const key in tree) {
  23. if(key === '_config' || key === '_key') {
  24. continue
  25. }
  26. const config = tree[key]
  27. const _config = config['_config']
  28. const type = _config['type']
  29. const mKey = _config['mKey']
  30. if(type === 'object') {
  31. tmp[mKey] = _converObj(model[key], tree[key])
  32. } else if(type === 'Array') {
  33. tmp[mKey] = _converArray(model[key], tree[key])
  34. } else {
  35. tmp[mKey] = model[key]
  36. }
  37. }
  38. return tmp
  39. }
  40. const _converArray = (models, tree) => {
  41. const tmps = []
  42. for(const model of models) {
  43. tmps.push(_converObj(model, tree))
  44. }
  45. return tmps;
  46. }
  47. _done()