@@ -78,7 +78,7 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
7878 private readonly onEnvironmentCallbacks : Array < ( this : this, env : Environment ) => any > = [ ] ;
7979
8080 private readonly inDirCallbacks : any [ ] = [ ] ;
81- private readonly Generator : string | GeneratorConstructor < GeneratorType > | typeof Generator ;
81+ private readonly Generator ? : string | GeneratorConstructor < GeneratorType > | typeof Generator ;
8282 private readonly helpers : YeomanTest ;
8383 private readonly temporaryDir = path . join ( tempDirectory , crypto . randomBytes ( 20 ) . toString ( 'hex' ) ) ;
8484
@@ -102,7 +102,7 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
102102 */
103103
104104 constructor (
105- generatorType : string | GeneratorConstructor < GeneratorType > | typeof Generator ,
105+ generatorType ? : string | GeneratorConstructor < GeneratorType > | typeof Generator ,
106106 settings ?: RunContextSettings ,
107107 envOptions : Options = { } ,
108108 helpers = defaultHelpers ,
@@ -530,17 +530,7 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
530530 return this ;
531531 }
532532
533- protected assertNotBuild ( ) {
534- if ( this . built || this . completed ) {
535- throw new Error ( 'The context is already built' ) ;
536- }
537- }
538-
539- /**
540- * Build the generator and the environment.
541- * @return {RunContext|false } this
542- */
543- protected async build ( ) : Promise < void > {
533+ async prepare ( ) {
544534 this . assertNotBuild ( ) ;
545535
546536 this . built = true ;
@@ -576,6 +566,20 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
576566 // eslint-disable-next-line no-await-in-loop
577567 await onTargetDirectory . call ( this , this . targetDirectory ) ;
578568 }
569+ }
570+
571+ protected assertNotBuild ( ) {
572+ if ( this . built || this . completed ) {
573+ throw new Error ( 'The context is already built' ) ;
574+ }
575+ }
576+
577+ /**
578+ * Build the generator and the environment.
579+ * @return {RunContext|false } this
580+ */
581+ protected async build ( ) : Promise < void > {
582+ await this . prepare ( ) ;
579583
580584 const testEnv = await this . helpers . createTestEnv ( this . envOptions . createEnv , {
581585 cwd : this . settings . forwardCwd ? this . targetDirectory : undefined ,
@@ -616,6 +620,22 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
616620 return this . environmentPromise ?? this . run ( ) ;
617621 }
618622
623+ protected _createRunResultOptions ( ) : RunResultOptions < GeneratorType > {
624+ return {
625+ env : this . env ,
626+ generator : this . generator ,
627+ memFs : this . env ?. sharedFs ?? this . memFs ,
628+ settings : {
629+ ...this . settings ,
630+ } ,
631+ oldCwd : this . oldCwd ! ,
632+ cwd : this . targetDirectory ! ,
633+ envOptions : this . envOptions ,
634+ mockedGenerators : this . mockedGenerators ,
635+ helpers : this . helpers ,
636+ } ;
637+ }
638+
619639 /**
620640 * Keeps compatibility with events
621641 */
@@ -672,22 +692,6 @@ export class RunContextBase<GeneratorType extends Generator = Generator> extends
672692 this . targetDirectory = dirPath ;
673693 return this ;
674694 }
675-
676- private _createRunResultOptions ( ) : RunResultOptions < GeneratorType > {
677- return {
678- env : this . env ,
679- generator : this . generator ,
680- memFs : this . env . sharedFs ,
681- settings : {
682- ...this . settings ,
683- } ,
684- oldCwd : this . oldCwd ! ,
685- cwd : this . targetDirectory ! ,
686- envOptions : this . envOptions ,
687- mockedGenerators : this . mockedGenerators ,
688- helpers : this . helpers ,
689- } ;
690- }
691695}
692696
693697export default class RunContext < GeneratorType extends Generator = Generator >
@@ -716,3 +720,10 @@ export default class RunContext<GeneratorType extends Generator = Generator>
716720 return `RunContext` ;
717721 }
718722}
723+
724+ export class BasicRunContext extends RunContext {
725+ async run ( ) : PromiseRunResult < any > {
726+ await this . prepare ( ) ;
727+ return new RunResult ( this . _createRunResultOptions ( ) ) ;
728+ }
729+ }
0 commit comments