file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import * as path from 'path' ; import * as iq from '../modules/sfdx-falcon-util/interview-questions' ; import { SfdxFalconDebug } from '../modules/sfdx-falcon-debug' ; import { SfdxFalconInterview } from '../modules/sfdx-falcon-interview' ; import { SfdxFalconKeyValueTableDataRow } from '../modules/sfdx-falcon-util/ux' ; import { SfdxFalconTableData } from '../modules/sfdx-falcon-util/ux' ; import { GeneratorOptions } from '../modules/sfdx-falcon-yeoman-command' ; import { SfdxFalconYeomanGenerator } from '../modules/sfdx-falcon-yeoman-generator' ; import { YeomanChoice } from '../modules/sfdx-falcon-types' ; import { SfdxOrgInfoMap } from '../modules/sfdx-falcon-types' ; const chalk = require ( 'chalk' ) ; const dbgNs = 'GENERATOR:create-appx-demo:' ; interface description interface InterviewAnswers { projectFamily : 'APK' | 'ADK' ; projectType : 'single-demo' | 'multi-demo' ; projectVersion : string ; targetDirectory : string ; developerName : string ; developerAlias : string ; projectName : string ; projectAlias : string ; packageDirectory : string ; defaultRecipe : string ; devHubAlias : string ; envHubAlias : string ; devHubUsername : string ; envHubUsername : string ; scratchDefOrgName : string ; scratchDefDescription : string ; isInitializingGit : boolean ; hasGitRemote : boolean ; isGitRemoteReachable : boolean ; ackGitRemoteUnreachable : boolean ; gitRemoteUri : string ; gitHubUrl : string ; schemaVersion : string ; pluginVersion : string ; sfdcApiVersion : string ; } class extends SfdxFalconYeomanGenerator summary description public export default class CreateAppxDemoProject extends SfdxFalconYeomanGenerator < InterviewAnswers > { protected devHubAliasChoices : YeomanChoice [ ] ; protected envHubAliasChoices : YeomanChoice [ ] ; protected sourceDirectory : string ; constructs param { string | string [ ] } args param { GeneratorOptions } opts description public constructor ( args , opts ) { super ( args , opts ) ; this . confirmationQuestion = 'Create a new AppExchange Demo Kit (ADK) project using the above settings?' ; this . sourceDirectory = require . resolve ( 'sfdx-falcon-appx-demo-kit' ) ; this . devHubAliasChoices = new Array < YeomanChoice > ( ) ; this . envHubAliasChoices = new Array < YeomanChoice > ( ) ; this . defaultAnswers . projectFamily = 'ADK' ; this . defaultAnswers . projectType = 'single-demo' ; this . defaultAnswers . projectVersion = '0.0.1' ; this . defaultAnswers . targetDirectory = path . resolve ( opts . outputDir as string ) ; this . defaultAnswers . developerName = 'Universal Containers' ; this . defaultAnswers . developerAlias = 'univ-ctrs' ; this . defaultAnswers . projectName = 'Universal Containers Demo App' ; this . defaultAnswers . projectAlias = 'uc-demo-app' ; this . defaultAnswers . defaultRecipe = 'demo-recipe.json' ; this . defaultAnswers . devHubAlias = 'NOT_SPECIFIED' ; this . defaultAnswers . envHubAlias = 'NOT_SPECIFIED' ; this . defaultAnswers . devHubUsername = 'NOT_SPECIFIED' ; this . defaultAnswers . envHubUsername = 'NOT_SPECIFIED' ; this . defaultAnswers . scratchDefOrgName = 'ADK Demo Org' ; this . defaultAnswers . scratchDefDescription = 'ADK Demo Org' ; this . defaultAnswers . isInitializingGit = true ; this . defaultAnswers . hasGitRemote = true ; this . defaultAnswers . isGitRemoteReachable = false ; this . defaultAnswers . ackGitRemoteUnreachable = false ; this . defaultAnswers . gitRemoteUri = 'https://github.com/my-org/my-repo.git' ; this . defaultAnswers . gitHubUrl = 'https://github.com/my-org/my-repo' ; this . defaultAnswers . schemaVersion = '0.0.1' ; this . defaultAnswers . sfdcApiVersion = this . sfdcApiVersion ; this . defaultAnswers . pluginVersion = this . pluginVersion ; this . metaAnswers . devHubAlias = `<%-finalAnswers.devHubAlias%>` ; this . metaAnswers . envHubAlias = `<%-finalAnswers.envHubAlias%>` ; this . sharedData [ 'devHubAliasChoices' ] = this . devHubAliasChoices ; this . sharedData [ 'envHubAliasChoices' ] = this . envHubAliasChoices ; this . sharedData [ 'cliCommandName' ] = this . cliCommandName ; } method returns { SfdxFalconInterview < InterviewAnswers > } description protected protected _buildInterview ( ) { const interview = new SfdxFalconInterview < InterviewAnswers > ( { defaultAnswers : this . defaultAnswers , confirmation : iq . confirmProceedRestart , confirmationHeader : chalk . yellow ( 'Review Your Settings:' ) , display : this . _buildInterviewAnswersTableData , context : this , sharedData : this . sharedData } ) ; interview . createGroup ( { title : chalk . yellow ( '\nTarget Directory:' ) , questions : iq . provideTargetDirectory } ) ; interview . createGroup ( { title : chalk . yellow ( '\nDevHub Selection:' ) , questions : iq . chooseDevHub , confirmation : iq . confirmNoDevHub , abort : groupAnswers => { if ( groupAnswers . devHubUsername === 'NOT_SPECIFIED' ) { return 'A connection to your DevHub is required to continue.' ; } else { return false ; } } } ) ; interview . createGroup ( { title : chalk . yellow ( '\nEnvironment Hub Selection:' ) , questions : iq . chooseEnvHub , confirmation : iq . confirmNoEnvHub } ) ; interview . createGroup ( { title : chalk . yellow ( '\nDeveloper Info:' ) , questions : iq . provideDeveloperInfo } ) ; interview . createGroup ( { title : chalk . yellow ( '\nProject Info:' ) , questions : iq . provideProjectInfo } ) ; interview . createGroup ( { title : chalk . yellow ( '\nGit Configuration:' ) , questions : iq . provideGitRemote , confirmation : iq . confirmNoGitHubRepo , invertConfirmation : true } ) ; return interview ; } method param { InterviewAnswers } userAnswers returns { Promise < SfdxFalconTableData > } description protected protected async _buildInterviewAnswersTableData ( interviewAnswers ) { const tableData = new Array < SfdxFalconKeyValueTableDataRow > ( ) ; const sfdxOrgInfoMap = this . sharedData [ 'sfdxOrgInfoMap' ] as SfdxOrgInfoMap ; tableData . push ( { option : 'Target Directory:' , value : `${ interviewAnswers . targetDirectory }` } ) ; const devHubAlias = sfdxOrgInfoMap . get ( interviewAnswers . devHubUsername ) ? sfdxOrgInfoMap . get ( interviewAnswers . devHubUsername ) . alias : 'NOT_SPECIFIED' ; tableData . push ( { option : 'Dev Hub Alias:' , value : `${ devHubAlias }` } ) ; const envHubAlias = sfdxOrgInfoMap . get ( interviewAnswers . envHubUsername ) ? sfdxOrgInfoMap . get ( interviewAnswers . envHubUsername ) . alias : 'NOT_SPECIFIED' ; tableData . push ( { option : 'Env Hub Alias:' , value : `${ envHubAlias }` } ) ; tableData . push ( { option : 'Developer Name:' , value : `${ interviewAnswers . developerName }` } ) ; tableData . push ( { option : 'Developer Alias:' , value : `${ interviewAnswers . developerAlias }` } ) ; tableData . push ( { option : 'Project Name:' , value : `${ interviewAnswers . projectName }` } ) ; tableData . push ( { option : 'Project Alias:' , value : `${ interviewAnswers . projectAlias }` } ) ; tableData . push ( { option : 'Initialize Git:' , value : `${ interviewAnswers . isInitializingGit ? 'Yes' : 'No' }` } ) ; if ( interviewAnswers . hasGitRemote && interviewAnswers . isInitializingGit ) { tableData . push ( { option : 'Git Remote URI:' , value : `${ interviewAnswers . gitRemoteUri }` } ) ; if ( interviewAnswers . isGitRemoteReachable ) { tableData . push ( { option : 'Git Remote Status:' , value : `${ chalk . blue ( 'AVAILABLE' ) }` } ) ; } else { tableData . push ( { option : 'Git Remote Status:' , value : `${ chalk . red ( 'UNREACHABLE' ) }` } ) ; } } return tableData ; } method returns { Promise < void > } description protected async protected async initializing ( ) { return this . _default_initializing ( ) ; } method returns { Promise < void > } description protected async protected async prompting ( ) { console . log ( chalk `{yellow Starting ADK project creation interview...}` ) ; return this . _default_prompting ( ) ; } method returns { void } description protected protected configuring ( ) { return this . _default_configuring ( ) ; } method returns { void } description protected protected writing ( ) { if ( this . generatorStatus . aborted ) { SfdxFalconDebug . msg ( `${ dbgNs }writing:` , `generatorStatus.aborted found as TRUE inside writing()` ) ; return ; } const sfdxOrgInfoMap = this . sharedData [ 'sfdxOrgInfoMap' ] as SfdxOrgInfoMap ; this . finalAnswers . scratchDefOrgName = `${ this . finalAnswers . projectName } - Demo Org` ; this . finalAnswers . scratchDefDescription = `ADK Sample Demo Org` ; this . finalAnswers . devHubAlias = sfdxOrgInfoMap . get ( this . finalAnswers . devHubUsername ) ? sfdxOrgInfoMap . get ( this . finalAnswers . devHubUsername ) . alias : 'NOT_SPECIFIED' ; this . finalAnswers . envHubAlias = sfdxOrgInfoMap . get ( this . finalAnswers . envHubUsername ) ? sfdxOrgInfoMap . get ( this . finalAnswers . envHubUsername ) . alias : 'NOT_SPECIFIED' ; this . sourceRoot ( path . dirname ( this . sourceDirectory ) ) ; this . destinationRoot ( path . resolve ( this . finalAnswers . targetDirectory , this . finalAnswers . projectAlias ) ) ; SfdxFalconDebug . str ( `${ dbgNs }writing:sourceRoot:` , this . sourceRoot ( ) , `this.sourceRoot(): ` ) ; SfdxFalconDebug . str ( `${ dbgNs }writing:destinationRoot:` , this . destinationRoot ( ) , `this.destinationRoot(): ` ) ; this . log ( chalk `{yellow Writing project files to ${ this . destinationRoot ( ) }...}` ) ; this . fs . copyTpl ( this . templatePath ( '.templates' ) , this . destinationPath ( '.templates' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'config' ) , this . destinationPath ( 'config' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'data' ) , this . destinationPath ( 'data' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'docs' ) , this . destinationPath ( 'docs' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'mdapi-source' ) , this . destinationPath ( 'mdapi-source' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'sfdx-source' ) , this . destinationPath ( 'sfdx-source' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'temp' ) , this . destinationPath ( 'temp' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'tools' ) , this . destinationPath ( 'tools' ) , this ) ; this . fs . copyTpl ( this . templatePath ( '.forceignore' ) , this . destinationPath ( '.forceignore' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'DEMO_README.md' ) , this . destinationPath ( 'README.md' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'LICENSE' ) , this . destinationPath ( 'LICENSE' ) , this ) ; this . fs . copyTpl ( this . templatePath ( 'sfdx-project.json' ) , this . destinationPath ( 'sfdx-project.json' ) , this ) ; let ignoreFile = '.gitignore' ; try { this . fs . read ( this . templatePath ( '.gitignore' ) ) ; } catch { ignoreFile = '.npmignore' ; } this . fs . copyTpl ( this . templatePath ( `${ ignoreFile }` ) , this . destinationPath ( '.gitignore' ) , this ) ; this . fs . copyTpl ( this . templatePath ( `temp/${ ignoreFile }` ) , this . destinationPath ( 'temp/.gitignore' ) , this ) ; this . fs . copyTpl ( this . templatePath ( `tools/${ ignoreFile }` ) , this . destinationPath ( 'tools/.gitignore' ) , this ) ; this . metaAnswers . devHubAlias = this . finalAnswers . devHubAlias ; this . metaAnswers . envHubAlias = this . finalAnswers . envHubAlias ; this . fs . copyTpl ( this . templatePath ( '.templates/sfdx-falcon-config.json.ejs' ) , this . destinationPath ( '.sfdx-falcon/sfdx-falcon-config.json' ) , this ) ; return ; } method returns { void } description protected async protected async install ( ) { if ( this . _finalizeProjectCreation ( ) !== true ) { return ; } await this . _finalizeGitActions ( this . destinationRoot ( ) , this . finalAnswers . isInitializingGit , this . finalAnswers . hasGitRemote ? this . finalAnswers . gitRemoteUri : '' , this . finalAnswers . projectAlias ) ; } method returns { void } description protected protected end ( ) { return this . _default_end ( ) ; } }