Skip to content

Commit

Permalink
Merge pull request #19 from Enet4/change/parcel
Browse files Browse the repository at this point in the history
Change the generated project builder to Parcel
  • Loading branch information
Enet4 authored Feb 21, 2024
2 parents 28d5715 + 572efd6 commit 38d9602
Show file tree
Hide file tree
Showing 19 changed files with 3,691 additions and 6,985 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:

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

steps:
Expand All @@ -29,7 +29,4 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- if: matrix.node-version == '18.x'
run: NODE_OPTIONS=--openssl-legacy-provider npm test
- if: matrix.node-version != '18.x'
run: npm test
- run: npm test
19 changes: 14 additions & 5 deletions __tests__/generate-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
"module-file": "module.js"
},
devDependencies: {
webpack: /.+/,
parcel: /.+/,
// only Dicoogle 3.1.0 uses dicoogle client v5
"dicoogle-client": /\^5/,
}
Expand All @@ -53,10 +53,8 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
// has source files and build files
runResult.assertFile([
'src/index.ts',
'webpack.common.js',
'webpack.dev.js',
'webpack.prod.js',
'tsconfig.json',
'build-package-json.js',
'.gitignore',
'README.md',
]);
Expand All @@ -67,6 +65,17 @@ describe('generator test 1: menu webplugin project in TypeScript', () => {
child_process.execSync('npm install --no-audit', {cwd: runResult.cwd});

// has the output file module.js via `prepare`
runResult.assertFileContent('module.js', 'module.exports');
runResult.assertFileContent('dist/module.js', 'module.exports');
// has the simplified output file package.json
runResult.assertJsonFileContent('dist/package.json', {
name: "plugin1",
description: "A test plugin (#1)",
license: "MIT",
dicoogle: {
"slot-id": "menu",
"caption": "Test1",
"module-file": "module.js"
}
});
});
});
19 changes: 14 additions & 5 deletions __tests__/generate-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('generator test 2: legacy result-options webplugin project in ECMAScrip
slotId: "result-options",
caption: "Test2",
minimumVersion: "2.5.0",
projectType: "babel",
projectType: "javascript",
license: "MIT",
authorName: "John Doe",
authorEmail: "doe.j@nowhere",
Expand Down Expand Up @@ -51,9 +51,6 @@ describe('generator test 2: legacy result-options webplugin project in ECMAScrip
// has source files and build files
runResult.assertFile([
'src/index.js',
'webpack.common.js',
'webpack.dev.js',
'webpack.prod.js',
'.gitignore',
'README.md',
]);
Expand All @@ -64,6 +61,18 @@ describe('generator test 2: legacy result-options webplugin project in ECMAScrip
child_process.execSync('npm install --no-audit', {cwd: runResult.cwd});

// has the output file module.js via `prepare`
runResult.assertFileContent('module.js', 'module.exports');
runResult.assertFileContent('dist/module.js', 'module.exports');
// has the simplified output file package.json
runResult.assertJsonFileContent('dist/package.json', {
name: "plugin2",
description: "A test plugin (#2)",
license: "MIT",
dicoogle: {
"slot-id": "result-options",
"caption": "Test2",
"module-file": "module.js"
}
});

});
});
18 changes: 14 additions & 4 deletions __tests__/generate-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ describe('generator test 3: result-batch webplugin project in TypeScript', () =>
}
});

// has source files and build files
// has source files and build files
runResult.assertFile([
'src/index.ts',
'webpack.common.js',
'webpack.dev.js',
'webpack.prod.js',
'build-package-json.js',
'.gitignore',
'README.md',
]);
Expand All @@ -65,6 +64,17 @@ describe('generator test 3: result-batch webplugin project in TypeScript', () =>
child_process.execSync('npm install --no-audit', {cwd: runResult.cwd});

// has the output file module.js via `prepare`
runResult.assertFileContent('module.js', 'module.exports');
runResult.assertFileContent('dist/module.js', 'module.exports');
// has the simplified output file package.json
runResult.assertJsonFileContent('dist/package.json', {
name: "plugin3",
description: "A test plugin (#3)",
license: "MIT",
dicoogle: {
"slot-id": "result-batch",
"caption": "Test3",
"module-file": "module.js"
}
});
});
});
109 changes: 57 additions & 52 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const semver = require('semver');
const PLUGIN_TYPES = ['menu', 'result-options', 'result-batch', 'settings' ];
const EXPERIMENTAL_PLUGIN_TYPES = [...PLUGIN_TYPES, 'search', 'query', 'result' ];

/** Dependencies which are already in Dicoogle webapp
* and should not be bundled into the web plugin by default.
*/
const EXTERNAL_DEPENDENCIES = [
'react', 'react-dom', 'dicoogle-client', 'dicoogle-webcore', 'reflux', 'react-bootstrap',
'react-bootstrap-table', 'react-imageloader', 'react-router', 'react-router-bootstrap'
];

module.exports = class WebpluginGenerator extends Generator {

constructor(args, opts) {
Expand Down Expand Up @@ -39,21 +47,7 @@ module.exports = class WebpluginGenerator extends Generator {
initializing() {
this.author = {};
this.appname = this.helper.cleanAppname(this.appname);
this.devDependencies = [
'webpack@^4.28.2',
'webpack-cli@^3.1.2',
'webpack-merge@^4.1.5',
'babel-minify-webpack-plugin@^0.3.1',
'file-loader@^3.0.1'
];
this.babelPresets = [['@babel/env', {
targets: {
browsers: [
"> 1%",
"last 2 versions"
]
}
}]];
this.devDependencies = ['parcel@^2.11.0'];
}

prompting() {
Expand Down Expand Up @@ -96,12 +90,12 @@ module.exports = class WebpluginGenerator extends Generator {
{
type: 'list',
name: 'projectType',
message: 'Would you like to use JavaScript with Babel, or TypeScript?',
message: 'Would you like to use plain JavaScript or TypeScript?',
choices: [
{name: 'ECMAScript2016+ with Babel', value: 'babel'},
{name: 'JavaScript', value: 'javascript'},
{name: 'TypeScript', value: 'typescript'}
],
default: 'babel'
default: 'javascript'
}];

if (this.options['experimental'] === 'experimental') {
Expand Down Expand Up @@ -172,35 +166,22 @@ module.exports = class WebpluginGenerator extends Generator {
this.componentType = componentType;
this.projectType = answers.projectType;

if (this.projectType === 'typescript') {
this.devDependencies.push(
'typescript@^2.9.2',
'ts-loader@^4.5.0');
} else if (this.projectType === 'babel') {
this.devDependencies.push(
'babel-loader@^8.0.0-beta.0',
'@babel/core@^7.0.0-beta.31',
'@babel/preset-env@^7.0.0-beta.31'
);
}

if (this.componentType === 'react') {
if (this.projectType === 'babel') {
this.data.entry = './src/index.jsx';
this.devDependencies.push('@babel/preset-react@^7.0.0-beta.31');
if (this.projectType === 'javascript') {
this.data.entry = 'src/index.jsx';

this.babelPresets.push('@babel/react');
} else if (this.projectType === 'typescript') {
this.data.entry = './src/index.tsx';
this.data.entry = 'src/index.tsx';
this.devDependencies.push('@types/react@^0.14.0');
}
} else if (this.componentType === 'dom') {
if (this.projectType === 'babel') {
this.data.entry = './src/index.js';
if (this.projectType === 'javascript') {
this.data.entry = 'src/index.js';
} else {
this.data.entry = './src/index.ts';
this.data.entry = 'src/index.ts';
}
}
this.data.babelPresets = this.babelPresets;
});
}

Expand All @@ -214,18 +195,21 @@ module.exports = class WebpluginGenerator extends Generator {
dicoogle,
} = this.data;

const source = this.data.entry;

const pkg = {
name: appname,
version: "0.1.0",
description: description,
main: "module.js",
source,
main: "dist/module.js",
files: [
"module.js"
"dist/module.js"
],
scripts: {
"build": "webpack --config webpack.prod.js",
"build-debug": "webpack --config webpack.dev.js",
"build-watch": "webpack --config webpack.dev.js --watch",
"build": "node build-package-json.js && parcel build --no-source-maps",
"build-debug": "node build-package-json.js && parcel build --no-optimize",
"build-watch": "node build-package-json.js && parcel watch",
"prepare": "npm run build"
},
keywords: [
Expand All @@ -234,9 +218,35 @@ module.exports = class WebpluginGenerator extends Generator {
dicoogle: {
"slot-id": dicoogle.slotId,
"module-file": "module.js"
}
},
engines: {
node: ">= 16",
npm: ">= 7"
},
targets: {
main: {
context: "browser",
outputFormat: "commonjs",
isLibrary: false,
includeNodeModules: {
"@swc/helpers": true,
},
optimize: true,
sourceMap: {
inline: true
},
engines: {
browsers: "> 1%, last 2 versions, not dead"
},
},
},
};

// external dependencies
for (const dep of EXTERNAL_DEPENDENCIES) {
pkg.targets.main.includeNodeModules[dep] = false;
}

if (author.name && author.email) {
pkg.author = author.name + " " + author.email;
} else if (author.name) {
Expand Down Expand Up @@ -282,6 +292,7 @@ module.exports = class WebpluginGenerator extends Generator {

const copyStatics = () => {
this.fs.copy(this.templatePath('_gitignore'), this.destinationPath('.gitignore'));
this.fs.copy(this.templatePath('_build-package-json.js'), this.destinationPath('build-package-json.js'));

if (this.projectType === 'typescript') {
this.fs.copy(this.templatePath('src/_webcore.ts'), this.destinationPath('src/webcore.ts'));
Expand All @@ -290,13 +301,9 @@ module.exports = class WebpluginGenerator extends Generator {
};
const copyTemplates = () => {
this.fs.copyTpl(this.templatePath('_README.md'), this.destinationPath('README.md'), this.data);
this.fs.copyTpl(this.templatePath('_webpack.dev.js'), this.destinationPath('webpack.dev.js'), this.data);
this.fs.copyTpl(this.templatePath('_webpack.prod.js'), this.destinationPath('webpack.prod.js'), this.data);

if (this.projectType === 'babel') {
// ES2016 project

this.fs.copyTpl(this.templatePath('_babel_webpack.common.js'), this.destinationPath('webpack.common.js'), this.data);
if (this.projectType === 'javascript') {
// JavaScript project

let indexFile;
if (this.componentType === 'dom') {
Expand All @@ -311,8 +318,6 @@ module.exports = class WebpluginGenerator extends Generator {
} else if (this.projectType === 'typescript') {
// TypeScript project

this.fs.copyTpl(this.templatePath('_ts_webpack.common.js'), this.destinationPath('webpack.common.js'), this.data);

let indexFile;
if (this.componentType === 'dom') {
indexFile = 'src/_index.ts';
Expand Down
13 changes: 10 additions & 3 deletions app/templates/_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
This is a web UI <%= dicoogle.slotId %> plugin for Dicoogle.

**Minimum Dicoogle version required: `<%= minimumVersion %>`**

## Building

The `prepare` and `build` scripts are prepared to build the plugin module
using [Parcel](https://parceljs.org/).

```bash
npm install # OR npm run build
npm install # OR npm run build if `node_modules` is already populated
```

## Debugging
Expand All @@ -18,5 +23,7 @@ npm run build-watch # build for debugging and watch for source code changes

## Deploying

Place `module.js` and `package.json` in a folder in the WebPlugins directory at the base of Dicoogle.
Alternatively, create a WebPlugins folder with the same structure and add it to a jar file, then move it to the Plugins directory.
Place `dist/module.js` and `dist/package.json` in a folder,
in the WebPlugins directory at the base of Dicoogle.
Alternatively, create a WebPlugins folder with the same structure
and add it to a jar file, then move it to the Plugins directory.
28 changes: 0 additions & 28 deletions app/templates/_babel_webpack.common.js

This file was deleted.

Loading

0 comments on commit 38d9602

Please sign in to comment.