diff --git a/bundle.mjs b/bundle.mjs new file mode 100644 index 00000000..0f4ffe9b --- /dev/null +++ b/bundle.mjs @@ -0,0 +1,46 @@ +import * as esbuild from 'esbuild'; +import fs from 'fs'; + +const plugins = [{ + name: 'my-plugin', + setup(build) { + let count = 0; + build.onEnd(({ errors, warnings }) => { + count++; + const message = errors.length === 0 && warnings.length === 0 + ? 'Build completed.' + : `Build completed with ${errors.length} error(s) and ${warnings.length} warning(s).`; + console.log(`[BUILD #${count.toString().padStart(3, '0')}]:`, message); }); + }, +}]; + +const buildOptions = { + bundle: true, + entryPoints: ['./src/js/L.PM.js'], + loader: { + '.js': 'jsx', + '.css': 'css', + '.svg': 'dataurl' }, + minify: true, + outfile: './dist/leaflet-geoman.js', + //plugins: plugins, + sourcemap: true, +} + +const ctx = await esbuild.context({ ...buildOptions, plugins }); + +if (process.env.DEV) { + await ctx.watch(); + console.log('watching...'); + const { host, port } = await ctx.serve({ + port: 5500, + servedir: '.', + fallback: "./index.html" + }); + console.log(`Serving app at ${host}:${port}.`); +} else { + await ctx.rebuild(); + ctx.dispose(); + fs.copyFileSync('leaflet-geoman.d.ts', './dist/leaflet-geoman.d.ts'); + fs.copyFileSync('./dist/leaflet-geoman.js', './dist/leaflet-geoman.min.js'); +} diff --git a/bundle.ts b/bundle.ts deleted file mode 100644 index 569fd7a1..00000000 --- a/bundle.ts +++ /dev/null @@ -1,39 +0,0 @@ -const esbuild = require('esbuild'); -const path = require('path'); -const fs = require('fs'); - -// Define the entry point -const entryPoint = './src/js/L.PM.js'; - -// Define the output directory -const outdir = path.resolve(__dirname, 'dist'); -fs.mkdirSync(outdir, { recursive: true }); - -// Define an async function to handle the build -async function build() { - try { - await esbuild.build({ - entryPoints: [entryPoint], - bundle: true, - minify: true, - sourcemap: false, - outdir, - loader: { - '.js': 'jsx', - '.css': 'css', - '.svg': 'dataurl', - }, - }); - - // Copy the leaflet-geoman.d.ts file - fs.copyFileSync('leaflet-geoman.d.ts', path.join(outdir, 'leaflet-geoman.d.ts')); - fs.renameSync(path.join(outdir, 'L.PM.js'), path.join(outdir, 'leaflet-geoman.min.js')); - fs.renameSync(path.join(outdir, 'L.PM.css'), path.join(outdir, 'leaflet-geoman.css')); - } catch (error) { - console.error(error); - process.exit(1); - } -} - -// Call the build function -build(); \ No newline at end of file diff --git a/demo/customcontrols.html b/demo/customcontrols.html index e3aad608..d11bafd2 100644 --- a/demo/customcontrols.html +++ b/demo/customcontrols.html @@ -28,9 +28,9 @@

Custom Controls in the Toolbar

- + - + diff --git a/demo/events.html b/demo/events.html index cf8820cf..5cf7a0fb 100644 --- a/demo/events.html +++ b/demo/events.html @@ -21,9 +21,9 @@

Overview of the available events (Console)

- + - + diff --git a/demo/index-canvas.html b/demo/index-canvas.html index 91a41d33..e89be302 100644 --- a/demo/index-canvas.html +++ b/demo/index-canvas.html @@ -40,9 +40,9 @@

Editing A Layer Group

- + - + diff --git a/demo/index.html b/demo/index.html index 0c3d0a5d..88ec8108 100644 --- a/demo/index.html +++ b/demo/index.html @@ -40,9 +40,9 @@

Editing A Layer Group

- + - + diff --git a/index.html b/index.html index eb2081b8..4823f875 100644 --- a/index.html +++ b/index.html @@ -41,9 +41,9 @@
- + diff --git a/package-lock.json b/package-lock.json index 8a421706..602e5310 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ }, "devDependencies": { "@types/leaflet": "^1.7.9", + "cross-env": "^7.0.3", "cypress": "6.9.1", "cypress-wait-until": "1.7.1", "esbuild": "^0.20.0", @@ -1546,6 +1547,24 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -6977,6 +6996,15 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.1" + } + }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index 20a70f4e..431da4c5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "files": [ "dist" ], - "main": "dist/leaflet-geoman.min.js", + "main": "dist/leaflet-geoman.js", "types": "dist/leaflet-geoman.d.ts", "dependencies": { "@turf/boolean-contains": "^6.5.0", @@ -30,6 +30,7 @@ }, "devDependencies": { "@types/leaflet": "^1.7.9", + "cross-env": "^7.0.3", "cypress": "6.9.1", "cypress-wait-until": "1.7.1", "esbuild": "^0.20.0", @@ -50,8 +51,8 @@ }, "scripts": { "start": "npm run dev", - "dev": "esbuild ./src/js/L.PM.js --bundle --watch --loader:.svg=dataurl --outfile=dist/leaflet-geoman.min.js", - "build": "ts-node bundle.ts", + "dev": "cross-env DEV=true ts-node bundle.mjs", + "build": "ts-node bundle.mjs", "test": "cypress run", "cypress": "cypress open", "prepare": "npm run build && husky install", diff --git a/src/assets/translations/index.js b/src/assets/translations/index.js index 86de09e2..e3788649 100644 --- a/src/assets/translations/index.js +++ b/src/assets/translations/index.js @@ -56,4 +56,4 @@ export default { fi, ko, ky, -}; \ No newline at end of file +}; diff --git a/src/js/Mixins/Keyboard.js b/src/js/Mixins/Keyboard.js index ff2c5f16..8b24a469 100644 --- a/src/js/Mixins/Keyboard.js +++ b/src/js/Mixins/Keyboard.js @@ -10,8 +10,8 @@ const createKeyboardMixins = () => ({ map.once('unload', this._unbindKeyListenerEvents, this); }, _unbindKeyListenerEvents() { - L.DomEvent.off(document, 'keydown keyup', this._onKeyListener, this); - L.DomEvent.off(window, 'blur', this._onBlur, this); + L.DomEvent.off(document, 'keydown keyup', this._onKeyListener, this); + L.DomEvent.off(window, 'blur', this._onBlur, this); }, _onKeyListener(e) { let focusOn = 'document';