x4js 2.0.13 → 2.0.14
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/.vscode/launch.json +14 -0
- package/README.md +5 -0
- package/{lib/src/demo → demo}/main.scss +3 -1
- package/{lib/src/demo/main.tsx → demo/main.ts} +37 -36
- package/demo/package.json +26 -0
- package/demo/scss.d.ts +4 -0
- package/demo/svg.d.ts +1 -0
- package/demo/tsconfig.json +14 -0
- package/lib/README.txt +5 -0
- package/lib/cjs/x4.css +1 -1
- package/lib/cjs/x4.js +2 -1
- package/lib/esm/x4.css +1 -1
- package/lib/esm/x4.mjs +2 -1
- package/lib/src/components/boxes/boxes.module.scss +17 -0
- package/lib/src/components/boxes/boxes.ts +162 -13
- package/lib/src/components/breadcrumb/breadcrumb.scss +56 -28
- package/lib/src/components/breadcrumb/breadcrumb.ts +93 -84
- package/lib/src/components/btngroup/btngroup.module.scss +12 -0
- package/lib/src/components/btngroup/btngroup.ts +41 -8
- package/lib/src/components/button/button.module.scss +23 -5
- package/lib/src/components/button/button.ts +72 -4
- package/lib/src/components/canvas/canvas.module.scss +25 -0
- package/lib/src/components/canvas/canvas.ts +189 -0
- package/lib/src/components/canvas/canvas_ex.ts +269 -0
- package/lib/src/components/checkbox/checkbox.ts +18 -4
- package/lib/src/components/combobox/combobox.module.scss +24 -15
- package/lib/src/components/combobox/combobox.ts +107 -24
- package/lib/src/components/components.ts +7 -0
- package/lib/src/components/dialog/dialog.module.scss +37 -3
- package/lib/src/components/dialog/dialog.ts +149 -31
- package/lib/src/components/filedrop/cloud-arrow-up.svg +1 -0
- package/lib/src/components/filedrop/filedrop.module.scss +70 -0
- package/lib/src/components/filedrop/filedrop.ts +131 -0
- package/lib/src/components/form/form.module.scss +4 -0
- package/lib/src/components/form/form.ts +137 -6
- package/lib/src/components/gridview/arrow-down-light.svg +1 -0
- package/lib/src/components/gridview/arrow-up-light.svg +1 -0
- package/lib/src/components/gridview/gridview.module.scss +324 -0
- package/lib/src/components/gridview/gridview.ts +1175 -0
- package/lib/src/components/icon/icon.module.scss +1 -1
- package/lib/src/components/icon/icon.ts +4 -1
- package/lib/src/components/image/image.module.scss +8 -1
- package/lib/src/components/image/image.ts +105 -6
- package/lib/src/components/input/input.module.scss +8 -3
- package/lib/src/components/input/input.ts +137 -14
- package/lib/src/components/keyboard/arrow-up.svg +1 -0
- package/lib/src/components/keyboard/delete-left.svg +1 -0
- package/lib/src/components/keyboard/eye-slash.svg +1 -0
- package/lib/src/components/keyboard/keyboard.module.scss +134 -0
- package/lib/src/components/keyboard/keyboard.ts +525 -0
- package/lib/src/components/label/label.module.scss +22 -4
- package/lib/src/components/label/label.ts +33 -0
- package/lib/src/components/link/link.ts +81 -78
- package/lib/src/components/listbox/listbox.module.scss +61 -3
- package/lib/src/components/listbox/listbox.ts +164 -56
- package/lib/src/components/menu/menu.module.scss +10 -1
- package/lib/src/components/menu/menu.ts +4 -1
- package/lib/src/components/messages/messages.module.scss +44 -0
- package/lib/src/components/messages/messages.ts +164 -18
- package/lib/src/components/messages/pen-field.svg +1 -0
- package/lib/src/components/normalize.scss +5 -0
- package/lib/src/components/notification/notification.module.scss +4 -2
- package/lib/src/components/notification/notification.ts +2 -4
- package/lib/src/components/panel/panel.module.scss +12 -0
- package/lib/src/components/popup/popup.module.scss +4 -2
- package/lib/src/components/popup/popup.ts +136 -92
- package/lib/src/components/propgrid/folder-closed.svg +1 -0
- package/lib/src/components/propgrid/folder-open.svg +1 -0
- package/lib/src/components/propgrid/progrid.module.scss +108 -0
- package/lib/src/components/propgrid/propgrid.ts +271 -0
- package/lib/src/components/propgrid/updown.svg +4 -0
- package/lib/src/components/radio/radio.module.scss +147 -0
- package/lib/src/components/radio/radio.svg +4 -0
- package/lib/src/components/radio/radio.ts +142 -0
- package/lib/src/components/select/select.module.scss +9 -0
- package/lib/src/components/select/select.ts +134 -0
- package/lib/src/components/shared.scss +47 -0
- package/lib/src/components/sizers/sizer.ts +9 -2
- package/lib/src/components/slider/slider.module.scss +77 -30
- package/lib/src/components/slider/slider.ts +72 -22
- package/lib/src/components/tabs/tabs.module.scss +1 -2
- package/lib/src/components/tabs/tabs.ts +43 -12
- package/lib/src/components/textarea/textarea.module.scss +6 -2
- package/lib/src/components/textarea/textarea.ts +73 -8
- package/lib/src/components/textedit/textedit.module.scss +3 -1
- package/lib/src/components/textedit/textedit.ts +31 -4
- package/lib/src/components/themes.scss +7 -0
- package/lib/src/components/tickline/tickline.module.scss +26 -0
- package/lib/src/components/tickline/tickline.ts +82 -0
- package/lib/src/components/tooltips/comments-question.svg +1 -0
- package/lib/src/components/tooltips/tooltips.scss +30 -9
- package/lib/src/components/tooltips/tooltips.ts +10 -5
- package/lib/src/components/treeview/treeview.module.scss +129 -60
- package/lib/src/components/treeview/treeview.ts +47 -12
- package/lib/src/components/viewport/viewport.module.scss +7 -0
- package/lib/src/core/component.ts +102 -32
- package/lib/src/core/core_application.ts +222 -2
- package/lib/src/core/core_colors.ts +2 -2
- package/lib/src/{components/grid/datastore.ts → core/core_data.ts} +261 -250
- package/lib/src/core/core_dragdrop.ts +3 -3
- package/lib/src/core/core_element.ts +13 -1
- package/lib/src/core/core_events.ts +28 -0
- package/lib/src/core/core_i18n.ts +18 -2
- package/lib/src/core/core_react.ts +79 -0
- package/lib/src/core/core_router.ts +23 -7
- package/lib/src/core/core_styles.ts +5 -5
- package/lib/src/core/core_svg.ts +173 -12
- package/lib/src/core/core_tools.ts +305 -87
- package/lib/src/x4tsx.d.ts +25 -0
- package/lib/styles/x4.css +1 -1
- package/lib/types/x4js.d.ts +767 -92
- package/package.json +4 -4
- package/scripts/build.mjs +378 -0
- package/scripts/prepack.mjs +346 -0
- package/src/components/base.scss +25 -0
- package/src/components/boxes/boxes.module.scss +54 -0
- package/src/components/boxes/boxes.ts +278 -0
- package/src/components/breadcrumb/breadcrumb.scss +56 -0
- package/src/components/breadcrumb/breadcrumb.ts +93 -0
- package/src/components/breadcrumb/chevron-right.svg +1 -0
- package/src/components/btngroup/btngroup.module.scss +41 -0
- package/src/components/btngroup/btngroup.ts +153 -0
- package/src/components/button/button.module.scss +173 -0
- package/src/components/button/button.ts +185 -0
- package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/src/components/calendar/calendar.module.scss +163 -0
- package/src/components/calendar/calendar.ts +327 -0
- package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/src/components/canvas/canvas.module.scss +25 -0
- package/src/components/canvas/canvas.ts +189 -0
- package/src/components/canvas/canvas_ex.ts +269 -0
- package/src/components/checkbox/check.svg +4 -0
- package/src/components/checkbox/checkbox.module.scss +142 -0
- package/src/components/checkbox/checkbox.ts +140 -0
- package/src/components/colorinput/colorinput.module.scss +65 -0
- package/src/components/colorinput/colorinput.ts +91 -0
- package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/src/components/colorpicker/colorpicker.ts +482 -0
- package/src/components/combobox/combobox.module.scss +133 -0
- package/src/components/combobox/combobox.ts +275 -0
- package/src/components/combobox/updown.svg +4 -0
- package/src/components/components.ts +41 -0
- package/src/components/dialog/dialog.module.scss +105 -0
- package/src/components/dialog/dialog.ts +212 -0
- package/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/src/components/filedrop/cloud-arrow-up.svg +1 -0
- package/src/components/filedrop/filedrop.module.scss +70 -0
- package/src/components/filedrop/filedrop.ts +131 -0
- package/src/components/form/form.module.scss +38 -0
- package/src/components/form/form.ts +172 -0
- package/src/components/gridview/arrow-down-light.svg +1 -0
- package/src/components/gridview/arrow-up-light.svg +1 -0
- package/src/components/gridview/gridview.module.scss +324 -0
- package/src/components/gridview/gridview.ts +1175 -0
- package/src/components/header/header.module.scss +40 -0
- package/src/components/header/header.ts +130 -0
- package/src/components/icon/icon.module.scss +30 -0
- package/src/components/icon/icon.ts +139 -0
- package/src/components/image/image.module.scss +28 -0
- package/src/components/image/image.ts +168 -0
- package/src/components/input/input.module.scss +74 -0
- package/src/components/input/input.ts +398 -0
- package/src/components/keyboard/arrow-up.svg +1 -0
- package/src/components/keyboard/delete-left.svg +1 -0
- package/src/components/keyboard/eye-slash.svg +1 -0
- package/src/components/keyboard/keyboard.module.scss +134 -0
- package/src/components/keyboard/keyboard.ts +525 -0
- package/src/components/label/label.module.scss +76 -0
- package/src/components/label/label.ts +97 -0
- package/src/components/link/link.ts +81 -0
- package/src/components/listbox/listbox.module.scss +161 -0
- package/src/components/listbox/listbox.ts +539 -0
- package/src/components/menu/caret-right-solid.svg +1 -0
- package/src/components/menu/menu.module.scss +117 -0
- package/src/components/menu/menu.ts +174 -0
- package/src/components/messages/circle-exclamation.svg +1 -0
- package/src/components/messages/messages.module.scss +92 -0
- package/src/components/messages/messages.ts +215 -0
- package/src/components/messages/pen-field.svg +1 -0
- package/src/components/normalize.scss +391 -0
- package/src/components/notification/circle-check-solid.svg +1 -0
- package/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/src/components/notification/circle-notch-light.svg +1 -0
- package/src/components/notification/notification.module.scss +84 -0
- package/src/components/notification/notification.ts +107 -0
- package/src/components/notification/xmark-sharp-light.svg +1 -0
- package/src/components/panel/panel.module.scss +60 -0
- package/src/components/panel/panel.ts +58 -0
- package/src/components/popup/popup.module.scss +45 -0
- package/src/components/popup/popup.ts +440 -0
- package/src/components/progress/progress.module.scss +57 -0
- package/src/components/progress/progress.ts +44 -0
- package/src/components/propgrid/folder-closed.svg +1 -0
- package/src/components/propgrid/folder-open.svg +1 -0
- package/src/components/propgrid/progrid.module.scss +108 -0
- package/src/components/propgrid/propgrid.ts +271 -0
- package/src/components/propgrid/updown.svg +4 -0
- package/src/components/radio/radio.module.scss +147 -0
- package/src/components/radio/radio.svg +4 -0
- package/src/components/radio/radio.ts +142 -0
- package/src/components/rating/rating.module.scss +23 -0
- package/src/components/rating/rating.ts +131 -0
- package/src/components/rating/star-sharp-light.svg +1 -0
- package/src/components/rating/star-sharp-solid.svg +1 -0
- package/src/components/select/select.module.scss +9 -0
- package/src/components/select/select.ts +134 -0
- package/src/components/shared.scss +137 -0
- package/src/components/sizers/sizer.module.scss +90 -0
- package/src/components/sizers/sizer.ts +131 -0
- package/src/components/slider/slider.module.scss +118 -0
- package/src/components/slider/slider.ts +198 -0
- package/src/components/switch/switch.module.scss +127 -0
- package/src/components/switch/switch.ts +62 -0
- package/src/components/tabs/tabs.module.scss +45 -0
- package/src/components/tabs/tabs.ts +199 -0
- package/src/components/textarea/textarea.module.scss +63 -0
- package/src/components/textarea/textarea.ts +125 -0
- package/src/components/textedit/textedit.module.scss +116 -0
- package/src/components/textedit/textedit.ts +110 -0
- package/src/components/themes.scss +88 -0
- package/src/components/tickline/tickline.module.scss +26 -0
- package/src/components/tickline/tickline.ts +82 -0
- package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/src/components/tooltips/comments-question.svg +1 -0
- package/src/components/tooltips/tooltips.scss +72 -0
- package/src/components/tooltips/tooltips.ts +109 -0
- package/src/components/treeview/chevron-down-light.svg +1 -0
- package/src/components/treeview/treeview.module.scss +185 -0
- package/src/components/treeview/treeview.ts +445 -0
- package/src/components/viewport/viewport.module.scss +32 -0
- package/src/components/viewport/viewport.ts +41 -0
- package/src/core/component.ts +1072 -0
- package/src/core/core_application.ts +264 -0
- package/src/core/core_colors.ts +250 -0
- package/src/core/core_data.ts +1309 -0
- package/src/core/core_dom.ts +471 -0
- package/src/core/core_dragdrop.ts +201 -0
- package/src/core/core_element.ts +110 -0
- package/src/core/core_events.ts +177 -0
- package/src/core/core_i18n.ts +393 -0
- package/src/core/core_react.ts +79 -0
- package/src/core/core_router.ts +237 -0
- package/src/core/core_styles.ts +214 -0
- package/src/core/core_svg.ts +711 -0
- package/src/core/core_tools.ts +906 -0
- package/src/types/scss.d.ts +4 -0
- package/src/types/svg.d.ts +1 -0
- package/src/types/x4react.d.ts +9 -0
- package/src/x4.scss +19 -0
- package/src/x4tsx.d.ts +25 -0
- package/tsconfig.json +14 -0
- package/lib/src/components/grid/gridview.ts +0 -1108
- package/lib/src/components/grid/memdb.ts +0 -325
- /package/{lib/src/demo → demo}/assets/house-light.svg +0 -0
- /package/{lib/src/demo → demo}/assets/radio.svg +0 -0
- /package/{lib/src/demo → demo}/index.html +0 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x4js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.14",
|
|
4
4
|
"description": "X4 framework",
|
|
5
5
|
"author": "etienne cochard",
|
|
6
6
|
"main": "src/x4.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"typess": "lib/types/x4js.d.ts",
|
|
8
|
+
"filess": [
|
|
9
9
|
"lib/**/*"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://x4js.org",
|
|
33
33
|
"module": "lib/esm/x4.mjs",
|
|
34
|
-
"
|
|
34
|
+
"exportss": {
|
|
35
35
|
".": {
|
|
36
36
|
"import": {
|
|
37
37
|
"types": "./lib/types/x4.d.ts",
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file build.mjs
|
|
5
|
+
* @author Etienne Cochard
|
|
6
|
+
* @copyright (c) 2024 R-libre ingenierie, all rights reserved.
|
|
7
|
+
* @version 1.2
|
|
8
|
+
**/
|
|
9
|
+
|
|
10
|
+
import * as fs from "node:fs"
|
|
11
|
+
import * as path from "node:path"
|
|
12
|
+
import * as url from "node:url"
|
|
13
|
+
import * as http from "node:http"
|
|
14
|
+
|
|
15
|
+
import chalk from "chalk"
|
|
16
|
+
import esbuild from "esbuild"
|
|
17
|
+
import { WebSocketServer } from 'ws';
|
|
18
|
+
import Watcher from "watcher"
|
|
19
|
+
|
|
20
|
+
import { sassPlugin } from "esbuild-sass-plugin";
|
|
21
|
+
import { dtsPlugin } from "esbuild-plugin-d.ts";
|
|
22
|
+
//import { hostname } from 'node:os'
|
|
23
|
+
|
|
24
|
+
console.log( chalk.green("\n\n-- X4Build 1.2 -------------------") );
|
|
25
|
+
|
|
26
|
+
const releaseMode = process.argv.some(a => a == "--release")
|
|
27
|
+
const hmrMode = process.argv.some(a => a == "--hmr") // hot module replacement
|
|
28
|
+
const watchMode = process.argv.some(a => a == "--watch" ) // watch modifications
|
|
29
|
+
const serveMode = process.argv.some(a => a == "--serve") // watch modifications
|
|
30
|
+
const cjsMode = process.argv.some(a => a == "--cjs") // output mode
|
|
31
|
+
const dtsMode = process.argv.some(a => a == "--dts") // generate .d.ts
|
|
32
|
+
|
|
33
|
+
// forced outdir in command line
|
|
34
|
+
let outDir = process.argv.find( a => a.startsWith("--outdir=") );
|
|
35
|
+
if( outDir ) {
|
|
36
|
+
outDir = outDir.substring(9);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log( "outdir =", outDir );
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function readPackage() {
|
|
43
|
+
|
|
44
|
+
let cpath = process.cwd();
|
|
45
|
+
|
|
46
|
+
// check here
|
|
47
|
+
let pth = path.join(cpath, "package.json");
|
|
48
|
+
if (fs.existsSync(pth)) {
|
|
49
|
+
const raw = fs.readFileSync(pth, "utf-8");
|
|
50
|
+
return JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw new Error("cannot find package.json");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const def_settings = {
|
|
57
|
+
"outdir": "./bin",
|
|
58
|
+
"copy": [],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const pkg_settings = readPackage();
|
|
62
|
+
const settings = { ...def_settings, ...pkg_settings.x4build };
|
|
63
|
+
|
|
64
|
+
if( !settings.entryPoints ) {
|
|
65
|
+
settings.entryPoints = [pkg_settings.main];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if( outDir ) {
|
|
69
|
+
settings.outdir = outDir;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log( chalk.green(" release mode ..", releaseMode ) );
|
|
73
|
+
console.log( chalk.green(" hmr ...........", hmrMode ) );
|
|
74
|
+
console.log( chalk.green(" watching ......", watchMode ) );
|
|
75
|
+
console.log( chalk.green(" serve files ...", serveMode ) );
|
|
76
|
+
console.log( chalk.green(" output dir ....", settings.outdir ) );
|
|
77
|
+
console.log( chalk.green(" entry point ...", settings.entryPoints ) );
|
|
78
|
+
console.log( chalk.green(" generate .d.ts.", dtsMode ) );
|
|
79
|
+
console.log( chalk.green(" copying .......", settings.copy ) );
|
|
80
|
+
|
|
81
|
+
console.log( chalk.green("----------------------------------") );
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
const js_hmr = ` // X4 Hot Module Replacement v1.1
|
|
87
|
+
{
|
|
88
|
+
const ws = new WebSocket( "ws://127.0.0.1:9998", "hmr" );
|
|
89
|
+
|
|
90
|
+
ws.onmessage = ( ev ) => {
|
|
91
|
+
if( ev.data=="reload-css" ) {
|
|
92
|
+
const gen_id = Date.now( );
|
|
93
|
+
document.querySelectorAll( "link[rel=stylesheet]").forEach( link => {
|
|
94
|
+
link.href = link.href.replace(/\\?.*|$/, "?" + gen_id)
|
|
95
|
+
} );
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
location.reload();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}`
|
|
102
|
+
|
|
103
|
+
/** custom plugin to copy element after the build */
|
|
104
|
+
|
|
105
|
+
const post_plugin = {
|
|
106
|
+
name: 'post-cmd',
|
|
107
|
+
setup(build) {
|
|
108
|
+
|
|
109
|
+
build.onEnd(result => {
|
|
110
|
+
if (result.errors.length) {
|
|
111
|
+
console.error(`build ended with ${result.errors.length} errors`)
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
settings.copy?.forEach((desc) => {
|
|
115
|
+
const { from, to } = desc;
|
|
116
|
+
|
|
117
|
+
if (fs.existsSync(from)) {
|
|
118
|
+
fs.cpSync(from, path.join(settings.outdir, to), { recursive: true });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let buildcnt = 1;
|
|
127
|
+
|
|
128
|
+
const other_plugins = [];
|
|
129
|
+
|
|
130
|
+
if( dtsMode ) {
|
|
131
|
+
other_plugins.push( dtsPlugin( {
|
|
132
|
+
}) );
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function build() {
|
|
136
|
+
|
|
137
|
+
console.log(chalk.cyan(`building (${buildcnt++})...`));
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
/** @type {esbuild.BuildOptions} */
|
|
141
|
+
const options = {
|
|
142
|
+
target: "node12",
|
|
143
|
+
logLevel: "error",
|
|
144
|
+
entryPoints: settings.entryPoints,
|
|
145
|
+
bundle: true,
|
|
146
|
+
charset: "utf8",
|
|
147
|
+
outdir: settings.outdir,
|
|
148
|
+
keepNames: true,
|
|
149
|
+
platform: "browser",
|
|
150
|
+
format: cjsMode ? "cjs" : "esm",
|
|
151
|
+
minify: releaseMode,
|
|
152
|
+
plugins: [
|
|
153
|
+
sassPlugin( {
|
|
154
|
+
type: "css",
|
|
155
|
+
filter: /\.scss$/,
|
|
156
|
+
}),
|
|
157
|
+
post_plugin,
|
|
158
|
+
...other_plugins,
|
|
159
|
+
],
|
|
160
|
+
assetNames: "assets/[name]-[hash]",
|
|
161
|
+
loader: {
|
|
162
|
+
".svg": "dataurl",
|
|
163
|
+
".jpg": "file",
|
|
164
|
+
".png": "file",
|
|
165
|
+
".woff": "file",
|
|
166
|
+
".woff2": "file",
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!releaseMode) {
|
|
171
|
+
options.sourcemap = "inline";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (hmrMode) {
|
|
175
|
+
options.banner = { js: js_hmr }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
await esbuild.build(options);
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
console.error(chalk.bgRed.white("build failure, waiting for correction"));
|
|
182
|
+
console.log(e.message);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// :: WEBSOCKET SERVER FOR HRM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
187
|
+
|
|
188
|
+
if (watchMode) {
|
|
189
|
+
|
|
190
|
+
const wsServer = new WebSocketServer({
|
|
191
|
+
port: 9998
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// all connected clients (1)
|
|
195
|
+
const clients = [];
|
|
196
|
+
|
|
197
|
+
wsServer.on('connection', (ws) => {
|
|
198
|
+
clients.push(ws);
|
|
199
|
+
|
|
200
|
+
wsServer.on('error', (err) => {
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
wsServer.on('message', function message(data) {
|
|
204
|
+
console.log('received: %s', data);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const sendClientMessage = (msg) => {
|
|
209
|
+
clients.forEach(ws => {
|
|
210
|
+
ws.send(msg);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// file watcher ------------------------------------------
|
|
215
|
+
const selfPath = url.fileURLToPath(import.meta.url);
|
|
216
|
+
const cPath = process.cwd();
|
|
217
|
+
|
|
218
|
+
const watcher = new Watcher("./", {
|
|
219
|
+
recursive: true,
|
|
220
|
+
ignoreInitial: true,
|
|
221
|
+
ignore: (targetPath) => {
|
|
222
|
+
if (targetPath.startsWith(cPath)) {
|
|
223
|
+
targetPath = path.join(".", targetPath.substring(cPath.length));
|
|
224
|
+
targetPath = path.normalize(targetPath);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (targetPath.startsWith(settings.outdir) || targetPath.startsWith("node_modules") ) {
|
|
228
|
+
//console.log("skip watch", targetPath);
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
watcher.on('all', async (event, targetPath, targetPathNext) => {
|
|
238
|
+
|
|
239
|
+
if (event == "change" || event == "add") {
|
|
240
|
+
// one of our copy path ?
|
|
241
|
+
if (targetPath.startsWith(cPath)) {
|
|
242
|
+
let pth = "." + targetPath.substring(cPath.length);
|
|
243
|
+
pth = path.normalize(pth);
|
|
244
|
+
|
|
245
|
+
//console.log( targetPath );
|
|
246
|
+
if (settings.copy?.some(desc => {
|
|
247
|
+
const from = path.normalize(desc.from);
|
|
248
|
+
if (pth == from || pth.startsWith(from)) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
})) {
|
|
252
|
+
await build();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (event == "change") {
|
|
259
|
+
// somebody changed this file, so leave
|
|
260
|
+
if (targetPath == selfPath) {
|
|
261
|
+
process.exit(0);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// depending of the extension, we send the correct type of refresh
|
|
265
|
+
switch (path.extname(targetPath)) {
|
|
266
|
+
case ".svg":
|
|
267
|
+
case ".css":
|
|
268
|
+
case ".scss": {
|
|
269
|
+
await build();
|
|
270
|
+
sendClientMessage("reload-css");
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
case ".html":
|
|
275
|
+
case ".ts":
|
|
276
|
+
case ".js":
|
|
277
|
+
case ".jsx":
|
|
278
|
+
case ".tsx": {
|
|
279
|
+
await build();
|
|
280
|
+
sendClientMessage("reload-js");
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
case ".json": {
|
|
285
|
+
if (path.basename(targetPath) == 'package.json') {
|
|
286
|
+
build();
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
//console.log ( event ); // => could be any target event: 'add', 'addDir', 'change', 'rename', 'renameDir', 'unlink' or 'unlinkDir'
|
|
293
|
+
//console.log ( targetPath ); // => the file system path where the event took place, this is always provided
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// :: WEB SERVER ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
299
|
+
|
|
300
|
+
function serve() {
|
|
301
|
+
|
|
302
|
+
// maps file extention to MIME types
|
|
303
|
+
// full list can be found here: https://www.freeformatter.com/mime-types-list.html
|
|
304
|
+
const mimeType = {
|
|
305
|
+
'.ico': 'image/x-icon',
|
|
306
|
+
'.html': 'text/html',
|
|
307
|
+
'.js': 'text/javascript',
|
|
308
|
+
'.json': 'application/json',
|
|
309
|
+
'.css': 'text/css',
|
|
310
|
+
'.png': 'image/png',
|
|
311
|
+
'.jpg': 'image/jpeg',
|
|
312
|
+
'.wav': 'audio/wav',
|
|
313
|
+
'.mp3': 'audio/mpeg',
|
|
314
|
+
'.svg': 'image/svg+xml',
|
|
315
|
+
'.pdf': 'application/pdf',
|
|
316
|
+
'.zip': 'application/zip',
|
|
317
|
+
'.doc': 'application/msword',
|
|
318
|
+
'.eot': 'application/vnd.ms-fontobject',
|
|
319
|
+
'.ttf': 'application/x-font-ttf',
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const server = http.createServer( {
|
|
323
|
+
hostname: "127.0.0.1"
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
server.on('request', (req, res) => {
|
|
327
|
+
//console.log(`${req.method} ${req.url}`);
|
|
328
|
+
|
|
329
|
+
// parse URL
|
|
330
|
+
const parsedUrl = url.parse(req.url);
|
|
331
|
+
|
|
332
|
+
// extract URL path
|
|
333
|
+
// Avoid https://en.wikipedia.org/wiki/Directory_traversal_attack
|
|
334
|
+
// e.g curl --path-as-is http://localhost:9000/../fileInDanger.txt
|
|
335
|
+
// by limiting the path to current directory only
|
|
336
|
+
const sanitizePath = path.normalize(parsedUrl.pathname).replace(/^(\.\.[\/\\])+/, '');
|
|
337
|
+
let pathname = path.join(settings.outdir, sanitizePath);
|
|
338
|
+
|
|
339
|
+
if( fs.existsSync(pathname) ) {
|
|
340
|
+
// if is a directory, then look for index.html
|
|
341
|
+
if (fs.statSync(pathname).isDirectory()) {
|
|
342
|
+
pathname = path.join( pathname, 'index.html' );
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// read file from file system
|
|
346
|
+
fs.readFile(pathname, function (err, data) {
|
|
347
|
+
if (err) {
|
|
348
|
+
res.statusCode = 500;
|
|
349
|
+
res.end(`Error getting the file: ${err}.`);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
// based on the URL path, extract the file extention. e.g. .js, .doc, ...
|
|
353
|
+
const ext = path.parse(pathname).ext;
|
|
354
|
+
// if the file is found, set Content-type and send data
|
|
355
|
+
res.setHeader('Content-type', mimeType[ext] || 'text/plain');
|
|
356
|
+
res.end(data);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
// if the file is not found, return 404
|
|
362
|
+
res.statusCode = 404;
|
|
363
|
+
res.end(`File ${pathname} not found!`);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
server.listen(3000);
|
|
369
|
+
console.log( chalk.yellow("listening on http://127.0.0.1:3000") );
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
build();
|
|
373
|
+
|
|
374
|
+
if( serveMode ) {
|
|
375
|
+
serve();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
|