update.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 + '/_config.yml'
  7. var config = fs.readFileSync(configPath, 'utf-8')
  8. var version = require(uppyRoot + '/package.json').version
  9. // Inject current Uppy version and sizes in website's _config.yml
  10. var sizes = {}
  11. var locations = {
  12. min: uppyRoot + '/dist/uppy.js',
  13. gz : uppyRoot + '/dist/uppy.js',
  14. dev: uppyRoot + '/dist/uppy.js',
  15. css: uppyRoot + '/dist/uppy.css'
  16. }
  17. // @todo: ^-- Refer to actual minified builds in dist:
  18. for (var file in locations) {
  19. var filesize = fs.statSync(locations[file], 'utf-8').size
  20. sizes[file] = (filesize / 1024).toFixed(2)
  21. }
  22. fs.writeFileSync(
  23. configPath,
  24. config
  25. .replace(/uppy_version: .*/, 'uppy_version: ' + version)
  26. .replace(/uppy_(\w+)_size:.*/g, function (m, p1) {
  27. return 'uppy_' + p1 + '_size: "' + (sizes[p1] || 99999) + '"'
  28. })
  29. )
  30. var exec = require('child_process').exec
  31. exec('cp -fR ' + uppyRoot + '/dist/ ' + webRoot + '/themes/uppy/source/uppy', function (error, stdout, stderr) {
  32. if (error) {
  33. console.error(
  34. chalk.red('x failed to inject: '),
  35. chalk.dim('uppy umd build into site, because: ' + error)
  36. )
  37. return
  38. }
  39. console.info(chalk.green('✓ injected: '), chalk.dim('uppy umd build into site'))
  40. })