How to use isProjectRemote method in redwood

Best JavaScript code snippet using redwood

scripts.js

Source:scripts.js Github

copy

Full Screen

...36 res.json({foundResults:returnValue,error:null});37 })38};39exports.notPushedScripts = function(req,res){40 isProjectRemote(req.cookies.project,function(remote,externalRepoURL) {41 var repo = "origin/master";42 if (remote == true) {43 repo = "remotes/remoteRepo/"+req.cookies.username;44 }45 git.filesNotPushed(rootDir+req.cookies.project+"/"+req.cookies.username,true,repo,function(filesNotPushed){46 var filesNP = [];47 if ((filesNotPushed != "")&&(filesNotPushed.indexOf("\n") != -1)){48 filesNP = filesNotPushed.split("\n",filesNotPushed.match(/\n/g).length);49 }50 var notPushedTree = [];51 var dirsAdded = {};52 filesNP.forEach(function(file){53 var state = file.split("\t")[0];54 file = file.split("\t")[1];55 var dirs = file.split("/");56 var lastDir = null;57 dirs.forEach(function(dir,index){58 if(index >= dirs.length - 1){59 var fileNotPushed = {checked:true,leaf:true,name:dir,fullpath:file,icon:getFileTypeIcon(file)};60 if(state == "A"){61 fileNotPushed.text = '<span style="color:green">' + dir + '</span>';62 }63 else if(state == "M"){64 fileNotPushed.text = '<span style="color:blue">' + dir + '</span>';65 }66 else if(state == "D"){67 fileNotPushed.text = '<span style="color:red">' + dir + '</span>';68 }69 else{70 fileNotPushed.text = '<span style="color:black">' + dir + '</span>';71 }72 if(lastDir == null){73 notPushedTree.push(fileNotPushed);74 }75 else{76 lastDir.children.push(fileNotPushed);77 }78 return;79 }80 if(lastDir == null){81 for(var i=0;i<notPushedTree.length;i++){82 if(dir == notPushedTree[i].name){83 lastDir = notPushedTree[i];84 return;85 }86 }87 lastDir = {expanded:true,checked:true,text:dir,name:dir,cls:"folder",leaf:false,children:[]};88 notPushedTree.push(lastDir);89 }90 else{91 for(var i2=0;i2<lastDir.children.length;i2++){92 if(dir == lastDir.children[i2].name){93 lastDir = lastDir.children[i2];94 return;95 }96 }97 var DirToAdd = {expanded:true,checked:true,text:dir,name:dir,cls:"folder",leaf:false,children:[]};98 lastDir.children.push(DirToAdd);99 lastDir = DirToAdd;100 }101 })102 });103 res.contentType('json');104 res.json({notPushed:notPushedTree});105 });106 });107};108exports.scriptsPush = function(req,res) {109 executionengine.compileBuild(req.cookies.project, req.cookies.username, function (err) {110 if (err != null) {111 res.contentType('json');112 res.json({error: "Unable to compile scripts. Make sure compilation problems are fixed before you push."});113 return;114 }115 git.gitStatus(rootDir + req.cookies.project + "/" + req.cookies.username, function (data) {116 if (data.indexOf("You have unmerged paths") != -1) {117 res.json({error: "You have unmerged files. Please resolve all conflicts first."});118 return;119 }120 var files = "";121 req.body.files.forEach(function (file) {122 if (files == "") {123 files = '"'+file+'"'124 }125 else {126 files = files + ' "' + file + '"'127 }128 });129 git.attachHEAD(rootDir + req.cookies.project + "/" + req.cookies.username, function () {130 //git.addAll(rootDir + req.cookies.project + "/" + req.cookies.username, function () {131 git.commit(rootDir + req.cookies.project + "/" + req.cookies.username,req.body.files, req.body.comment,function () {132 isProjectRemote(req.cookies.project,function(remote,externalRepoURL){133 if(remote == true){134 git.pushRemote(rootDir+req.cookies.project+"/"+req.cookies.username,"remoteRepo",req.cookies.username,function(code,cliOut) {135 res.contentType('json');136 if(code != 0){137 res.json({success:true,error:"Push did not succeed please do a pull first. "+cliOut});138 }139 else{140 res.json({success:true});141 }142 });143 }144 else{145 git.push(rootDir+req.cookies.project+"/"+req.cookies.username,function(code,error) {146 res.contentType('json');147 if(code != 0){148 res.json({success:true,error:"Push did not succeed please do a pull first.\r\n"+error});149 }150 else{151 res.json({success:true});152 }153 });154 }155 });156 });157 //});158 });159 });160 });161};162exports.scriptsPush_old = function(req,res){163 executionengine.compileBuild(req.cookies.project,req.cookies.username,function(err){164 if (err != null){165 res.contentType('json');166 res.json({error:"Unable to compile scripts. Make sure compilation problems are fixed before you push."});167 return;168 }169 git.gitStatus(rootDir+req.cookies.project+"/"+req.cookies.username,function(data){170 if(data.indexOf("You have unmerged paths") != -1){171 res.json({error:"You have unmerged files. Please resolve all conflicts first."});172 return;173 }174 var files = "";175 req.body.files.forEach(function(file){176 if(files == ""){177 files = file178 }179 else{180 files = files + "|" + file181 }182 });183 git.attachHEAD(rootDir+req.cookies.project+"/"+req.cookies.username,function(){184 git.pushDryRun(rootDir+req.cookies.project+"/"+req.cookies.username,function(code){185 if(code != 0){186 res.json({success:true,error:"Push did not succeed please do a pull first."});187 }188 else{189 git.addAll(rootDir+req.cookies.project+"/"+req.cookies.username,function() {190 git.commitAll(rootDir + req.cookies.project + "/" + req.cookies.username, function () {191 git.rebaseInteractive(rootDir+req.cookies.project+"/"+req.cookies.username,files,req.body.comment,function(cliOUT){192 var skipCommits = cliOUT.split("|||")[1];193 if(skipCommits == "0"){194 git.push(rootDir+req.cookies.project+"/"+req.cookies.username,function(code){195 res.json({success:true});196 git.filesInConflict(rootDir+req.cookies.project+"/"+req.cookies.username,function(filesInConflict) {197 git.filesNotPushed(rootDir + req.cookies.project + "/" + req.cookies.username, false, function (filesNotPushed) {198 if (filesNotPushed == "" && filesInConflict == "") {199 git.reset(rootDir + req.cookies.project + "/" + req.cookies.username, function () {200 });201 }202 git.attachHEAD(rootDir+req.cookies.project+"/"+req.cookies.username,function() {});203 });204 });205 })206 }207 else{208 git.pushSkipCommits(rootDir+req.cookies.project+"/"+req.cookies.username,skipCommits,function(code){209 res.json({success:true});210 git.filesInConflict(rootDir+req.cookies.project+"/"+req.cookies.username,function(filesInConflict) {211 git.filesNotPushed(rootDir + req.cookies.project + "/" + req.cookies.username, false, function (filesNotPushed) {212 if (filesNotPushed == "" && filesInConflict == "") {213 git.reset(rootDir + req.cookies.project + "/" + req.cookies.username, function () {214 });215 }216 git.attachHEAD(rootDir+req.cookies.project+"/"+req.cookies.username,function() {});217 });218 });219 })220 }221 })222 });223 });224 }225 });226 });227 });228 /*229 git.addAll(rootDir+req.cookies.project+"/"+req.cookies.username,function(){230 git.commitAll(rootDir+req.cookies.project+"/"+req.cookies.username,function(){231 git.push(rootDir+req.cookies.project+"/"+req.cookies.username,function(code){232 res.contentType('json');233 if(code != 0){234 res.json({success:true,error:"Push did not succeed please do a pull first."});235 }236 else{237 res.json({success:true});238 }239 });240 });241 });242 */243 })244};245function isProjectRemote(name,callback){246 var app = require('../common');247 var db = app.getDB();248 db.collection('projects', function(err, collection) {249 collection.findOne({name:name},{},function(err,project){250 callback(project.externalRepo,project.externalRepoURL);251 })252 })253}254exports.scriptsPull = function(req,res) {255 var handleConflictsAndPip = function(cliOut){256 git.filesInConflict(rootDir+req.cookies.project+"/"+req.cookies.username,function(filesInConflict){257 var files = [];258 if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){259 files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);260 }261 handleConflicts(rootDir+req.cookies.project+"/"+req.cookies.username,files,function(nonBinaryFiles){262 if(cliOut.indexOf("PipRequirements ") != -1){263 var uninstallAll = false;264 fs.readFile(rootDir+req.cookies.project+"/"+req.cookies.username+"/PipRequirements","utf8",function(err,data){265 if(!data.match(/[^\W_]/)){266 uninstallAll = true;267 }268 script.runPip(rootDir+req.cookies.project+"/"+req.cookies.username+"/PipRequirements",uninstallAll,req.cookies.username,function(freezeData){269 res.contentType('json');270 res.json({success:true,conflicts:nonBinaryFiles});271 realtime.emitMessage("PythonRequirementRun"+req.cookies.username,{freezeData:freezeData});272 })273 });274 }275 else{276 res.contentType('json');277 res.json({success:true,conflicts:nonBinaryFiles});278 }279 //try and delete jar file to trigger compile from execution280 try{281 git.attachHEAD(rootDir+req.cookies.project+"/"+req.cookies.username,function() {});282 fs.unlink(rootDir+req.cookies.project+"/"+req.cookies.username+"/build/jar/"+req.cookies.project+".jar",function(err){});283 }284 catch(err){}285 })286 });287 };288 var handleMerges = function(cliOut,remote,callback){289 var index = cliOut.indexOf("Your local changes to the following files would be overwritten by merge:\n");290 if(index != -1){291 var n2 = cliOut.indexOf("Please, commit");292 if (n2 != -1){293 var conflictingFiles = cliOut.substring(index+74,n2).split("\n");294 conflictingFiles.pop();295 var count = 0;296 conflictingFiles.forEach(function(file){297 git.commit(rootDir + req.cookies.project + "/" + req.cookies.username,file,"merge commit",function(){298 count++;299 if(count == conflictingFiles.length){300 if(remote == true){301 //git.pullRemote(rootDir + req.cookies.project + "/" + req.cookies.username,'remoteRepo', req.cookies.username,function (cliOut) {302 git.pullRemote(rootDir + req.cookies.project + "/" + req.cookies.username,'remoteRepo', "master",function (cliOut,error) {303 var index = error.indexOf("Your local changes to the following files would be overwritten by merge:\n");304 if(index != -1){305 handleMerges2(error,remote,function(cliOut){306 callback(cliOut);307 })308 }309 else{310 callback(cliOut);311 }312 });313 }314 else{315 git.pull(rootDir + req.cookies.project + "/" + req.cookies.username,function(cliOut,error){316 var index = error.indexOf("Your local changes to the following files would be overwritten by merge:\n");317 if(index != -1){318 handleMerges2(error,remote,function(cliOut){319 callback(cliOut);320 })321 }322 else{323 callback(cliOut);324 }325 })326 }327 }328 });329 })330 }331 }332 else{333 callback(cliOut);334 }335 };336 var handleMerges2 = function(cliOut,remote,callback){337 var index = cliOut.indexOf("Your local changes to the following files would be overwritten by merge:\n");338 if(index != -1){339 var n2 = cliOut.indexOf("Please, commit");340 if (n2 != -1){341 var conflictingFiles = cliOut.substring(index+74,n2).split("\n");342 conflictingFiles.pop();343 var count = 0;344 conflictingFiles.forEach(function(file){345 git.checkoutFileFromHead(rootDir + req.cookies.project + "/" + req.cookies.username,file,function(cliOut,error){346 count++;347 if(count == conflictingFiles.length){348 if(remote == true){349 //git.pullRemote(rootDir + req.cookies.project + "/" + req.cookies.username,'remoteRepo', req.cookies.username,function (cliOut) {350 git.pullRemote(rootDir + req.cookies.project + "/" + req.cookies.username,'remoteRepo', "master",function (cliOut,error) {351 callback(cliOut);352 });353 }354 else{355 git.pull(rootDir + req.cookies.project + "/" + req.cookies.username,function(cliOut,error){356 callback(cliOut);357 })358 }359 }360 });361 })362 }363 }364 else{365 callback(cliOut);366 }367 };368 git.filesInConflict(rootDir + req.cookies.project + "/" + req.cookies.username, function (filesInConflict) {369 if (filesInConflict != "") {370 res.json({371 success: true,372 conflicts: [],373 error: "Unable to pull. You still have unresoved conflicts.\n" + filesInConflict374 });375 return;376 }377 //git.addAll(rootDir + req.cookies.project + "/" + req.cookies.username, function () {378 //git.commitAll(rootDir + req.cookies.project + "/" + req.cookies.username, function () {379 isProjectRemote(req.cookies.project,function(remote,externalRepoURL){380 if(remote == true){381 //git.createBranch(rootDir + req.cookies.project + "/" + req.cookies.username,req.cookies.username,function(){382 //git.pullRemote(rootDir + req.cookies.project + "/" + req.cookies.username,'remoteRepo', req.cookies.username,function (cliOut) {383 git.pullRemote(rootDir + req.cookies.project + "/" + req.cookies.username,'remoteRepo', 'master',function (cliOut,error) {384 //git.pushRemote(rootDir + req.cookies.project + "/" + req.cookies.username,"remoteRepo",req.cookies.username,function(){385 handleMerges(error,true,function(cliOut){386 handleConflictsAndPip(cliOut);387 });388 //})389 });390 //})391 }392 else{393 git.pull(rootDir + req.cookies.project + "/" + req.cookies.username, function (cliOut,error) {394 handleMerges(error,false,function(cliOut){395 handleConflictsAndPip(cliOut);396 });397 //git.gitFetch(rootDir + req.cookies.project + "/" + req.cookies.username, function () {398 //accept theirs for binary399 //});400 });401 }402 });403 //});404 //});405 });406};407exports.scriptsPull_old = function(req,res){408 git.filesInConflict(rootDir+req.cookies.project+"/"+req.cookies.username,function(filesInConflict){409 if(filesInConflict != ""){410 res.json({success:true,conflicts:[],error:"Unable to pull. You still have unresoved conflicts.\n"+filesInConflict});411 return;412 }413 git.rebaseAbort(rootDir+req.cookies.project+"/"+req.cookies.username,function(){414 git.rebase(rootDir+req.cookies.project+"/"+req.cookies.username,function(){415 git.attachHEAD(rootDir+req.cookies.project+"/"+req.cookies.username,function() {416 git.addAll(rootDir+req.cookies.project+"/"+req.cookies.username,function(){417 git.commitAll(rootDir+req.cookies.project+"/"+req.cookies.username,function(){418 git.pull(rootDir+req.cookies.project+"/"+req.cookies.username,function(cliOut){419 git.gitFetch(rootDir+req.cookies.project+"/"+req.cookies.username,function(){420 git.filesInConflict(rootDir+req.cookies.project+"/"+req.cookies.username,function(filesInConflict){421 git.filesNotPushed(rootDir+req.cookies.project+"/"+req.cookies.username,false,function(filesNotPushed){422 if(filesNotPushed == "" && filesInConflict == ""){423 git.reset(rootDir+req.cookies.project+"/"+req.cookies.username,function(){});424 }425 });426 var files = [];427 if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){428 files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);429 }430 //accept theirs for binary431 handleConflicts(rootDir+req.cookies.project+"/"+req.cookies.username,files,function(nonBinaryFiles){432 if(cliOut.indexOf("PipRequirements ") != -1){433 var uninstallAll = false;434 fs.readFile(rootDir+req.cookies.project+"/"+req.cookies.username+"/PipRequirements","utf8",function(err,data){435 if(!data.match(/[^\W_]/)){436 uninstallAll = true;437 }438 script.runPip(rootDir+req.cookies.project+"/"+req.cookies.username+"/PipRequirements",uninstallAll,req.cookies.username,function(freezeData){439 res.contentType('json');440 res.json({success:true,conflicts:nonBinaryFiles});441 realtime.emitMessage("PythonRequirementRun"+req.cookies.username,{freezeData:freezeData});442 })443 });444 }445 else{446 res.contentType('json');447 res.json({success:true,conflicts:nonBinaryFiles});448 }449 //try and delete jar file to trigger compile from execution450 try{451 fs.unlink(rootDir+req.cookies.project+"/"+req.cookies.username+"/build/jar/"+req.cookies.project+".jar",function(err){})452 git.attachHEAD(rootDir+req.cookies.project+"/"+req.cookies.username,function() {});453 }454 catch(err){}455 })456 })457 });458 });459 });460 });461 });462 });463 });464 })465};466exports.handleConflicts = function(workingDir,files,callback){467 handleConflicts(workingDir,files,callback)468};469//accept theirs for binary files470function handleConflicts(workingDir,files,callback){471 var returnedFiles = [];472 if(files.length == 0){473 git.status(workingDir,function(cliOut){474 var cliFiles = [];475 if ((cliOut != "")&&(cliOut.indexOf("\n") != -1)){476 cliFiles = cliOut.split("\n",cliOut.match(/\n/g).length);477 }478 var matchHead = common.ArrayIndexOf(cliFiles,function(file){479 return file.indexOf("~HEAD") != -1 && file.indexOf("??") != -1;480 });481 if(matchHead != -1){482 var fileName = cliFiles[matchHead].split(" ")[1];483 fileName = fileName.split("~")[0];484 fs.unlink(workingDir+"/"+cliFiles[matchHead].split(" ")[1],function(err){});485 git.resetFile(workingDir,fileName,function() {486 git.acceptTheirs(workingDir, fileName, function () {487 git.add(workingDir, fileName, function () {488 //git.rebaseContinue(workingDir, function (cliOut) {489 //if (cliOut.indexOf("No changes - did you forget to use 'git add'?") != -1) {490 // git.rebaseSkip(workingDir, function () {491 // git.filesInConflict(workingDir,function(filesInConflict){492 // var files = [];493 // if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){494 // files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);495 // }496 // handleConflicts(workingDir,files,function(){497 //callback([])498 // })499 // })500 // });501 //}502 //else{503 git.filesInConflict(workingDir,function(filesInConflict){504 var files = [];505 if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){506 files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);507 }508 handleConflicts(workingDir,files,function(){509 callback([])510 })511 });512 //}513 //});514 });515 });516 });517 }518 else{519 callback(files);520 }521 });522 return;523 }524 var i = 1;525 git.isBinary(workingDir,files[0],function(binary){526 if(binary == true){527 git.resetFile(workingDir,files[0],function(){528 git.acceptTheirs(workingDir,files[0],function(){529 git.add(workingDir,files[0],function(){530 //git.rebaseContinue(workingDir,function(cliOut){531 //if(cliOut.indexOf("No changes - did you forget to use 'git add'?") != -1){532 // git.rebaseSkip(workingDir,function(){533 // git.filesInConflict(workingDir,function(filesInConflict){534 // var files = [];535 // if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){536 // files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);537 // }538 // handleConflicts(workingDir,files,function(){539 // callback([])540 // })541 // })542 // })543 //}544 //else{545 git.filesInConflict(workingDir,function(filesInConflict){546 var files = [];547 if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){548 files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);549 }550 handleConflicts(workingDir,files,function(){551 callback([])552 })553 });554 //}555 //})556 });557 });558 })559 }560 else{561 callback(files)562 }563 })564}565exports.scriptsGet = function(req, res){566 GetScripts(rootDir+req.cookies.project+"/"+req.cookies.username,req.cookies.project,req.cookies.username,function(data){567 res.contentType('json');568 res.json(data);569 /*570 res.json({571 success: true,572 text: "src",573 cls:"folder",574 expanded: true,575 children: data576 });*/577 });578};579exports.scriptsDelete = function(req, res){580 req.body.forEach(function(script, index, array){581 git.delete(rootDir+req.cookies.project+"/"+req.cookies.username,script.fullpath,function(){582 //git.commit(rootDir+req.cookies.project+"/"+req.cookies.username,"",function(){583 fs.exists(rootDir+req.cookies.project+"/"+req.cookies.username+"/bin",function(exists){584 if(exists == false){585 fs.mkdir(rootDir+req.cookies.project+"/"+req.cookies.username+"/bin")586 }587 });588 fs.exists(rootDir+req.cookies.project+"/"+req.cookies.username+"/src",function(exists){589 if(exists == false){590 fs.mkdir(rootDir+req.cookies.project+"/"+req.cookies.username+"/src")591 }592 });593 fs.exists(rootDir+req.cookies.project+"/"+req.cookies.username+"/External Libraries",function(exists){594 if(exists == false){595 fs.mkdir(rootDir+req.cookies.project+"/"+req.cookies.username+"/External Libraries")596 }597 });598 res.json({error:null});599 //if python delete any unneeded __init__.py files600 return;601 if (script.fullpath.slice(-2) == "py" && script.fullpath.indexOf("__init__.py") == -1){602 var parentPath = path.resolve(filePath,"../");603 var finalPath = path.resolve(projectPath+"/src","./");604 console.log(parentPath);605 //commit(filePath,function(){606 callback(null);607 while(finalPath != parentPath){608 if(fs.existsSync(parentPath+"/__init__.py") == false){609 fs.writeFileSync(parentPath+"/__init__.py","",'utf8');610 //commit(parentPath+"/__init__.py",function(){});611 }612 parentPath = path.resolve(parentPath,"../");613 }614 //});615 }616 //})617 })618 });619 //DeleteScripts(req.body,function(err){620 // res.json({error:null});621 //});622};623exports.scriptsCopy = function(req, res){624 //prevent multiple errors from sending625 var sent = false;626 CopyScripts(req.body.scripts,req.body.destDir,rootDir+req.cookies.project+"/"+req.cookies.username,function(err){627 git.add(rootDir+req.cookies.project+"/"+req.cookies.username,".",function(){628 //git.commit(rootDir+req.cookies.project+"/"+req.cookies.username,".",'copy',function(){629 if (sent) return;630 sent = true;631 if (err){632 res.json({error:err});633 }else{634 res.json({error:null});635 }636 //});637 });638 });639};640exports.CreateNewProject = function(projectName,language,template,callback){641 var templatePath = "";642 if(language == "Java/Groovy"){643 if (template == "Java Based Selenium") {644 template = "java_project_selenium";645 }646 else{647 template = "java_project";648 }649 //templatePath = path.resolve(__dirname,"../project_templates/"+"multi_test");650 templatePath = path.resolve(__dirname,"../project_templates/"+template);651 }652 var common = require('../common');653 var files = [];654 common.walkDir(templatePath,function(){655 var newProjectPath = path.resolve(__dirname,"../public/automationscripts/"+projectName);656 fs.mkdirSync(newProjectPath);657 var adminBranch = newProjectPath + "/admin";658 fs.mkdirSync(adminBranch);659 var masterBranch = newProjectPath + "/master.git";660 fs.mkdirSync(masterBranch);661 git.initBare(masterBranch,function(){662 git.clone(adminBranch,masterBranch,function(){663 fs.writeFile(newProjectPath + "/admin/.gitignore","build\r\nPythonWorkDir\r\n**/*.pyc\r\n.ssh/*",function(){});664 //fs.writeFile(newProjectPath + "/admin/.gitignore","build\r\nPythonWorkDir\r\n**/*.pyc\r\n**/__init__.py\r\n.ssh/*",function(){});665 SetupPython(adminBranch);666 files.forEach(function(file,index,array){667 var destName = file.replace(templatePath,"");668 destName = adminBranch+destName;669 //console.log(destName);670 if (fs.statSync(file).isDirectory()){671 fs.mkdirSync(destName);672 }673 else{674 var data = "";675 if (file.indexOf("build.xml") != -1){676 data = fs.readFileSync(file,"utf8");677 data = data.replace('<project name="ProjectName"','<project name="'+ projectName +'"');678 }679 else{680 data = fs.readFileSync(file);681 }682 fs.writeFileSync(destName,data);683 }684 });685 if(fs.existsSync(newProjectPath + "/admin/src") == false){686 fs.mkdirSync(newProjectPath + "/admin/src");687 }688 if(fs.existsSync(newProjectPath + "/admin/" +"bin") == false){689 fs.mkdirSync(newProjectPath + "/admin/" +"bin");690 }691 git.add(adminBranch,".",function(){692 git.commit(adminBranch,"","new project",function(){693 git.push(adminBranch,function(){694 users.getAllUsers(function(users){695 console.log('--eval var projectName="'+projectName+'" '+path.resolve(__dirname,"../project_templates/"+template+".js"));696 if(fs.existsSync(path.resolve(__dirname,"../project_templates/"+template+".js"))){697 var mongoScript = spawn(path.resolve(__dirname,'../vendor/MongoDB/bin/mongo'),['--eval','var projectName="'+projectName+'"',path.resolve(__dirname,"../project_templates/"+template+".js")],{cwd: path.resolve(__dirname,'../vendor/MongoDB/bin'),timeout:300000});698 //var mongoScript = spawn(path.resolve(__dirname,'../vendor/MongoDB/bin/mongo.exe'),['--eval','localhost:27017/automationframework','var projectName="'+projectName+'"',path.resolve(__dirname,"../project_templates/"+template+".js")],{cwd: path.resolve(__dirname,'../vendor/MongoDB/bin'),timeout:300000});699 mongoScript.stdout.on('data', function (data) {700 common.logger.info(data.toString());701 });702 mongoScript.stderr.on('data', function (data) {703 common.logger.error('stderr: ' + data.toString());704 });705 mongoScript.on('exit', function (code) {706 callback();707 });708 }709 else{710 callback();711 }712 users.forEach(function(user){713 if (user.username !== "admin"){714 fs.mkdirSync(newProjectPath + "/" + user.username);715 SetupPython(newProjectPath + "/" + user.username);716 git.clone(newProjectPath + "/" + user.username,masterBranch,function(){717 if(fs.existsSync(newProjectPath + "/" + user.username + "/src") == false){718 fs.mkdirSync(newProjectPath + "/" + user.username + "/src");719 }720 if(fs.existsSync(newProjectPath + "/" + user.username + "/" +"bin") == false){721 fs.mkdirSync(newProjectPath + "/" + user.username + "/" +"bin");722 }723 git.setGitUser(newProjectPath + "/" + user.username,user.username,user.email);724 fs.writeFile(newProjectPath + "/" + user.username+"/.gitignore","build\r\nPythonWorkDir\r\n**/*.pyc\r\n.ssh/*",function(){725 //fs.writeFile(newProjectPath + "/" + user.username+"/.gitignore","build\r\nPythonWorkDir\r\n**/*.pyc\r\n**/__init__.py\r\n.ssh/*",function(){726 git.addAll(newProjectPath + "/" + user.username,function(){727 git.commitAll(newProjectPath + "/" + user.username,function(){728 git.push(newProjectPath + "/" + user.username,function(){})729 })730 })731 });732 });733 }734 else{735 git.setGitUser(newProjectPath + "/admin","admin","admin@admin.com");736 }737 });738 });739 })740 })741 });742 });743 });744 },function(file){files.push(file)})745};746exports.setupPython = function(userFolder,callback){SetupPython(userFolder,callback)};747function SetupPython(userFolder,callback){748 var python;749 if(process.platform == "win32") {750 python = spawn("cmd.exe", ["/K"]);751 python.stdin.write("cd \"" + path.resolve(__dirname, '../vendor/Python') + "\"\r\n");752 python.stdin.write("for %I in (.) do cd %~sI\r\n");753 python.stdin.write('python Lib/site-packages/virtualenv.py "' + userFolder + '/PythonWorkDir"\r\n');754 //python.stdin.end();755 //python.disconnect();756 //python = python.stdin.write(path.resolve(__dirname,'../vendor/Python/Scripts/virtualenv.exe'),['PythonWorkDir'],{cwd: userFolder,timeout:300000});757 }758 else{759 if(fs.existsSync("/usr/local/bin/virtualenv")){760 python = spawn('/usr/local/bin/virtualenv',['PythonWorkDir'],{cwd: userFolder,timeout:300000});761 }762 else{763 python = spawn('/usr/bin/virtualenv',['PythonWorkDir'],{cwd: userFolder,timeout:300000});764 }765 }766 var cliData = "";767 python.stdout.on('data', function (data) {768 cliData = cliData + data.toString();769 if(cliData.indexOf("done.") != -1){770 python.stdin.end();771 //python.disconnect();772 }773 //common.logger.info('stdout: ' + data);774 });775 python.stderr.on('data', function (data) {776 common.logger.error('Setup Python Scripts stderr: ' + data);777 });778 python.on('close', function (code) {779 //fs.writeFile(userFolder + "/" + ".gitignore","Scripts");780 //callback(cliData);781 if(callback)callback();782 });783}784function CopyScripts(scripts,destDir,projectDir,callback){785 var errFound = false;786 var lastLoop = false;787 scripts.forEach(function(script, index, array){788 if (errFound){789 return;790 }791 if (index == array.length -1){792 lastLoop = true;793 }794 if (fs.statSync(script).isDirectory()){795 var DirName = script.substring(script.lastIndexOf("/")+1,script.length);796 DirName = destDir+"/"+DirName;797 if (fs.existsSync(DirName)){798 callback("Directory:" +DirName+" already exists.");799 errFound = true;800 return;801 }802 fs.mkdirSync(DirName);803 var walker = walk.walkSync(script);804 var files = [];805 walker.on("file", function (root, fileStats, next) {806 files.push({from:script+"/"+fileStats.name,to:DirName + "/"+fileStats.name});807 next();808 });809 walker.on("directories", function (root, dirs, next) {810 dirs.forEach(function(dir){811 var writeDir = DirName + "/" + dir.name;812 fs.mkdirSync(writeDir);813 });814 next();815 });816 walker.on("end", function () {817 //console.log(files);818 var count = 0;819 files.forEach(function(file,index){820 fs.readFile(file.from,function(err,data){821 fs.writeFileSync(file.to,data);822 count++;823 if(count == files.length){824 if(lastLoop)callback();825 }826 })827 });828 });829 /*830 common.walkDir(script,function(){if(lastLoop)callback();},function(file){831 if(fs.statSync(file).isDirectory()){832 var writeDir = DirName + file.replace(script,"");833 fs.mkdirSync(writeDir);834 }835 else{836 fs.readFile(file,function(err,data){837 var writeDir = DirName + file.replace(script,"");838 if (err){839 callback(err);840 errFound = true;841 return;842 }843 fs.writeFile(writeDir,data,function(err){844 if (err){845 callback(err);846 errFound = true;847 }848 else{849 git.add(projectDir,writeDir,function(){850 git.commit(projectDir,writeDir,function(){851 //callback(null)852 });853 });854 }855 });856 })857 }858 });859 */860 }861 else{862 var data = fs.readFileSync(script);863 var name = script.substring(script.lastIndexOf("/")+1,script.length);864 if (fs.existsSync(destDir+"/"+name)){865 callback("File:" +destDir+"/"+name+" already exists.");866 errFound = true;867 return;868 }869 fs.writeFile(destDir+"/"+name,data,function(err){870 if (err){871 callback(err);872 errFound = true;873 return;874 }875 else{876 git.add(projectDir,destDir+"/"+name,function(){877 //git.commit(projectDir,destDir+"/"+name,'copy',function(){878 //callback(null)879 if((lastLoop)&& (errFound == false)){880 callback();881 }882 //});883 });884 }885 });886 }887 });888}889function GetScripts(rootDir,project,user,callback){890 git.filesInConflict(rootDir,function(filesInConflict){891 isProjectRemote(project,function(remote,externalRepoURL){892 var repo = "origin/master";893 if(remote == true){894 repo = "remotes/remoteRepo/"+user895 }896 git.filesNotPushed(rootDir,false,repo,function(filesNotPushed){897 var files = [];898 if ((filesInConflict != "")&&(filesInConflict.indexOf("\n") != -1)){899 files = filesInConflict.split("\n",filesInConflict.match(/\n/g).length);900 }901 var filesNP = [];902 if ((filesNotPushed != "")&&(filesNotPushed.indexOf("\n") != -1)){903 filesNP = filesNotPushed.split("\n",filesNotPushed.match(/\n/g).length);904 }905 walkDir(rootDir,files,filesNP, function(err, results) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var path = require('path');3var projectPath = path.join(__dirname, 'project');4redwood.isProjectRemote(projectPath, function (error, isRemote) {5 if (error) {6 console.log(error);7 } else {8 console.log(isRemote);9 }10});11isProjectRemote(projectPath, callback)12var redwood = require('redwood');13var path = require('path');14var projectPath = path.join(__dirname, 'project');15redwood.isProjectRemote(projectPath, function (error, isRemote) {16 if (error) {17 console.log(error);18 } else {19 console.log(isRemote);20 }21});22isProjectRemote(projectPath, callback)23var redwood = require('redwood');24var path = require('path');25var projectPath = path.join(__dirname, 'project');26redwood.isProjectRemote(projectPath, function (error, isRemote) {27 if (error) {28 console.log(error);29 } else {30 console.log(isRemote);31 }32});33isProjectRemote(projectPath, callback)34var redwood = require('redwood');35var path = require('path');36var projectPath = path.join(__dirname, 'project');37redwood.isProjectRemote(projectPath, function (error, isRemote) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var remote = redwood.isProjectRemote();3console.log(remote);4exports.isProjectRemote = function() {5 var remote = false;6 var projectPath = process.env.REDWOOD_PROJECT_PATH;7 if(projectPath) {8 remote = true;9 }10 return remote;11};12var redwood = require('/path/to/redwood.js');13var redwood = require('/path/to/redwood.js');14var redwood = require('redwood');15exports.isProjectRemote = function() {16 var remote = false;17 var projectPath = process.env.REDWOOD_PROJECT_PATH;18 if(projectPath) {19 remote = true;20 }21 return remote;22};23I was able to fix this by changing the redwood.js file to the following: var redwood = require('redwood'); exports.isProjectRemote = function() { var remote = false; var projectPath = process.env.REDWOOD_PROJECT_PATH; if(projectPath) { remote = true; } return remote; };

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var project = redwood.project;3console.log(project.isProjectRemote());4var redwood = require('/usr/local/lib/node_modules/redwood');5var redwood = require('usr/local/lib/node_modules/redwood');6var redwood = require('usr/local/lib/node_modules/redwood/lib/redwood');7var redwood = require('/usr/local/lib/node_modules/redwood/lib/redwood');8var redwood = require('redwood/lib/redwood');9var redwood = require('/usr/local/lib/node_modules/redwood/lib/redwood');10var redwood = require('/usr/local/lib/node_modules/redwood/lib');11var redwood = require('/usr/local/lib/node_modules/redwood');12var redwood = require('/usr/local/lib/node_modules/redwood/');13var redwood = require('/usr/local/lib/node_modules/redwood');14var redwood = require('/usr/local/lib/node_modules/redwood/'

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var red = redwood.createClient();3red.isProjectRemote(function(err, remote) {4 if (err) throw err;5 console.log(remote);6});7{ [Error: ENOENT, no such file or directory '/Users/username/.redwood/config.json'] errno: 34, code: 'ENOENT', path: '/Users/username/.redwood/config.json' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var project = redwood.project;3var myProject = project.open("myProject");4var isRemote = myProject.isProjectRemote();5console.log(isRemote);6var redwood = require('redwood');7var project = redwood.project;8var myProject = project.open("myProject");9var isRemote = myProject.isProjectRemote();10console.log(isRemote);11Your name to display (optional):12Your name to display (optional):13var redwood = require('redwood');14var project = redwood.project;15var myProject = project.open("myProject");16var isRemote = myProject.isProjectRemote();17console.log(isRemote);

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 redwood 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