update.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var fs = require('fs')
  2. var path = require('path')
  3. var chalk = require('chalk')
  4. var webRoot = __dirname
  5. var uppyRoot = path.dirname(__dirname)
  6. var configPath = webRoot + '/themes/uppy/_config.yml'
  7. var version = require(uppyRoot + '/package.json').version
  8. var config
  9. try {
  10. config = fs.readFileSync(configPath, 'utf-8')
  11. } catch (e) {
  12. config = '# Uppy versions, auto updated by update.js\nuppy_version: 0.0.1\n\nuppy_dev_size: "0.0"\nuppy_min_size: "0.0"\nuppy_gz_size: "0.0"'
  13. }
  14. // Inject current Uppy version and sizes in website's _config.yml
  15. var sizes = {}
  16. var locations = {
  17. min: uppyRoot + '/dist/uppy.js',
  18. gz: uppyRoot + '/dist/uppy.js',
  19. dev: uppyRoot + '/dist/uppy.js',
  20. css: uppyRoot + '/dist/uppy.css'
  21. }
  22. // @todo: ^-- Refer to actual minified builds in dist:
  23. for (var file in locations) {
  24. var filesize = fs.statSync(locations[file], 'utf-8').size
  25. sizes[file] = (filesize / 1024).toFixed(2)
  26. }
  27. fs.writeFileSync(
  28. configPath,
  29. config
  30. .replace(/uppy_version: .*/, 'uppy_version: ' + version)
  31. .replace(/uppy_(\w+)_size:.*/g, function (m, p1) {
  32. return 'uppy_' + p1 + '_size: "' + (sizes[p1] || 99999) + '"'
  33. })
  34. )
  35. var exec = require('child_process').exec
  36. exec('cp -fR ' + uppyRoot + '/dist/ ' + webRoot + '/themes/uppy/source/uppy', function (error, stdout, stderr) {
  37. if (error) {
  38. console.error(
  39. chalk.red('x failed to inject: '),
  40. chalk.dim('uppy umd build into site, because: ' + error)
  41. )
  42. return
  43. }
  44. console.info(chalk.green('✓ injected: '), chalk.dim('uppy umd build into site'))
  45. })