update-metadata.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import exec from './exec.js'
  2. export default function()
  3. {
  4. var metadata_changed = exec('git ls-files --modified PhoneNumberMetadata.xml')
  5. if (!metadata_changed)
  6. {
  7. console.log()
  8. console.log('========================================')
  9. console.log('= Metadata is up-to-date. Exiting. =')
  10. console.log('========================================')
  11. console.log()
  12. return
  13. }
  14. console.log()
  15. console.log('========================================')
  16. console.log('= Metadata has changed, updating files =')
  17. console.log('========================================')
  18. console.log()
  19. console.log(exec('npm run metadata:generate'))
  20. console.log()
  21. console.log('========================================')
  22. console.log('= Running tests =')
  23. console.log('========================================')
  24. console.log()
  25. // console.log('* Actually not running tests because if they fail then it won\'t be reported in any way, and if instead tests fail for the Pull Request on github then the repo owner will be notified by Travis CI about that.')
  26. console.log(exec('npm run build'))
  27. console.log(exec('npm test'))
  28. var modified_files = exec('git ls-files --modified').split(/\s/)
  29. var unexpected_modified_files = modified_files.filter(function(file)
  30. {
  31. return file !== 'PhoneNumberMetadata.xml' &&
  32. !/^metadata\.[a-z]+\.json$/.test(file) &&
  33. !/^examples\.[a-z]+\.json$/.test(file)
  34. })
  35. // Turned off this "modified files" check
  36. // because on Windows random files constantly got "modified"
  37. // without actually being modified.
  38. // (perhaps something related to line endings)
  39. if (false && unexpected_modified_files.length > 0)
  40. {
  41. var error
  42. error += 'Only `PhoneNumberMetadata.xml`, `metadata.*.json` and `examples.*.json` files should be modified. Unexpected modified files:'
  43. error += '\n'
  44. error += '\n'
  45. error += unexpected_modified_files.join('\n')
  46. console.log()
  47. console.log('========================================')
  48. console.log('= Error =')
  49. console.log('========================================')
  50. console.log()
  51. console.log(error)
  52. throw new Error(error)
  53. }
  54. // Doesn't work
  55. //
  56. // // http://stackoverflow.com/questions/33610682/git-list-of-staged-files
  57. // var staged_files = exec('git diff --name-only --cached').split(/\s/)
  58. //
  59. // if (staged_files.length > 0)
  60. // {
  61. // console.log()
  62. // console.log('========================================')
  63. // console.log('= Error =')
  64. // console.log('========================================')
  65. // console.log()
  66. // console.log('There are some staged files already. Aborting metadata update process.')
  67. // console.log()
  68. // console.log(staged_files.join('\n'))
  69. //
  70. // process.exit(1)
  71. // }
  72. return true
  73. }