14
14
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
********************************************************************************/
16
16
17
+ import type execa = require( 'execa' ) ;
17
18
import path = require( 'path' ) ;
18
19
import Base = require( 'yeoman-generator' ) ;
19
20
const request = require ( 'request' ) ;
@@ -68,8 +69,11 @@ module.exports = class TheiaExtension extends Base {
68
69
electronMainLocation : string
69
70
} ;
70
71
71
- constructor ( args : string | string [ ] , options : any ) {
72
- super ( args , options ) ;
72
+ constructor ( args : string | string [ ] , options : Base . GeneratorOptions ) {
73
+ // For v5 generators the '<npm|pnpm|yarn> install' task is implicitely invoked by 'yeoman-environment' since 'yeoman-environment@3', see
74
+ // https://github.com/yeoman/environment/commit/ab9582a70073203c7a6b58fb6dbf1f4eba249d48#diff-54bc5f4bd40f22e081d54b6c20bbf2523e438cf2f2716b91714a1f596e4d87cd
75
+ // since we spawn the pm processes on our own in 'install()', we need to declare that here in order to avoid errors because of concurrent runs!
76
+ super ( args , options , { customInstallTask : true } ) ;
73
77
74
78
this . argument ( 'extensionName' , {
75
79
type : String ,
@@ -270,7 +274,7 @@ module.exports = class TheiaExtension extends Base {
270
274
}
271
275
}
272
276
273
- writing ( ) {
277
+ async writing ( ) {
274
278
if ( this . params . extensionType !== ExtensionType . DiagramEditor ) {
275
279
if ( ! this . options . standalone ) {
276
280
/** common templates */
@@ -464,12 +468,10 @@ module.exports = class TheiaExtension extends Base {
464
468
this . fs . move (
465
469
this . extensionPath ( 'src/browser/README.md' ) ,
466
470
this . extensionPath ( `README.md` ) ,
467
- { params : this . params }
468
471
) ;
469
472
this . fs . move (
470
473
this . extensionPath ( 'src/browser/tree-frontend-module.ts' ) ,
471
474
this . extensionPath ( `src/browser/${ this . params . extensionPath } -frontend-module.ts` ) ,
472
- { params : this . params }
473
475
) ;
474
476
}
475
477
@@ -485,28 +487,28 @@ module.exports = class TheiaExtension extends Base {
485
487
return ;
486
488
}
487
489
488
- const done = this . async ( ) ;
489
- request . get ( `https://github.com/eclipse-glsp/glsp-examples/archive/refs/tags/${ glspExamplesRepositoryTag } .tar.gz` ) . pipe ( tar . x ( ) . on ( 'close' , ( ) => {
490
- fs . copy ( baseDir + '/README.md' , './README.md' ) ;
491
- fs . copy ( baseDir + templatePath , './' ) . then ( ( ) => {
492
- fs . rm ( baseDir , { recursive : true } ) ;
493
- done ( ) ;
494
- } ) ;
495
- } ) ) ;
490
+ return new Promise < void > ( ( resolve ) => {
491
+ request . get ( `https://github.com/eclipse-glsp/glsp-examples/archive/refs/tags/${ glspExamplesRepositoryTag } .tar.gz` ) . pipe ( tar . x ( ) . on ( 'close' , ( ) => {
492
+ fs . copy ( baseDir + '/README.md' , './README.md' ) ;
493
+ fs . copy ( baseDir + templatePath , './' ) . then ( ( ) => {
494
+ fs . rm ( baseDir , { recursive : true } ) ;
495
+ resolve ( ) ;
496
+ } ) ;
497
+ } ) ) ;
498
+ } ) ;
496
499
}
497
500
}
498
501
499
502
protected extensionPath ( ...paths : string [ ] ) {
500
503
return this . destinationPath ( this . params . extensionPath , ...paths ) ;
501
504
}
502
505
503
- install ( ) {
506
+ async install ( ) {
504
507
if ( ! ( this . options as any ) . skipInstall ) {
505
- if ( this . params . extensionType == ExtensionType . DiagramEditor ) {
506
- this . log ( 'Installing dependencies' ) ;
507
-
508
- const command = this . spawnCommand ( 'yarn' , [ ] ) ;
508
+ this . log ( 'Installing dependencies' ) ;
509
+ const command : execa . ExecaChildProcess = this . spawnCommand ( 'yarn' , [ ] ) ;
509
510
511
+ if ( this . params . extensionType == ExtensionType . DiagramEditor ) {
510
512
command . on ( 'close' , ( code :number ) => {
511
513
if ( code === 0 ) {
512
514
this . log (
@@ -518,15 +520,15 @@ module.exports = class TheiaExtension extends Base {
518
520
process . exit ( code ) ;
519
521
}
520
522
} ) ;
521
- } else {
522
- const command = this . spawnCommand ( 'yarn' , [ ] ) ;
523
-
523
+ } else {
524
524
command . on ( 'close' , function ( code : number ) {
525
525
if ( code !== 0 ) {
526
526
process . exit ( code ) ;
527
527
}
528
528
} )
529
529
}
530
+
531
+ return command ;
530
532
}
531
533
}
532
534
0 commit comments