Skip to content

Commit

Permalink
bumped yeoman version to "^5.0.0", solves #182 (#187)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
sailingKieler authored Dec 6, 2023
1 parent f337f93 commit c44e654
Show file tree
Hide file tree
Showing 4 changed files with 3,379 additions and 1,964 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Yo via NPM",
"type": "node",
"request": "launch",
"preLaunchTask": "npm: mkdir-debug-cwd",
"runtimeExecutable": "npx",
"program": "yo",
"args": [
"theia-extension"
],
"cwd": "${workspaceFolder}/testing",
"console": "integratedTerminal",
"skipFiles": [
"<node_internals>/**"
],
}
]
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
"fs-extra": "^10.0.0",
"request": "^2.88.2",
"tar": "^6.1.1",
"yeoman-generator": "^4.0.2"
"yeoman-generator": "^5.0.0"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/yeoman-generator": "^3.1.4",
"@types/yeoman-generator": "^5.0.0",
"mocha": "^6.2.0",
"rimraf": "^3.0.0",
"typescript": "~4.5.5",
"yeoman-assert": "^3.1.1",
"yeoman-test": "^2.0.0"
"yeoman-environment": "^3.0.0",
"yeoman-test": "^5.0.0"
},
"files": [
"generators",
Expand All @@ -43,6 +44,8 @@
"clean": "rimraf lib",
"build": "tsc",
"watch": "tsc -w",
"test": "mocha"
"test": "mocha",
"mkdir-debug-cwd": "mkdirp ./testing && rimraf ./testing/*",
"about:mkdir-debug-cwd": "echo 'Is used as preLaunchTask in .vscode/launch.json; mkdirp is transitively pulled by mocha'"
}
}
44 changes: 23 additions & 21 deletions src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import type execa = require('execa');
import path = require('path');
import Base = require('yeoman-generator');
const request = require('request');
Expand Down Expand Up @@ -68,8 +69,11 @@ module.exports = class TheiaExtension extends Base {
electronMainLocation: string
};

constructor(args: string | string[], options: any) {
super(args, options);
constructor(args: string | string[], options: Base.GeneratorOptions) {
// For v5 generators the '<npm|pnpm|yarn> install' task is implicitely invoked by 'yeoman-environment' since 'yeoman-environment@3', see
// https://github.com/yeoman/environment/commit/ab9582a70073203c7a6b58fb6dbf1f4eba249d48#diff-54bc5f4bd40f22e081d54b6c20bbf2523e438cf2f2716b91714a1f596e4d87cd
// 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!
super(args, options, { customInstallTask: true });

this.argument('extensionName', {
type: String,
Expand Down Expand Up @@ -270,7 +274,7 @@ module.exports = class TheiaExtension extends Base {
}
}

writing() {
async writing() {
if (this.params.extensionType !== ExtensionType.DiagramEditor) {
if (!this.options.standalone) {
/** common templates */
Expand Down Expand Up @@ -464,12 +468,10 @@ module.exports = class TheiaExtension extends Base {
this.fs.move(
this.extensionPath('src/browser/README.md'),
this.extensionPath(`README.md`),
{ params: this.params }
);
this.fs.move(
this.extensionPath('src/browser/tree-frontend-module.ts'),
this.extensionPath(`src/browser/${this.params.extensionPath}-frontend-module.ts`),
{ params: this.params }
);
}

Expand All @@ -485,28 +487,28 @@ module.exports = class TheiaExtension extends Base {
return;
}

const done = this.async();
request.get(`https://github.com/eclipse-glsp/glsp-examples/archive/refs/tags/${glspExamplesRepositoryTag}.tar.gz`).pipe(tar.x().on('close',() => {
fs.copy(baseDir+'/README.md', './README.md');
fs.copy(baseDir+templatePath, './').then(() => {
fs.rm(baseDir, { recursive: true });
done();
});
}));
return new Promise<void>((resolve) => {
request.get(`https://github.com/eclipse-glsp/glsp-examples/archive/refs/tags/${glspExamplesRepositoryTag}.tar.gz`).pipe(tar.x().on('close',() => {
fs.copy(baseDir+'/README.md', './README.md');
fs.copy(baseDir+templatePath, './').then(() => {
fs.rm(baseDir, { recursive: true });
resolve();
});
}));
});
}
}

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

install() {
async install() {
if (!(this.options as any).skipInstall) {
if (this.params.extensionType == ExtensionType.DiagramEditor) {
this.log('Installing dependencies');

const command = this.spawnCommand('yarn', []);
this.log('Installing dependencies');
const command: execa.ExecaChildProcess = this.spawnCommand('yarn', []);

if (this.params.extensionType == ExtensionType.DiagramEditor) {
command.on('close', (code:number) => {
if (code === 0 ) {
this.log(
Expand All @@ -518,15 +520,15 @@ module.exports = class TheiaExtension extends Base {
process.exit(code);
}
});
} else {
const command = this.spawnCommand('yarn', []);

} else {
command.on('close', function(code: number){
if (code !== 0 ) {
process.exit(code);
}
})
}

return command;
}
}

Expand Down
Loading

0 comments on commit c44e654

Please sign in to comment.