@openremote/util 1.8.0-snapshot.20250725120000 → 1.8.0-snapshot.20250725123024

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/cli.js +61 -61
  2. package/package.json +1 -1
  3. package/webpack.util.js +275 -275
package/cli.js CHANGED
@@ -1,61 +1,61 @@
1
- #!/usr/bin/env node
2
- const path = require("path");
3
- const fs = require("fs");
4
- const { spawnSync } = require("child_process");
5
- const { spawn } = require("child_process");
6
-
7
- /* THIS IS JUST A WRAPPER THAT LAUNCHES GRADLE TASKS */
8
-
9
- /* Try and find the gradle wrapper in a parent dir */
10
- function getGradleDirectory() {
11
- let dirs = process.cwd().split(path.sep);
12
- let cwd = dirs.join(path.sep);
13
-
14
- while (dirs.length > 0 && !fs.existsSync(path.join(cwd, "gradlew"))) {
15
- dirs.pop();
16
- cwd = dirs.join(path.sep);
17
- }
18
-
19
- if (!fs.existsSync(path.join(cwd, "gradlew"))) {
20
- console.log("Failed to locate gradlew in a parent directory of: " + process.cwd());
21
- process.exit(1);
22
- } else {
23
- console.log("Located gradlew in parent directory: " + cwd);
24
- }
25
-
26
- return cwd;
27
- }
28
-
29
- if (process.argv.length >= 3 && process.argv[2] =="watch") {
30
-
31
- // Do watch
32
- let cwd = getWorkingDirectory();
33
- console.log("Watching model for changes...");
34
- const child = spawn((process.platform === "win32" ? "gradlew" : "./gradlew"), ["-t", "modelWatch"], {
35
- cwd: cwd,
36
- shell: true
37
- });
38
- child.stdout.removeAllListeners("data");
39
- child.stderr.removeAllListeners("data");
40
- child.stdout.pipe(process.stdout);
41
- child.stderr.pipe(process.stderr);
42
-
43
- child.on("exit", function() {
44
- console.log("gradlew modelWatch finished! Status = " + child.status);
45
- process.exit(child.status);
46
- });
47
- } else {
48
-
49
- // Do build
50
- let cwd = getGradleDirectory();
51
- console.log("Running gradlew modelBuild task in " + cwd + " ...");
52
- const gradleModelWatch = spawnSync((process.platform === "win32" ? "gradlew" : "./gradlew"), ["modelWatch"], {
53
- cwd: cwd,
54
- shell: true
55
- });
56
- console.log("gradlew modelWatch finished! Status = " + gradleModelWatch.status);
57
- if (gradleModelWatch.stderr) {
58
- console.log(gradleModelWatch.stderr.toString());
59
- }
60
- process.exit(gradleModelWatch.status);
61
- }
1
+ #!/usr/bin/env node
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+ const { spawnSync } = require("child_process");
5
+ const { spawn } = require("child_process");
6
+
7
+ /* THIS IS JUST A WRAPPER THAT LAUNCHES GRADLE TASKS */
8
+
9
+ /* Try and find the gradle wrapper in a parent dir */
10
+ function getGradleDirectory() {
11
+ let dirs = process.cwd().split(path.sep);
12
+ let cwd = dirs.join(path.sep);
13
+
14
+ while (dirs.length > 0 && !fs.existsSync(path.join(cwd, "gradlew"))) {
15
+ dirs.pop();
16
+ cwd = dirs.join(path.sep);
17
+ }
18
+
19
+ if (!fs.existsSync(path.join(cwd, "gradlew"))) {
20
+ console.log("Failed to locate gradlew in a parent directory of: " + process.cwd());
21
+ process.exit(1);
22
+ } else {
23
+ console.log("Located gradlew in parent directory: " + cwd);
24
+ }
25
+
26
+ return cwd;
27
+ }
28
+
29
+ if (process.argv.length >= 3 && process.argv[2] =="watch") {
30
+
31
+ // Do watch
32
+ let cwd = getWorkingDirectory();
33
+ console.log("Watching model for changes...");
34
+ const child = spawn((process.platform === "win32" ? "gradlew" : "./gradlew"), ["-t", "modelWatch"], {
35
+ cwd: cwd,
36
+ shell: true
37
+ });
38
+ child.stdout.removeAllListeners("data");
39
+ child.stderr.removeAllListeners("data");
40
+ child.stdout.pipe(process.stdout);
41
+ child.stderr.pipe(process.stderr);
42
+
43
+ child.on("exit", function() {
44
+ console.log("gradlew modelWatch finished! Status = " + child.status);
45
+ process.exit(child.status);
46
+ });
47
+ } else {
48
+
49
+ // Do build
50
+ let cwd = getGradleDirectory();
51
+ console.log("Running gradlew modelBuild task in " + cwd + " ...");
52
+ const gradleModelWatch = spawnSync((process.platform === "win32" ? "gradlew" : "./gradlew"), ["modelWatch"], {
53
+ cwd: cwd,
54
+ shell: true
55
+ });
56
+ console.log("gradlew modelWatch finished! Status = " + gradleModelWatch.status);
57
+ if (gradleModelWatch.stderr) {
58
+ console.log(gradleModelWatch.stderr.toString());
59
+ }
60
+ process.exit(gradleModelWatch.status);
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openremote/util",
3
- "version": "1.8.0-snapshot.20250725120000",
3
+ "version": "1.8.0-snapshot.20250725123024",
4
4
  "description": "Build Util",
5
5
  "author": "OpenRemote",
6
6
  "main": "webpack.util.js",
package/webpack.util.js CHANGED
@@ -1,275 +1,275 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const { rspack } = require('@rspack/core');
4
- const HtmlWebpackPlugin = require("html-webpack-plugin");
5
-
6
- function getStandardModuleRules() {
7
- return {
8
- rules: [
9
- {
10
- test: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/, //output css as strings
11
- type: "asset/source"
12
- },
13
- {
14
- test: /\.css$/, //
15
- exclude: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/,
16
- use: [
17
- { loader: "css-loader" }
18
- ]
19
- },
20
- {
21
- test: /\.(png|jpg|ico|gif|svg|eot|ttf|woff|woff2|mp4)$/,
22
- type: "asset",
23
- generator: {
24
- filename: 'images/[hash][ext][query]'
25
- }
26
- },
27
- {
28
- test: /\.tsx?$/,
29
- exclude: /node_modules/,
30
- use: {
31
- // TODO: Switch to builtin:swc-loader, and remove ts-loader / webpack dependency
32
- loader: "ts-loader",
33
- options: {
34
- projectReferences: true
35
- }
36
- }
37
- }
38
- ]
39
- };
40
- }
41
-
42
- function getAppConfig(mode, isDevServer, dirname, managerUrl, keycloakUrl, port) {
43
- const production = mode === "production";
44
- port = port || 9000;
45
- managerUrl = managerUrl || (production && !isDevServer ? undefined : "http://localhost:8080");
46
- const OUTPUT_PATH = isDevServer ? 'src' : 'dist';
47
-
48
- if (isDevServer) {
49
- console.log("");
50
- console.log("To customise the URL of the manager and/or keycloak use the managerUrl and/or keycloakUrl");
51
- console.log(" environment arguments e.g: ");
52
- console.log("");
53
- console.log("npm run serve -- --env managerUrl=https://localhost");
54
- console.log("npm run serve -- --env keycloakUrl=https://localhost/auth");
55
- console.log("");
56
- console.log("MANAGER URL: " + managerUrl || "");
57
- console.log("KEYCLOAK URL: " + keycloakUrl || (managerUrl + "/auth"));
58
- console.log("");
59
- }
60
-
61
- const config = {
62
- entry: {
63
- 'bundle': './src/index.ts'
64
- },
65
- output: {
66
- path: dirname + "/dist",
67
- publicPath: isDevServer ? "/" + dirname.split(path.sep).slice(-1)[0] + "/" : "./",
68
- filename: production ? "[name].[contenthash].js" : "[name].js"
69
- },
70
- module: {...getStandardModuleRules()},
71
- // optimization: {
72
- // minimize: true,
73
- // minimizer: [
74
- // // For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
75
- // // `...`,
76
- // new CssMinimizerPlugin(),
77
- // ],
78
- // },
79
- resolve: {
80
- extensions: [".ts", ".tsx", "..."],
81
- fallback: {
82
- "vm": false,
83
- "querystring": require.resolve("querystring-es3")
84
- }
85
- }
86
- };
87
-
88
- config.plugins = [
89
- // Conditional compilation variables
90
- new rspack.DefinePlugin({
91
- PRODUCTION: JSON.stringify(production),
92
- MANAGER_URL: JSON.stringify(managerUrl),
93
- KEYCLOAK_URL: JSON.stringify(keycloakUrl),
94
- "process.env": {
95
- BABEL_ENV: JSON.stringify(mode)
96
- }
97
- }),
98
- // Generate our index page
99
- new HtmlWebpackPlugin({
100
- chunksSortMode: 'none',
101
- inject: false,
102
- template: 'index.html'
103
- })
104
- ];
105
-
106
- if (production) {
107
- config.module.rules.push(
108
- {
109
- test: /\.js$/,
110
- include: function(modulePath) {
111
- return /(@webcomponents[\/|\\]shadycss|lit-css|styled-lit-element|lit-element|lit-html|@polymer|@lit|pwa-helpers)/.test(modulePath) || !/node_modules/.test(modulePath);
112
- },
113
- loader: 'builtin:swc-loader',
114
- },
115
- );
116
- }
117
-
118
- if (isDevServer) {
119
- // Load source maps generated by typescript
120
- // config.devtool = 'inline-source-map';
121
- config.module.rules.push(
122
- {
123
- test: /\.js$/,
124
- use: ["source-map-loader"],
125
- enforce: "pre",
126
- exclude: [
127
- /node_modules/
128
- ]
129
- },
130
- );
131
- }
132
-
133
- // Build list of resources to copy
134
- const patterns = [
135
- {
136
- from: path.dirname(require.resolve("@webcomponents/webcomponentsjs")),
137
- to: "modules/@webcomponents/webcomponentsjs",
138
- globOptions: {
139
- ignore: ["!*.js"]
140
- }
141
- },
142
- ];
143
- // Check if images dir exists
144
- if (fs.existsSync(path.join(dirname, "images"))) {
145
- patterns.push(
146
- {
147
- from: "./images",
148
- to: "images"
149
- }
150
- );
151
- }
152
- // Check if locales dir exists
153
- if (fs.existsSync(path.join(dirname, "locales"))) {
154
- patterns.push(
155
- {
156
- from: "./locales",
157
- to: "locales"
158
- }
159
- );
160
- }
161
- // Check if htaccess file exists
162
- if (fs.existsSync(path.join(dirname, ".htaccess"))) {
163
- patterns.push(
164
- {
165
- from: ".htaccess",
166
- to: ".htaccess",
167
- toType: 'file'
168
- }
169
- );
170
- }
171
- //Check if .appignore file exists
172
- if (fs.existsSync(path.join(dirname, ".appignore"))) {
173
- patterns.push(
174
- {
175
- from: ".appignore",
176
- to: ".appignore",
177
- toType: 'file'
178
- }
179
- );
180
- }
181
-
182
- // Copy unprocessed files
183
- config.plugins.push(
184
- new rspack.CopyRspackPlugin({
185
- patterns: patterns
186
- })
187
- );
188
-
189
- config.devtool = !isDevServer ? false : "inline-source-map";
190
- config.devServer = {
191
- historyApiFallback: {
192
- index: "/" + dirname.split(path.sep).slice(-1)[0] + "/",
193
- },
194
- port: port,
195
- open: false,
196
- hot: false, // HMR doesn't work with webcomponents at present
197
- liveReload: true,
198
- static: OUTPUT_PATH
199
- };
200
- config.watchOptions = {
201
- ignored: ['node_modules']
202
- }
203
-
204
- return config;
205
- }
206
-
207
- function getLibName(componentName) {
208
- if (componentName.startsWith("or-")) {
209
- componentName = componentName.substr(3);
210
- }
211
- componentName = componentName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
212
- return "OR" + componentName.charAt(0).toUpperCase() + componentName.substring(1);
213
- }
214
-
215
- function ORExternals(context, callback) {
216
- const match = context.request.match(/^@openremote\/([^\/]*)$/);
217
- if (match) {
218
- let component = getLibName(match[1]);
219
- console.log(context.request + " => " + component);
220
- return callback(null, "umd " + component);
221
- }
222
- callback();
223
- }
224
-
225
- function generateExternals(bundle) {
226
- if (!bundle) {
227
- return;
228
- }
229
-
230
- const externals = [];
231
-
232
- if (bundle.excludeOr) {
233
- externals.push(ORExternals);
234
- }
235
- if (bundle.vendor) {
236
- externals.push(bundle.vendor);
237
- }
238
-
239
- return externals;
240
- }
241
-
242
- function generateExports(dirname) {
243
-
244
- let libName = getLibName(dirname.split(path.sep).pop());
245
-
246
- return Object.entries(bundles).map(([name, bundle]) => {
247
- const entry = {};
248
- entry[name] = "./src/index.ts";
249
-
250
- const config = {
251
- entry: entry,
252
- mode: "production",
253
- output: {
254
- filename: "[name].js",
255
- path: path.resolve(dirname, "dist/umd"),
256
- library: libName,
257
- libraryTarget: "umd"
258
- },
259
- resolve: {
260
- extensions: [".ts", ".tsx", "..."],
261
- fallback: { "vm": false }
262
- },
263
- module: {...getStandardModuleRules()},
264
- externals: generateExternals(bundle)
265
- };
266
-
267
- return config;
268
- });
269
- }
270
-
271
- module.exports = {
272
- getLibName: getLibName,
273
- generateExports: generateExports,
274
- getAppConfig: getAppConfig
275
- };
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { rspack } = require('@rspack/core');
4
+ const HtmlWebpackPlugin = require("html-webpack-plugin");
5
+
6
+ function getStandardModuleRules() {
7
+ return {
8
+ rules: [
9
+ {
10
+ test: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/, //output css as strings
11
+ type: "asset/source"
12
+ },
13
+ {
14
+ test: /\.css$/, //
15
+ exclude: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/,
16
+ use: [
17
+ { loader: "css-loader" }
18
+ ]
19
+ },
20
+ {
21
+ test: /\.(png|jpg|ico|gif|svg|eot|ttf|woff|woff2|mp4)$/,
22
+ type: "asset",
23
+ generator: {
24
+ filename: 'images/[hash][ext][query]'
25
+ }
26
+ },
27
+ {
28
+ test: /\.tsx?$/,
29
+ exclude: /node_modules/,
30
+ use: {
31
+ // TODO: Switch to builtin:swc-loader, and remove ts-loader / webpack dependency
32
+ loader: "ts-loader",
33
+ options: {
34
+ projectReferences: true
35
+ }
36
+ }
37
+ }
38
+ ]
39
+ };
40
+ }
41
+
42
+ function getAppConfig(mode, isDevServer, dirname, managerUrl, keycloakUrl, port) {
43
+ const production = mode === "production";
44
+ port = port || 9000;
45
+ managerUrl = managerUrl || (production && !isDevServer ? undefined : "http://localhost:8080");
46
+ const OUTPUT_PATH = isDevServer ? 'src' : 'dist';
47
+
48
+ if (isDevServer) {
49
+ console.log("");
50
+ console.log("To customise the URL of the manager and/or keycloak use the managerUrl and/or keycloakUrl");
51
+ console.log(" environment arguments e.g: ");
52
+ console.log("");
53
+ console.log("npm run serve -- --env managerUrl=https://localhost");
54
+ console.log("npm run serve -- --env keycloakUrl=https://localhost/auth");
55
+ console.log("");
56
+ console.log("MANAGER URL: " + managerUrl || "");
57
+ console.log("KEYCLOAK URL: " + keycloakUrl || (managerUrl + "/auth"));
58
+ console.log("");
59
+ }
60
+
61
+ const config = {
62
+ entry: {
63
+ 'bundle': './src/index.ts'
64
+ },
65
+ output: {
66
+ path: dirname + "/dist",
67
+ publicPath: isDevServer ? "/" + dirname.split(path.sep).slice(-1)[0] + "/" : "./",
68
+ filename: production ? "[name].[contenthash].js" : "[name].js"
69
+ },
70
+ module: {...getStandardModuleRules()},
71
+ // optimization: {
72
+ // minimize: true,
73
+ // minimizer: [
74
+ // // For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
75
+ // // `...`,
76
+ // new CssMinimizerPlugin(),
77
+ // ],
78
+ // },
79
+ resolve: {
80
+ extensions: [".ts", ".tsx", "..."],
81
+ fallback: {
82
+ "vm": false,
83
+ "querystring": require.resolve("querystring-es3")
84
+ }
85
+ }
86
+ };
87
+
88
+ config.plugins = [
89
+ // Conditional compilation variables
90
+ new rspack.DefinePlugin({
91
+ PRODUCTION: JSON.stringify(production),
92
+ MANAGER_URL: JSON.stringify(managerUrl),
93
+ KEYCLOAK_URL: JSON.stringify(keycloakUrl),
94
+ "process.env": {
95
+ BABEL_ENV: JSON.stringify(mode)
96
+ }
97
+ }),
98
+ // Generate our index page
99
+ new HtmlWebpackPlugin({
100
+ chunksSortMode: 'none',
101
+ inject: false,
102
+ template: 'index.html'
103
+ })
104
+ ];
105
+
106
+ if (production) {
107
+ config.module.rules.push(
108
+ {
109
+ test: /\.js$/,
110
+ include: function(modulePath) {
111
+ return /(@webcomponents[\/|\\]shadycss|lit-css|styled-lit-element|lit-element|lit-html|@polymer|@lit|pwa-helpers)/.test(modulePath) || !/node_modules/.test(modulePath);
112
+ },
113
+ loader: 'builtin:swc-loader',
114
+ },
115
+ );
116
+ }
117
+
118
+ if (isDevServer) {
119
+ // Load source maps generated by typescript
120
+ // config.devtool = 'inline-source-map';
121
+ config.module.rules.push(
122
+ {
123
+ test: /\.js$/,
124
+ use: ["source-map-loader"],
125
+ enforce: "pre",
126
+ exclude: [
127
+ /node_modules/
128
+ ]
129
+ },
130
+ );
131
+ }
132
+
133
+ // Build list of resources to copy
134
+ const patterns = [
135
+ {
136
+ from: path.dirname(require.resolve("@webcomponents/webcomponentsjs")),
137
+ to: "modules/@webcomponents/webcomponentsjs",
138
+ globOptions: {
139
+ ignore: ["!*.js"]
140
+ }
141
+ },
142
+ ];
143
+ // Check if images dir exists
144
+ if (fs.existsSync(path.join(dirname, "images"))) {
145
+ patterns.push(
146
+ {
147
+ from: "./images",
148
+ to: "images"
149
+ }
150
+ );
151
+ }
152
+ // Check if locales dir exists
153
+ if (fs.existsSync(path.join(dirname, "locales"))) {
154
+ patterns.push(
155
+ {
156
+ from: "./locales",
157
+ to: "locales"
158
+ }
159
+ );
160
+ }
161
+ // Check if htaccess file exists
162
+ if (fs.existsSync(path.join(dirname, ".htaccess"))) {
163
+ patterns.push(
164
+ {
165
+ from: ".htaccess",
166
+ to: ".htaccess",
167
+ toType: 'file'
168
+ }
169
+ );
170
+ }
171
+ //Check if .appignore file exists
172
+ if (fs.existsSync(path.join(dirname, ".appignore"))) {
173
+ patterns.push(
174
+ {
175
+ from: ".appignore",
176
+ to: ".appignore",
177
+ toType: 'file'
178
+ }
179
+ );
180
+ }
181
+
182
+ // Copy unprocessed files
183
+ config.plugins.push(
184
+ new rspack.CopyRspackPlugin({
185
+ patterns: patterns
186
+ })
187
+ );
188
+
189
+ config.devtool = !isDevServer ? false : "inline-source-map";
190
+ config.devServer = {
191
+ historyApiFallback: {
192
+ index: "/" + dirname.split(path.sep).slice(-1)[0] + "/",
193
+ },
194
+ port: port,
195
+ open: false,
196
+ hot: false, // HMR doesn't work with webcomponents at present
197
+ liveReload: true,
198
+ static: OUTPUT_PATH
199
+ };
200
+ config.watchOptions = {
201
+ ignored: ['node_modules']
202
+ }
203
+
204
+ return config;
205
+ }
206
+
207
+ function getLibName(componentName) {
208
+ if (componentName.startsWith("or-")) {
209
+ componentName = componentName.substr(3);
210
+ }
211
+ componentName = componentName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
212
+ return "OR" + componentName.charAt(0).toUpperCase() + componentName.substring(1);
213
+ }
214
+
215
+ function ORExternals(context, callback) {
216
+ const match = context.request.match(/^@openremote\/([^\/]*)$/);
217
+ if (match) {
218
+ let component = getLibName(match[1]);
219
+ console.log(context.request + " => " + component);
220
+ return callback(null, "umd " + component);
221
+ }
222
+ callback();
223
+ }
224
+
225
+ function generateExternals(bundle) {
226
+ if (!bundle) {
227
+ return;
228
+ }
229
+
230
+ const externals = [];
231
+
232
+ if (bundle.excludeOr) {
233
+ externals.push(ORExternals);
234
+ }
235
+ if (bundle.vendor) {
236
+ externals.push(bundle.vendor);
237
+ }
238
+
239
+ return externals;
240
+ }
241
+
242
+ function generateExports(dirname) {
243
+
244
+ let libName = getLibName(dirname.split(path.sep).pop());
245
+
246
+ return Object.entries(bundles).map(([name, bundle]) => {
247
+ const entry = {};
248
+ entry[name] = "./src/index.ts";
249
+
250
+ const config = {
251
+ entry: entry,
252
+ mode: "production",
253
+ output: {
254
+ filename: "[name].js",
255
+ path: path.resolve(dirname, "dist/umd"),
256
+ library: libName,
257
+ libraryTarget: "umd"
258
+ },
259
+ resolve: {
260
+ extensions: [".ts", ".tsx", "..."],
261
+ fallback: { "vm": false }
262
+ },
263
+ module: {...getStandardModuleRules()},
264
+ externals: generateExternals(bundle)
265
+ };
266
+
267
+ return config;
268
+ });
269
+ }
270
+
271
+ module.exports = {
272
+ getLibName: getLibName,
273
+ generateExports: generateExports,
274
+ getAppConfig: getAppConfig
275
+ };