Skip to content

Commit 42bdf19

Browse files
author
Illia Obukhau
committedFeb 14, 2023
chore(signature-web): add signature-web package
- add add signature-web to workspace - update scripts and tooling
1 parent 14b542a commit 42bdf19

18 files changed

+214
-96
lines changed
 

‎.pnpmfile.cjs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
function readPackage(pkg, context) {
2-
if (pkg.name === "@mendix/pluggable-widgets-tools") {
3-
delete pkg.dependencies["react-native"];
4-
}
5-
6-
if (pkg && pkg.name === "react-big-calendar") {
7-
pkg.peerDependencies["react"] = "^15.3.0 || ^16.0.0 || ^17.0.0";
8-
pkg.peerDependencies["react-dom"] = "^15.3.0 || ^16.0.0 || ^17.0.0";
2+
if (pkg) {
3+
switch (pkg.name) {
4+
case "@mendix/pluggable-widgets-tools": {
5+
delete pkg.dependencies["react-native"];
6+
break;
7+
}
8+
case "react-big-calendar":
9+
case "react-resize-detector": {
10+
pkg.peerDependencies["react"] = "^15.3.0 || ^16.0.0 || ^17.0.0";
11+
pkg.peerDependencies["react-dom"] = "^15.3.0 || ^16.0.0 || ^17.0.0";
12+
break;
13+
}
14+
}
915
}
1016

1117
return pkg;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
tests
4+

‎packages/customWidgets/signature-web/package.json

+37-20
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,55 @@
1313
"branchName": "signature-web"
1414
},
1515
"license": "Apache-2.0",
16+
"mxpackage": {
17+
"name": "Signature",
18+
"type": "widget",
19+
"mpkName": "Signature.mpk"
20+
},
21+
"packagePath": "com.mendix.widget.custom",
1622
"marketplace": {
1723
"minimumMXVersion": "7.13.1",
24+
"appName": "Signature",
1825
"appNumber": 107984
1926
},
2027
"scripts": {
21-
"start": "utils-react-widgets start",
22-
"dev": "utils-react-widgets dev",
23-
"test": "npm run test:unit",
24-
"test:unit": "jest --config ../../../scripts/test/jest.web.config.js",
25-
"pretest:e2e": "npm run release && node ../../../scripts/test/updateAtlas.js --latest-atlas",
26-
"test:e2e": "pluggable-widgets-tools test:e2e:web:cypress --no-widget-update --remove-atlas-files",
27-
"test:e2e:local": "pluggable-widgets-tools test:e2e:web:cypress:local -- --config-file ../../../configs/e2e/cypress/cypress.json",
28+
"build": "ts-node --project scripts/tsconfig.json scripts/build.ts development",
29+
"release": "ts-node --project scripts/tsconfig.json scripts/build.ts production",
30+
"format": "prettier --write .",
2831
"lint": "eslint --ext .jsx,.js,.ts,.tsx src/ cypress/",
29-
"lint:fix": "npm run lint -- --fix",
30-
"build": "utils-react-widgets build",
31-
"release": "utils-react-widgets release",
32-
"format": "prettier --write ."
33-
},
34-
"config": {
35-
"mendixHost": "http://localhost:8080",
36-
"developmentPort": 3000
32+
"test": "pluggable-widgets-tools test:unit:web"
3733
},
3834
"devDependencies": {
39-
"@mendix/custom-widgets-utils-internal": "workspace:*",
40-
"@mendix/pluggable-widgets-tools": ">=9.20.0",
41-
"@types/classnames": "^2.2.6",
35+
"@mendix-internal/automation-utils": "workspace:*",
36+
"@mendix/eslint-config-web-widgets": "workspace:*",
37+
"@mendix/pluggable-widgets-tools": "^9.20.0",
38+
"@mendix/prettier-config-web-widgets": "workspace:*",
39+
"@types/enzyme": "^3.10.12",
40+
"@types/jest": "^26.0.24",
41+
"@types/node": "^18.8.3",
42+
"@types/react": "^17.0.53",
43+
"@types/react-dom": "^17.0.18",
4244
"@types/react-resize-detector": "^5.0.0",
45+
"css-loader": "^6.7.3",
4346
"eslint": "^7.32.0",
44-
"jest": "^26.6.3"
47+
"jest": "^26.6.3",
48+
"jest-canvas-mock": "^2.4.0",
49+
"mendix-client": "^7.15.8",
50+
"mini-css-extract-plugin": "^2.7.2",
51+
"prettier": "^2.5.1",
52+
"react": "~17.0.2",
53+
"react-dom": "~17.0.2",
54+
"rollup": "^2.79.1",
55+
"sass-loader": "^13.2.0",
56+
"to-string-loader": "^1.1.6",
57+
"ts-loader": "^9.4.2",
58+
"ts-node": "^9.1.1",
59+
"typescript": "4.5.4",
60+
"webpack": "^5.75.0",
61+
"webpack-cli": "^5.0.1"
4562
},
4663
"dependencies": {
47-
"classnames": "^2.2.6",
64+
"classnames": "^2.3.2",
4865
"react-resize-detector": "^5.2.0",
4966
"signature_pad": "https://github.com/Andries-Smit/signature_pad/releases/download/v3.0.0-beta.4/signature_pad.tar.gz"
5067
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env ts-node-script
2+
3+
import { cp, mkdir, zip, exec } from "@mendix-internal/automation-utils/shell";
4+
import { logStep, removeDist, runWidgetSteps, WidgetStepParams } from "@mendix-internal/automation-utils/steps";
5+
import { dirname, join } from "node:path";
6+
7+
const [, , env] = process.argv;
8+
const isProd = env === "production";
9+
const copyToProject = !isProd && process.env.MX_PROJECT_PATH;
10+
11+
async function createMPK({ config }: WidgetStepParams): Promise<void> {
12+
logStep("Create mpk");
13+
const { paths, output } = config;
14+
mkdir("-p", dirname(output.files.mpk));
15+
await zip(paths.tmp, output.files.mpk);
16+
}
17+
18+
async function main(): Promise<void> {
19+
await runWidgetSteps({
20+
packagePath: process.cwd(),
21+
steps: [
22+
removeDist,
23+
async () => {
24+
logStep("Bundling");
25+
await exec(`webpack -c webpack.config.js`);
26+
},
27+
createMPK,
28+
async ({ config }) => {
29+
if (copyToProject) {
30+
logStep("Copy widget to targetProject");
31+
const dir = join(config.paths.targetProject, "widgets");
32+
mkdir("-p", dir);
33+
cp(config.output.files.mpk, dir);
34+
}
35+
}
36+
]
37+
});
38+
}
39+
40+
main().catch(err => {
41+
console.error(err);
42+
process.exit(1);
43+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@mendix-internal/automation-utils/tsconfig"
3+
}

‎packages/customWidgets/signature-web/src/components/Signature.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export interface SignatureProps extends Dimensions {
3030
export type penOptions = "fountain" | "ballpoint" | "marker";
3131

3232
export class Signature extends PureComponent<SignatureProps> {
33-
// @ts-ignore
34-
private canvasNode: HTMLCanvasElement;
33+
private canvasNode: HTMLCanvasElement | null = null;
3534
private signaturePad: SignaturePad;
3635

3736
render(): ReactNode {

‎packages/customWidgets/signature-web/src/components/SignatureContainer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface SignatureContainerState {
3131

3232
export default class SignatureContainer extends Component<SignatureContainerProps, SignatureContainerState> {
3333
private subscriptionHandles: number[] = [];
34-
private base64Uri: string;
34+
private base64Uri = "";
3535
private formHandle?: number;
3636

3737
readonly state = {

‎packages/customWidgets/signature-web/src/components/_tests_/Signature.spec.ts renamed to ‎packages/customWidgets/signature-web/src/components/__tests__/Signature.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { shallow, ShallowWrapper } from "enzyme";
22
import { createElement } from "react";
33

44
import { Signature, SignatureProps } from "../Signature";
5+
import "jest-canvas-mock";
56

67
describe("Signature", () => {
78
const renderCanvas = (props: SignatureProps): ShallowWrapper<SignatureProps, any> =>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
{
2-
"extends": "@mendix/custom-widgets-utils-internal/configs/tsconfig.json",
32
"compilerOptions": {
4-
"baseUrl": ".",
53
"rootDir": "./",
6-
"outDir": "dist/tsc/"
4+
"outDir": "dist/tsc/",
5+
"noEmitOnError": true,
6+
"sourceMap": true,
7+
"module": "CommonJS",
8+
"target": "es5",
9+
"lib": ["es2015", "dom"],
10+
"moduleResolution": "node",
11+
"declaration": false,
12+
"removeComments": true,
13+
"noLib": false,
14+
"watch": false,
15+
"forceConsistentCasingInFileNames": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"strict": true,
18+
"strictFunctionTypes": false,
19+
"skipLibCheck": true,
20+
"noUnusedLocals": true,
21+
"noUnusedParameters": true,
22+
"allowSyntheticDefaultImports": true,
23+
"esModuleInterop": true,
24+
"jsx": "react",
25+
"jsxFactory": "createElement"
726
},
8-
"exclude": ["dist/", "tests/", "**/*.spec.ts", "node_modules/"]
27+
"files": ["./node_modules/mendix-client/index.d.ts"],
28+
"include": ["./src", "./typings"],
29+
"exclude": ["dist/", "node_modules/", "tests/", "scripts/"]
930
}

‎packages/customWidgets/signature-web/tsconfig.spec.json

-8
This file was deleted.

‎packages/customWidgets/signature-web/webpack.config.dev.js

-27
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const webpack = require("webpack");
2+
const path = require("path");
3+
const CopyWebpackPlugin = require("copy-webpack-plugin");
4+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5+
6+
const name = "signature";
7+
const widgetName = "Signature";
8+
9+
const widgetConfig = {
10+
mode: "production",
11+
devtool: false,
12+
externals: ["react", "react-dom"],
13+
entry: "./src/components/SignatureContainer.ts",
14+
output: {
15+
path: path.resolve(__dirname, "dist/tmp"),
16+
filename: `com/mendix/widget/custom/${name}/${widgetName}.js`,
17+
libraryTarget: "amd",
18+
publicPath: "/widgets/"
19+
},
20+
resolve: {
21+
extensions: [".ts", ".js", ".tsx", ".jsx"],
22+
alias: {
23+
tests: path.resolve(__dirname, "./tests")
24+
}
25+
},
26+
module: {
27+
rules: [
28+
{
29+
test: /\.tsx?$/,
30+
use: "ts-loader"
31+
},
32+
{
33+
test: /\.(sa|sc|c)ss$/,
34+
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
35+
}
36+
]
37+
},
38+
plugins: [
39+
new MiniCssExtractPlugin({
40+
filename: `com/mendix/widget/custom/${name}/ui/${widgetName}.css`
41+
}),
42+
new CopyWebpackPlugin({
43+
patterns: [
44+
{
45+
from: path.join(process.cwd(), "src/**/*.xml").replace(/\\/g, "/"),
46+
toType: "template",
47+
to: "./[name][ext]"
48+
}
49+
]
50+
})
51+
]
52+
};
53+
54+
const previewConfig = {
55+
mode: "production",
56+
devtool: false,
57+
externals: ["react", "react-dom"],
58+
entry: `./src/${widgetName}.webmodeler.ts`,
59+
output: {
60+
path: path.resolve(__dirname, "dist/tmp"),
61+
filename: `${widgetName}.webmodeler.js`,
62+
libraryTarget: "commonjs"
63+
},
64+
resolve: {
65+
extensions: [".ts", ".js", ".tsx", ".jsx"]
66+
},
67+
module: {
68+
rules: [
69+
{
70+
test: /\.tsx?$/,
71+
loader: "ts-loader",
72+
options: {
73+
compilerOptions: {
74+
module: "CommonJS"
75+
}
76+
}
77+
},
78+
{
79+
test: /\.(sa|sc|c)ss$/,
80+
use: ["to-string-loader", "css-loader", "sass-loader"]
81+
}
82+
]
83+
}
84+
};
85+
86+
module.exports = [widgetConfig, previewConfig];

‎packages/customWidgets/signature-web/webpack.config.prod.js

-26
This file was deleted.

‎pnpm-workspace.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
packages:
22
- "packages/*/*"
33
- "automation/*"
4-
- "!packages/customWidgets/signature-web"
54
- "!packages/tools/custom-widgets-utils-internal"

0 commit comments

Comments
 (0)
Please sign in to comment.