LOCAL YEOMAN GENERATOR
generator-cmd >> yo cmd
- YEOMAN SFDX Generator with AUTO COMPLETE
- This will allow faster typing of SFDX commands
- Rely on"sfdx commands --json"
command in order to generate the options as auto-complete
- Simply Typeyo [generator name]
and yeoman will walk you through the command you wish to invoke
DEMO
- This will allow to auto-complete any SFDX command
yo cmd
- will show the first prompt question
⣾ getting sfdx commands...
✔ all SFDX commands were pulled successfully
? Choose a Command : (Use arrow keys or type to search)
❯ commands
force:alias:list
force:alias:set
force:apex:class:create
force:apex:execute
(Move up and down to reveal more choices)
sfdx commands
Few simple steps, install Yeoman (we assume you have pre-installed node.js and sfdx cli ).
- Install SFDX
npm install sfdx-cli --global
- Install Yo
npm install -g yo
-
Clone this repository
-
Rename the git folder to
generator-cmd
or whatever you wish to call it.
-- just make sure to change theproject.json
file accordingly and step inside it
mv [sourceFolder] [targetName] // to rename the folder as the generator named
cd generator-cmd
- Once finished editing the
project.json
file link required npm modules
npm link
Then call your new workflow generator with:
yo cmd
Feel Free to build your own Generator using the generator for generators
npm install -g yo generator-generator
- Yeoman has a heart of gold.
- Yeoman is a person with feelings and opinions, but is very easy to work with.
- Yeoman can be too opinionated at times but is easily convinced not to be.
- Feel free to learn more about Yeoman.
yosay - Tell Yo to Say Hello
details: - description: yosay will tell yo what to say using yeoman ASCII image sample: this.log( yosay( 'Hello World' );
chalk.js - Give some colour
details: - description: Will allow to add colours to the input/output sample: this.log( chalk.redBright.underline('Hello World') );
shelljs - Unix shell commands on top of the Node.js API
details: - description: Will allow to run shell commands examples: // get the output of the command silently - shell.exec(' sfdx force:org:list --json', { silent: true } ) -- .stdout // output -- .stderr // error -- .code // code ( 0 : SUCCESS ) // get list of directories in folder - const folders = shell.ls('-L',this.destinationPath() );- <a href="https://devhints.io/shelljs" target="_blank"> shelljs </a> - cheat sheet
ora - Elegant terminal spinner
details: - description: Will allow to show a spinner for running process require : - const spinner = require('ora'); sample: // Start loading spinner this.loading = new spinner( { spinner:'dots', color : 'yellow' } ).start('Start Spinning...'); // Success - this.loading.succeed('Successfully loaded'); // Failure - this.loading.fail('Failed to load');
inquirer-autocomplete-prompt - A plugin for Inquirer that allows autocomplete select prompt.
const fuzzy = require('fuzzy');initializing() { this.env.adapter.promptModule.registerPrompt("autocomplete", require("inquirer-autocomplete-prompt")); }
prompting() { const colors = [ { name : 'red', value : 'red'}, { name : 'blue', value : 'blue'}, { name : 'green', value : 'green'}, ]; this.props = {}; return this.prompt( [ { type: 'autocomplete', name: 'color', message: 'Select a state to travel from', source: function(answersSoFar, input) { input = input || ''; return new Promise(function(resolve) { var fuzzyResult = fuzzy.filter(input, colors, { extract: function(item) { return item['name']; } }); var data = fuzzyResult.map(function(element) { return element.original; }); resolve(data); }); })].then((answers) => { this.props = answers.color; // etc }); } }
inquirer-checkbox-plus-prompt - A plugin for Inquirer that allows multi select with autocomplete.
const fuzzy = require('fuzzy');initializing() { this.env.adapter.promptModule.registerPrompt("checkbox-plus", require("inquirer-checkbox-plus-prompt")); }
prompting() { const colors = [ { name : 'red', value : 'red'}, { name : 'blue', value : 'blue'}, { name : 'green', value : 'green'}, ]; this.props = {}; return this.prompt( [ { type: 'checkbox-plus', name: 'colors', message: 'Select color', pageSize: 5, highlight: true, searchable: true, default: ['red','blue'], validate: function(answer) { return answer.length != 0 ? true : 'You must choose at least one color.'; }, source: function(answersSoFar, input) { input = input || ''; return new Promise(function(resolve) { var fuzzyResult = fuzzy.filter(input, colors, { extract: function(item) { return item['name']; } });
var data = fuzzyResult.map(function(element) { return element.original; }); resolve(data); }); })].then((answers) => { this.props = answers.colors; });
} }
Inquirer.js - Dynamic questions and validation of prompt questions
details: - description: Will allow to add logic to questions sample: const questions = [{ type: 'checkbox', name: 'mainMenu', message: 'What would you like to do ?', validate: function(choices) { return choices.length > 0 ? true : chalk.redBright('Must Select at least one option'); }, choices: [ { type: 'separator', line:'-˯-˯-˯-˯-˯-˯-˯' }, { name: 'New Project', value: 'create-project' , checked: false }, { name: 'New Scratch Org', value: 'create-org', checked: false }, { type: 'separator', line: '-^-^-^-^-^-^-^' } ] }, { type: "input", name: "inputName", message: "Please give a name to your project : "), default:'Yuval', when: function(answers) { return answers.mainMenu.includes("create-project"); }, validate: function(value) { return value ? true : 'Please enter a name'; } } ];
mem-fs-editor - helpers working on top of mem-fs
details: - description: Will allow to access file system sample: // read file as Json object - this.fs.readJSON('filePath'); // check if file path exists - this.fs.exists('filePath'); // delete file - this.fs.delete('filePath');