run build on prepare and pretty
This commit is contained in:
parent
04dcc2d636
commit
084b56f24b
@ -16,8 +16,8 @@
|
|||||||
"./lib/index.node": "./lib/index.node.cjs"
|
"./lib/index.node": "./lib/index.node.cjs"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "tsc",
|
"prepare": "tsc && ./build.js",
|
||||||
"compile": "./build.mjs",
|
"compile": "tsc && ./build.js",
|
||||||
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|
||||||
"pretty": "prettier --write src"
|
"pretty": "prettier --write src"
|
||||||
},
|
},
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
|
import { clk, setGlobalLogLevelFromString } from "@gnu-taler/taler-util";
|
||||||
import {
|
|
||||||
clk, setGlobalLogLevelFromString
|
|
||||||
} from "@gnu-taler/taler-util";
|
|
||||||
import { serve } from "./serve.js";
|
import { serve } from "./serve.js";
|
||||||
|
|
||||||
|
|
||||||
export const walletCli = clk
|
export const walletCli = clk
|
||||||
.program("wallet", {
|
.program("wallet", {
|
||||||
help: "Command line interface for the GNU Taler wallet.",
|
help: "Command line interface for the GNU Taler wallet.",
|
||||||
@ -20,7 +16,7 @@ export const walletCli = clk
|
|||||||
})
|
})
|
||||||
.flag("verbose", ["-V", "--verbose"], {
|
.flag("verbose", ["-V", "--verbose"], {
|
||||||
help: "Enable verbose output.",
|
help: "Enable verbose output.",
|
||||||
})
|
});
|
||||||
|
|
||||||
walletCli
|
walletCli
|
||||||
.subcommand("serve", "serve", { help: "Create a server." })
|
.subcommand("serve", "serve", { help: "Create a server." })
|
||||||
@ -39,12 +35,9 @@ walletCli
|
|||||||
return serve({
|
return serve({
|
||||||
folder: args.serve.folder || "./dist",
|
folder: args.serve.folder || "./dist",
|
||||||
port: args.serve.port || 8000,
|
port: args.serve.port || 8000,
|
||||||
development: args.serve.development
|
development: args.serve.development,
|
||||||
})
|
});
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
declare const __VERSION__: string;
|
declare const __VERSION__: string;
|
||||||
function printVersion(): void {
|
function printVersion(): void {
|
||||||
@ -55,5 +48,3 @@ function printVersion(): void {
|
|||||||
export function main(): void {
|
export function main(): void {
|
||||||
walletCli.run();
|
walletCli.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
//`ws://localhost:8003/socket`
|
//`ws://localhost:8003/socket`
|
||||||
export function setupLiveReload(wsURL: string | undefined) {
|
export function setupLiveReload(wsURL: string | undefined) {
|
||||||
if (!wsURL) return;
|
if (!wsURL) return;
|
||||||
const ws = new WebSocket(wsURL);
|
const ws = new WebSocket(wsURL);
|
||||||
ws.addEventListener('message', (message) => {
|
ws.addEventListener("message", (message) => {
|
||||||
const event = JSON.parse(message.data);
|
const event = JSON.parse(message.data);
|
||||||
if (event.type === "LOG") {
|
if (event.type === "LOG") {
|
||||||
console.log(event.message);
|
console.log(event.message);
|
||||||
@ -12,7 +11,7 @@ export function setupLiveReload(wsURL: string | undefined) {
|
|||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
if (event.type === "UPDATE") {
|
if (event.type === "UPDATE") {
|
||||||
const c = document.getElementById("container")
|
const c = document.getElementById("container");
|
||||||
if (c) {
|
if (c) {
|
||||||
document.body.removeChild(c);
|
document.body.removeChild(c);
|
||||||
}
|
}
|
||||||
@ -35,4 +34,4 @@ export function setupLiveReload(wsURL: string | undefined) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { renderStories, parseGroupImport } from "./stories.js"
|
export { renderStories, parseGroupImport } from "./stories.js";
|
||||||
|
@ -1,3 +1 @@
|
|||||||
export { serve } from "./serve.js"
|
export { serve } from "./serve.js";
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1 @@
|
|||||||
|
export default {};
|
||||||
|
|
||||||
|
|
||||||
export default {}
|
|
||||||
|
@ -15,7 +15,7 @@ function setupLiveReload(): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
console.log("unsupported", event);
|
console.log("unsupported", event);
|
||||||
});
|
});
|
||||||
@ -29,7 +29,6 @@ function setupLiveReload(): void {
|
|||||||
}
|
}
|
||||||
setupLiveReload();
|
setupLiveReload();
|
||||||
|
|
||||||
|
|
||||||
function showReloadOverlay(): void {
|
function showReloadOverlay(): void {
|
||||||
const d = document.createElement("div");
|
const d = document.createElement("div");
|
||||||
d.style.position = "absolute";
|
d.style.position = "absolute";
|
||||||
@ -49,4 +48,3 @@ function showReloadOverlay(): void {
|
|||||||
document.body.appendChild(d);
|
document.body.appendChild(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,22 +1,19 @@
|
|||||||
import {
|
import { Logger } from "@gnu-taler/taler-util";
|
||||||
Logger
|
import chokidar from "chokidar";
|
||||||
} from "@gnu-taler/taler-util";
|
|
||||||
import chokidar from 'chokidar';
|
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import https from "https";
|
import https from "https";
|
||||||
import { parse } from 'url';
|
import { parse } from "url";
|
||||||
import WebSocket, { Server } from 'ws';
|
import WebSocket, { Server } from "ws";
|
||||||
|
|
||||||
|
import locahostCrt from "./keys/localhost.crt";
|
||||||
import locahostCrt from './keys/localhost.crt';
|
import locahostKey from "./keys/localhost.key";
|
||||||
import locahostKey from './keys/localhost.key';
|
import storiesHtml from "./stories.html";
|
||||||
import storiesHtml from './stories.html';
|
|
||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const httpServerOptions = {
|
const httpServerOptions = {
|
||||||
key: locahostKey,
|
key: locahostKey,
|
||||||
cert: locahostCrt
|
cert: locahostCrt,
|
||||||
};
|
};
|
||||||
|
|
||||||
const logger = new Logger("serve.ts");
|
const logger = new Logger("serve.ts");
|
||||||
@ -26,42 +23,40 @@ const PATHS = {
|
|||||||
NOTIFY: "/notify",
|
NOTIFY: "/notify",
|
||||||
EXAMPLE: "/examples",
|
EXAMPLE: "/examples",
|
||||||
APP: "/app",
|
APP: "/app",
|
||||||
}
|
};
|
||||||
|
|
||||||
export async function serve(opts: {
|
export async function serve(opts: {
|
||||||
folder: string,
|
folder: string;
|
||||||
port: number,
|
port: number;
|
||||||
source?: string,
|
source?: string;
|
||||||
development?: boolean,
|
development?: boolean;
|
||||||
examplesLocationJs?: string,
|
examplesLocationJs?: string;
|
||||||
examplesLocationCss?: string,
|
examplesLocationCss?: string;
|
||||||
onUpdate?: () => Promise<void>;
|
onUpdate?: () => Promise<void>;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
|
const app = express();
|
||||||
|
|
||||||
const app = express()
|
app.use(PATHS.APP, express.static(opts.folder));
|
||||||
|
const server = https.createServer(httpServerOptions, app);
|
||||||
app.use(PATHS.APP, express.static(opts.folder))
|
|
||||||
const server = https.createServer(httpServerOptions, app)
|
|
||||||
server.listen(opts.port);
|
server.listen(opts.port);
|
||||||
logger.info(`serving ${opts.folder} on ${opts.port}`)
|
logger.info(`serving ${opts.folder} on ${opts.port}`);
|
||||||
logger.info(` ${PATHS.APP}: application`)
|
logger.info(` ${PATHS.APP}: application`);
|
||||||
logger.info(` ${PATHS.EXAMPLE}: examples`)
|
logger.info(` ${PATHS.EXAMPLE}: examples`);
|
||||||
logger.info(` ${PATHS.WS}: websocket`)
|
logger.info(` ${PATHS.WS}: websocket`);
|
||||||
logger.info(` ${PATHS.NOTIFY}: broadcast`)
|
logger.info(` ${PATHS.NOTIFY}: broadcast`);
|
||||||
|
|
||||||
if (opts.development) {
|
if (opts.development) {
|
||||||
|
|
||||||
const wss = new Server({ noServer: true });
|
const wss = new Server({ noServer: true });
|
||||||
|
|
||||||
wss.on('connection', function connection(ws) {
|
wss.on("connection", function connection(ws) {
|
||||||
ws.send('welcome');
|
ws.send("welcome");
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on('upgrade', function upgrade(request, socket, head) {
|
server.on("upgrade", function upgrade(request, socket, head) {
|
||||||
const { pathname } = parse(request.url || "");
|
const { pathname } = parse(request.url || "");
|
||||||
if (pathname === PATHS.WS) {
|
if (pathname === PATHS.WS) {
|
||||||
wss.handleUpgrade(request, socket, head, function done(ws) {
|
wss.handleUpgrade(request, socket, head, function done(ws) {
|
||||||
wss.emit('connection', ws, request);
|
wss.emit("connection", ws, request);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
@ -73,36 +68,44 @@ export async function serve(opts: {
|
|||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
client.send(JSON.stringify(data));
|
client.send(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
const watchingFolder = opts.source ?? opts.folder
|
const watchingFolder = opts.source ?? opts.folder;
|
||||||
logger.info(`watching ${watchingFolder} for change`)
|
logger.info(`watching ${watchingFolder} for change`);
|
||||||
|
|
||||||
chokidar.watch(watchingFolder).on('change', (path, stats) => {
|
chokidar.watch(watchingFolder).on("change", (path, stats) => {
|
||||||
logger.trace(`changed ${path}`)
|
logger.trace(`changed ${path}`);
|
||||||
|
|
||||||
sendToAllClients({ type: 'file-updated-start', data: { path } })
|
sendToAllClients({ type: "file-updated-start", data: { path } });
|
||||||
if (opts.onUpdate) {
|
if (opts.onUpdate) {
|
||||||
opts.onUpdate().then(result => {
|
opts.onUpdate().then((result) => {
|
||||||
sendToAllClients({ type: 'file-updated-done', data: { path, result } })
|
sendToAllClients({
|
||||||
})
|
type: "file-updated-done",
|
||||||
|
data: { path, result },
|
||||||
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
sendToAllClients({ type: 'file-change-done', data: { path } })
|
sendToAllClients({ type: "file-change-done", data: { path } });
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
app.get(PATHS.EXAMPLE, function (req: any, res: any) {
|
app.get(PATHS.EXAMPLE, function (req: any, res: any) {
|
||||||
res.set('Content-Type', 'text/html')
|
res.set("Content-Type", "text/html");
|
||||||
res.send(storiesHtml
|
res.send(
|
||||||
.replace('__EXAMPLES_JS_FILE_LOCATION__', opts.examplesLocationJs ?? `.${PATHS.APP}/stories.js`)
|
storiesHtml
|
||||||
.replace('__EXAMPLES_CSS_FILE_LOCATION__', opts.examplesLocationCss ?? `.${PATHS.APP}/stories.css`))
|
.replace(
|
||||||
})
|
"__EXAMPLES_JS_FILE_LOCATION__",
|
||||||
|
opts.examplesLocationJs ?? `.${PATHS.APP}/stories.js`,
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"__EXAMPLES_CSS_FILE_LOCATION__",
|
||||||
|
opts.examplesLocationCss ?? `.${PATHS.APP}/stories.css`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
app.get(PATHS.NOTIFY, function (req: any, res: any) {
|
app.get(PATHS.NOTIFY, function (req: any, res: any) {
|
||||||
res.send('ok')
|
res.send("ok");
|
||||||
})
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>WebUtils: Stories</title>
|
<title>WebUtils: Stories</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="data:;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAABILAAASCwAAAAAAAAAAAAD///////////////////////////////////////////////////////////////////////////////////////////////////7//v38//78/P/+/fz//vz7///+/v/+/f3//vz7///+/v/+/fz//v38///////////////////////+/v3///7+/////////////////////////////////////////////////////////v3//v79///////+/v3///////r28v/ct5//06SG/9Gffv/Xqo7/7N/V/9e2nf/bsJb/6uDW/9Sskf/euKH/+/j2///////+/v3//////+3azv+/eE3/2rWd/9Kkhv/Vr5T/48i2/8J+VP/Qn3//3ryn/795Tf/WrpP/2LCW/8B6T//w4Nb///////Pn4P+/d0v/9u3n/+7d0v/EhV7//v///+HDr//fxLD/zph2/+TJt//8/Pv/woBX//Lm3f/y5dz/v3hN//bu6f/JjGn/4sW0///////Df1j/8OLZ//v6+P+/elH/+vj1//jy7f+/elL//////+zYzP/Eg13//////967p//MlHT/wn5X///////v4Nb/yY1s///////jw7H/06KG////////////z5t9/+fNvf//////x4pn//Pp4v/8+vn/w39X/8WEX///////5s/A/9CbfP//////27Oc/9y2n////////////9itlf/gu6f//////86Vdf/r2Mz//////8SCXP/Df1j//////+7d0v/KkG7//////+HBrf/VpYr////////////RnoH/5sq6///////Ii2n/8ubf//39/P/Cf1j/xohk/+bNvv//////wn5W//Tq4//58/D/wHxV//7+/f/59fH/v3xU//39/P/w4Nf/xIFb///////hw7H/yo9t/+/f1f/AeU3/+/n2/+nSxP/FhmD//////9qzm//Upon/4MSx/96+qf//////xINc/+3bz//48e3/v3hN//Pn3///////6M+//752S//gw6//06aK/8J+VP/kzLr/zZd1/8OCWv/q18r/17KZ/9Ooi//fv6r/v3dK/+vWyP///////v39///////27un/1aeK/9Opjv/m1cf/1KCC/9a0nP/n08T/0Jx8/82YdP/QnHz/16yR//jx7P///////v39///////+/f3///7+///////+//7//v7+///////+/v7//v/+/////////////////////////v7//v79///////////////////+/v/+/Pv//v39///+/v/+/Pv///7+//7+/f/+/Pv//v39//79/P/+/Pv///7+////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" />
|
<link
|
||||||
|
rel="icon"
|
||||||
|
href="data:;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAABILAAASCwAAAAAAAAAAAAD///////////////////////////////////////////////////////////////////////////////////////////////////7//v38//78/P/+/fz//vz7///+/v/+/f3//vz7///+/v/+/fz//v38///////////////////////+/v3///7+/////////////////////////////////////////////////////////v3//v79///////+/v3///////r28v/ct5//06SG/9Gffv/Xqo7/7N/V/9e2nf/bsJb/6uDW/9Sskf/euKH/+/j2///////+/v3//////+3azv+/eE3/2rWd/9Kkhv/Vr5T/48i2/8J+VP/Qn3//3ryn/795Tf/WrpP/2LCW/8B6T//w4Nb///////Pn4P+/d0v/9u3n/+7d0v/EhV7//v///+HDr//fxLD/zph2/+TJt//8/Pv/woBX//Lm3f/y5dz/v3hN//bu6f/JjGn/4sW0///////Df1j/8OLZ//v6+P+/elH/+vj1//jy7f+/elL//////+zYzP/Eg13//////967p//MlHT/wn5X///////v4Nb/yY1s///////jw7H/06KG////////////z5t9/+fNvf//////x4pn//Pp4v/8+vn/w39X/8WEX///////5s/A/9CbfP//////27Oc/9y2n////////////9itlf/gu6f//////86Vdf/r2Mz//////8SCXP/Df1j//////+7d0v/KkG7//////+HBrf/VpYr////////////RnoH/5sq6///////Ii2n/8ubf//39/P/Cf1j/xohk/+bNvv//////wn5W//Tq4//58/D/wHxV//7+/f/59fH/v3xU//39/P/w4Nf/xIFb///////hw7H/yo9t/+/f1f/AeU3/+/n2/+nSxP/FhmD//////9qzm//Upon/4MSx/96+qf//////xINc/+3bz//48e3/v3hN//Pn3///////6M+//752S//gw6//06aK/8J+VP/kzLr/zZd1/8OCWv/q18r/17KZ/9Ooi//fv6r/v3dK/+vWyP///////v39///////27un/1aeK/9Opjv/m1cf/1KCC/9a0nP/n08T/0Jx8/82YdP/QnHz/16yR//jx7P///////v39///////+/f3///7+///////+//7//v7+///////+/v7//v/+/////////////////////////v7//v79///////////////////+/v/+/Pv//v39///+/v/+/Pv///7+//7+/f/+/Pv//v39//79/P/+/Pv///7+////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
|
||||||
|
/>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
type="text/css"
|
type="text/css"
|
||||||
|
Loading…
Reference in New Issue
Block a user