Last active
November 5, 2019 20:34
-
-
Save vyuvalv/cc337918de56521c0970286005947d5a to your computer and use it in GitHub Desktop.
Will Initialize the generator with spinner, pull defaults and yosay image success
This file contains hidden or 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 Generator = require('yeoman-generator'); // this | |
const yosay = require('yosay'); // Yeoman Image | |
const chalk = require('chalk'); // color text | |
const shell = require('shelljs'); // shell commands | |
const spinner = require('ora'); // spinner | |
module.exports = class extends Generator { | |
initializing() { | |
// Start loading spinners | |
this.loading = new spinner( | |
{ spinner:'monkey', | |
color : 'yellow' } | |
); | |
// Silently get the available orgs as JSON | |
let orgsOutput = JSON.parse( shell.exec(' sfdx force:org:list --json', { silent: true } ).stdout ); | |
// Parse all non Scratch orgs | |
const nonScratchOrgs = orgsOutput.result.nonScratchOrgs; | |
// Parse all Scratch orgs | |
const scratchOrgs = orgsOutput.result.scratchOrgs; | |
// sets Default DevHub | |
this.devHubOrg = nonScratchOrgs.find(org => org.isDevHub); | |
// sets Default Org | |
this.defaultOrg = scratchOrgs.find(org => org.isDefaultUsername); | |
this.defaultOrg.alias = this.defaultOrg.alias ? this.defaultOrg.alias : { alias : 'NONE'}; | |
if(this.devHubOrg){ | |
// tell yo to say something colourful | |
this.log(yosay( chalk.redBright( "SFDX Default Orgs ") + | |
chalk.yellow( "Default DevHub : ") + chalk.cyan(this.devHubOrg.alias) + | |
chalk.yellow( " Default Org : ") + chalk.cyan( this.defaultOrg.alias ) )); | |
// Stops Spinner and show success | |
this.loading.succeed('Pulled defaults successfully'); | |
} | |
else { | |
// Stops Spinner and show failure | |
this.loading.fail('Failed to pull defaults'); | |
// Tell yo to say you need to connect | |
this.log( yosay( chalk.redBright('NEED TO CONNECT DEVHUB') )); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment