@openremote/util 1.2.0-snapshot.20240512162641
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.
- package/cli.js +58 -0
- package/package.json +50 -0
- package/webpack.util.js +300 -0
package/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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 get the openremote project dir or custom project dir */
|
|
10
|
+
function getWorkingDirectory() {
|
|
11
|
+
let dirs = __dirname.split(path.sep);
|
|
12
|
+
dirs.pop();
|
|
13
|
+
|
|
14
|
+
// get CWD as the openremote repo root
|
|
15
|
+
let cwd = dirs.join(path.sep);
|
|
16
|
+
cwd = path.join(cwd, "..");
|
|
17
|
+
|
|
18
|
+
if (fs.existsSync(path.join(cwd, "..", ".gitmodules"))) {
|
|
19
|
+
// Assume we're in a custom project
|
|
20
|
+
cwd = path.join(cwd, "..");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return cwd;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (process.argv.length >= 3 && process.argv[2] =="watch") {
|
|
27
|
+
|
|
28
|
+
// Do watch
|
|
29
|
+
let cwd = getWorkingDirectory();
|
|
30
|
+
console.log("Watching model for changes...");
|
|
31
|
+
const child = spawn((process.platform === "win32" ? "gradlew" : "./gradlew"), ["-t", "modelWatch"], {
|
|
32
|
+
cwd: cwd,
|
|
33
|
+
shell: true
|
|
34
|
+
});
|
|
35
|
+
child.stdout.removeAllListeners("data");
|
|
36
|
+
child.stderr.removeAllListeners("data");
|
|
37
|
+
child.stdout.pipe(process.stdout);
|
|
38
|
+
child.stderr.pipe(process.stderr);
|
|
39
|
+
|
|
40
|
+
child.on("exit", function() {
|
|
41
|
+
console.log("gradlew modelWatch finished! Status = " + child.status);
|
|
42
|
+
process.exit(child.status);
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
|
|
46
|
+
// Do build
|
|
47
|
+
let cwd = getWorkingDirectory();
|
|
48
|
+
console.log("Running gradlew modelBuild task in " + cwd + " ...");
|
|
49
|
+
const gradleModelWatch = spawnSync((process.platform === "win32" ? "gradlew" : "./gradlew"), ["modelWatch"], {
|
|
50
|
+
cwd: cwd,
|
|
51
|
+
shell: true
|
|
52
|
+
});
|
|
53
|
+
console.log("gradlew modelWatch finished! Status = " + gradleModelWatch.status);
|
|
54
|
+
if (gradleModelWatch.stderr) {
|
|
55
|
+
console.log(gradleModelWatch.stderr.toString());
|
|
56
|
+
}
|
|
57
|
+
process.exit(gradleModelWatch.status);
|
|
58
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openremote/util",
|
|
3
|
+
"version": "1.2.0-snapshot.20240512162641",
|
|
4
|
+
"description": "Build Util",
|
|
5
|
+
"author": "OpenRemote",
|
|
6
|
+
"main": "webpack.util.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"orutil": "./cli.js"
|
|
9
|
+
},
|
|
10
|
+
"license": "AGPL-3.0-or-later",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@babel/core": "^7.16.0",
|
|
13
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
14
|
+
"@babel/plugin-syntax-object-rest-spread": "^7.8.3",
|
|
15
|
+
"@babel/plugin-transform-regenerator": "^7.16.0",
|
|
16
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
17
|
+
"@babel/preset-env": "^7.16.4",
|
|
18
|
+
"@babel/runtime": "^7.16.3",
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^5.9.0",
|
|
20
|
+
"@typescript-eslint/parser": "^5.9.0",
|
|
21
|
+
"babel-loader": "^8.2.3",
|
|
22
|
+
"copy-webpack-plugin": "^10.0.0",
|
|
23
|
+
"cross-env": "^7.0.3",
|
|
24
|
+
"css-loader": "^6.5.1",
|
|
25
|
+
"eslint": "^8.6.0",
|
|
26
|
+
"eslint-config-prettier": "^8.3.0",
|
|
27
|
+
"eslint-config-standard": "^16.0.3",
|
|
28
|
+
"eslint-plugin-import": "^2.25.4",
|
|
29
|
+
"eslint-plugin-node": "^11.1.0",
|
|
30
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
31
|
+
"fast-async": "^6.3.8",
|
|
32
|
+
"file-loader": "^6.2.0",
|
|
33
|
+
"fork-ts-checker-notifier-webpack-plugin": "^9.0.0",
|
|
34
|
+
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
35
|
+
"html-webpack-plugin": "^5.5.0",
|
|
36
|
+
"prettier": "^2.5.1",
|
|
37
|
+
"querystring-es3": "^0.2.1",
|
|
38
|
+
"shx": "^0.3.3",
|
|
39
|
+
"source-map-loader": "^3.0.0",
|
|
40
|
+
"style-loader": "^3.3.1",
|
|
41
|
+
"ts-loader": "^9.2.6",
|
|
42
|
+
"typescript": "^5.3.3",
|
|
43
|
+
"webpack": "^5.90.1",
|
|
44
|
+
"webpack-cli": "^5.1.4",
|
|
45
|
+
"webpack-dev-server": "^4.15.1"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/webpack.util.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const webpack = require("webpack");
|
|
4
|
+
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
5
|
+
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
6
|
+
const ForkTsCheckerNotifierWebpackPlugin = require("fork-ts-checker-notifier-webpack-plugin");
|
|
7
|
+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
|
8
|
+
|
|
9
|
+
function getStandardModuleRules() {
|
|
10
|
+
return {
|
|
11
|
+
rules: [
|
|
12
|
+
{
|
|
13
|
+
test: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/, //output css as strings
|
|
14
|
+
type: "asset/source"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
test: /\.css$/, //
|
|
18
|
+
exclude: /(maplibre|mapbox|@material|gridstack|@mdi).*\.css$/,
|
|
19
|
+
use: [
|
|
20
|
+
{ loader: "css-loader" }
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
test: /\.(png|jpg|ico|gif|svg|eot|ttf|woff|woff2|mp4)$/,
|
|
25
|
+
type: "asset",
|
|
26
|
+
generator: {
|
|
27
|
+
filename: 'images/[hash][ext][query]'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
test: /\.tsx?$/,
|
|
32
|
+
exclude: /node_modules/,
|
|
33
|
+
use: {
|
|
34
|
+
loader: "ts-loader",
|
|
35
|
+
options: {
|
|
36
|
+
projectReferences: true
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getAppConfig(mode, isDevServer, dirname, managerUrl, keycloakUrl, port) {
|
|
45
|
+
const production = mode === "production";
|
|
46
|
+
port = port || 9000;
|
|
47
|
+
managerUrl = managerUrl || (production && !isDevServer ? undefined : "http://localhost:8080");
|
|
48
|
+
const OUTPUT_PATH = isDevServer ? 'src' : 'dist';
|
|
49
|
+
|
|
50
|
+
if (isDevServer) {
|
|
51
|
+
console.log("");
|
|
52
|
+
console.log("To customise the URL of the manager and/or keycloak use the managerUrl and/or keycloakUrl");
|
|
53
|
+
console.log(" environment arguments e.g: ");
|
|
54
|
+
console.log("");
|
|
55
|
+
console.log("npm run serve -- --env managerUrl=https://localhost");
|
|
56
|
+
console.log("npm run serve -- --env keycloakUrl=https://localhost/auth");
|
|
57
|
+
console.log("");
|
|
58
|
+
console.log("MANAGER URL: " + managerUrl || "");
|
|
59
|
+
console.log("KEYCLOAK URL: " + keycloakUrl || (managerUrl + "/auth"));
|
|
60
|
+
console.log("");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const config = {
|
|
64
|
+
entry: {
|
|
65
|
+
'bundle': './src/index.ts'
|
|
66
|
+
},
|
|
67
|
+
output: {
|
|
68
|
+
path: dirname + "/dist",
|
|
69
|
+
publicPath: "/" + dirname.split(path.sep).slice(-1)[0] + "/",
|
|
70
|
+
filename: "[name].[contenthash].js"
|
|
71
|
+
},
|
|
72
|
+
module: {...getStandardModuleRules()},
|
|
73
|
+
// optimization: {
|
|
74
|
+
// minimize: true,
|
|
75
|
+
// minimizer: [
|
|
76
|
+
// // For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
|
|
77
|
+
// // `...`,
|
|
78
|
+
// new CssMinimizerPlugin(),
|
|
79
|
+
// ],
|
|
80
|
+
// },
|
|
81
|
+
resolve: {
|
|
82
|
+
extensions: [".ts", ".tsx", "..."],
|
|
83
|
+
fallback: {
|
|
84
|
+
"vm": false,
|
|
85
|
+
"querystring": require.resolve("querystring-es3")
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
config.plugins = [
|
|
91
|
+
// Conditional compilation variables
|
|
92
|
+
new webpack.DefinePlugin({
|
|
93
|
+
PRODUCTION: JSON.stringify(production),
|
|
94
|
+
MANAGER_URL: JSON.stringify(managerUrl),
|
|
95
|
+
KEYCLOAK_URL: JSON.stringify(keycloakUrl),
|
|
96
|
+
"process.env": {
|
|
97
|
+
BABEL_ENV: JSON.stringify(mode)
|
|
98
|
+
}
|
|
99
|
+
}),
|
|
100
|
+
// Generate our index page
|
|
101
|
+
new HtmlWebpackPlugin({
|
|
102
|
+
chunksSortMode: 'none',
|
|
103
|
+
inject: false,
|
|
104
|
+
template: 'index.html'
|
|
105
|
+
})
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
if (production) {
|
|
109
|
+
config.plugins = [
|
|
110
|
+
// new ForkTsCheckerWebpackPlugin({
|
|
111
|
+
// async: false,
|
|
112
|
+
// typescript: {
|
|
113
|
+
// memoryLimit: 4096
|
|
114
|
+
// }
|
|
115
|
+
// }),
|
|
116
|
+
...config.plugins
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
// Only use babel for production otherwise source maps don't work
|
|
120
|
+
config.module.rules.push(
|
|
121
|
+
{
|
|
122
|
+
test: /\.js$/,
|
|
123
|
+
include: function(modulePath) {
|
|
124
|
+
return /(@webcomponents[\/|\\]shadycss|lit-css|styled-lit-element|lit-element|lit-html|@polymer|@lit|pwa-helpers)/.test(modulePath) || !/node_modules/.test(modulePath);
|
|
125
|
+
},
|
|
126
|
+
use: [
|
|
127
|
+
{
|
|
128
|
+
loader: 'babel-loader'
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
config.plugins = [
|
|
135
|
+
// new ForkTsCheckerWebpackPlugin({
|
|
136
|
+
// typescript: {
|
|
137
|
+
// memoryLimit: 4096
|
|
138
|
+
// }
|
|
139
|
+
// }),
|
|
140
|
+
// new ForkTsCheckerNotifierWebpackPlugin({ title: 'TypeScript', excludeWarnings: false }),
|
|
141
|
+
...config.plugins
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (isDevServer) {
|
|
146
|
+
// Load source maps generated by typescript
|
|
147
|
+
// config.devtool = 'inline-source-map';
|
|
148
|
+
config.module.rules.push(
|
|
149
|
+
{
|
|
150
|
+
test: /\.js$/,
|
|
151
|
+
use: ["source-map-loader"],
|
|
152
|
+
enforce: "pre",
|
|
153
|
+
exclude: [
|
|
154
|
+
/node_modules/
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Build list of resources to copy
|
|
161
|
+
const patterns = [
|
|
162
|
+
{
|
|
163
|
+
from: path.dirname(require.resolve("@webcomponents/webcomponentsjs")),
|
|
164
|
+
to: "modules/@webcomponents/webcomponentsjs",
|
|
165
|
+
globOptions: {
|
|
166
|
+
ignore: ["!*.js"]
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
// Check if images dir exists
|
|
171
|
+
if (fs.existsSync(path.join(dirname, "images"))) {
|
|
172
|
+
patterns.push(
|
|
173
|
+
{
|
|
174
|
+
from: "./images",
|
|
175
|
+
to: "images"
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
// Check if locales dir exists
|
|
180
|
+
if (fs.existsSync(path.join(dirname, "locales"))) {
|
|
181
|
+
patterns.push(
|
|
182
|
+
{
|
|
183
|
+
from: "./locales",
|
|
184
|
+
to: "locales"
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
// Check if htaccess file exists
|
|
189
|
+
if (fs.existsSync(path.join(dirname, ".htaccess"))) {
|
|
190
|
+
patterns.push(
|
|
191
|
+
{
|
|
192
|
+
from: ".htaccess",
|
|
193
|
+
to: ".htaccess",
|
|
194
|
+
toType: 'file'
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
//Check if .appignore file exists
|
|
199
|
+
if (fs.existsSync(path.join(dirname, ".appignore"))) {
|
|
200
|
+
patterns.push(
|
|
201
|
+
{
|
|
202
|
+
from: ".appignore",
|
|
203
|
+
to: ".appignore",
|
|
204
|
+
toType: 'file'
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Copy unprocessed files
|
|
210
|
+
config.plugins.push(
|
|
211
|
+
new CopyWebpackPlugin({
|
|
212
|
+
patterns: patterns
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
config.devtool = !isDevServer ? false : "inline-source-map";
|
|
217
|
+
config.devServer = {
|
|
218
|
+
historyApiFallback: {
|
|
219
|
+
index: "/" + dirname.split(path.sep).slice(-1)[0] + "/",
|
|
220
|
+
},
|
|
221
|
+
port: port,
|
|
222
|
+
open: false,
|
|
223
|
+
hot: false, // HMR doesn't work with webcomponents at present
|
|
224
|
+
liveReload: true,
|
|
225
|
+
static: OUTPUT_PATH
|
|
226
|
+
};
|
|
227
|
+
config.watchOptions = {
|
|
228
|
+
ignored: ['node_modules']
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return config;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function getLibName(componentName) {
|
|
235
|
+
if (componentName.startsWith("or-")) {
|
|
236
|
+
componentName = componentName.substr(3);
|
|
237
|
+
}
|
|
238
|
+
componentName = componentName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
239
|
+
return "OR" + componentName.charAt(0).toUpperCase() + componentName.substring(1);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function ORExternals(context, request, callback) {
|
|
243
|
+
const match = request.match(/^@openremote\/([^\/]*)$/);
|
|
244
|
+
if (match) {
|
|
245
|
+
let component = getLibName(match[1]);
|
|
246
|
+
console.log(request + " => " + component);
|
|
247
|
+
return callback(null, "umd " + component);
|
|
248
|
+
}
|
|
249
|
+
callback();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function generateExternals(bundle) {
|
|
253
|
+
if (!bundle) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const externals = [];
|
|
258
|
+
|
|
259
|
+
if (bundle.excludeOr) {
|
|
260
|
+
externals.push(ORExternals);
|
|
261
|
+
}
|
|
262
|
+
if (bundle.vendor) {
|
|
263
|
+
externals.push(bundle.vendor);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return externals;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function generateExports(dirname) {
|
|
270
|
+
|
|
271
|
+
let libName = getLibName(dirname.split(path.sep).pop());
|
|
272
|
+
|
|
273
|
+
return Object.entries(bundles).map(([name, bundle]) => {
|
|
274
|
+
const entry = {};
|
|
275
|
+
entry[name] = "./src/index.ts";
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
entry: entry,
|
|
279
|
+
mode: "production",
|
|
280
|
+
output: {
|
|
281
|
+
filename: "[name].js",
|
|
282
|
+
path: path.resolve(dirname, "dist/umd"),
|
|
283
|
+
library: libName,
|
|
284
|
+
libraryTarget: "umd"
|
|
285
|
+
},
|
|
286
|
+
resolve: {
|
|
287
|
+
extensions: [".ts", ".tsx", "..."],
|
|
288
|
+
fallback: { "vm": false }
|
|
289
|
+
},
|
|
290
|
+
module: {...getStandardModuleRules()},
|
|
291
|
+
externals: generateExternals(bundle)
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
module.exports = {
|
|
297
|
+
getLibName: getLibName,
|
|
298
|
+
generateExports: generateExports,
|
|
299
|
+
getAppConfig: getAppConfig
|
|
300
|
+
};
|