1
0

updateVersionPlugin.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var fs = require('fs');
  2. var path = require('path');
  3. function processDate () {
  4. var date = new Date();
  5. var day = date.getUTCDate();
  6. day = day > 9 ? day : '0' + day;
  7. var month = date.getMonth() + 1;
  8. month = month > 9 ? month : '0' + month;
  9. var minutes = date.getMinutes();
  10. minutes = minutes > 9 ? minutes : '0' + minutes;
  11. var hour = date.getHours();
  12. hour = hour > 9 ? hour : '0' + hour;
  13. return {
  14. year: date.getFullYear(),
  15. month: month,
  16. day: day,
  17. hour: hour,
  18. minutes: minutes
  19. }
  20. }
  21. function writeVersionFile () {
  22. var versionInfo = processDate();
  23. var versionString = `${versionInfo.year}_${versionInfo.month}_${versionInfo.day} ${versionInfo.hour}_${versionInfo.minutes}`;
  24. var fileData = `{ "version":"${versionString}" }`;
  25. var filePath = path.join(__dirname, '.ima_version.json');
  26. fs.writeFileSync(filePath, fileData);
  27. }
  28. function UpdateVersionPlugin () { }
  29. UpdateVersionPlugin.prototype.apply = function (compiler) {
  30. compiler.hooks.beforeCompile.tap("UpdateVersionPlugin", function() {
  31. writeVersionFile();
  32. });
  33. }
  34. module.exports = UpdateVersionPlugin;