Skip to content

Commit 6d65fca

Browse files
committed
Update project
- convert to ES modules - add minimumVersion 3.5.1, drop support for minimumVersion 2.5.0 and 3.1.0, simplify templates accordingly - bump dependencies: - `yeoman-generator` 8 - `yeoman-test` 11 - `yeoman-environment` 6 - force `@yeoman/adapter` to v4 - bump minimum Node.js version to 22 - drop Jest, use `node --test` instead - update tests
1 parent 8f5603e commit 6d65fca

15 files changed

Lines changed: 3859 additions & 7954 deletions

.github/workflows/node.js.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [16.x, lts/*, latest]
19+
node-version: [22.x, lts/*, latest]
2020
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21-
# Minimum supported version for project scaffolding is 16,
21+
# Minimum supported version for project scaffolding is 22,
2222
# but building the new plugin project may have different requirements.
2323

2424
steps:
25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v6
2626
- name: Use Node.js ${{ matrix.node-version }}
27-
uses: actions/setup-node@v3
27+
uses: actions/setup-node@v6
2828
with:
2929
node-version: ${{ matrix.node-version }}
3030
cache: 'npm'

__tests__/generate-2.js

Lines changed: 0 additions & 78 deletions
This file was deleted.

__tests__/generate-menu-js.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import path from 'path';
2+
import helpers, { result } from 'yeoman-test';
3+
import child_process from 'child_process';
4+
import {describe, before, beforeEach, it} from 'node:test';
5+
6+
const __dirname = import.meta.dirname;
7+
8+
describe('menu webplugin project in JavaScript', () => {
9+
const dir = path.join(__dirname, '..');
10+
11+
before(() => helpers.prepareTemporaryDir());
12+
13+
beforeEach(async () => {
14+
await result
15+
.create(dir)
16+
.withAnswers({
17+
appname: "plugin1",
18+
description: "A test plugin (#1)",
19+
slotId: "menu",
20+
caption: "Test1",
21+
minimumVersion: "3.5.1",
22+
projectType: "javascript",
23+
license: "MIT",
24+
authorName: "John Doe",
25+
authorEmail: "doe.j@nowhere",
26+
authorGithub: "",
27+
})
28+
.run();
29+
});
30+
31+
it('generates correctly', () => {
32+
// contains package.json
33+
result.assertJsonFileContent('package.json', {
34+
name: "plugin1",
35+
description: "A test plugin (#1)",
36+
license: "MIT",
37+
scripts: {
38+
"build": /.+/,
39+
},
40+
dicoogle: {
41+
"slot-id": "menu",
42+
"caption": "Test1",
43+
"module-file": "module.js"
44+
},
45+
devDependencies: {
46+
parcel: /.+/,
47+
}
48+
});
49+
50+
// has source files and build files
51+
result.assertFile([
52+
'src/index.js',
53+
'build-package-json.js',
54+
'.gitignore',
55+
'README.md',
56+
]);
57+
58+
result.assertFileContent('src/index.js', 'export default class MyPlugin');
59+
60+
// force running npm install on target directory
61+
child_process.execSync('npm install --no-audit', {cwd: result.cwd});
62+
63+
// has the output file module.js via `prepare`
64+
result.assertFileContent('dist/module.js', 'module.exports');
65+
// has the simplified output file package.json
66+
result.assertJsonFileContent('dist/package.json', {
67+
name: "plugin1",
68+
description: "A test plugin (#1)",
69+
license: "MIT",
70+
dicoogle: {
71+
"slot-id": "menu",
72+
"caption": "Test1",
73+
"module-file": "module.js"
74+
}
75+
});
76+
});
77+
});
Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
const path = require('path');
2-
const helpers = require('yeoman-test');
3-
const child_process = require('child_process');
1+
import path from 'path';
2+
import helpers, { result } from 'yeoman-test';
3+
import child_process from 'child_process';
4+
import {describe, before, beforeEach, it} from 'node:test';
45

5-
describe('generator test 1: menu webplugin project in TypeScript', () => {
6-
/** @type {helpers.RunResult} */
7-
let runResult;
6+
const __dirname = import.meta.dirname;
7+
8+
describe('menu webplugin project in TypeScript', () => {
9+
const dir = path.join(__dirname, '..');
10+
11+
before(() => helpers.prepareTemporaryDir());
812

913
beforeEach(async () => {
10-
runResult = await helpers
11-
.create(path.join(__dirname, '..'))
12-
.withPrompts({
14+
await result
15+
.create(dir)
16+
.withAnswers({
1317
appname: "plugin1",
1418
description: "A test plugin (#1)",
1519
slotId: "menu",
1620
caption: "Test1",
17-
minimumVersion: "3.1.0",
21+
minimumVersion: "3.5.1",
1822
projectType: "typescript",
1923
license: "MIT",
2024
authorName: "John Doe",
@@ -23,15 +27,10 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
2327
})
2428
.run();
2529
});
26-
afterEach(() => {
27-
if (runResult) {
28-
runResult.restore();
29-
}
30-
});
3130

3231
it('generates correctly', () => {
3332
// contains package.json
34-
runResult.assertJsonFileContent('package.json', {
33+
result.assertJsonFileContent('package.json', {
3534
name: "plugin1",
3635
description: "A test plugin (#1)",
3736
license: "MIT",
@@ -45,29 +44,28 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
4544
},
4645
devDependencies: {
4746
parcel: /.+/,
48-
// only Dicoogle 3.1.0 uses dicoogle client v5
4947
"dicoogle-client": /\^5/,
5048
}
5149
});
5250

5351
// has source files and build files
54-
runResult.assertFile([
52+
result.assertFile([
5553
'src/index.ts',
5654
'tsconfig.json',
5755
'build-package-json.js',
5856
'.gitignore',
5957
'README.md',
6058
]);
6159

62-
runResult.assertFileContent('src/index.ts', 'export default class MyPlugin');
60+
result.assertFileContent('src/index.ts', 'export default class MyPlugin');
6361

6462
// force running npm install on target directory
65-
child_process.execSync('npm install --no-audit', {cwd: runResult.cwd});
63+
child_process.execSync('npm install --no-audit', {cwd: result.cwd});
6664

6765
// has the output file module.js via `prepare`
68-
runResult.assertFileContent('dist/module.js', 'module.exports');
66+
result.assertFileContent('dist/module.js', 'module.exports');
6967
// has the simplified output file package.json
70-
runResult.assertJsonFileContent('dist/package.json', {
68+
result.assertJsonFileContent('dist/package.json', {
7169
name: "plugin1",
7270
description: "A test plugin (#1)",
7371
license: "MIT",
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
const path = require('path');
2-
const helpers = require('yeoman-test');
3-
const child_process = require('child_process');
1+
import path from 'path';
2+
import helpers, { result } from 'yeoman-test';
3+
import child_process from 'child_process';
4+
import {describe, before, beforeEach, it} from 'node:test';
45

5-
describe('generator test 3: result-batch webplugin project in TypeScript', () => {
6-
/** @type {helpers.RunResult} */
7-
let runResult;
6+
const __dirname = import.meta.dirname;
7+
8+
describe('result-batch webplugin project in TypeScript', () => {
9+
const dir = path.join(__dirname, '..');
10+
11+
before(() => helpers.prepareTemporaryDir());
812

913
beforeEach(async () => {
10-
runResult = await helpers
11-
.create(path.join(__dirname, '..'))
12-
.withPrompts({
14+
await result
15+
.create(dir)
16+
.withAnswers({
1317
appname: "plugin3",
1418
description: "A test plugin (#3)",
1519
slotId: "result-batch",
@@ -23,15 +27,10 @@ describe('generator test 3: result-batch webplugin project in TypeScript', () =>
2327
})
2428
.run();
2529
});
26-
afterEach(() => {
27-
if (runResult) {
28-
runResult.restore();
29-
}
30-
});
3130

3231
it('generates correctly', () => {
3332
// contains package.json
34-
runResult.assertJsonFileContent('package.json', {
33+
result.assertJsonFileContent('package.json', {
3534
name: "plugin3",
3635
description: "A test plugin (#3)",
3736
license: "MIT",
@@ -44,29 +43,28 @@ describe('generator test 3: result-batch webplugin project in TypeScript', () =>
4443
"module-file": "module.js"
4544
},
4645
devDependencies: {
47-
webpack: /.+/,
46+
parcel: /.+/,
4847
}
4948
});
5049

5150
// has source files and build files
52-
// has source files and build files
53-
runResult.assertFile([
51+
result.assertFile([
5452
'src/index.ts',
5553
'build-package-json.js',
5654
'.gitignore',
5755
'README.md',
5856
]);
5957

60-
runResult.assertFileContent('src/index.ts', 'export default class MyPlugin');
61-
runResult.assertFileContent('src/index.ts', "slot.addEventListener('result-selection-ready', (ev) => {");
58+
result.assertFileContent('src/index.ts', 'export default class MyPlugin');
59+
result.assertFileContent('src/index.ts', "slot.addEventListener('result-selection-ready', (ev) => {");
6260

6361
// force running npm install on target directory
64-
child_process.execSync('npm install --no-audit', {cwd: runResult.cwd});
62+
child_process.execSync('npm install --no-audit', {cwd: result.cwd});
6563

6664
// has the output file module.js via `prepare`
67-
runResult.assertFileContent('dist/module.js', 'module.exports');
65+
result.assertFileContent('dist/module.js', 'module.exports');
6866
// has the simplified output file package.json
69-
runResult.assertJsonFileContent('dist/package.json', {
67+
result.assertJsonFileContent('dist/package.json', {
7068
name: "plugin3",
7169
description: "A test plugin (#3)",
7270
license: "MIT",

app/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const Generator = require('yeoman-generator');
2-
const capitalize = require('capitalize');
3-
const semver = require('semver');
1+
import Generator from 'yeoman-generator';
2+
import capitalize from 'capitalize';
3+
import semver from 'semver';
44

55
const PLUGIN_TYPES = ['menu', 'result-options', 'result-batch', 'settings' ];
66
const EXPERIMENTAL_PLUGIN_TYPES = [...PLUGIN_TYPES, 'search', 'query', 'result' ];
@@ -13,7 +13,7 @@ const EXTERNAL_DEPENDENCIES = [
1313
'react-bootstrap-table', 'react-imageloader', 'react-router', 'react-router-bootstrap'
1414
];
1515

16-
module.exports = class WebpluginGenerator extends Generator {
16+
export default class WebpluginGenerator extends Generator {
1717

1818
constructor(args, opts) {
1919
super(args, opts)
@@ -81,11 +81,10 @@ module.exports = class WebpluginGenerator extends Generator {
8181
name: 'minimumVersion',
8282
message: 'Please specify the minimum version of Dicoogle required for this plugin.',
8383
choices: [
84+
{name: '3.5.1', value: '3.5.1'},
8485
{name: '3.3.2', value: '3.3.2'},
85-
{name: '3.1.0', value: '3.1.0'},
86-
{name: '2.5.0 (legacy)', value: '2.5.0'},
8786
],
88-
default: '3.3.2'
87+
default: '3.5.1'
8988
},
9089
{
9190
type: 'list',
@@ -220,8 +219,8 @@ module.exports = class WebpluginGenerator extends Generator {
220219
"module-file": "module.js"
221220
},
222221
engines: {
223-
node: ">= 16",
224-
npm: ">= 7"
222+
node: ">= 22",
223+
npm: ">= 9"
225224
},
226225
targets: {
227226
main: {
@@ -275,7 +274,7 @@ module.exports = class WebpluginGenerator extends Generator {
275274
pkg.devDependencies[name] = req;
276275
}
277276
if (this.projectType === 'typescript') {
278-
let dicoogleClientVersion = semver.gte(minimumVersion, '3.1.0') ? '5.1.0' : '^4.1.1';
277+
let dicoogleClientVersion = semver.gte(minimumVersion, '3.5.1') ? '^5.3.0' : '~5.1.0';
279278
pkg.devDependencies['dicoogle-client'] = dicoogleClientVersion;
280279
if (this.componentType === 'react') {
281280
pkg.devDependencies['@types/react'] = "^0.14.0";

0 commit comments

Comments
 (0)