update-package-jsons.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. ]
  15. exec([ path.join(__dirname, 'require-clean-working-tree.sh') ])
  16. let mainConfig = require('../package.json')
  17. let premiumConfig = require('../packages-premium/package.json')
  18. let configPaths = []
  19. let subjectStructs = publicPackageStructs.concat(bundleStructs)
  20. for (let struct of subjectStructs) {
  21. let configPath = path.join(__dirname, '..', struct.dir, 'package.json')
  22. let config = require(configPath)
  23. for (let propName of PROPS_TO_COPY) {
  24. if (propName in mainConfig) {
  25. config[propName] = mainConfig[propName]
  26. }
  27. if (struct.isPremium && (propName in premiumConfig)) {
  28. config[propName] = premiumConfig[propName]
  29. }
  30. }
  31. writeFileSync(configPath, JSON.stringify(config, null, ' ') + '\n')
  32. configPaths.push(configPath)
  33. }
  34. for (let configPath of configPaths) {
  35. exec(
  36. [ 'git', 'add', path.basename(configPath) ],
  37. { cwd: path.dirname(configPath) } // will do it in whatever git repo
  38. )
  39. }
  40. exec([ 'git', 'commit', '-m', 'updated package.jsons' ], { cwd: path.join(__dirname, '../packages-premium') })
  41. exec([ 'git', 'add', 'packages-premium' ], { cwd: path.join(__dirname, '..') })
  42. exec([ 'git', 'commit', '-m', 'updated package.jsons' ], { cwd: path.join(__dirname, '..') })