CheckSourceHeader.hx 921 B

1234567891011121314151617181920212223242526272829303132333435
  1. final FILE = "main.js";
  2. function main() {
  3. final args = Sys.args();
  4. switch args {
  5. case [""]:
  6. checkForEmptySourceHeader(FILE);
  7. case [expected]:
  8. checkSourceHeader(FILE, expected);
  9. case _:
  10. Tools.exitWithError("Incorrect number of arguments to script.");
  11. }
  12. Tools.exit(0);
  13. }
  14. function checkForEmptySourceHeader(path:String) {
  15. final content = getJsSourceContent(path);
  16. if (StringTools.startsWith(content, "// "))
  17. Tools.exitWithError("File has a source header when none was expected: " + content.split("\n")[0]);
  18. }
  19. function checkSourceHeader(path:String, expected:String) {
  20. final content = getJsSourceContent(path);
  21. if (!StringTools.startsWith(content, "// " + expected))
  22. Tools.exitWithError("File source header does not start with expected: // " + expected +
  23. "\nSource header: " + content.split("\n")[0]);
  24. }
  25. function getJsSourceContent(path:String) {
  26. return sys.io.File.getContent(path);
  27. }