Skip to content

Commit 1f119bb

Browse files
author
Illia Obukhau
committed
build(calendar-web): fix build scripts
1 parent c04eb9b commit 1f119bb

File tree

7 files changed

+40587
-18
lines changed

7 files changed

+40587
-18
lines changed

packages/customWidgets/calendar-web/package-lock.json

Lines changed: 40342 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/customWidgets/calendar-web/package.json

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,39 @@
1818
"appNumber": 107954
1919
},
2020
"scripts": {
21-
"start": "utils-react-widgets start",
22-
"dev": "utils-react-widgets dev",
23-
"format": "prettier --config \"../../prettier.config.js\" --write \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
24-
"test": "npm run test:unit",
25-
"test:unit": "jest --config ../../../scripts/test/jest.web.config.js",
26-
"pretest:e2e": "npm run release && node ../../../scripts/test/updateAtlas.js --latest-atlas",
27-
"test:e2e": "pluggable-widgets-tools test:e2e:web:cypress --remove-atlas-files",
28-
"test:e2e:local": "pluggable-widgets-tools test:e2e:web:cypress:local -- --config-file ../../../configs/e2e/cypress/cypress.json",
29-
"lint": "eslint --config ../../../.eslintrc.js --ext .jsx,.js,.ts,.tsx src/",
30-
"lint:fix": "npm run lint -- --fix",
31-
"build": "utils-react-widgets build",
32-
"release": "utils-react-widgets release"
21+
"format": "echo \"Error: no format specified\" && exit 1",
22+
"lint": "echo \"Error: no lint specified\" && exit 1",
23+
"lint:fix": "echo \"Error: no lint:fix specified\" && exit 1",
24+
"build": "webpack-cli -c webpack.config.dev.js && npm run create-mpk",
25+
"release": "webpack-cli -c webpack.config.prod.js && npm run create-mpk",
26+
"create-mpk": "node ./scripts/create-mpk.js"
3327
},
3428
"config": {
3529
"mendixHost": "http://localhost:8080",
3630
"developmentPort": 3000
3731
},
3832
"devDependencies": {
39-
"@mendix/custom-widgets-utils-internal": "workspace:*",
4033
"@mendix/pluggable-widgets-tools": ">=9.0.0",
4134
"@types/classnames": "^2.2.6",
4235
"@types/date-arithmetic": "^3.1.2",
4336
"@types/react-big-calendar": "0.20.20",
4437
"@types/react-dnd": "^3.0.2",
4538
"@types/react-dnd-html5-backend": "^3.0.2",
4639
"eslint": "^7.20.0",
47-
"jest": "^26.6.1"
40+
"jest": "^26.6.1",
41+
"webpack": "^5.3.2",
42+
"webpack-cli": "^4.1.0",
43+
"babel-loader": "^8.2.1",
44+
"fork-ts-checker-webpack-plugin": "^5.2.1",
45+
"copy-webpack-plugin": "^6.2.1",
46+
"ts-loader": "^8.0.7",
47+
"style-loader": "^2.0.0",
48+
"css-loader": "^5.0.0",
49+
"sass": "^1.43.4",
50+
"sass-loader": "^12.4.0",
51+
"typescript": "4.5.4",
52+
"mendix-client": "^7.15.8",
53+
"to-string-loader": "^1.1.6"
4854
},
4955
"dependencies": {
5056
"classnames": "^2.2.6",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { execSync } = require("node:child_process");
2+
const { join } = require("path");
3+
const { rm, mkdir } = require("node:fs/promises");
4+
const cwd = process.cwd();
5+
const package = require(join(cwd, "package.json"));
6+
const widgetName = package.widgetName;
7+
const filesDir = join(cwd, "dist", "tmp", "widgets");
8+
const dest = join(cwd, "dist", package.version);
9+
const outputFile = join(dest, `${widgetName}.mpk`);
10+
11+
async function main() {
12+
await rm(dest, { force: true, recursive: true });
13+
await mkdir(dest, { recursive: true });
14+
process.chdir(filesDir);
15+
execSync(`zip -vr ${outputFile} .`, { stdio: "inherit" });
16+
process.chdir(cwd);
17+
}
18+
19+
main().catch(e => {
20+
console.error(e);
21+
process.exit(1);
22+
});
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
{
2-
"extends": "@mendix/custom-widgets-utils-internal/configs/tsconfig.json",
2+
"include": ["./src", "./typings"],
33
"compilerOptions": {
4+
"noEmitOnError": true,
5+
"sourceMap": true,
6+
"module": "amd",
7+
"target": "es5",
8+
"lib": ["es2015", "dom"],
9+
"types": ["mendix-client", "jest"],
10+
"moduleResolution": "node",
11+
"declaration": false,
12+
"removeComments": true,
13+
"noLib": false,
14+
"watch": false,
15+
"forceConsistentCasingInFileNames": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"noImplicitAny": true,
18+
"noImplicitReturns": true,
19+
"noImplicitThis": true,
20+
"skipLibCheck": true,
21+
"strictNullChecks": true,
22+
"noUnusedLocals": true,
23+
"noUnusedParameters": true,
24+
"jsx": "react",
25+
"jsxFactory": "createElement",
26+
"allowSyntheticDefaultImports": true,
27+
"esModuleInterop": true,
428
"baseUrl": ".",
529
"rootDir": "./",
630
"outDir": "dist/tsc/"
731
},
8-
"exclude": ["dist/", "tests/", "**/*.spec.ts", "node_modules/"]
32+
"exclude": ["dist/", "tests/", "**/*.spec.ts", "**/*.specs.ts", "node_modules/"]
933
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
const webpack = require("webpack");
2+
const { join, resolve } = require("path");
3+
const CopyWebpackPlugin = require("copy-webpack-plugin");
4+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
5+
const cwd = process.cwd();
6+
7+
const package = require(join(cwd, "package.json"));
8+
const widgetName = package.widgetName;
9+
const name = widgetName !== "RangeSlider" ? widgetName.toLowerCase() : widgetName;
10+
11+
const packageName = name;
12+
const mxHost = "http://localhost:8080";
13+
const developmentPort = "3000";
14+
15+
const widgetConfig = {
16+
context: cwd,
17+
entry: join(cwd, `src/components/${widgetName}Container.ts`),
18+
output: {
19+
path: resolve(cwd, "dist/tmp"),
20+
filename: chunkData => {
21+
const fileName = chunkData.chunk.name === "main" ? widgetName : "[name]";
22+
return `widgets/com/mendix/widget/custom/${name}/${fileName}.js`;
23+
},
24+
libraryTarget: "umd",
25+
publicPath: "/"
26+
},
27+
devServer: {
28+
compress: true,
29+
port: developmentPort,
30+
hot: true,
31+
proxy: [
32+
{
33+
target: mxHost,
34+
context: [`!/widgets/com/mendix/widget/custom/${name}/${widgetName}.ts`],
35+
onError(err, req, res) {
36+
if (res && res.writeHead) {
37+
res.writeHead(500, {
38+
"Content-Type": "text/plain"
39+
});
40+
if (err.code === "ECONNREFUSED") {
41+
res.end(
42+
"Please make sure that the Mendix server is running at " +
43+
mxHost +
44+
" or change the configuration \n " +
45+
"> npm config set " +
46+
packageName +
47+
":mendixhost http://host:port"
48+
);
49+
} else {
50+
res.end("Error connecting to Mendix server" + "\n " + JSON.stringify(err, null, 2));
51+
}
52+
}
53+
}
54+
}
55+
],
56+
stats: "errors-only"
57+
},
58+
resolve: {
59+
extensions: [".ts", ".js", ".tsx", ".jsx"],
60+
alias: {
61+
tests: resolve(cwd, "./tests")
62+
}
63+
},
64+
module: {
65+
rules: [
66+
{
67+
test: /\.tsx?$/,
68+
exclude: /node_modules/,
69+
use: [
70+
{
71+
loader: "ts-loader",
72+
options: {
73+
transpileOnly: true
74+
}
75+
}
76+
]
77+
},
78+
{
79+
test: /\.jsx?$/,
80+
exclude: /node_modules/,
81+
use: {
82+
loader: "babel-loader",
83+
options: {
84+
cacheDirectory: true,
85+
presets: ["@babel/preset-env", "@babel/preset-react"],
86+
plugins: [
87+
["@babel/plugin-proposal-class-properties", { loose: true }],
88+
["@babel/plugin-transform-react-jsx", { pragma: "createElement" }]
89+
]
90+
}
91+
}
92+
},
93+
{
94+
test: /\.(sa|sc|c)ss$/,
95+
use: [
96+
"style-loader",
97+
"css-loader",
98+
{
99+
loader: "sass-loader",
100+
options: {
101+
implementation: require("sass"),
102+
sassOptions: {
103+
fiber: false
104+
}
105+
}
106+
}
107+
]
108+
}
109+
]
110+
},
111+
mode: "development",
112+
devtool: "source-map",
113+
externals: ["react", "react-dom"],
114+
plugins: [
115+
new webpack.HotModuleReplacementPlugin(),
116+
new ForkTsCheckerWebpackPlugin(),
117+
new CopyWebpackPlugin({
118+
patterns: [
119+
{
120+
from: join(cwd, "src/**/*.xml").replace(/\\/g, "/"),
121+
toType: "template",
122+
to: "widgets/[name].[ext]"
123+
}
124+
]
125+
})
126+
]
127+
};
128+
129+
const previewConfig = {
130+
entry: resolve(cwd, `./src/${widgetName}.webmodeler.ts`),
131+
output: {
132+
path: resolve(cwd, "dist/tmp"),
133+
filename: `widgets/${widgetName}.webmodeler.js`,
134+
libraryTarget: "commonjs"
135+
},
136+
resolve: {
137+
extensions: [".ts", ".js", ".tsx", ".jsx"]
138+
},
139+
module: {
140+
rules: [
141+
{
142+
test: /\.tsx?$/,
143+
loader: "ts-loader",
144+
options: {
145+
compilerOptions: {
146+
module: "CommonJS"
147+
}
148+
}
149+
},
150+
{
151+
test: /\.jsx?$/,
152+
exclude: /node_modules/,
153+
use: {
154+
loader: "babel-loader",
155+
options: {
156+
cacheDirectory: true,
157+
presets: ["@babel/preset-env", "@babel/preset-react"],
158+
plugins: [
159+
["@babel/plugin-proposal-class-properties", { loose: true }],
160+
["@babel/plugin-transform-react-jsx", { pragma: "createElement" }]
161+
]
162+
}
163+
}
164+
},
165+
{
166+
test: /\.(sa|sc|c)ss$/,
167+
use: ["to-string-loader", "css-loader", "sass-loader"]
168+
}
169+
]
170+
},
171+
mode: "development",
172+
externals: ["react", "react-dom"]
173+
};
174+
175+
module.exports = [widgetConfig, previewConfig];

packages/customWidgets/calendar-web/webpack.config.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { merge } = require("webpack-merge");
2-
const baseConfig = require("@mendix/custom-widgets-utils-internal/configs/webpack.config.dev");
2+
const baseConfig = require("./webpack.base.dev");
33

44
const overridingConfig = {
55
module: {

packages/customWidgets/calendar-web/webpack.config.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { merge } = require("webpack-merge");
2-
const baseConfig = require("@mendix/custom-widgets-utils-internal/configs/webpack.config.dev");
2+
const baseConfig = require("./webpack.base.dev");
33

44
const overridingConfig = {
55
module: {

0 commit comments

Comments
 (0)