Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:

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

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
Expand Down
78 changes: 0 additions & 78 deletions __tests__/generate-2.js

This file was deleted.

77 changes: 77 additions & 0 deletions __tests__/generate-menu-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import path from 'path';
import helpers, { result } from 'yeoman-test';
import child_process from 'child_process';
import {describe, before, beforeEach, it} from 'node:test';

const __dirname = import.meta.dirname;

describe('menu webplugin project in JavaScript', () => {
const dir = path.join(__dirname, '..');

before(() => helpers.prepareTemporaryDir());

beforeEach(async () => {
await result
.create(dir)
.withAnswers({
appname: "plugin1",
description: "A test plugin (#1)",
slotId: "menu",
caption: "Test1",
minimumVersion: "3.5.1",
projectType: "javascript",
license: "MIT",
authorName: "John Doe",
authorEmail: "doe.j@nowhere",
authorGithub: "",
})
.run();
});

it('generates correctly', () => {
// contains package.json
result.assertJsonFileContent('package.json', {
name: "plugin1",
description: "A test plugin (#1)",
license: "MIT",
scripts: {
"build": /.+/,
},
dicoogle: {
"slot-id": "menu",
"caption": "Test1",
"module-file": "module.js"
},
devDependencies: {
parcel: /.+/,
}
});

// has source files and build files
result.assertFile([
'src/index.js',
'build-package-json.js',
'.gitignore',
'README.md',
]);

result.assertFileContent('src/index.js', 'export default class MyPlugin');

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

// has the output file module.js via `prepare`
result.assertFileContent('dist/module.js', 'module.exports');
// has the simplified output file package.json
result.assertJsonFileContent('dist/package.json', {
name: "plugin1",
description: "A test plugin (#1)",
license: "MIT",
dicoogle: {
"slot-id": "menu",
"caption": "Test1",
"module-file": "module.js"
}
});
});
});
42 changes: 20 additions & 22 deletions __tests__/generate-1.js → __tests__/generate-menu-ts.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
const path = require('path');
const helpers = require('yeoman-test');
const child_process = require('child_process');
import path from 'path';
import helpers, { result } from 'yeoman-test';
import child_process from 'child_process';
import {describe, before, beforeEach, it} from 'node:test';

describe('generator test 1: menu webplugin project in TypeScript', () => {
/** @type {helpers.RunResult} */
let runResult;
const __dirname = import.meta.dirname;

describe('menu webplugin project in TypeScript', () => {
const dir = path.join(__dirname, '..');

before(() => helpers.prepareTemporaryDir());

beforeEach(async () => {
runResult = await helpers
.create(path.join(__dirname, '..'))
.withPrompts({
await result
.create(dir)
.withAnswers({
appname: "plugin1",
description: "A test plugin (#1)",
slotId: "menu",
caption: "Test1",
minimumVersion: "3.1.0",
minimumVersion: "3.5.1",
projectType: "typescript",
license: "MIT",
authorName: "John Doe",
Expand All @@ -23,15 +27,10 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
})
.run();
});
afterEach(() => {
if (runResult) {
runResult.restore();
}
});

it('generates correctly', () => {
// contains package.json
runResult.assertJsonFileContent('package.json', {
result.assertJsonFileContent('package.json', {
name: "plugin1",
description: "A test plugin (#1)",
license: "MIT",
Expand All @@ -45,29 +44,28 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
},
devDependencies: {
parcel: /.+/,
// only Dicoogle 3.1.0 uses dicoogle client v5
"dicoogle-client": /\^5/,
}
});

// has source files and build files
runResult.assertFile([
result.assertFile([
'src/index.ts',
'tsconfig.json',
'build-package-json.js',
'.gitignore',
'README.md',
]);

runResult.assertFileContent('src/index.ts', 'export default class MyPlugin');
result.assertFileContent('src/index.ts', 'export default class MyPlugin');

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

// has the output file module.js via `prepare`
runResult.assertFileContent('dist/module.js', 'module.exports');
result.assertFileContent('dist/module.js', 'module.exports');
// has the simplified output file package.json
runResult.assertJsonFileContent('dist/package.json', {
result.assertJsonFileContent('dist/package.json', {
name: "plugin1",
description: "A test plugin (#1)",
license: "MIT",
Expand Down
44 changes: 21 additions & 23 deletions __tests__/generate-3.js → __tests__/generate-result-batch-ts.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const path = require('path');
const helpers = require('yeoman-test');
const child_process = require('child_process');
import path from 'path';
import helpers, { result } from 'yeoman-test';
import child_process from 'child_process';
import {describe, before, beforeEach, it} from 'node:test';

describe('generator test 3: result-batch webplugin project in TypeScript', () => {
/** @type {helpers.RunResult} */
let runResult;
const __dirname = import.meta.dirname;

describe('result-batch webplugin project in TypeScript', () => {
const dir = path.join(__dirname, '..');

before(() => helpers.prepareTemporaryDir());

beforeEach(async () => {
runResult = await helpers
.create(path.join(__dirname, '..'))
.withPrompts({
await result
.create(dir)
.withAnswers({
appname: "plugin3",
description: "A test plugin (#3)",
slotId: "result-batch",
Expand All @@ -23,15 +27,10 @@ describe('generator test 3: result-batch webplugin project in TypeScript', () =>
})
.run();
});
afterEach(() => {
if (runResult) {
runResult.restore();
}
});

it('generates correctly', () => {
// contains package.json
runResult.assertJsonFileContent('package.json', {
result.assertJsonFileContent('package.json', {
name: "plugin3",
description: "A test plugin (#3)",
license: "MIT",
Expand All @@ -44,29 +43,28 @@ describe('generator test 3: result-batch webplugin project in TypeScript', () =>
"module-file": "module.js"
},
devDependencies: {
webpack: /.+/,
parcel: /.+/,
}
});

// has source files and build files
// has source files and build files
runResult.assertFile([
result.assertFile([
'src/index.ts',
'build-package-json.js',
'.gitignore',
'README.md',
]);

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

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

// has the output file module.js via `prepare`
runResult.assertFileContent('dist/module.js', 'module.exports');
result.assertFileContent('dist/module.js', 'module.exports');
// has the simplified output file package.json
runResult.assertJsonFileContent('dist/package.json', {
result.assertJsonFileContent('dist/package.json', {
name: "plugin3",
description: "A test plugin (#3)",
license: "MIT",
Expand Down
19 changes: 9 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Generator = require('yeoman-generator');
const capitalize = require('capitalize');
const semver = require('semver');
import Generator from 'yeoman-generator';
import capitalize from 'capitalize';
import semver from 'semver';

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

module.exports = class WebpluginGenerator extends Generator {
export default class WebpluginGenerator extends Generator {

constructor(args, opts) {
super(args, opts)
Expand Down Expand Up @@ -81,11 +81,10 @@ module.exports = class WebpluginGenerator extends Generator {
name: 'minimumVersion',
message: 'Please specify the minimum version of Dicoogle required for this plugin.',
choices: [
{name: '3.5.1', value: '3.5.1'},
{name: '3.3.2', value: '3.3.2'},
{name: '3.1.0', value: '3.1.0'},
{name: '2.5.0 (legacy)', value: '2.5.0'},
],
default: '3.3.2'
default: '3.5.1'
},
{
type: 'list',
Expand Down Expand Up @@ -220,8 +219,8 @@ module.exports = class WebpluginGenerator extends Generator {
"module-file": "module.js"
},
engines: {
node: ">= 16",
npm: ">= 7"
node: ">= 22",
npm: ">= 9"
},
targets: {
main: {
Expand Down Expand Up @@ -275,7 +274,7 @@ module.exports = class WebpluginGenerator extends Generator {
pkg.devDependencies[name] = req;
}
if (this.projectType === 'typescript') {
let dicoogleClientVersion = semver.gte(minimumVersion, '3.1.0') ? '5.1.0' : '^4.1.1';
let dicoogleClientVersion = semver.gte(minimumVersion, '3.5.1') ? '^5.3.0' : '~5.1.0';
pkg.devDependencies['dicoogle-client'] = dicoogleClientVersion;
if (this.componentType === 'react') {
pkg.devDependencies['@types/react'] = "^0.14.0";
Expand Down
Loading