@sealcode/sealgen 0.11.5 → 0.11.7
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/@types/notifier.d.ts +1 -0
- package/lib/build.js +3 -1
- package/lib/notifier.js +26 -0
- package/lib/page/stateful-page.js +2 -15
- package/package.json +3 -1
- package/src/build.ts +3 -1
- package/src/notifier.ts +22 -0
- package/src/page/stateful-page.ts +3 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function make_notifier(port: number): (message: string) => void;
|
package/lib/build.js
CHANGED
|
@@ -37,6 +37,7 @@ const sleep_1 = require("./utils/sleep");
|
|
|
37
37
|
const generate_collections_1 = require("./generate-collections");
|
|
38
38
|
const generate_routes_1 = require("./generate-routes");
|
|
39
39
|
const generate_components_1 = require("./generate-components");
|
|
40
|
+
const notifier_1 = require("./notifier");
|
|
40
41
|
const generate_names = (function* generate_names() {
|
|
41
42
|
const base_name = "____unique_import_";
|
|
42
43
|
let count = 0;
|
|
@@ -110,7 +111,6 @@ async function build_ts() {
|
|
|
110
111
|
}
|
|
111
112
|
async function complex_build(watch) {
|
|
112
113
|
const loader = Object.fromEntries(["png", "svg", "jpg", "gif", "jpeg", "otf", "ttf"].map((ext) => ["." + ext, "file"]));
|
|
113
|
-
console.log({ loader });
|
|
114
114
|
let css_build = await (0, esbuild_1.context)({
|
|
115
115
|
entryPoints: ["./src/main.css"],
|
|
116
116
|
sourcemap: true,
|
|
@@ -124,6 +124,7 @@ async function complex_build(watch) {
|
|
|
124
124
|
let ongoing_css = false;
|
|
125
125
|
if (watch) {
|
|
126
126
|
const watcher = chokidar.watch("src", { ignoreInitial: true });
|
|
127
|
+
const notifier = (0, notifier_1.make_notifier)(60808);
|
|
127
128
|
watcher.on("all", async (_, path) => {
|
|
128
129
|
if (!css_build)
|
|
129
130
|
return;
|
|
@@ -149,6 +150,7 @@ async function complex_build(watch) {
|
|
|
149
150
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
150
151
|
.catch((e) => console.error(e?.message));
|
|
151
152
|
}
|
|
153
|
+
notifier("css");
|
|
152
154
|
ongoing_css = false;
|
|
153
155
|
}
|
|
154
156
|
if ((path.endsWith(".ts") || path.endsWith(".tsx")) &&
|
package/lib/notifier.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.make_notifier = void 0;
|
|
7
|
+
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
function make_notifier(port) {
|
|
9
|
+
const server = new ws_1.default.Server({
|
|
10
|
+
port,
|
|
11
|
+
});
|
|
12
|
+
let sockets = [];
|
|
13
|
+
server.on("connection", function (socket) {
|
|
14
|
+
sockets.push(socket);
|
|
15
|
+
// When a socket closes, or disconnects, remove it from the array.
|
|
16
|
+
socket.on("close", function () {
|
|
17
|
+
sockets = sockets.filter((s) => s !== socket);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
console.log("build notifier listening on websocket at port " + port);
|
|
21
|
+
return function notify(message) {
|
|
22
|
+
sockets.forEach((s) => s.send(message));
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.make_notifier = make_notifier;
|
|
26
|
+
//# sourceMappingURL=notifier.js.map
|
|
@@ -62,22 +62,9 @@ class StatefulPage extends mountable_1.Mountable {
|
|
|
62
62
|
// the "$" key is parsed as dot notation and overrides the state
|
|
63
63
|
const original_state = JSON.parse((0, base64_1.from_base64)(ctx.$body.state));
|
|
64
64
|
const modified_state = (0, deepmerge_1.default)(original_state, ctx.$body.$ || {}, {
|
|
65
|
-
arrayMerge: (
|
|
65
|
+
arrayMerge: (_target, source, _options) => {
|
|
66
66
|
// https://github.com/TehShrike/deepmerge#user-content-arraymerge-example-combine-arrays
|
|
67
|
-
|
|
68
|
-
source.forEach((item, index) => {
|
|
69
|
-
if (typeof destination[index] === "undefined") {
|
|
70
|
-
destination[index] =
|
|
71
|
-
options.cloneUnlessOtherwiseSpecified(item, options);
|
|
72
|
-
}
|
|
73
|
-
else if (options.isMergeableObject(item)) {
|
|
74
|
-
destination[index] = (0, deepmerge_1.default)(target[index], item, options);
|
|
75
|
-
}
|
|
76
|
-
else if (target.indexOf(item) === -1) {
|
|
77
|
-
destination.push(item);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return destination;
|
|
67
|
+
return source;
|
|
81
68
|
},
|
|
82
69
|
});
|
|
83
70
|
if (ctx.$body.action && ctx.$body.args) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.7",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@types/prettier": "^2.7.0",
|
|
28
28
|
"@types/prompts": "^2.0.14",
|
|
29
29
|
"@types/recursive-readdir": "^2.2.4",
|
|
30
|
+
"@types/ws": "^8.5.10",
|
|
30
31
|
"@typescript-eslint/eslint-plugin": "^4.29.3",
|
|
31
32
|
"@typescript-eslint/parser": "^4.29.3",
|
|
32
33
|
"eslint": "^7.32.0",
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
"recursive-readdir": "^2.2.3",
|
|
61
62
|
"tempstream": "^0.3.0",
|
|
62
63
|
"tiny-glob": "^0.2.9",
|
|
64
|
+
"ws": "^8.16.0",
|
|
63
65
|
"yargs": "^17.6.2"
|
|
64
66
|
},
|
|
65
67
|
"peerDependencies": {
|
package/src/build.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { sleep } from "./utils/sleep";
|
|
|
8
8
|
import { generateCollections } from "./generate-collections";
|
|
9
9
|
import { generateRoutes } from "./generate-routes";
|
|
10
10
|
import { generateComponents } from "./generate-components";
|
|
11
|
+
import { make_notifier } from "./notifier";
|
|
11
12
|
|
|
12
13
|
const generate_names = (function* generate_names() {
|
|
13
14
|
const base_name = "____unique_import_";
|
|
@@ -124,7 +125,6 @@ async function complex_build(watch: boolean): Promise<void> {
|
|
|
124
125
|
(ext) => <const>["." + ext, "file"]
|
|
125
126
|
)
|
|
126
127
|
);
|
|
127
|
-
console.log({ loader });
|
|
128
128
|
let css_build: BuildContext = await context({
|
|
129
129
|
entryPoints: ["./src/main.css"],
|
|
130
130
|
sourcemap: true,
|
|
@@ -138,6 +138,7 @@ async function complex_build(watch: boolean): Promise<void> {
|
|
|
138
138
|
let ongoing_css = false;
|
|
139
139
|
if (watch) {
|
|
140
140
|
const watcher = chokidar.watch("src", { ignoreInitial: true });
|
|
141
|
+
const notifier = make_notifier(60808);
|
|
141
142
|
watcher.on("all", async (_, path) => {
|
|
142
143
|
if (!css_build) return;
|
|
143
144
|
if (path.includes(".#")) return;
|
|
@@ -160,6 +161,7 @@ async function complex_build(watch: boolean): Promise<void> {
|
|
|
160
161
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
161
162
|
.catch((e) => console.error(e?.message));
|
|
162
163
|
}
|
|
164
|
+
notifier("css");
|
|
163
165
|
ongoing_css = false;
|
|
164
166
|
}
|
|
165
167
|
if (
|
package/src/notifier.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
|
|
3
|
+
export function make_notifier(port: number) {
|
|
4
|
+
const server = new WebSocket.Server({
|
|
5
|
+
port,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
let sockets: WebSocket[] = [];
|
|
9
|
+
server.on("connection", function (socket) {
|
|
10
|
+
sockets.push(socket);
|
|
11
|
+
|
|
12
|
+
// When a socket closes, or disconnects, remove it from the array.
|
|
13
|
+
socket.on("close", function () {
|
|
14
|
+
sockets = sockets.filter((s) => s !== socket);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
console.log("build notifier listening on websocket at port " + port);
|
|
19
|
+
return function notify(message: string) {
|
|
20
|
+
sockets.forEach((s) => s.send(message));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -128,31 +128,12 @@ export abstract class StatefulPage<
|
|
|
128
128
|
|
|
129
129
|
const modified_state = deepmerge(original_state, ctx.$body.$ || {}, {
|
|
130
130
|
arrayMerge: (
|
|
131
|
-
|
|
131
|
+
_target: any[],
|
|
132
132
|
source: any[],
|
|
133
|
-
|
|
133
|
+
_options: ArrayMergeOptions
|
|
134
134
|
) => {
|
|
135
135
|
// https://github.com/TehShrike/deepmerge#user-content-arraymerge-example-combine-arrays
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
source.forEach((item, index) => {
|
|
139
|
-
if (typeof destination[index] === "undefined") {
|
|
140
|
-
destination[index] =
|
|
141
|
-
options.cloneUnlessOtherwiseSpecified(
|
|
142
|
-
item,
|
|
143
|
-
options
|
|
144
|
-
);
|
|
145
|
-
} else if (options.isMergeableObject(item)) {
|
|
146
|
-
destination[index] = deepmerge(
|
|
147
|
-
target[index],
|
|
148
|
-
item,
|
|
149
|
-
options
|
|
150
|
-
);
|
|
151
|
-
} else if (target.indexOf(item) === -1) {
|
|
152
|
-
destination.push(item);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return destination;
|
|
136
|
+
return source;
|
|
156
137
|
},
|
|
157
138
|
}) as State;
|
|
158
139
|
|