-
Notifications
You must be signed in to change notification settings - Fork 6
/
create.ts
131 lines (116 loc) · 8.2 KB
/
create.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
/**
* @file commands/falcon/adk/create.ts
* @copyright Vivek M. Chawla - 2018
* @author Vivek M. Chawla <@VivekMChawla>
* @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
* 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
* @license MIT
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
// 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 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 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:';
// Use SfdxCore's Messages framework to get the message bundle for this command.
Messages.importMessagesDirectory(__dirname);
const commandMessages = Messages.loadMessages('sfdx-falcon', 'falconAdkCreate');
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
/**
* @class FalconDemoCreate
* @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
* @public
*/
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
export default class FalconDemoCreate extends SfdxFalconYeomanCommand {
// Define the basic properties of this CLI command.
public static description = commandMessages.getMessage('commandDescription');
public static hidden = false;
public static examples = [
`$ sfdx falcon:adk:create`,
`$ 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',
required: false,
description: commandMessages.getMessage('outputdir_FlagDescription'),
default: '.',
hidden: false
}),
// IMPORTANT! The next line MUST be here to import the FalconDebug flags.
...SfdxFalconYeomanCommand.falconBaseflagsConfig
};
//───────────────────────────────────────────────────────────────────────────┐
/**
* @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.
* @description Entrypoint function for "sfdx falcon:adk:create".
* @version 1.0.0
* @public @async
*/
//───────────────────────────────────────────────────────────────────────────┘
public async run(): Promise<any> {
// Initialize the SfdxFalconCommand (required by ALL classes that extend SfdxFalconCommand).
this.sfdxFalconCommandInit('falcon:adk:create', SfdxFalconCommandType.APPX_DEMO);
// Run a Yeoman Generator to interact with and run tasks for the user.
await super.runYeomanGenerator({
generatorType: 'create-appx-demo-project',
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
// Return the JSON Response that was created by onSuccess()
return this.falconJsonResponse;
}
//───────────────────────────────────────────────────────────────────────────┐
/**
* @method buildFinalError
* @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
* error state.
* @protected
*/
//───────────────────────────────────────────────────────────────────────────┘
protected buildFinalError(cmdError:SfdxFalconError):SfdxError {
// If not implementing anything special here, simply return cmdError.
return cmdError;
}
}