verify.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const fs = require('fs');
  2. // Parse package.json
  3. const packageFile = './package.json';
  4. const packageText = fs.readFileSync(packageFile, 'utf8');
  5. const packageJson = JSON.parse(packageText);
  6. const packageVersion = packageJson.version;
  7. // Check for preview.html
  8. const previewFile = './preview.html';
  9. if (!fs.existsSync(previewFile)) {
  10. throw new Error('Error: preview.html must exist!');
  11. }
  12. const previewText = fs.readFileSync(previewFile, 'utf8');
  13. const parts = previewText.match(/<span class="version">([^<]+)<\/span>/);
  14. if (parts === null) {
  15. // Did you modify preview.html file ???
  16. throw new Error('Error: preview.html version string not found!');
  17. }
  18. // Never include a index.html file!
  19. const indexFile = './index.html';
  20. if (fs.existsSync(indexFile)) {
  21. throw new Error('Error: index.html should not exist, only preview.html');
  22. }
  23. const previewVersion = parts[1];
  24. if (packageVersion != previewVersion) {
  25. // Not good, almost published the wrong version
  26. throw new Error(`Error: package "${packageVersion}" != preview.html "${previewVersion}"`);
  27. }
  28. // Verify SCSS Version
  29. const scssVariablesFile = './scss/_variables.scss';
  30. const scssVariablesText = fs.readFileSync(scssVariablesFile, 'utf8');
  31. const vParts = scssVariablesText.match(/"(\d+).(\d+).(\d+)" !default;/);
  32. if (vParts === null) {
  33. throw new Error('Error: Could not parse SCSS version!');
  34. }
  35. const scssVersion = `${vParts[1]}.${vParts[2]}.${vParts[3]}`;
  36. if (packageVersion != scssVersion) {
  37. // Not good, almost published the wrong version
  38. throw new Error(`Error: package "${packageVersion}" != scss/variables.scss "${previewVersion}"`);
  39. }
  40. console.log(`Success: ${packageVersion} looks good!`);