Skip to content

Commit

Permalink
chore(cleanup): Minor cleanup in Generator files
Browse files Browse the repository at this point in the history
Minor cleanup in files related to Yeoman Generator logic.  Most of these
files already had their big refactoring moments. This commit is mostly
small cleanup items discovered while refactoring the falcon:apk:create
command.

Related to: #22 #139
  • Loading branch information
VivekMChawla committed Apr 6, 2019
1 parent 7e4240b commit 5465166
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 100 deletions.
2 changes: 0 additions & 2 deletions src/commands/falcon/adk/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const commandMessages = Messages.loadMessages('sfdx-falcon', 'falconAdkClone');
* existing project that's based on the AppExchange Demo Kit (ADK) template. After
* the project is cloned, the user is taken through an interview to help set up
* developer-specific project variables.
* @version 1.0.0
* @public
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
Expand Down Expand Up @@ -111,7 +110,6 @@ export default class FalconAdkClone extends SfdxFalconYeomanCommand {
* @returns {Promise<AnyJson>} Resolves with a JSON object that the CLI
* will pass to the user as stdout if the --json flag was set.
* @description Entrypoint function for "sfdx falcon:adk:clone".
* @version 1.0.0
* @public @async
*/
//───────────────────────────────────────────────────────────────────────────┘
Expand Down
55 changes: 27 additions & 28 deletions src/commands/falcon/adk/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @summary Implements the CLI command "falcon:adk:create"
* @description Salesforce CLI Plugin command (falcon:adk:create) that allows a Salesforce DX
* developer to create an empty project based on the AppExchange Demo Kit (ADK)
* template. Once the ADK project is created, the user is guided through an
* template. Once the ADK project is created, the user is guided through an
* interview where they define key ADK project settings which are then used to
* customize the ADK project scaffolding that gets created on their local machine.
* @version 1.0.0
Expand All @@ -17,17 +17,17 @@
import {flags} from '@salesforce/command'; // Allows creation of flags for CLI commands.
import {Messages} from '@salesforce/core'; // Messages library that simplifies using external JSON for string reuse.
import {SfdxError} from '@salesforce/core'; // Generalized SFDX error which also contains an action.
import {AnyJson} from '@salesforce/ts-types'; // Safe type for use where "any" might otherwise be used.

// Import Local Modules
import {SfdxFalconYeomanCommand} from '../../../modules/sfdx-falcon-yeoman-command'; // Base class that CLI commands in this project that use Yeoman should use.
import {SfdxFalconError} from '../../../modules/sfdx-falcon-error'; // Extends SfdxError to provide specialized error structures for SFDX-Falcon modules.
import {SfdxFalconYeomanCommand} from '../../../modules/sfdx-falcon-yeoman-command'; // Base class that CLI commands in this project that use Yeoman should use.

// Import Internal Types
import {SfdxFalconCommandType} from '../../../modules/sfdx-falcon-command'; // Enum. Represents the types of SFDX-Falcon Commands.

// Set the File Local Debug Namespace
//const dbgNs = 'COMMAND:falcon-demo-create:';
//const clsDbgNs = 'FalconDemoCreate:';
//const dbgNs = 'COMMAND:falcon-adk-create:';

// Use SfdxCore's Messages framework to get the message bundle for this command.
Messages.importMessagesDirectory(__dirname);
Expand All @@ -36,17 +36,16 @@ const commandMessages = Messages.loadMessages('sfdx-falcon', 'falconAdkCreate');

//─────────────────────────────────────────────────────────────────────────────────────────────────┐
/**
* @class FalconDemoCreate
* @class FalconAdkCreate
* @extends SfdxFalconYeomanCommand
* @summary Implements the CLI Command "falcon:adk:create"
* @description The command "falcon:adk:create" creates a local AppExchange Demo Kit (ADK)
* project using the ADK template found at ???. Uses Yeoman to create customized ADK
* project scaffolding on the user's local machine.
* @version 1.0.0
* the project at https://github.com/sfdx-isv/sfdx-falcon-appx-demo-kit as a template.
* Uses Yeoman to create customized ADK project scaffolding on the user's machine.
* @public
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
export default class FalconDemoCreate extends SfdxFalconYeomanCommand {
export default class FalconAdkCreate extends SfdxFalconYeomanCommand {

// Define the basic properties of this CLI command.
public static description = commandMessages.getMessage('commandDescription');
Expand All @@ -56,21 +55,14 @@ export default class FalconDemoCreate extends SfdxFalconYeomanCommand {
`$ sfdx falcon:adk:create --outputdir ~/ADK-Projects`
];

// Identify the core SFDX arguments/features required by this command.
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
protected static requiresUsername = false; // True if an org username is REQUIRED.
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
protected static supportsUsername = false; // True if an org username is OPTIONAL.
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.

//───────────────────────────────────────────────────────────────────────────┐
// Define the flags used by this command.
// -d --OUTPUTDIR Directory where the AppX Demo Kit project will be created.
// Defaults to . (current directory) if not specified.
//───────────────────────────────────────────────────────────────────────────┘
protected static flagsConfig = {
outputdir: flags.directory({
char: 'd',
char: 'd',
required: false,
description: commandMessages.getMessage('outputdir_FlagDescription'),
default: '.',
Expand All @@ -81,17 +73,23 @@ export default class FalconDemoCreate extends SfdxFalconYeomanCommand {
...SfdxFalconYeomanCommand.falconBaseflagsConfig
};

// Identify the core SFDX arguments/features required by this command.
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
protected static requiresUsername = false; // True if an org username is REQUIRED.
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
protected static supportsUsername = false; // True if an org username is OPTIONAL.
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.

//───────────────────────────────────────────────────────────────────────────┐
/**
* @function run
* @returns {Promise<any>} Resolves with a JSON object that the CLI will
* pass to the user as stdout if the --json flag was set.
* @returns {Promise<AnyJson>} Resolves with a JSON object that the CLI
* will pass to the user as stdout if the --json flag was set.
* @description Entrypoint function for "sfdx falcon:adk:create".
* @version 1.0.0
* @public @async
*/
//───────────────────────────────────────────────────────────────────────────┘
public async run(): Promise<any> {
public async run():Promise<AnyJson> {

// Initialize the SfdxFalconCommand (required by ALL classes that extend SfdxFalconCommand).
this.sfdxFalconCommandInit('falcon:adk:create', SfdxFalconCommandType.APPX_DEMO);
Expand All @@ -102,30 +100,31 @@ export default class FalconDemoCreate extends SfdxFalconYeomanCommand {
outputDir: this.outputDirectory,
options: []
})
.then(statusReport => {this.onSuccess(statusReport)}) // <-- Preps this.falconJsonResponse for return
.catch(error => {this.onError(error)}); // <-- Wraps any errors and displays to user
.then(generatorResult => this.onSuccess(generatorResult)) // Implemented by parent class
.catch(generatorResult => this.onError(generatorResult)); // Implemented by parent class

// Return the JSON Response that was created by onSuccess()
return this.falconJsonResponse;
return this.falconJsonResponse as unknown as AnyJson;
}

//───────────────────────────────────────────────────────────────────────────┐
/**
* @method buildFinalError
* @param {SfdxFalconError} cmdError Required. Error object used as
* the basis for the "friendly error message" being created
* @param {SfdxFalconError} cmdError Required. Error object used as
* the basis for the "friendly error message" being created
* by this method.
* @returns {SfdxError}
* @description Builds a user-friendly error message that is appropriate to
* the CLI command that's being implemented by this class. The
* output of this method will always be used by the onError()
* method from the base class to communicate the end-of-command
* method from the base class to communicate the end-of-command
* error state.
* @protected
*/
//───────────────────────────────────────────────────────────────────────────┘
protected buildFinalError(cmdError:SfdxFalconError):SfdxError {

// If not implementing anything special here, simply return cmdError.
return cmdError;
}
}
}
16 changes: 8 additions & 8 deletions src/commands/falcon/adk/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ export default class FalconDemoInstall extends SfdxFalconCommand {
` --configfile my-alternate-demo-config.json`
];

// Identify the core SFDX arguments/features required by this command.
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
protected static requiresUsername = false; // True if an org username is REQUIRED.
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
protected static supportsUsername = false; // True if an org username is OPTIONAL.
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.

//───────────────────────────────────────────────────────────────────────────┐
// -d --PROJECTDIR Directory where a fully configured AppX Demo Kit (ADK)
// project exists. All commands for deployment must be
Expand Down Expand Up @@ -106,10 +99,17 @@ export default class FalconDemoInstall extends SfdxFalconCommand {
...SfdxFalconCommand.falconBaseflagsConfig
};

// Identify the core SFDX arguments/features required by this command.
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
protected static requiresUsername = false; // True if an org username is REQUIRED.
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
protected static supportsUsername = false; // True if an org username is OPTIONAL.
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.

//───────────────────────────────────────────────────────────────────────────┐
/**
* @function run
* @returns {Promise<any>} This should resolve by returning a JSON object
* @returns {Promise<AnyJson>} This should resolve by returning a JSON object
* that the CLI will then forward to the user if the --json flag
* was set when this command was called.
* @description Entrypoint function used by the CLI when the user wants to
Expand Down
Loading

0 comments on commit 5465166

Please sign in to comment.