update.js 1.6 KB

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