Created
December 19, 2017 16:08
-
-
Save amphro/770a72972825406b62718f125a834289 to your computer and use it in GitHub Desktop.
SFDX List Project Orgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exec = require('child_process').execSync; | |
let lines = exec('sfdx force:org:list --all').toString().split(/\n/); | |
let index; | |
// Skip the non-scratch orgs | |
for (var i in lines) { | |
if (lines[i].toString().match(/.*SCRATCH ORG NAME.*/)) { | |
index = i; | |
break; | |
} | |
} | |
if (!index) { | |
console.log('No scratch orgs'); | |
process.exit(1); | |
} | |
lines = lines.slice(index); | |
// Global scratch orgs | |
const globalorgs = lines.slice(3, -4); | |
// Project scratch orgs, assuming you have pushed to them | |
const projectorgs = exec('ls .sfdx/orgs').toString().split(/\s+/); | |
const orglines = []; | |
// Find project orgs that match the global orgs | |
globalorgs.forEach(line => { | |
projectorgs.forEach(orgname => { | |
if (orgname && line.indexOf(orgname) >= 0) { | |
console.log(line.indexOf(orgname), orgname) | |
orglines.push(line) | |
} | |
}) | |
}); | |
if (orglines.length > 0) { | |
console.log(lines.slice(0, 3).join('\n')) | |
console.log(orglines.join('\n')) | |
console.log(lines.slice(-4).join('\n')) | |
} else { | |
console.log('No active project scratch orgs'); | |
process.exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment