import * as fs from 'fs' ; import * as path from 'path' ; import * as Generator from 'yeoman-generator' ; import { TemplateService } from '../service/templateService' ; import { TemplateOptions } from '../utils/types' ; /**
 * Base class for generators
 */ export abstract class SfdxGenerator < TOptions extends TemplateOptions > extends Generator < Generator . GeneratorOptions > { options ! : TOptions & { apiversion : string ; outputdir : string ; } ; /**
     * Set by sourceRootWithPartialPath called in generator
     */ public builtInTemplatesRootPath ? : string ; constructor ( args , options ) { super ( args , options ) ; this . options . apiversion = this . options . apiversion ?? TemplateService . getDefaultApiVersion ( ) ; this . options . outputdir = this . options . outputdir ?? process . cwd ( ) ; this . validateOptions ( ) ; } /**
     * Validate provided options
     */ public abstract validateOptions ( ) ; param partialPath public sourceRootWithPartialPath ( partialPath ) { this . builtInTemplatesRootPath = path . join ( __dirname , '..' , 'templates' , partialPath ) ; const { customTemplatesRootPath } = TemplateService . getInstance ( ) ; if ( ! customTemplatesRootPath ) { this . sourceRoot ( path . join ( this . builtInTemplatesRootPath ) ) ; } else { if ( fs . existsSync ( path . join ( customTemplatesRootPath , partialPath ) ) ) { this . sourceRoot ( path . join ( customTemplatesRootPath , partialPath ) ) ; } } } public templatePath ( ... paths ) { const customPath = super . templatePath ( ... paths ) ; if ( fs . existsSync ( customPath ) ) { return customPath ; } else { return super . templatePath ( path . join ( this . builtInTemplatesRootPath ! , ... paths ) ) ; } } }