update.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_anchor: "001"\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_anchor: .*/, 'uppy_version_anchor: "' + version.replace(/[^\d]+/g, '') + '"')
  34. .replace(/uppy_version: .*/, 'uppy_version: "' + version + '"')
  35. .replace(/uppy_(\w+)_size:.*/g, function (m, p1) {
  36. return 'uppy_' + p1 + '_size: "' + (sizes[p1] || 99999) + '"'
  37. })
  38. )
  39. var exec = require('child_process').exec
  40. exec('cp -fR ' + uppyRoot + '/dist/ ' + webRoot + '/themes/uppy/source/uppy', function (error, stdout, stderr) {
  41. if (error) {
  42. console.error(
  43. chalk.red('x failed to inject: '),
  44. chalk.dim('uppy bundle into site, because: ' + error)
  45. )
  46. return
  47. }
  48. console.info(chalk.green('✓ injected: '), chalk.dim('uppy bundle into site'))
  49. })