Skip to content

Commit c44e654

Browse files
bumped yeoman version to "^5.0.0", solves #182 (#187)
* related refinements in the 'TheiaExtension' generator * added launch config for debugging the generator * tested with yo@4 and yo@5 Signed-off-by: Christian Schneider <[email protected]>
1 parent f337f93 commit c44e654

File tree

4 files changed

+3379
-1964
lines changed

4 files changed

+3379
-1964
lines changed

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Yo via NPM",
9+
"type": "node",
10+
"request": "launch",
11+
"preLaunchTask": "npm: mkdir-debug-cwd",
12+
"runtimeExecutable": "npx",
13+
"program": "yo",
14+
"args": [
15+
"theia-extension"
16+
],
17+
"cwd": "${workspaceFolder}/testing",
18+
"console": "integratedTerminal",
19+
"skipFiles": [
20+
"<node_internals>/**"
21+
],
22+
}
23+
]
24+
}

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
"fs-extra": "^10.0.0",
2424
"request": "^2.88.2",
2525
"tar": "^6.1.1",
26-
"yeoman-generator": "^4.0.2"
26+
"yeoman-generator": "^5.0.0"
2727
},
2828
"devDependencies": {
2929
"@types/mocha": "^5.2.7",
30-
"@types/yeoman-generator": "^3.1.4",
30+
"@types/yeoman-generator": "^5.0.0",
3131
"mocha": "^6.2.0",
3232
"rimraf": "^3.0.0",
3333
"typescript": "~4.5.5",
3434
"yeoman-assert": "^3.1.1",
35-
"yeoman-test": "^2.0.0"
35+
"yeoman-environment": "^3.0.0",
36+
"yeoman-test": "^5.0.0"
3637
},
3738
"files": [
3839
"generators",
@@ -43,6 +44,8 @@
4344
"clean": "rimraf lib",
4445
"build": "tsc",
4546
"watch": "tsc -w",
46-
"test": "mocha"
47+
"test": "mocha",
48+
"mkdir-debug-cwd": "mkdirp ./testing && rimraf ./testing/*",
49+
"about:mkdir-debug-cwd": "echo 'Is used as preLaunchTask in .vscode/launch.json; mkdirp is transitively pulled by mocha'"
4750
}
4851
}

src/app/index.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
********************************************************************************/
1616

17+
import type execa = require('execa');
1718
import path = require('path');
1819
import Base = require('yeoman-generator');
1920
const request = require('request');
@@ -68,8 +69,11 @@ module.exports = class TheiaExtension extends Base {
6869
electronMainLocation: string
6970
};
7071

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 });
7377

7478
this.argument('extensionName', {
7579
type: String,
@@ -270,7 +274,7 @@ module.exports = class TheiaExtension extends Base {
270274
}
271275
}
272276

273-
writing() {
277+
async writing() {
274278
if (this.params.extensionType !== ExtensionType.DiagramEditor) {
275279
if (!this.options.standalone) {
276280
/** common templates */
@@ -464,12 +468,10 @@ module.exports = class TheiaExtension extends Base {
464468
this.fs.move(
465469
this.extensionPath('src/browser/README.md'),
466470
this.extensionPath(`README.md`),
467-
{ params: this.params }
468471
);
469472
this.fs.move(
470473
this.extensionPath('src/browser/tree-frontend-module.ts'),
471474
this.extensionPath(`src/browser/${this.params.extensionPath}-frontend-module.ts`),
472-
{ params: this.params }
473475
);
474476
}
475477

@@ -485,28 +487,28 @@ module.exports = class TheiaExtension extends Base {
485487
return;
486488
}
487489

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+
});
496499
}
497500
}
498501

499502
protected extensionPath(...paths: string[]) {
500503
return this.destinationPath(this.params.extensionPath, ...paths);
501504
}
502505

503-
install() {
506+
async install() {
504507
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', []);
509510

511+
if (this.params.extensionType == ExtensionType.DiagramEditor) {
510512
command.on('close', (code:number) => {
511513
if (code === 0 ) {
512514
this.log(
@@ -518,15 +520,15 @@ module.exports = class TheiaExtension extends Base {
518520
process.exit(code);
519521
}
520522
});
521-
} else {
522-
const command = this.spawnCommand('yarn', []);
523-
523+
} else {
524524
command.on('close', function(code: number){
525525
if (code !== 0 ) {
526526
process.exit(code);
527527
}
528528
})
529529
}
530+
531+
return command;
530532
}
531533
}
532534

0 commit comments

Comments
 (0)