Skip to content

Commit

Permalink
refactor(yeoman): Update create/clone commands
Browse files Browse the repository at this point in the history
Continued refactoring of create/clone commands in an effort to clean up
tslint errors and reduce repetitive code across Generators.

Related to: #22 #139
  • Loading branch information
VivekMChawla committed Apr 6, 2019
1 parent 5465166 commit 976e80a
Show file tree
Hide file tree
Showing 5 changed files with 919 additions and 1,612 deletions.
50 changes: 24 additions & 26 deletions src/commands/falcon/apk/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @file commands/falcon/apk/create.ts
* @copyright Vivek M. Chawla - 2018
* @author Vivek M. Chawla <@VivekMChawla>
* @summary Yeoman Generator for scaffolding an SFDX-Falcon project.
* @summary Implements the CLI command "falcon:apk:create"
* @description Salesforce CLI Plugin command (falcon:apk:create) that allows a Salesforce DX
* developer to create an empty project based on the SFDX-Falcon template. Before
* the project is created, the user is guided through an interview where they define
Expand All @@ -13,21 +13,21 @@
* @license MIT
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
// External Imports
// Import External Modules
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 Internal Modules
import {SfdxFalconYeomanCommand} from '../../../modules/sfdx-falcon-yeoman-command'; // Base class that CLI commands in this project that use Yeoman should use.
// Import Local Modules
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-apk-create:';
//const clsDbgNs = 'FalconApkCreate:';

// Use SfdxCore's Messages framework to get the message bundle for this command.
Messages.importMessagesDirectory(__dirname);
Expand All @@ -42,7 +42,6 @@ const commandMessages = Messages.loadMessages('sfdx-falcon', 'falconApkCreate');
* @description The command "falcon:apk:create" creates a local SFDX project using the
* scaffolding found at https://github.com/sfdx-isv/sfdx-falcon-appx-package-kit.
* Uses Yeoman to create customized project scaffolding on the user's machine.
* @version 1.0.0
* @public
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
Expand All @@ -56,21 +55,14 @@ export default class FalconApkCreate extends SfdxFalconYeomanCommand {
`$ sfdx falcon:apk:create --outputdir ~/projects/sfdx-falcon-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 SFDX-Falcon 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,52 +73,58 @@ export default class FalconApkCreate 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:apk: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:apk:create', SfdxFalconCommandType.APPX_PACKAGE);

// Run a Yeoman Generator to interact with and run tasks for the user.
await super.runYeomanGenerator({
generatorType: 'create-appx-package-project',
gitRemoteUri: this.gitRemoteUri,
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;
}
}
}
Loading

0 comments on commit 976e80a

Please sign in to comment.