@torpor/build 0.1.1 → 0.1.3
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/CHANGELOG.md +12 -0
- package/dist/{Server-CB99REgs.d.cts → Site-Df1k0TuQ.d.cts} +27 -1
- package/dist/{Server-CB99REgs.d.ts → Site-Df1k0TuQ.d.ts} +27 -1
- package/dist/bin/index.cjs +357 -199
- package/dist/bin/index.cjs.map +1 -1
- package/dist/bin/index.js +10 -507
- package/dist/bin/index.js.map +1 -1
- package/dist/chunk-L3QBUPXY.js +176 -0
- package/dist/chunk-L3QBUPXY.js.map +1 -0
- package/dist/chunk-Q623TPGO.js +527 -0
- package/dist/chunk-Q623TPGO.js.map +1 -0
- package/dist/index.cjs +174 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/run.cjs +753 -0
- package/dist/run.cjs.map +1 -0
- package/dist/run.d.cts +13 -0
- package/dist/run.d.ts +13 -0
- package/dist/run.js +15 -0
- package/package.json +8 -3
- package/src/bin/index.ts +7 -43
- package/src/index.ts +4 -1
- package/src/run.ts +6 -0
- package/src/site/Site.ts +2 -2
- package/src/site/defaultAdapter.ts +11 -0
- package/src/site/run.ts +60 -0
- package/src/site/runBuild.ts +4 -5
- package/src/site/runDev.ts +4 -6
- package/tsconfig.json +1 -1
- package/tsup.config.ts +1 -8
- package/dist/Site-CgoeDt8k.d.cts +0 -29
- package/dist/Site-D95nwrAg.d.ts +0 -29
- package/dist/adapters/cloudflare/index.cjs +0 -125
- package/dist/adapters/cloudflare/index.cjs.map +0 -1
- package/dist/adapters/cloudflare/index.d.cts +0 -13
- package/dist/adapters/cloudflare/index.d.ts +0 -13
- package/dist/adapters/cloudflare/index.js +0 -80
- package/dist/adapters/cloudflare/index.js.map +0 -1
- package/dist/adapters/node/index.cjs +0 -152
- package/dist/adapters/node/index.cjs.map +0 -1
- package/dist/adapters/node/index.d.cts +0 -8
- package/dist/adapters/node/index.d.ts +0 -8
- package/dist/adapters/node/index.js +0 -8
- package/dist/chunk-5X4T3PZN.js +0 -23
- package/dist/chunk-5X4T3PZN.js.map +0 -1
- package/dist/chunk-ALHFYD7U.js +0 -113
- package/dist/chunk-ALHFYD7U.js.map +0 -1
- package/dist/chunk-V4XTDQEV.js +0 -19
- package/dist/chunk-V4XTDQEV.js.map +0 -1
- package/src/adapters/cloudflare/_worker.ts +0 -38
- package/src/adapters/cloudflare/index.ts +0 -98
- package/src/adapters/node/constants.ts +0 -1
- package/src/adapters/node/createFetchHandler.ts +0 -29
- package/src/adapters/node/createNodeServer.ts +0 -8
- package/src/adapters/node/index.ts +0 -18
- package/src/adapters/node/nodeMessageToRequest.ts +0 -43
- package/src/adapters/node/responseToNodeResponse.ts +0 -44
- /package/dist/{adapters/node/index.js.map → run.js.map} +0 -0
- /package/src/{adapters/node → server/connect}/createMiddlewareHandler.ts +0 -0
- /package/src/{adapters/node → server/connect}/flattenHeaders.ts +0 -0
- /package/src/{adapters/node → server/connect}/nodeMessageToNodeResponse.ts +0 -0
- /package/src/{adapters/node → server/connect}/readableToBuffer.ts +0 -0
- /package/src/{adapters/node → server/connect}/requestToNodeMessage.ts +0 -0
package/dist/bin/index.cjs
CHANGED
|
@@ -23,16 +23,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
-
// src/
|
|
27
|
-
var
|
|
28
|
-
var
|
|
26
|
+
// src/site/run.ts
|
|
27
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
28
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
29
29
|
var import_vite5 = require("vite");
|
|
30
30
|
|
|
31
31
|
// src/site/runBuild.ts
|
|
32
32
|
var import_vite = __toESM(require("@torpor/unplugin/vite"), 1);
|
|
33
33
|
var import_node_fs2 = require("fs");
|
|
34
34
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
35
|
-
var import_node_url = require("url");
|
|
36
35
|
var import_vite2 = require("vite");
|
|
37
36
|
|
|
38
37
|
// src/site/manifest.ts
|
|
@@ -73,8 +72,6 @@ export default {
|
|
|
73
72
|
}
|
|
74
73
|
|
|
75
74
|
// src/site/runBuild.ts
|
|
76
|
-
var import_meta = {};
|
|
77
|
-
var __dirname = import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
78
75
|
async function runBuild(site) {
|
|
79
76
|
const distFolder = import_node_path2.default.resolve(site.root, "dist");
|
|
80
77
|
if ((0, import_node_fs2.existsSync)(distFolder)) {
|
|
@@ -86,8 +83,9 @@ async function runBuild(site) {
|
|
|
86
83
|
await site.adapter.prebuild(site);
|
|
87
84
|
}
|
|
88
85
|
let siteHtml = import_node_path2.default.resolve(site.root, "src/site.html");
|
|
89
|
-
|
|
90
|
-
let
|
|
86
|
+
const siteFolder = import_node_path2.default.resolve(site.root, "./node_modules/@torpor/build/src/site/");
|
|
87
|
+
let clientScript = import_node_path2.default.join(siteFolder, "clientEntry.ts");
|
|
88
|
+
let serverScript = import_node_path2.default.join(siteFolder, "serverEntry.ts");
|
|
91
89
|
await (0, import_vite2.build)(
|
|
92
90
|
(0, import_vite2.defineConfig)({
|
|
93
91
|
plugins: [
|
|
@@ -139,170 +137,8 @@ var import_vite3 = __toESM(require("@torpor/unplugin/vite"), 1);
|
|
|
139
137
|
var import_dotenv = require("dotenv");
|
|
140
138
|
var import_node_fs3 = require("fs");
|
|
141
139
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
142
|
-
var import_node_url2 = require("url");
|
|
143
140
|
var import_vite4 = require("vite");
|
|
144
141
|
|
|
145
|
-
// src/adapters/node/flattenHeaders.ts
|
|
146
|
-
function flattenHeaders(headers) {
|
|
147
|
-
const flatHeaders = new Headers();
|
|
148
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
149
|
-
if (value === void 0 || value === null) {
|
|
150
|
-
continue;
|
|
151
|
-
} else if (Array.isArray(value)) {
|
|
152
|
-
for (const v of value) {
|
|
153
|
-
if (v !== void 0 && v !== null) {
|
|
154
|
-
value.forEach((v2) => flatHeaders.append(key, v2));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
flatHeaders.set(key, String(value));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return flatHeaders;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// src/adapters/node/nodeMessageToNodeResponse.ts
|
|
165
|
-
var import_node_http = require("http");
|
|
166
|
-
var import_node_stream = require("stream");
|
|
167
|
-
function nodeMessageToNodeResponse(incomingMessage) {
|
|
168
|
-
const res = new import_node_http.ServerResponse(incomingMessage);
|
|
169
|
-
const passThrough = new import_node_stream.PassThrough();
|
|
170
|
-
let handled = false;
|
|
171
|
-
const onReadable = (cb) => {
|
|
172
|
-
const handleReadable = () => {
|
|
173
|
-
if (handled) return;
|
|
174
|
-
handled = true;
|
|
175
|
-
cb({
|
|
176
|
-
readable: import_node_stream.Readable.from(passThrough),
|
|
177
|
-
headers: res.getHeaders(),
|
|
178
|
-
status: res.statusCode
|
|
179
|
-
});
|
|
180
|
-
};
|
|
181
|
-
passThrough.once("readable", handleReadable);
|
|
182
|
-
passThrough.once("end", handleReadable);
|
|
183
|
-
};
|
|
184
|
-
passThrough.once("finish", () => {
|
|
185
|
-
res.emit("finish");
|
|
186
|
-
});
|
|
187
|
-
passThrough.once("close", () => {
|
|
188
|
-
res.destroy();
|
|
189
|
-
res.emit("close");
|
|
190
|
-
});
|
|
191
|
-
passThrough.on("drain", () => {
|
|
192
|
-
res.emit("drain");
|
|
193
|
-
});
|
|
194
|
-
res.write = passThrough.write.bind(passThrough);
|
|
195
|
-
res.end = passThrough.end.bind(passThrough);
|
|
196
|
-
res.writeHead = function writeHead(statusCode, statusMessage, headers) {
|
|
197
|
-
res.statusCode = statusCode;
|
|
198
|
-
if (typeof statusMessage === "object") {
|
|
199
|
-
headers = statusMessage;
|
|
200
|
-
statusMessage = void 0;
|
|
201
|
-
}
|
|
202
|
-
if (headers) {
|
|
203
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
204
|
-
if (value !== void 0) {
|
|
205
|
-
res.setHeader(key, value);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return res;
|
|
210
|
-
};
|
|
211
|
-
return {
|
|
212
|
-
res,
|
|
213
|
-
onReadable
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// src/adapters/node/readableToBuffer.ts
|
|
218
|
-
function readableToBuffer(req) {
|
|
219
|
-
return new Promise((resolve, reject) => {
|
|
220
|
-
const chunks = [];
|
|
221
|
-
req.on("data", (chunk) => {
|
|
222
|
-
chunks.push(chunk);
|
|
223
|
-
});
|
|
224
|
-
req.on("end", () => {
|
|
225
|
-
resolve(Buffer.concat(chunks));
|
|
226
|
-
});
|
|
227
|
-
req.on("error", (err) => {
|
|
228
|
-
reject(err);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/adapters/node/requestToNodeMessage.ts
|
|
234
|
-
var import_node_stream2 = require("stream");
|
|
235
|
-
var DUMMY_BASE_URL = "http://localhost";
|
|
236
|
-
function requestToNodeMessage(request) {
|
|
237
|
-
const parsedUrl = new URL(request.url, DUMMY_BASE_URL);
|
|
238
|
-
const pathAndQuery = (parsedUrl.pathname || "") + (parsedUrl.search || "");
|
|
239
|
-
const body = (
|
|
240
|
-
/*request.body ? Readable.fromWeb(request.body as any) :*/
|
|
241
|
-
import_node_stream2.Readable.from([])
|
|
242
|
-
);
|
|
243
|
-
return Object.assign(body, {
|
|
244
|
-
url: pathAndQuery,
|
|
245
|
-
method: request.method,
|
|
246
|
-
headers: Object.fromEntries(request.headers)
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/adapters/node/createMiddlewareHandler.ts
|
|
251
|
-
function createMiddlewareHandler(handler) {
|
|
252
|
-
return async (ev, next) => {
|
|
253
|
-
const req = requestToNodeMessage(ev.request);
|
|
254
|
-
const { res, onReadable } = nodeMessageToNodeResponse(req);
|
|
255
|
-
return new Promise(async (resolve, reject) => {
|
|
256
|
-
onReadable(async ({ readable, headers, status }) => {
|
|
257
|
-
const responseBody = statusCodesWithoutBody.includes(status) ? null : (
|
|
258
|
-
//(Readable.toWeb(readable) as ReadableStream);
|
|
259
|
-
// HACK: Chunked bodies are not being
|
|
260
|
-
// read correctly somewhere...
|
|
261
|
-
await readableToBuffer(readable)
|
|
262
|
-
);
|
|
263
|
-
ev.response = new Response(responseBody, {
|
|
264
|
-
status,
|
|
265
|
-
headers: flattenHeaders(headers)
|
|
266
|
-
});
|
|
267
|
-
resolve();
|
|
268
|
-
});
|
|
269
|
-
const cnext = async (error) => {
|
|
270
|
-
if (error) {
|
|
271
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
272
|
-
} else {
|
|
273
|
-
await next();
|
|
274
|
-
resolve();
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
try {
|
|
278
|
-
const handled = await handler(req, res, cnext);
|
|
279
|
-
if (handled === false) {
|
|
280
|
-
res.destroy();
|
|
281
|
-
resolve();
|
|
282
|
-
}
|
|
283
|
-
} catch (e) {
|
|
284
|
-
cnext(e);
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
var statusCodesWithoutBody = [
|
|
290
|
-
100,
|
|
291
|
-
// Continue
|
|
292
|
-
101,
|
|
293
|
-
// Switching Protocols
|
|
294
|
-
102,
|
|
295
|
-
// Processing (WebDAV)
|
|
296
|
-
103,
|
|
297
|
-
// Early Hints
|
|
298
|
-
204,
|
|
299
|
-
// No Content
|
|
300
|
-
205,
|
|
301
|
-
// Reset Content
|
|
302
|
-
304
|
|
303
|
-
// Not Modified
|
|
304
|
-
];
|
|
305
|
-
|
|
306
142
|
// src/response/response.ts
|
|
307
143
|
function response(status, body) {
|
|
308
144
|
let headers = void 0;
|
|
@@ -326,8 +162,8 @@ function serverError(body) {
|
|
|
326
162
|
}
|
|
327
163
|
|
|
328
164
|
// src/site/pathToRegex.ts
|
|
329
|
-
function pathToRegex(
|
|
330
|
-
const pattern =
|
|
165
|
+
function pathToRegex(path6) {
|
|
166
|
+
const pattern = path6.split("/").map((p) => {
|
|
331
167
|
return p.replace(/\[([^\/]+?)\]/, "(?<$1>[^\\/]+?)");
|
|
332
168
|
}).join("\\/").replaceAll("*", ".*");
|
|
333
169
|
return new RegExp(`^${pattern}$`);
|
|
@@ -463,13 +299,13 @@ var Server = class {
|
|
|
463
299
|
* @param fn The function to call when the pattern is matched.
|
|
464
300
|
* @returns
|
|
465
301
|
*/
|
|
466
|
-
add(
|
|
467
|
-
this.routes.push(new RouteHandler(
|
|
302
|
+
add(path6, fn) {
|
|
303
|
+
this.routes.push(new RouteHandler(path6, fn));
|
|
468
304
|
return this;
|
|
469
305
|
}
|
|
470
|
-
match(
|
|
306
|
+
match(path6) {
|
|
471
307
|
for (let handler of this.routes) {
|
|
472
|
-
let match =
|
|
308
|
+
let match = path6.match(handler.regex);
|
|
473
309
|
if (match) {
|
|
474
310
|
return {
|
|
475
311
|
fn: handler.fn,
|
|
@@ -477,7 +313,7 @@ var Server = class {
|
|
|
477
313
|
};
|
|
478
314
|
}
|
|
479
315
|
}
|
|
480
|
-
console.log(`Server path not found: ${
|
|
316
|
+
console.log(`Server path not found: ${path6}`);
|
|
481
317
|
}
|
|
482
318
|
// TODO:
|
|
483
319
|
//use(path: string, ...fn: MiddlewareFunction[])
|
|
@@ -490,13 +326,174 @@ var RouteHandler = class {
|
|
|
490
326
|
path;
|
|
491
327
|
regex;
|
|
492
328
|
fn;
|
|
493
|
-
constructor(
|
|
494
|
-
this.path =
|
|
495
|
-
this.regex = pathToRegex(
|
|
329
|
+
constructor(path6, fn) {
|
|
330
|
+
this.path = path6;
|
|
331
|
+
this.regex = pathToRegex(path6);
|
|
496
332
|
this.fn = fn;
|
|
497
333
|
}
|
|
498
334
|
};
|
|
499
335
|
|
|
336
|
+
// src/server/connect/flattenHeaders.ts
|
|
337
|
+
function flattenHeaders(headers) {
|
|
338
|
+
const flatHeaders = new Headers();
|
|
339
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
340
|
+
if (value === void 0 || value === null) {
|
|
341
|
+
continue;
|
|
342
|
+
} else if (Array.isArray(value)) {
|
|
343
|
+
for (const v of value) {
|
|
344
|
+
if (v !== void 0 && v !== null) {
|
|
345
|
+
value.forEach((v2) => flatHeaders.append(key, v2));
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
flatHeaders.set(key, String(value));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return flatHeaders;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/server/connect/nodeMessageToNodeResponse.ts
|
|
356
|
+
var import_node_http = require("http");
|
|
357
|
+
var import_node_stream = require("stream");
|
|
358
|
+
function nodeMessageToNodeResponse(incomingMessage) {
|
|
359
|
+
const res = new import_node_http.ServerResponse(incomingMessage);
|
|
360
|
+
const passThrough = new import_node_stream.PassThrough();
|
|
361
|
+
let handled = false;
|
|
362
|
+
const onReadable = (cb) => {
|
|
363
|
+
const handleReadable = () => {
|
|
364
|
+
if (handled) return;
|
|
365
|
+
handled = true;
|
|
366
|
+
cb({
|
|
367
|
+
readable: import_node_stream.Readable.from(passThrough),
|
|
368
|
+
headers: res.getHeaders(),
|
|
369
|
+
status: res.statusCode
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
passThrough.once("readable", handleReadable);
|
|
373
|
+
passThrough.once("end", handleReadable);
|
|
374
|
+
};
|
|
375
|
+
passThrough.once("finish", () => {
|
|
376
|
+
res.emit("finish");
|
|
377
|
+
});
|
|
378
|
+
passThrough.once("close", () => {
|
|
379
|
+
res.destroy();
|
|
380
|
+
res.emit("close");
|
|
381
|
+
});
|
|
382
|
+
passThrough.on("drain", () => {
|
|
383
|
+
res.emit("drain");
|
|
384
|
+
});
|
|
385
|
+
res.write = passThrough.write.bind(passThrough);
|
|
386
|
+
res.end = passThrough.end.bind(passThrough);
|
|
387
|
+
res.writeHead = function writeHead(statusCode, statusMessage, headers) {
|
|
388
|
+
res.statusCode = statusCode;
|
|
389
|
+
if (typeof statusMessage === "object") {
|
|
390
|
+
headers = statusMessage;
|
|
391
|
+
statusMessage = void 0;
|
|
392
|
+
}
|
|
393
|
+
if (headers) {
|
|
394
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
395
|
+
if (value !== void 0) {
|
|
396
|
+
res.setHeader(key, value);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return res;
|
|
401
|
+
};
|
|
402
|
+
return {
|
|
403
|
+
res,
|
|
404
|
+
onReadable
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/server/connect/readableToBuffer.ts
|
|
409
|
+
function readableToBuffer(req) {
|
|
410
|
+
return new Promise((resolve, reject) => {
|
|
411
|
+
const chunks = [];
|
|
412
|
+
req.on("data", (chunk) => {
|
|
413
|
+
chunks.push(chunk);
|
|
414
|
+
});
|
|
415
|
+
req.on("end", () => {
|
|
416
|
+
resolve(Buffer.concat(chunks));
|
|
417
|
+
});
|
|
418
|
+
req.on("error", (err) => {
|
|
419
|
+
reject(err);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/server/connect/requestToNodeMessage.ts
|
|
425
|
+
var import_node_stream2 = require("stream");
|
|
426
|
+
var DUMMY_BASE_URL = "http://localhost";
|
|
427
|
+
function requestToNodeMessage(request) {
|
|
428
|
+
const parsedUrl = new URL(request.url, DUMMY_BASE_URL);
|
|
429
|
+
const pathAndQuery = (parsedUrl.pathname || "") + (parsedUrl.search || "");
|
|
430
|
+
const body = (
|
|
431
|
+
/*request.body ? Readable.fromWeb(request.body as any) :*/
|
|
432
|
+
import_node_stream2.Readable.from([])
|
|
433
|
+
);
|
|
434
|
+
return Object.assign(body, {
|
|
435
|
+
url: pathAndQuery,
|
|
436
|
+
method: request.method,
|
|
437
|
+
headers: Object.fromEntries(request.headers)
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/server/connect/createMiddlewareHandler.ts
|
|
442
|
+
function createMiddlewareHandler(handler) {
|
|
443
|
+
return async (ev, next) => {
|
|
444
|
+
const req = requestToNodeMessage(ev.request);
|
|
445
|
+
const { res, onReadable } = nodeMessageToNodeResponse(req);
|
|
446
|
+
return new Promise(async (resolve, reject) => {
|
|
447
|
+
onReadable(async ({ readable, headers, status }) => {
|
|
448
|
+
const responseBody = statusCodesWithoutBody.includes(status) ? null : (
|
|
449
|
+
//(Readable.toWeb(readable) as ReadableStream);
|
|
450
|
+
// HACK: Chunked bodies are not being
|
|
451
|
+
// read correctly somewhere...
|
|
452
|
+
await readableToBuffer(readable)
|
|
453
|
+
);
|
|
454
|
+
ev.response = new Response(responseBody, {
|
|
455
|
+
status,
|
|
456
|
+
headers: flattenHeaders(headers)
|
|
457
|
+
});
|
|
458
|
+
resolve();
|
|
459
|
+
});
|
|
460
|
+
const cnext = async (error) => {
|
|
461
|
+
if (error) {
|
|
462
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
463
|
+
} else {
|
|
464
|
+
await next();
|
|
465
|
+
resolve();
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
try {
|
|
469
|
+
const handled = await handler(req, res, cnext);
|
|
470
|
+
if (handled === false) {
|
|
471
|
+
res.destroy();
|
|
472
|
+
resolve();
|
|
473
|
+
}
|
|
474
|
+
} catch (e) {
|
|
475
|
+
cnext(e);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
var statusCodesWithoutBody = [
|
|
481
|
+
100,
|
|
482
|
+
// Continue
|
|
483
|
+
101,
|
|
484
|
+
// Switching Protocols
|
|
485
|
+
102,
|
|
486
|
+
// Processing (WebDAV)
|
|
487
|
+
103,
|
|
488
|
+
// Early Hints
|
|
489
|
+
204,
|
|
490
|
+
// No Content
|
|
491
|
+
205,
|
|
492
|
+
// Reset Content
|
|
493
|
+
304
|
|
494
|
+
// Not Modified
|
|
495
|
+
];
|
|
496
|
+
|
|
500
497
|
// src/site/prepareTemplate.ts
|
|
501
498
|
function prepareTemplate(template, clientScript) {
|
|
502
499
|
let contentStart = regexIndexOf(template, /\<div\s+id=("app"|'app'|app)\s+/);
|
|
@@ -513,8 +510,6 @@ function regexIndexOf(string, regex, position) {
|
|
|
513
510
|
}
|
|
514
511
|
|
|
515
512
|
// src/site/runDev.ts
|
|
516
|
-
var import_meta2 = {};
|
|
517
|
-
var __dirname2 = import_node_path3.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url));
|
|
518
513
|
async function runDev(site) {
|
|
519
514
|
const server = new Server();
|
|
520
515
|
const vite = await (0, import_vite4.createServer)({
|
|
@@ -530,8 +525,9 @@ async function runDev(site) {
|
|
|
530
525
|
const templateFile = import_node_path3.default.resolve(site.root, "src/site.html");
|
|
531
526
|
let template = await import_node_fs3.promises.readFile(templateFile, "utf-8");
|
|
532
527
|
template = await vite.transformIndexHtml("", template);
|
|
533
|
-
const
|
|
534
|
-
|
|
528
|
+
const siteFolder = import_node_path3.default.resolve(site.root, "./node_modules/@torpor/build/src/site/");
|
|
529
|
+
let clientScript = import_node_path3.default.join(siteFolder, "clientEntry.ts");
|
|
530
|
+
let serverScript = import_node_path3.default.join(siteFolder, "serverEntry.ts");
|
|
535
531
|
template = prepareTemplate(template, clientScript);
|
|
536
532
|
server.use(createMiddlewareHandler(vite.middlewares));
|
|
537
533
|
server.add("*", async (ev) => {
|
|
@@ -550,22 +546,158 @@ async function runDev(site) {
|
|
|
550
546
|
site.adapter.serve(server, site);
|
|
551
547
|
}
|
|
552
548
|
|
|
553
|
-
// src/
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
549
|
+
// src/site/runPreview.ts
|
|
550
|
+
var import_dotenv2 = require("dotenv");
|
|
551
|
+
var import_node_fs4 = require("fs");
|
|
552
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
553
|
+
|
|
554
|
+
// src/server/contentType.ts
|
|
555
|
+
function contentType(extension) {
|
|
556
|
+
return types[extension] || "application/octet-stream";
|
|
557
|
+
}
|
|
558
|
+
var types = {
|
|
559
|
+
".aac": "audio/aac",
|
|
560
|
+
".abw": "application/x-abiword",
|
|
561
|
+
".apng": "image/apng",
|
|
562
|
+
".arc": "application/x-freearc",
|
|
563
|
+
".avif": "image/avif",
|
|
564
|
+
".avi": "video/x-msvideo",
|
|
565
|
+
".azw": "application/vnd.amazon.ebook",
|
|
566
|
+
".bin": "application/octet-stream",
|
|
567
|
+
".bmp": "image/bmp",
|
|
568
|
+
".bz": "application/x-bzip",
|
|
569
|
+
".bz2": "application/x-bzip2",
|
|
570
|
+
".cda": "application/x-cdf",
|
|
571
|
+
".csh": "application/x-csh",
|
|
572
|
+
".css": "text/css",
|
|
573
|
+
".csv": "text/csv",
|
|
574
|
+
".doc": "application/msword",
|
|
575
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
576
|
+
".eot": "application/vnd.ms-fontobject",
|
|
577
|
+
".epub": "application/epub+zip",
|
|
578
|
+
".gz": "application/gzip",
|
|
579
|
+
".gif": "image/gif",
|
|
580
|
+
".htm": "text/html",
|
|
581
|
+
".html": "text/html",
|
|
582
|
+
".ico": "image/vnd.microsoft.icon",
|
|
583
|
+
".ics": "text/calendar",
|
|
584
|
+
".jar": "application/java-archive",
|
|
585
|
+
".jpeg": "image/jpeg",
|
|
586
|
+
".jpg": "image/jpeg",
|
|
587
|
+
".js": "text/javascript",
|
|
588
|
+
".json": "application/json",
|
|
589
|
+
".jsonld": "application/ld+json",
|
|
590
|
+
".mid": "audio/midi",
|
|
591
|
+
".midi": "audio/midi",
|
|
592
|
+
".mjs": "text/javascript",
|
|
593
|
+
".mp3": "audio/mpeg",
|
|
594
|
+
".mp4": "video/mp4",
|
|
595
|
+
".mpeg": "video/mpeg",
|
|
596
|
+
".mpkg": "application/vnd.apple.installer+xml",
|
|
597
|
+
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
598
|
+
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
599
|
+
".odt": "application/vnd.oasis.opendocument.text",
|
|
600
|
+
".oga": "audio/ogg",
|
|
601
|
+
".ogv": "video/ogg",
|
|
602
|
+
".ogx": "application/ogg",
|
|
603
|
+
".opus": "audio/ogg",
|
|
604
|
+
".otf": "font/otf",
|
|
605
|
+
".png": "image/png",
|
|
606
|
+
".pdf": "application/pdf",
|
|
607
|
+
".php": "application/x-httpd-php",
|
|
608
|
+
".ppt": "application/vnd.ms-powerpoint",
|
|
609
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
610
|
+
".rar": "application/vnd.rar",
|
|
611
|
+
".rtf": "application/rtf",
|
|
612
|
+
".sh": "application/x-sh",
|
|
613
|
+
".svg": "image/svg+xml",
|
|
614
|
+
".tar": "application/x-tar",
|
|
615
|
+
".tif": "image/tiff",
|
|
616
|
+
".tiff": "image/tiff",
|
|
617
|
+
".ts": "video/mp2t",
|
|
618
|
+
".ttf": "font/ttf",
|
|
619
|
+
".txt": "text/plain",
|
|
620
|
+
".vsd": "application/vnd.visio",
|
|
621
|
+
".wav": "audio/wav",
|
|
622
|
+
".weba": "audio/webm",
|
|
623
|
+
".webm": "video/webm",
|
|
624
|
+
".webp": "image/webp",
|
|
625
|
+
".woff": "font/woff",
|
|
626
|
+
".woff2": "font/woff2",
|
|
627
|
+
".xhtml": "application/xhtml+xml",
|
|
628
|
+
".xls": "application/vnd.ms-excel",
|
|
629
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
630
|
+
".xml": "application/xml",
|
|
631
|
+
".xul": "application/vnd.mozilla.xul+xml",
|
|
632
|
+
".zip": "application/zip",
|
|
633
|
+
".3gp": "video/3gpp",
|
|
634
|
+
".3g2": "video/3gpp2",
|
|
635
|
+
".7z": "application/x-7z-compressed"
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// src/site/runPreview.ts
|
|
639
|
+
async function runPreview(site) {
|
|
640
|
+
await runBuild(site);
|
|
641
|
+
const distFolder = import_node_path4.default.resolve(site.root, "dist");
|
|
642
|
+
const clientFolder = import_node_path4.default.join(distFolder, "client");
|
|
643
|
+
const serverFolder = import_node_path4.default.join(distFolder, "server");
|
|
644
|
+
let clientScript = (await import_node_fs4.promises.readdir(import_node_path4.default.join(clientFolder, "assets"))).find(
|
|
645
|
+
(f) => f.startsWith("clientEntry-")
|
|
646
|
+
);
|
|
647
|
+
if (!clientScript) {
|
|
648
|
+
throw new Error("clientEntry.js not found");
|
|
649
|
+
}
|
|
650
|
+
clientScript = `/assets/${clientScript}`;
|
|
651
|
+
let siteHtml = import_node_path4.default.join(clientFolder, "site.html");
|
|
652
|
+
let template = await import_node_fs4.promises.readFile(siteHtml, "utf-8");
|
|
653
|
+
template = prepareTemplate(template, clientScript);
|
|
654
|
+
const server = new Server();
|
|
655
|
+
server.add("/assets/*", async (ev) => {
|
|
656
|
+
try {
|
|
657
|
+
const url = new URL(ev.request.url);
|
|
658
|
+
const file = import_node_path4.default.join(site.root, "dist", "client", url.pathname);
|
|
659
|
+
if ((0, import_node_fs4.existsSync)(file)) {
|
|
660
|
+
return new Response(await import_node_fs4.promises.readFile(file), {
|
|
661
|
+
status: 200,
|
|
662
|
+
headers: {
|
|
663
|
+
"Content-Type": contentType(import_node_path4.default.extname(file))
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
} catch (e) {
|
|
668
|
+
return serverError(e);
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
const serverScript = import_node_path4.default.resolve(serverFolder, "serverEntry.js");
|
|
672
|
+
server.add("*", async (ev) => {
|
|
673
|
+
try {
|
|
674
|
+
const { load } = await import(serverScript);
|
|
675
|
+
return await load(ev, template);
|
|
676
|
+
} catch (e) {
|
|
677
|
+
return serverError(e);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
(0, import_dotenv2.configDotenv)();
|
|
681
|
+
process.env.PROTOCOL ??= "http:";
|
|
682
|
+
process.env.HOST ??= "localhost";
|
|
683
|
+
process.env.PORT ??= "7059";
|
|
684
|
+
site.adapter.serve(server, site);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// src/site/run.ts
|
|
688
|
+
async function run(folder, mode) {
|
|
557
689
|
let configFile = "";
|
|
558
690
|
let deleteConfigFile = false;
|
|
559
|
-
const jsConfigFile =
|
|
560
|
-
const tsConfigFile =
|
|
561
|
-
if (
|
|
691
|
+
const jsConfigFile = import_node_path5.default.join(folder, "site.config.js");
|
|
692
|
+
const tsConfigFile = import_node_path5.default.join(folder, "site.config.ts");
|
|
693
|
+
if (import_node_fs5.default.existsSync(jsConfigFile)) {
|
|
562
694
|
configFile = jsConfigFile;
|
|
563
|
-
} else if (
|
|
564
|
-
configFile =
|
|
565
|
-
let source = (await (0, import_vite5.transformWithEsbuild)(
|
|
695
|
+
} else if (import_node_fs5.default.existsSync(tsConfigFile)) {
|
|
696
|
+
configFile = import_node_path5.default.join(folder, "site.config.temp.js");
|
|
697
|
+
let source = (await (0, import_vite5.transformWithEsbuild)(import_node_fs5.default.readFileSync(tsConfigFile, "utf-8"), tsConfigFile, {
|
|
566
698
|
loader: "ts"
|
|
567
699
|
})).code;
|
|
568
|
-
|
|
700
|
+
import_node_fs5.default.writeFileSync(configFile, source);
|
|
569
701
|
deleteConfigFile = true;
|
|
570
702
|
} else {
|
|
571
703
|
throw new Error("site.config file not found");
|
|
@@ -575,12 +707,38 @@ async function run() {
|
|
|
575
707
|
throw new Error("Invalid site in config file");
|
|
576
708
|
}
|
|
577
709
|
if (deleteConfigFile) {
|
|
578
|
-
|
|
710
|
+
import_node_fs5.default.rmSync(configFile);
|
|
711
|
+
}
|
|
712
|
+
switch (mode) {
|
|
713
|
+
case "dev": {
|
|
714
|
+
await runDev(site);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
case "build": {
|
|
718
|
+
await runBuild(site);
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
case "preview": {
|
|
722
|
+
await runPreview(site);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
default: {
|
|
726
|
+
console.log("No mode passed, running in dev");
|
|
727
|
+
await runDev(site);
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
579
730
|
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/bin/index.ts
|
|
734
|
+
(async () => {
|
|
735
|
+
const workingDir = process.cwd();
|
|
580
736
|
if (process.argv.includes("--dev")) {
|
|
581
|
-
await
|
|
737
|
+
await run(workingDir, "dev");
|
|
582
738
|
} else if (process.argv.includes("--build")) {
|
|
583
|
-
await
|
|
739
|
+
await run(workingDir, "build");
|
|
740
|
+
} else if (process.argv.includes("--preview")) {
|
|
741
|
+
await run(workingDir, "preview");
|
|
584
742
|
}
|
|
585
|
-
}
|
|
743
|
+
})();
|
|
586
744
|
//# sourceMappingURL=index.cjs.map
|