Skip to content

Commit f0d53f4

Browse files
author
Illia Obukhau
authored
refactor(web-widgets): connect signature-web to workspace (#339)
2 parents 1dfadea + 04ceab7 commit f0d53f4

28 files changed

+496
-1245
lines changed

.pnpmfile.cjs

Lines changed: 13 additions & 7 deletions
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;
Lines changed: 4 additions & 0 deletions
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

Lines changed: 37 additions & 20 deletions
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
},
Lines changed: 43 additions & 0 deletions
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+
});
Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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_/Alert.spec.ts renamed to packages/customWidgets/signature-web/src/components/__tests__/Alert.spec.ts

File renamed without changes.

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

File renamed without changes.

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

Lines changed: 1 addition & 0 deletions
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> =>

0 commit comments

Comments
 (0)