How to use crawlDir method in stryker-parent

Best JavaScript code snippet using stryker-parent

app.js

Source:app.js Github

copy

Full Screen

1const express = require("express");2const bodyParser = require("body-parser");3const axios = require("axios");4const path = require("path");5const fs = require("fs");6const cheerio = require("cheerio");7const { userInfo } = require("os");8const app = express();9const async = require("async");10const { createBrotliCompress } = require("zlib");11const { setFlagsFromString } = require("v8");12app.set(express.static(path.join(__dirname)));13app.use(bodyParser.json());14app.listen("80", () => {15 console.log("READY");16})17function scriptReplacer(htmlDataO, data, url, crawlDir, time, $Main) {18 let htmlData = htmlDataO;19 return new Promise((resolve, reject) => {20 // script Auto-replacer21 const scripts = $Main("script");22 fs.mkdirSync(path.join(crawlDir, time, '/scripts'));23 console.log(`TOTAL Scripts: ${scripts.length}`)24 // script tag ignorance section25 let lstIdxSECA = 0;26 let lstIdxSECB = 0;27 let tagStartPointSEC = [];28 let tagEndPointSEC = [];29 while(true) {30 let searchResSECA = data.indexOf("<!--", lstIdxSECA);31 // console.log(`searchResSECA: ${searchResSECA}`);32 if (searchResSECA == -1) break;33 else {34 tagStartPointSEC.push(searchResSECA);35 lstIdxSECA = searchResSECA+1;36 }37 let searchResSECB = data.indexOf("-->", lstIdxSECB);38 // console.log(`searchResSECB: ${searchResSECB}`);39 if (searchResSECB == -1) break;40 else {41 tagEndPointSEC.push(searchResSECB+3);42 lstIdxSECB = searchResSECB+1;43 }44 }45 // console.log(tagStartPointSEC.length);46 // console.log(tagEndPointSEC.length);47 // script tag location find48 let lstIdxA = 0;49 let lstIdxB = 0;50 let tagStartPoint = [];51 let tagEndPoint = [];52 let cngCont = [];53 let cnt = 0;54 let ignIdx = [];55 while(true) {56 let searchRESA = data.indexOf("<script", lstIdxA);57 // console.log(`searchRESA: ${searchRESA}`);58 let isPushA = true;59 if (searchRESA == -1) break;60 else {61 tagStartPointSEC.forEach((val, idx) => {62 if (val<searchRESA && searchRESA <tagEndPointSEC[idx]) {isPushA = false;}63 })64 // console.log(`isPushA: ${isPushA}`);65 if (isPushA) {66 tagStartPoint.push(searchRESA);67 // console.log(`IGNORANCE SECTION: NOT INCLUDED [indexNum [${cnt}] || scriptTagCNGREGNum [${tagStartPoint.length-1}]]`)68 } else {69 console.log(`IGNORANCE SECTION: INCLUDED [indexNum [${cnt}] || scriptTagCNGREGNum [NaN]]`)70 ignIdx.push(cnt);71 }72 lstIdxA = searchRESA+1;73 }74 let searchRESB = data.indexOf("</script>", lstIdxB);75 // console.log(`searchRESB: ${searchRESB}`);76 let isPushB = true;77 if (searchRESB == -1) break;78 else {79 tagStartPointSEC.forEach((val, idx) => {80 if (val<searchRESB && searchRESB <tagEndPointSEC[idx]) isPushB = false;81 })82 // console.log(`isPushB: ${isPushB}`);83 if (isPushB) tagEndPoint.push(searchRESB+9); // +8: for get '>' location84 lstIdxB = searchRESB+1;85 }86 if (isPushA && isPushB) cngCont.push(data.substring(searchRESA, searchRESB+9));87 cnt++;88 }89 // console.log(ignIdx);90 let scriptEndCnt = 0;91 function scriptSave(scriptObj, scIdx, dir, scriptLocARRS) {92 let cont = "";93 scriptObj.children.forEach((val, idx) => {94 if (val.type == "text") (cont =="") ? (cont += val.data) : (cont += "\n" + val.data);95 else console.log(val);96 })97 try {98 fs.writeFileSync(path.join(dir, `/scripts/script[${scIdx}].js`), `/*\n\nHTML-WRITTEN FILE || Script sequence: [${scIdx}]\n\n*/\n\n` + cont, {encoding: "utf-8"});99 } catch(e) {100 console.error(`Script Save Error: [${scIdx}]`);101 }102 console.log(`Progressing Script Sequence: ${scIdx} || willChange: ${!ignIdx.includes(scIdx)}`);103 // if (!ignIdx.includes(scIdx)) {104 // console.log(htmlData.includes(scriptLocARRS.cngCont[scIdx]));105 htmlData = htmlData.replace(scriptLocARRS.cngCont[scIdx], `<script src="./scripts/script[${scIdx}].js"></script>`);106 // console.log(`<script src="./scripts/script[${scIdx}].js"></script>: ` + htmlData.includes(`<script src="./scripts/script[${scIdx}].js"></script>`));107 // console.log(!htmlData.includes(scriptLocARRS.cngCont[scIdx]) ? `Script Modified: [${scIdx}]` : `Script NOT Modified: [${scIdx}]`);108 scriptEndCnt++;109 console.log(`scriptEndCnt: ${scriptEndCnt}`);110 // } else {111 // scriptEndCnt++;112 // console.log(`scriptEndCnt: ${scriptEndCnt}`);113 // }114 }115 let scriptDownloadQueue = [];116 117 function scriptDownload(scriptURL, scIdx, dir, orgDomain, scriptLocARRS) {118 // console.log(`${orgDomain.split("/")[0]}//${baseDMN}${scriptURL}`);119 const baseDMN = orgDomain.split("/")[2];120 // console.log(`${orgDomain.split("/")[0]}//${baseDMN}${stylesheetURL}`);121 let domain;122 // console.log(stylesheetURL.split("/")[0].includes("http"));123 if (scriptURL.split("/")[0].includes("http")) domain = scriptURL;124 else if (scriptURL[0] == "/") domain = `${orgDomain.split("/")[0]}//${baseDMN}${scriptURL}`;125 else domain = `${orgDomain.split("/")[0]}//${baseDMN}/${scriptURL}`;126 let queueInfo = {127 scriptURLinHTML: scriptURL,128 scriptURL: domain,129 scIdx,130 dir,131 orgDomain,132 scriptLocARRS133 };134 scriptDownloadQueue.push(queueInfo);135 // console.log(domain);136 axios.get(domain)137 .then(({data}) => {138 scriptDownloadQueue.splice(scriptDownloadQueue.indexOf(queueInfo), 1);139 try {140 fs.appendFileSync(path.join(dir, `/scripts/script[${scIdx}].js`), `/*\n\nBase URL: ${scriptURL} || Script sequence: [${scIdx}]\n\n*/\n\n` + data, {encoding: "utf-8"});141 } catch(e) {142 console.error(`Script Save Error: [${scIdx}]`);143 }144 console.log(`Progressing Script Sequence: ${scIdx} || willChange: ${!ignIdx.includes(scIdx)}`);145 // if (!ignIdx.includes(scIdx)) {146 // console.log(htmlData.includes(scriptLocARRS.cngCont[scIdx]));147 htmlData = htmlData.replace(scriptLocARRS.cngCont[scIdx], `<script src="./scripts/script[${scIdx}].js"></script>`);148 // console.log(`<script src="./scripts/script[${scIdx}].js"></script>: ` + htmlData.includes(`<script src="./scripts/script[${scIdx}].js"></script>`));149 // console.log(!htmlData.includes(scriptLocARRS.cngCont[scIdx]) ? `Script Modified: [${scIdx}] || DEPENDENCIES TAG` : `Script NOT Modified: [${scIdx}] || DEPENDENCIES TAG`);150 scriptEndCnt++;151 console.log(`scriptEndCnt: ${scriptEndCnt}`);152 // } else {153 // scriptEndCnt++;154 // console.log(`scriptEndCnt: ${scriptEndCnt}`);155 // }156 157 })158 .catch((e) => {159 scriptEndCnt++;160 console.log(`scriptEndCnt: ${scriptEndCnt}`);161 console.error(`ERR: ${scriptURL} || BASEURL: ${baseDMN} || SEND: ${`${orgDomain.split("/")[0]}://${baseDMN}${scriptURL}`}`)162 });163 }164 for (var idx = 0; idx < scripts.length; idx++) {165 var script = scripts[idx];166 // console.log(idx);167 // console.log(`${tagStartPoint.length} || ${scripts.length}`);168 if (!script.attribs.src) {169 // text script170 scriptSave(script, idx, path.join(crawlDir, time), {tagStartPoint, tagEndPoint, cngCont});171 } else {172 // dependencies script173 scriptDownload(script.attribs.src, idx, path.join(crawlDir, time), url, {tagStartPoint, tagEndPoint, cngCont});174 }175 // const start = $Main('script').get(idx).startIndex;176 // const lineNumber = data.substr(0, start).split('\n').length;177 // console.log(lineNumber)178 }179 // console.log("type: " + typeof data);180 // console.log(tagStartPoint);181 // console.log(tagEndPoint);182 // cngCont.forEach((value, index) => {183 // if (htmlData.includes(value)) {184 // console.log(`Script CHANGE TRY: ${index}`);185 // htmlData = htmlData.replace(value, `<script src="./scripts/script[${index}].js"></script>`);186 // console.log(!htmlData.includes(value) ? "SUCCESS" : "FAIED");187 // }188 // })189 // script Auto-replacer190 endLooper();191 function endLooper() {192 console.log(`Progressing... || Script Download Progressing: ${scriptDownloadQueue.length}`);193 if (scriptEndCnt == scripts.length) {194 resolve(htmlData)195 } else setTimeout(() => {196 endLooper();197 }, 150);198 }199 });200}201function stylesheetReplacer(htmlDataO, data, url, crawlDir, time, $Main) {202 let htmlData = htmlDataO203 return new Promise((resolve, reject) => {204 // stylesheet Auto-replacer205 const stylesheets = $Main("link[rel='stylesheet']");206 fs.mkdirSync(path.join(crawlDir, time, '/stylesheets'));207 console.log(`TOTAL stylesheets: ${stylesheets.length}`)208 // stylesheet tag ignorance section209 let lstIdxSECA = 0;210 let lstIdxSECB = 0;211 let tagStartPointSEC = [];212 let tagEndPointSEC = [];213 while(true) {214 let searchResSECA = data.indexOf("<!--", lstIdxSECA);215 // console.log(`searchResSECA: ${searchResSECA}`);216 if (searchResSECA == -1) break;217 else {218 tagStartPointSEC.push(searchResSECA);219 lstIdxSECA = searchResSECA+1;220 }221 let searchResSECB = data.indexOf("-->", lstIdxSECB);222 // console.log(`searchResSECB: ${searchResSECB}`);223 if (searchResSECB == -1) break;224 else {225 tagEndPointSEC.push(searchResSECB+3);226 lstIdxSECB = searchResSECB+1;227 }228 }229 // console.log(tagStartPointSEC);230 // console.log(tagEndPointSEC);231 // stylesheet tag location find232 let lstIdxA = 0;233 let tagStartPoint = [];234 let tagEndPoint = [];235 let cngCont = [];236 let cnt = 0;237 let ignIdx = [];238 while(true) {239 let searchRESA = data.indexOf("<link", lstIdxA);240 lstIdxA = searchRESA+5;241 let searchRESB = data.indexOf(">", lstIdxA);242 let isPushA = true;243 let isPushB = true;244 // console.log(`searchRESA: ${searchRESA}`);245 // console.log(`searchRESB: ${searchRESB}`);246 247 if (searchRESA == -1) break;248 let relInfo = data.indexOf("rel=", searchRESA);249 if (relInfo > searchRESB) continue;250 else if (data.substr(relInfo+5,3) != "sty") {251 // console.log(data.substr(relInfo+5,3));252 continue;253 }254 else {255 tagStartPointSEC.forEach((val, idx) => {256 // console.log(val<searchRESA && searchRESA <tagEndPointSEC[idx]);257 // console.log(val<searchRESB && searchRESB <tagEndPointSEC[idx]);258 if (val<searchRESA && searchRESA <tagEndPointSEC[idx]) isPushA = false;259 if (val<searchRESB && searchRESB <tagEndPointSEC[idx]) isPushB = false;260 })261 // console.log(`isPushA: ${isPushA}`);262 if (isPushA) {263 tagStartPoint.push(searchRESA);264 // console.log(`IGNORANCE SECTION: NOT INCLUDED [indexNum [${cnt}] || stylesheetTagCNGREGNum [${tagStartPoint.length-1}]]`)265 } else {266 console.log(`IGNORANCE SECTION: INCLUDED [indexNum [${cnt}] || stylesheetTagCNGREGNum [NaN]]`)267 ignIdx.push(cnt);268 }269 270 // console.log(`isPushB: ${isPushB}`);271 if (isPushB) tagEndPoint.push(searchRESB); // +8: for get '>' location272 if (isPushA && isPushB) cngCont.push(data.substring(searchRESA, searchRESB));273 cnt++;274 }275 }276 // console.log(ignIdx);277 // console.log(tagStartPoint);278 let stylesheetEndCnt = 0;279 function stylesheetSave(stylesheetObj, scIdx, dir, stylesheetLocARRS) {280 let cont = "";281 stylesheetObj.children.forEach((val, idx) => {282 if (val.type == "text") (cont =="") ? (cont += val.data) : (cont += "\n" + val.data);283 // else console.log(val);284 })285 try {286 fs.writeFileSync(path.join(dir, `/stylesheets/stylesheet[${scIdx}].css`), `/*\n\nHTML-WRITTEN FILE || stylesheet sequence: [${scIdx}]\n\n*/\n\n` + cont, {encoding: "utf-8"});287 } catch(e) {288 console.error(`stylesheet Save Error: [${scIdx}]`);289 }290 console.log(`Progressing stylesheet Sequence: ${scIdx} || willChange: ${!ignIdx.includes(scIdx)}`);291 // if (!ignIdx.includes(scIdx)) {292 // console.log(htmlData.includes(stylesheetLocARRS.cngCont[scIdx]));293 htmlData = htmlData.replace(stylesheetLocARRS.cngCont[scIdx], `<link rel="stylesheet" href="./stylesheets/stylesheet[${scIdx}].js"/>`);294 // console.log(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>: ` + htmlData.includes(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>`));295 // console.log(!htmlData.includes(stylesheetLocARRS.cngCont[scIdx]) ? `stylesheet Modified: [${scIdx}]` : `stylesheet NOT Modified: [${scIdx}]`);296 stylesheetEndCnt++;297 console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);298 // } else {299 // stylesheetEndCnt++;300 // console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);301 // }302 }303 304 function stylesheetDownload(stylesheetURL, scIdx, dir, orgDomain, stylesheetLocARRS, filename) {305 const baseDMN = orgDomain.split("/")[2];306 // console.log(`${orgDomain.split("/")[0]}//${baseDMN}${stylesheetURL}`);307 let domain;308 let locExtSpliter = stylesheetURL.split("/");309 // console.log(stylesheetURL.split("/")[0].includes("http"));310 let saveLoc;311 // console.log(saveLoc);312 if (stylesheetURL.split("/")[0].includes("http")) {313 domain = stylesheetURL;314 saveLoc = stylesheetURL.replace(locExtSpliter[locExtSpliter.length-1], ""); 315 } else if (stylesheetURL[0] == "/") {316 domain = `${orgDomain.split("/")[0]}//${baseDMN}${stylesheetURL}`;317 saveLoc = stylesheetURL.replace(locExtSpliter[locExtSpliter.length-1], "");318 } else {319 domain = `${orgDomain.split("/")[0]}//${baseDMN}/${stylesheetURL}`;320 saveLoc = stylesheetURL.replace(locExtSpliter[locExtSpliter.length-1], "");321 }322 // console.log(`splited: ${stylesheetURL} --> ${saveLoc}`);323 // console.log(domain);324 axios.get(domain)325 .then((dataB) => {326 let data = dataB.data;327 // console.log(data);328 const realSaveLoc = path.join(dir, `/stylesheets`, (saveLoc[saveLoc.length-1] == "/" ? saveLoc.slice(0, -1) : saveLoc));329 console.log(`realSaveLoc: ${realSaveLoc}`);330 // check @import331 let importFIdx = 0;332 // console.log(stylesheetURL);333 while(true) {334 let searchRes = data.indexOf("@import", importFIdx);335 let searchResSP = data.indexOf("\'", searchRes+7);336 let searchResEP = data.indexOf("\'", searchRes+9);337 if(searchRes == -1) break;338 else {339 let urlExt = data.slice(searchResSP+1, searchResEP);340 // console.log(`--------------`);341 // console.log(stylesheetURL);342 let parentSub = stylesheetURL.split("/").pop();343 // console.log(stylesheetURL.replace(parentSub, ""));344 let importStylesheetURL = path.join(stylesheetURL.replace(parentSub, ""), urlExt);345 importFIdx = searchRes+9;346 // console.log(orgDomain.split("/")[0]);347 let importLocExtSpliter = importStylesheetURL.split("/");348 console.log(dir);349 console.log(importLocExtSpliter.pop());350 console.log(importStylesheetURL);351 console.log(path.join(dir, `/stylesheets`, (importLocExtSpliter.pop() == "/" ? importStylesheetURL.replace(importLocExtSpliter.pop(), "") : importLocExtSpliter)));352 // stylesheetDownload(importStylesheetURL[0] == "/" ? importStylesheetURL : "/" + importStylesheetURL, scIdx, path.join(dir, `/stylesheets`, (importLocExtSpliter.pop() == "/" ? importStylesheetURL.replace(importLocExtSpliter.pop(), "") : importLocExtSpliter)), orgDomain, stylesheetLocARRS, urlExt.split("/").pop());353 // data.replace(data.slice(searchRes, searchResEP), `@import '${}'`)354 }355 }356 // console.log(importLoc);357 // check @import358 try {359 // if (filename) {360 // console.log(filename);361 // console.log(!fs.existsSync(realSaveLoc));362 // }363 if (!fs.existsSync(realSaveLoc)) {364 // console.log(`make new directory: ${realSaveLoc}`);365 // fs.mkdirSync(realSaveLoc);366 let stbLoc = realSaveLoc.split("/");367 let extLoc = "";368 stbLoc.forEach((val, idx) => {369 if (idx != 0) {370 extLoc += "/" + val;371 // console.log(`${scIdx}: check Location Existence [${extLoc}]`)372 if (!fs.existsSync(extLoc)) fs.mkdirSync(extLoc);373 }374 })375 // console.log(`make new directory: ${fs.existsSync(realSaveLoc) ? "success" : "failed"}`);376 }377 setTimeout(() => {378 // console.log(`stylesheet: [${scIdx}] save route: ${realSaveLoc}`);379 // console.log(`stylesheet: [${scIdx}] save try: ${path.join(realSaveLoc, `${filename ? filename : `/stylesheet_typeA[${scIdx}].css`}`)}`);380 fs.appendFileSync(path.join(realSaveLoc, `${filename ? filename : `/stylesheet_typeA[${scIdx}].css`}`), `/*\n\nBase URL: ${stylesheetURL} || stylesheet sequence: [${scIdx}]\n\n*/\n\n` + data, {encoding: "utf-8"});381 }, 100);382 } catch(e) {383 console.error(`stylesheet Save Error: [${scIdx}] - ${e}`);384 }385 // console.log(`Progressing stylesheet Sequence: ${scIdx} || willChange: ${!ignIdx.includes(scIdx)}`);386 // if (!ignIdx.includes(scIdx)) {387 // console.log(htmlData.includes(stylesheetLocARRS.cngCont[scIdx]));388 if (!filename) htmlData = htmlData.replace(stylesheetLocARRS.cngCont[scIdx], `<link rel="stylesheet" href=".${path.join("/stylesheets/", saveLoc)}/stylesheet_typeA[${scIdx}].css"/>`);389 // console.log(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>: ` + htmlData.includes(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>`));390 // console.log(!htmlData.includes(stylesheetLocARRS.cngCont[scIdx]) ? `stylesheet Modified: [${scIdx}] || DEPENDENCIES TAG` : `stylesheet NOT Modified: [${scIdx}] || DEPENDENCIES TAG`);391 stylesheetEndCnt++;392 // console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);393 // } else {394 // stylesheetEndCnt++;395 // console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);396 // }397 })398 .catch((e) => {399 stylesheetEndCnt++;400 console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);401 console.error(`ERR: ${stylesheetURL} || BASEURL: ${baseDMN} || SEND: ${`${orgDomain.split("/")[0]}//${baseDMN}${stylesheetURL}`} ==> ${e}`)402 // throw e;403 });404 }405 for (var idx = 0; idx < tagStartPoint.length; idx++) {406 // console.log(idx);407 var stylesheet = stylesheets[idx];408 if (!stylesheet.attribs.href) {409 // text stylesheet410 stylesheetSave(stylesheet, idx, path.join(crawlDir, time), {tagStartPoint, tagEndPoint, cngCont});411 } else {412 // dependencies stylesheet413 stylesheetDownload(stylesheet.attribs.href, idx, path.join(crawlDir, time), url, {tagStartPoint, tagEndPoint, cngCont});414 }415 // const start = $Main('stylesheet').get(idx).startIndex;416 // const lineNumber = data.substr(0, start).split('\n').length;417 // console.log(lineNumber)418 }419 // stylesheet Auto-replacer420 endLooper();421 function endLooper() {422 console.log(`..? || ${stylesheetEndCnt} / ${stylesheets.length}`);423 if (stylesheetEndCnt >= stylesheets.length) {424 console.log("resolve");425 resolve(htmlData)426 } else setTimeout(() => {427 endLooper();428 }, 150);429 }430 });431}432function resourceReplacer(htmlDataO, data, url, crawlDir, time, $Main) {433 let htmlData = htmlDataO434 return new Promise((resolve, reject) => {435 // stylesheet Auto-replacer436 const stylesheets = $Main("link[rel='stylesheet']");437 fs.mkdirSync(path.join(crawlDir, time, '/stylesheets'));438 console.log(`TOTAL stylesheets: ${stylesheets.length}`)439 // stylesheet tag ignorance section440 let lstIdxSECA = 0;441 let lstIdxSECB = 0;442 let tagStartPointSEC = [];443 let tagEndPointSEC = [];444 while(true) {445 let searchResSECA = data.indexOf("<!--", lstIdxSECA);446 // console.log(`searchResSECA: ${searchResSECA}`);447 if (searchResSECA == -1) break;448 else {449 tagStartPointSEC.push(searchResSECA);450 lstIdxSECA = searchResSECA+1;451 }452 let searchResSECB = data.indexOf("-->", lstIdxSECB);453 // console.log(`searchResSECB: ${searchResSECB}`);454 if (searchResSECB == -1) break;455 else {456 tagEndPointSEC.push(searchResSECB+3);457 lstIdxSECB = searchResSECB+1;458 }459 }460 // console.log(tagStartPointSEC);461 // console.log(tagEndPointSEC);462 // stylesheet tag location find463 let lstIdxA = 0;464 let tagStartPoint = [];465 let tagEndPoint = [];466 let cngCont = [];467 let cnt = 0;468 let ignIdx = [];469 while(true) {470 let searchRESA = data.indexOf("<link", lstIdxA);471 lstIdxA = searchRESA+5;472 let searchRESB = data.indexOf(">", lstIdxA);473 let isPushA = true;474 let isPushB = true;475 // console.log(`searchRESA: ${searchRESA}`);476 // console.log(`searchRESB: ${searchRESB}`);477 478 if (searchRESA == -1) break;479 let relInfo = data.indexOf("rel=", searchRESA);480 if (relInfo > searchRESB) continue;481 else if (data.substr(relInfo+5,3) != "sty") {482 console.log(data.substr(relInfo+5,3));483 continue;484 } else {485 tagStartPointSEC.forEach((val, idx) => {486 // console.log(val<searchRESA && searchRESA <tagEndPointSEC[idx]);487 // console.log(val<searchRESB && searchRESB <tagEndPointSEC[idx]);488 if (val<searchRESA && searchRESA <tagEndPointSEC[idx]) isPushA = false;489 if (val<searchRESB && searchRESB <tagEndPointSEC[idx]) isPushB = false;490 })491 // console.log(`isPushA: ${isPushA}`);492 if (isPushA) {493 tagStartPoint.push(searchRESA);494 // console.log(`IGNORANCE SECTION: NOT INCLUDED [indexNum [${cnt}] || stylesheetTagCNGREGNum [${tagStartPoint.length-1}]]`)495 } else {496 console.log(`IGNORANCE SECTION: INCLUDED [indexNum [${cnt}] || stylesheetTagCNGREGNum [NaN]]`)497 ignIdx.push(cnt);498 }499 500 // console.log(`isPushB: ${isPushB}`);501 if (isPushB) tagEndPoint.push(searchRESB); // +8: for get '>' location502 if (isPushA && isPushB) cngCont.push(data.substring(searchRESA, searchRESB));503 cnt++;504 }505 }506 console.log(ignIdx);507 console.log(tagStartPoint);508 let stylesheetEndCnt = 0;509 function stylesheetSave(stylesheetObj, scIdx, dir, stylesheetLocARRS) {510 let cont = "";511 stylesheetObj.children.forEach((val, idx) => {512 if (val.type == "text") (cont == "") ? (cont += val.data) : (cont += "\n" + val.data);513 else console.log(val);514 })515 try {516 fs.writeFileSync(path.join(dir, `/stylesheets/stylesheet[${scIdx}].css`), `/*\n\nHTML-WRITTEN FILE || stylesheet sequence: [${scIdx}]\n\n*/\n\n` + cont, {encoding: "utf-8"});517 } catch(e) {518 console.error(`stylesheet Save Error: [${scIdx}]`);519 }520 console.log(`Progressing stylesheet Sequence: ${scIdx} || willChange: ${!ignIdx.includes(scIdx)}`);521 // if (!ignIdx.includes(scIdx)) {522 // console.log(htmlData.includes(stylesheetLocARRS.cngCont[scIdx]));523 htmlData = htmlData.replace(stylesheetLocARRS.cngCont[scIdx], `<link rel="stylesheet" href="./stylesheets/stylesheet[${scIdx}].js"/>`);524 // console.log(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>: ` + htmlData.includes(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>`));525 // console.log(!htmlData.includes(stylesheetLocARRS.cngCont[scIdx]) ? `stylesheet Modified: [${scIdx}]` : `stylesheet NOT Modified: [${scIdx}]`);526 stylesheetEndCnt++;527 console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);528 // } else {529 // stylesheetEndCnt++;530 // console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);531 // }532 }533 534 function stylesheetDownload(stylesheetURL, scIdx, dir, orgDomain, stylesheetLocARRS) {535 const baseDMN = orgDomain.split("/")[2];536 // console.log(`${orgDomain.split("/")[0]}//${baseDMN}${stylesheetURL}`);537 let domain;538 // console.log(stylesheetURL.split("/")[0].includes("http"));539 if (stylesheetURL.split("/")[0].includes("http")) domain = stylesheetURL;540 else if (stylesheetURL[0] == "/") domain = `${orgDomain.split("/")[0]}//${baseDMN}${stylesheetURL}`;541 else domain = `${orgDomain.split("/")[0]}//${baseDMN}/${stylesheetURL}`;542 // console.log(domain);543 axios.get(domain)544 .then(({data}) => {545 // console.log(data);546 try {547 fs.appendFileSync(path.join(dir, `/stylesheets/stylesheet_typeA[${scIdx}].css`), `/*\n\nBase URL: ${stylesheetURL} || stylesheet sequence: [${scIdx}]\n\n*/\n\n` + data, {encoding: "utf-8"});548 } catch(e) {549 console.error(`stylesheet Save Error: [${scIdx}]`);550 }551 console.log(`Progressing stylesheet Sequence: ${scIdx} || willChange: ${!ignIdx.includes(scIdx)}`);552 // if (!ignIdx.includes(scIdx)) {553 // console.log(htmlData.includes(stylesheetLocARRS.cngCont[scIdx]));554 htmlData = htmlData.replace(stylesheetLocARRS.cngCont[scIdx], `<link rel="stylesheet" href="./stylesheets/stylesheet_typeA[${scIdx}].css"/>`);555 // console.log(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>: ` + htmlData.includes(`<stylesheet src="./stylesheets/stylesheet[${scIdx}].js"></stylesheet>`));556 // console.log(!htmlData.includes(stylesheetLocARRS.cngCont[scIdx]) ? `stylesheet Modified: [${scIdx}] || DEPENDENCIES TAG` : `stylesheet NOT Modified: [${scIdx}] || DEPENDENCIES TAG`);557 stylesheetEndCnt++;558 console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);559 // } else {560 // stylesheetEndCnt++;561 // console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);562 // }563 })564 .catch((e) => {565 stylesheetEndCnt++;566 console.log(`stylesheetEndCnt: ${stylesheetEndCnt}`);567 console.error(`ERR: ${stylesheetURL} || BASEURL: ${baseDMN} || SEND: ${`${orgDomain.split("/")[0]}://${baseDMN}${stylesheetURL}`}`)568 });569 }570 for (var idx = 0; idx < tagStartPoint.length; idx++) {571 console.log(idx);572 var stylesheet = stylesheets[idx];573 if (!stylesheet.attribs.href) {574 // text stylesheet575 stylesheetSave(stylesheet, idx, path.join(crawlDir, time), {tagStartPoint, tagEndPoint, cngCont});576 } else {577 // dependencies stylesheet578 stylesheetDownload(stylesheet.attribs.href, idx, path.join(crawlDir, time), url, {tagStartPoint, tagEndPoint, cngCont});579 }580 // const start = $Main('stylesheet').get(idx).startIndex;581 // const lineNumber = data.substr(0, start).split('\n').length;582 // console.log(lineNumber)583 }584 // stylesheet Auto-replacer585 endLooper();586 function endLooper() {587 console.log(`..? || ${stylesheetEndCnt} / ${stylesheets.length}`);588 if (stylesheetEndCnt == stylesheets.length) {589 console.log("resolve");590 resolve(htmlData)591 } else setTimeout(() => {592 endLooper();593 }, 150);594 }595 });596}597function getter(urlB) {598 const url = urlB[urlB.length-1] == "/" ? urlB.substr(0, urlB.length-1) : urlB;599 if (!url | typeof url != "string") return new Error("params error");600 axios.get(url)601 .then(async ({data}) => {602 let htmlData = data;603 const crawlDir = path.join(__dirname, "../", "crawl");604 const time = Date.now().toString();605 fs.mkdirSync(path.join(crawlDir, time));606 const filename = url.split("/")[url.split("/").length-1];607 console.log(`filename: ${filename}`);608 console.log(`url: ${url}`);609 console.log(`urlSplited: ${url.split("/")}`);610 console.log(fs.existsSync(path.join(crawlDir, time)));611 const $Main = cheerio.load(data, {withStartIndices: true});612 async.waterfall([613 (cb) => {614 scriptReplacer(htmlData, data, url, crawlDir, time, $Main)615 .then((htmlDataCNG) => {616 console.log(`\n\n\n--|Script: END|--\n\n\n`);617 cb(null, htmlDataCNG) 618 })619 .catch(e => cb(e));620 },621 (htmlDataC, cb) => {622 stylesheetReplacer(htmlDataC, data, url, crawlDir, time, $Main)623 .then((htmlDataCNG) => {624 console.log(`\n\n\n--|Stylesheet: END|--\n\n\n`);625 cb(null, htmlDataCNG);626 })627 .catch(e => cb(e));628 }629 // (htmlDataC, cb) => {630 // resourceReplacer(htmlDataC, data, url, crawlDir, time, $Main)631 // .then((htmlDataCNG) => cb(null, htmlDataCNG))632 // .catch(e => cb(e));633 // }634 ], (err, htmlDataC) => {635 if (err) throw err;636 fs.writeFileSync(path.join(crawlDir, time, `/${filename}.html`), htmlDataC, {encoding: 'utf-8'});637 fs.writeFileSync(path.join(crawlDir, time, `/${filename}_ORG.html`), data, {encoding: 'utf-8'});638 })639 // scriptReplacer(htmlData, data, url, crawlDir, time, $Main)640 // .then((htmlDataA) => {641 // stylesheetAReplacer(htmlDataA, data, url, crawlDir, time, $Main)642 // .then((htmlDataB) => {643 // })644 // })645 646 // endLooper();647 // function endLooper() {648 // console.log("..");649 // if (scriptEndCnt == scripts.length) {650 // } else setTimeout(() => {651 // endLooper();652 // }, 150);653 // }654 })655 .catch((e) => {throw e});656}657app.get("/", (req, res) => (res.sendFile(__dirname + "/index.html")))658app.get("/siteData", (req, res) => (res.sendFile(__dirname + "/" + req.query.url + ".html")))659app.post("/getData", (req, res) => {660 getter(req.body.url);661 res.end();...

Full Screen

Full Screen

replace-module.js

Source:replace-module.js Github

copy

Full Screen

1const lib = new URL('../package/lib/', import.meta.url);2// eslint-disable-next-line @typescript-eslint/no-var-requires3async function crawlDir(dir) {4 for await (const dirEntry of Deno.readDir(dir)) {5 if(dirEntry.isFile && dirEntry.name.endsWith('.js')) {6 const fileUrl = new URL(dirEntry.name, dir);7 let text = await Deno.readTextFile(fileUrl);8 9 if(text.includes(`import { createRequire } from 'module';`)) {10 console.error(`Replacing in [${fileUrl.pathname}]`);11 text = text.replace(`import { createRequire } from 'module';`, '');12 text = text.replace(`const require = createRequire(import.meta.url);`, '');13 14 text = text.replace(`const escapeHtml = require('escape-html');`, `import escapeHtml from 'escape-html';`);15 text = text.replace(`const parse5 = require('parse5');`, `import * as parse5 from 'parse5';`);16 17 await Deno.writeTextFile(fileUrl, text);18 } 19 } else if(dirEntry.isDirectory) {20 await crawlDir(new URL(dirEntry.name + '/', dir));21 }22 }23}...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1#!/usr/bin/env node2import commander from 'commander';3import * as process from 'process';4import { fdir as FDir } from 'fdir';5import _ from 'lodash';6import * as fs from 'fs';7const program = new commander.Command();8program.option('-y, --yes', 'do actual rename');9program.parse(process.argv);10const crawlDir = '.';11const result = new FDir()12 .withDirs()13 .withMaxDepth(2)14 .filter(_.stubFalse)15 .crawl(crawlDir)16 .sync() as string[];17const toMove = result18 .filter((e) => /\d{4}\.\d{2}\.\d{2}/.test(e))19 .map((from) => ({ from, to: from.replace(/\d{4}\./, '') }));20toMove.forEach(({ from, to }) => {21 console.log(`${from.replace(crawlDir, '')} -> ${to.replace(crawlDir, '')}`);22 if (program.yes) fs.renameSync(from, to);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.crawlDir('test', (err, files) => {3 if (err) {4 console.error(err);5 } else {6 console.log(files);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var path = require('path');3r dir = path.resolve(__diname,'test');4parent.ir(dir, 'test.js', function (err, fles) {5 if (er) {6 console.error(err);7 } else {8 console.log(files);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.crawlDir('someDir', function(err, files) {3 if (err) {4 console.log('Error encountered: ' + err);5 return;6 }7 console.log('Files found: ' + files);8});9var parent = require('stryker-parent');10parent.crawlDir('someDir', function(err, files) {11 if (err) {12 console.log('Error encountered: ' + err);13 return;14 }15 console.log('Files found: ' + files);16});17var parent = require('stryker-parent');18parent.crawlDir('someDir', function(err, files) {19 if (err) {20 console.log('Error encountered: ' + err);21 return;22 }23 console.log('Files found: ' + files);24});

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stry);2console.log(filesker-parent');3class MyClass {4}5class MyOthe Class {6}7h');

Full Screen

Using AI Code Generation

copy

Full Screen

1var crawlDir = require'stryker-parent').crawlDir;2var s = crawlDir('rc'3console.log(files);4parent.crawlDir(dir, 'test.js', function (err, files) {5 if (err) {6 console.error(err);7 } else {8 console.log(files);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var crawlDir = require('stryker-parent').crawlDir;2var files = crawlDir('src');3console.log(files);4class MyClass {5}6class MyOtherClass {7}

Full Screen

Using AI Code Generation

copy

Full Screen

1var crawlDir = require('stryker-parent').crawlDir;2var files = crawlDir('src');3console.log(files);4{5 "scripts": {6 },7 "dependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var crawlDir = require('stryker-parent').crawlDir;2var files = crawlDir('src');3consol.log('files: ', files);4 }5}6var calculateCoverage = require('stryker-coverage').calculateCoverage;7var sourceCode = 'var foo = 1;';8var testRunner = 'mocha';9var testFramework = 'mocha';10calculateCoverage(sourceCode, testRunner, testFramework).then(function(coverageResult) {11 console.log(coverageResult);12});13{14 "scripts": {15 },16 "dependencies": {17 }18}19{ all: 100, perTest: { '0': 100 } }

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2parent.crawlDir('test', function (err, files) {3 console.log(files);4});5module.exports = function (config) {6 config.set({7 });8};9module.exports = function (config) {10 config.set({11 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var dir = 'C:\Users\user\stryker';3var callback = function(err, result) {4 if (err) {5 console.log('Error while crawling directory ' + dir + ': ' + err);6 } else {7 console.log('Directories and files under ' + dir + ': ');8 console.log(result);9 }10};11parent.crawlDir(dir, callback);12};13module.exports = function (config) {14 config.set({15 });16};17module.exports = function (config) {18 config.set({19 });20};21module.exports = function (config) {22 config.set({23 });24};25module.exports = function (config) {26 config.set({27 });28};29module.exports = function (config) {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful