update-package-jsons.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const path = require('path')
  2. const { writeFileSync } = require('./lib/util')
  3. const { publicPackageStructs, bundleStructs } = require('./lib/package-index')
  4. const exec = require('./lib/shell').sync.withOptions({
  5. exitOnError: true,
  6. live: true
  7. })
  8. const PROPS_TO_COPY = [
  9. 'homepage',
  10. 'bugs',
  11. 'repository',
  12. 'license',
  13. 'author',
  14. 'copyright'
  15. ]
  16. exec([ path.join(__dirname, 'require-clean-working-tree.sh') ])
  17. let mainConfig = require('../package.json')
  18. let premiumConfig = require('../packages-premium/package.json')
  19. let configPaths = []
  20. let subjectStructs = publicPackageStructs.concat(bundleStructs)
  21. for (let struct of subjectStructs) {
  22. let configPath = path.join(__dirname, '..', struct.dir, 'package.json')
  23. let config = require(configPath)
  24. for (let propName of PROPS_TO_COPY) {
  25. if (propName in mainConfig) {
  26. config[propName] = mainConfig[propName]
  27. }
  28. if (struct.isPremium && (propName in premiumConfig)) {
  29. config[propName] = premiumConfig[propName]
  30. }
  31. }
  32. writeFileSync(configPath, JSON.stringify(config, null, ' ') + '\n')
  33. configPaths.push(configPath)
  34. }
  35. for (let configPath of configPaths) {
  36. exec(
  37. [ 'git', 'add', path.basename(configPath) ],
  38. { cwd: path.dirname(configPath) } // will do it in whatever git repo
  39. )
  40. }
  41. exec([ 'git', 'commit', '-m', 'updated package.jsons' ], { cwd: path.join(__dirname, '../packages-premium') })
  42. exec([ 'git', 'add', 'packages-premium' ], { cwd: path.join(__dirname, '..') })
  43. exec([ 'git', 'commit', '-m', 'updated package.jsons' ], { cwd: path.join(__dirname, '..') })