diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2021-12-25 02:03:26 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2021-12-25 02:03:26 +0800 |
commit | d1d0dc3d76be997467c3f0511a41fb5771a1a11f (patch) | |
tree | 91711ba387bbf2025c5f3233bb2d880eaf3ed5f2 /CI | |
parent | 7c3f3d49243896f35ac11209466d9e017cff92b0 (diff) | |
download | SoopyV2-d1d0dc3d76be997467c3f0511a41fb5771a1a11f.tar.gz SoopyV2-d1d0dc3d76be997467c3f0511a41fb5771a1a11f.tar.bz2 SoopyV2-d1d0dc3d76be997467c3f0511a41fb5771a1a11f.zip |
finish first version of CI
Diffstat (limited to 'CI')
-rw-r--r-- | CI/supporttest.js | 217 | ||||
-rw-r--r-- | CI/utils/walk.js | 40 |
2 files changed, 252 insertions, 5 deletions
diff --git a/CI/supporttest.js b/CI/supporttest.js index 8076637..a1279ec 100644 --- a/CI/supporttest.js +++ b/CI/supporttest.js @@ -1,7 +1,214 @@ -let errored = false +(async ()=>{ -console.log("This is running nodejs code rn") -console.error("This is an error!") -errored = true + // SUPER BASIC CI THING + // This will test for basic support issues with chattriggers 1 and 2 -process.exit(errored?1:0)
\ No newline at end of file + let { walkP } = require("./utils/walk") + let fs = require("fs") + let errors = [] + + let dirName = __dirname.split("\\") + dirName.pop() + dirName = dirName.join("\\") + + console.log("Reading directory... ") + + let dirs = await walkP(dirName) + + console.log("Analizing files...") + + + for(let dir of dirs){ + if(!dir.includes("\\CI\\")){ + if(dir.endsWith(".js")){ + let file = await fs.promises.readFile(dir, "utf8") + + //TEST FOR GL11 THINGS + if(file.includes("GL11.") || file.includes("GL11[") + || file.includes("GlStateManager.") || file.includes("GlStateManager[")){ + //Ensure that they are defined + let defined = ((file.includes("GL11.") || file.includes("GL11[")) && file.includes("org.lwjgl.opengl.GL11")) && ((file.includes("GlStateManager.") || file.includes("GlStateManager[")) && file.includes("net.minecraft.client.renderer.GlStateManager")) + + //Ensure it checks if they are + let definedTestsExists = file.includes("if(!GlStateManager){") || file.includes("if(!GL11){") + + if(!defined){ + errors.push([ + "GL11 or GlStateManager NOT DEFINED IN FILE, this will cause the code to error on chattriggers 1.3 as it is not defined globally", + dir, + "This is an easy fix, just add this to the top of the file somewhere:", + "if(!GlStateManager){", + " var GL11 = Java.type(\"org.lwjgl.opengl.GL11\"); //using var so it goes to global scope", + " var GlStateManager = Java.type(\"net.minecraft.client.renderer.GlStateManager\");", + "}" + ]) + }else{ + if(!definedTestsExists){ + errors.push([ + "GL11 or GlStateManager NOT TESTED IN FILE, this will cause the code to error on chattriggers 2 as it is already a global const", + dir, + "This is an easy fix, just replace the existing GL defenitions with this", + "if(!GlStateManager){", + " var GL11 = Java.type(\"org.lwjgl.opengl.GL11\"); //using var so it goes to global scope", + " var GlStateManager = Java.type(\"net.minecraft.client.renderer.GlStateManager\");", + "}" + ]) + } + } + } + + //test for World.getBlockAt(x, y, z).getID() and World.getBlockAt(x, y, z).getType().getID() + if(file.includes("World.getBlockAt") && (file.includes("getID()"))){ + let includesTest = file.replace(/ /g, "").includes("if(World.getBlockAt(0,0,0).getID){") + + let actuallyHasUsage = false + let supportsV1 = false + let supportsV2 = false + + let instances = file.split("World.getBlockAt") + instances.shift() + instances.forEach(instance =>{ + let newArr = instance.split("(").map(x =>{ + x = x.split(")") + let start = x.shift() + x = x.map(z=>")" + z) + return [start, ...x] + }) + newArr.shift() + // newArr = newArr.map(z=>"("+z) + // newArr = newArr.flat() + + let newArr2 = [] + + newArr.forEach(x =>{ + newArr2.push("(" + (x.shift() || "")) + // console.log(x) + x.forEach(z=>newArr2.push(z)) + }) + + // console.log(newArr2) + + let bracketCount = 0 + let timesReached0 = 0 + newArr2.forEach((section, i)=>{ + if(section.startsWith("(")){ + bracketCount++ + } + if(section.startsWith(")")){ + bracketCount-- + + if(bracketCount < 0){ + timesReached0 = 1000 + } + } + + if(bracketCount == 0){ + // console.log(section, newArr2[i+1]) + if(section === ").getID" && newArr2[i+1].startsWith("(")){ + if(timesReached0 == 0){ + supportsV1 = true + actuallyHasUsage = true + }else if(timesReached0 == 1){ + supportsV2 = true + actuallyHasUsage = true + } + } + + timesReached0++ + } + }) + }) + + if(actuallyHasUsage){ + if(!includesTest){ + errors.push([ + "Block.getID NOT TESTED FOR EXISTANCE IN FILE, this will cause the code to not work on both ct 1 and 2 as syntax in v1 is Block.getID() and in v2 its Block.getType().getID()", + dir, + "This is an easy fix, just run the block id check twice, one for v1 and one for v2", + "surround it with \"if(World.getBlockAt(0,0,0).getID){\", this will be true if you should use v1 syntax and false if u should use v2", + "EG the code", + "if(World.getBlockAt(50,100,50).getID() === 100){", + " is100 = true", + "}", + "Should be changed into", + "if(World.getBlockAt(0,0,0).getID){", + " if(World.getBlockAt(50,100,50).getID() === 100){", + " is100 = true", + " }", + "}else{", + " if(World.getBlockAt(50,100,50).getType().getID() === 100){", + " is100 = true", + " }", + "}" + ]) + }else{ + if(!supportsV1){ + errors.push([ + "Block.getID() NOT SUPPORTED IN FILE, this will cause the code to not work on ct 1 as syntax is Block.getID()", + dir, + "This is an easy fix, just run the block id check twice, one for v1 and one for v2", + "surround it with \"if(World.getBlockAt(0,0,0).getID){\", this will be true if you should use v1 syntax and false if u should use v2", + "EG the code", + "if(World.getBlockAt(50,100,50).getType().getID() === 100){", + " is100 = true", + "}", + "Should be changed into", + "if(World.getBlockAt(0,0,0).getID){", + " if(World.getBlockAt(50,100,50).getID() === 100){", + " is100 = true", + " }", + "}else{", + " if(World.getBlockAt(50,100,50).getType().getID() === 100){", + " is100 = true", + " }", + "}" + ]) + }else if(!supportsV2){ + errors.push([ + "Block.getType().getID() NOT SUPPORTED IN FILE, this will cause the code to not work on ct 2 as syntax is Block.getType().getID()", + dir, + "This is an easy fix, just run the block id check twice, one for v1 and one for v2", + "surround it with \"if(World.getBlockAt(0,0,0).getID){\", this will be true if you should use v1 syntax and false if u should use v2", + "EG the code", + "if(World.getBlockAt(50,100,50).getID() === 100){", + " is100 = true", + "}", + "Should be changed into", + "if(World.getBlockAt(0,0,0).getID){", + " if(World.getBlockAt(50,100,50).getID() === 100){", + " is100 = true", + " }", + "}else{", + " if(World.getBlockAt(50,100,50).getType().getID() === 100){", + " is100 = true", + " }", + "}" + ]) + } + } + } + } + } + } + } + + + if(errors.length === 0){ + console.log("All tests passed!") + process.exit(0) + }else{ + console.log("Tests failed!") + console.log("ERRORS: \n") + + errors.forEach(e=>{ + if(typeof(e) === "string"){ + console.error(e) + }else{ + e.forEach(a=>console.error(a)) + } + console.log("") + }) + + process.exit(1) + } +})()
\ No newline at end of file diff --git a/CI/utils/walk.js b/CI/utils/walk.js new file mode 100644 index 0000000..101c1cf --- /dev/null +++ b/CI/utils/walk.js @@ -0,0 +1,40 @@ +var fs = require('fs'); +var path = require('path'); +var walk = function(dir, done) { + var results = []; + fs.readdir(dir, function(err, list) { + if (err) return done(err); + var pending = list.length; + if (!pending) return done(null, results); + list.forEach(function(file) { + file = path.resolve(dir, file); + fs.stat(file, function(err, stat) { + if (stat && stat.isDirectory()) { + walk(file, function(err, res) { + results = results.concat(res); + if (!--pending) done(null, results); + }); + } else { + results.push(file); + if (!--pending) done(null, results); + } + }); + }); + }); +}; + +async function walkP(dir){ + return new Promise((res, rej)=>{ + walk(dir, (err, resu)=>{ + if(err){ + rej(err) + return + } + + res(resu) + }); + }) +} + +module.exports = {walk, walkP} //https://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search +//i was just too lazy to code this myself OMEGALUL
\ No newline at end of file |