Skip to content

Commit 5465166

Browse files
committed
chore(cleanup): Minor cleanup in Generator files
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
1 parent 7e4240b commit 5465166

File tree

8 files changed

+99
-100
lines changed

8 files changed

+99
-100
lines changed

src/commands/falcon/adk/clone.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const commandMessages = Messages.loadMessages('sfdx-falcon', 'falconAdkClone');
4444
* existing project that's based on the AppExchange Demo Kit (ADK) template. After
4545
* the project is cloned, the user is taken through an interview to help set up
4646
* developer-specific project variables.
47-
* @version 1.0.0
4847
* @public
4948
*/
5049
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
@@ -111,7 +110,6 @@ export default class FalconAdkClone extends SfdxFalconYeomanCommand {
111110
* @returns {Promise<AnyJson>} Resolves with a JSON object that the CLI
112111
* will pass to the user as stdout if the --json flag was set.
113112
* @description Entrypoint function for "sfdx falcon:adk:clone".
114-
* @version 1.0.0
115113
* @public @async
116114
*/
117115
//───────────────────────────────────────────────────────────────────────────┘

src/commands/falcon/adk/create.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @summary Implements the CLI command "falcon:adk:create"
77
* @description Salesforce CLI Plugin command (falcon:adk:create) that allows a Salesforce DX
88
* developer to create an empty project based on the AppExchange Demo Kit (ADK)
9-
* template. Once the ADK project is created, the user is guided through an
9+
* template. Once the ADK project is created, the user is guided through an
1010
* interview where they define key ADK project settings which are then used to
1111
* customize the ADK project scaffolding that gets created on their local machine.
1212
* @version 1.0.0
@@ -17,17 +17,17 @@
1717
import {flags} from '@salesforce/command'; // Allows creation of flags for CLI commands.
1818
import {Messages} from '@salesforce/core'; // Messages library that simplifies using external JSON for string reuse.
1919
import {SfdxError} from '@salesforce/core'; // Generalized SFDX error which also contains an action.
20+
import {AnyJson} from '@salesforce/ts-types'; // Safe type for use where "any" might otherwise be used.
2021

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

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

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

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

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

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

59-
// Identify the core SFDX arguments/features required by this command.
60-
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
61-
protected static requiresUsername = false; // True if an org username is REQUIRED.
62-
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
63-
protected static supportsUsername = false; // True if an org username is OPTIONAL.
64-
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.
65-
6658
//───────────────────────────────────────────────────────────────────────────┐
6759
// Define the flags used by this command.
6860
// -d --OUTPUTDIR Directory where the AppX Demo Kit project will be created.
6961
// Defaults to . (current directory) if not specified.
7062
//───────────────────────────────────────────────────────────────────────────┘
7163
protected static flagsConfig = {
7264
outputdir: flags.directory({
73-
char: 'd',
65+
char: 'd',
7466
required: false,
7567
description: commandMessages.getMessage('outputdir_FlagDescription'),
7668
default: '.',
@@ -81,17 +73,23 @@ export default class FalconDemoCreate extends SfdxFalconYeomanCommand {
8173
...SfdxFalconYeomanCommand.falconBaseflagsConfig
8274
};
8375

76+
// Identify the core SFDX arguments/features required by this command.
77+
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
78+
protected static requiresUsername = false; // True if an org username is REQUIRED.
79+
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
80+
protected static supportsUsername = false; // True if an org username is OPTIONAL.
81+
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.
82+
8483
//───────────────────────────────────────────────────────────────────────────┐
8584
/**
8685
* @function run
87-
* @returns {Promise<any>} Resolves with a JSON object that the CLI will
88-
* pass to the user as stdout if the --json flag was set.
86+
* @returns {Promise<AnyJson>} Resolves with a JSON object that the CLI
87+
* will pass to the user as stdout if the --json flag was set.
8988
* @description Entrypoint function for "sfdx falcon:adk:create".
90-
* @version 1.0.0
9189
* @public @async
9290
*/
9391
//───────────────────────────────────────────────────────────────────────────┘
94-
public async run(): Promise<any> {
92+
public async run():Promise<AnyJson> {
9593

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

108106
// Return the JSON Response that was created by onSuccess()
109-
return this.falconJsonResponse;
107+
return this.falconJsonResponse as unknown as AnyJson;
110108
}
111109

112110
//───────────────────────────────────────────────────────────────────────────┐
113111
/**
114112
* @method buildFinalError
115-
* @param {SfdxFalconError} cmdError Required. Error object used as
116-
* the basis for the "friendly error message" being created
113+
* @param {SfdxFalconError} cmdError Required. Error object used as
114+
* the basis for the "friendly error message" being created
117115
* by this method.
118116
* @returns {SfdxError}
119117
* @description Builds a user-friendly error message that is appropriate to
120118
* the CLI command that's being implemented by this class. The
121119
* output of this method will always be used by the onError()
122-
* method from the base class to communicate the end-of-command
120+
* method from the base class to communicate the end-of-command
123121
* error state.
124122
* @protected
125123
*/
126124
//───────────────────────────────────────────────────────────────────────────┘
127125
protected buildFinalError(cmdError:SfdxFalconError):SfdxError {
126+
128127
// If not implementing anything special here, simply return cmdError.
129128
return cmdError;
130129
}
131-
}
130+
}

src/commands/falcon/adk/install.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ export default class FalconDemoInstall extends SfdxFalconCommand {
6565
` --configfile my-alternate-demo-config.json`
6666
];
6767

68-
// Identify the core SFDX arguments/features required by this command.
69-
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
70-
protected static requiresUsername = false; // True if an org username is REQUIRED.
71-
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
72-
protected static supportsUsername = false; // True if an org username is OPTIONAL.
73-
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.
74-
7568
//───────────────────────────────────────────────────────────────────────────┐
7669
// -d --PROJECTDIR Directory where a fully configured AppX Demo Kit (ADK)
7770
// project exists. All commands for deployment must be
@@ -106,10 +99,17 @@ export default class FalconDemoInstall extends SfdxFalconCommand {
10699
...SfdxFalconCommand.falconBaseflagsConfig
107100
};
108101

102+
// Identify the core SFDX arguments/features required by this command.
103+
protected static requiresProject = false; // True if an SFDX Project workspace is REQUIRED.
104+
protected static requiresUsername = false; // True if an org username is REQUIRED.
105+
protected static requiresDevhubUsername = false; // True if a hub org username is REQUIRED.
106+
protected static supportsUsername = false; // True if an org username is OPTIONAL.
107+
protected static supportsDevhubUsername = false; // True if a hub org username is OPTIONAL.
108+
109109
//───────────────────────────────────────────────────────────────────────────┐
110110
/**
111111
* @function run
112-
* @returns {Promise<any>} This should resolve by returning a JSON object
112+
* @returns {Promise<AnyJson>} This should resolve by returning a JSON object
113113
* that the CLI will then forward to the user if the --json flag
114114
* was set when this command was called.
115115
* @description Entrypoint function used by the CLI when the user wants to

0 commit comments

Comments
 (0)