Skip to content

Commit 887525e

Browse files
committed
Merge branch 'dev' of gs.github.com:greatsquare0/thy-weaver
2 parents 943b930 + 7bd1ccb commit 887525e

22 files changed

Lines changed: 318 additions & 86 deletions

packages/core/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
},
2222
"./types": {
2323
"types": "./types/index.d.ts"
24+
},
25+
"./plugin_helpers": {
26+
"import": "./dist/plugin_helpers.js",
27+
"require": "./dist/plugin_helpers.js",
28+
"types": "./dist/plugin_helpers.d.ts"
2429
}
2530
},
2631
"files": [

packages/core/pnpm-lock.yaml

Lines changed: 41 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/cli.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { runDev } from "./run_dev.ts";
88
import { rm } from "fs/promises";
99
import { resolveToProjectRoot } from "./utils.ts";
1010
import { handleTweegoSetup } from "./build_commands.ts";
11+
import { loadConfig } from "./config/config_handler.ts";
12+
13+
const config = await loadConfig();
1114

1215
program
1316
.name("weaver")
@@ -74,4 +77,12 @@ program
7477
console.log("WIP");
7578
});
7679

80+
if (config.plugins) {
81+
config.plugins.forEach((plugin) => {
82+
if (plugin.command !== undefined) {
83+
program.addCommand(plugin.command);
84+
}
85+
});
86+
}
87+
7788
program.parse();

packages/core/src/config/config_handler.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import swc from "@swc/core";
33
import { defaultConfig } from "./defaults.ts";
44
import { randomUUID } from "node:crypto";
55
import { writeFile, mkdir, rm } from "node:fs/promises";
6-
import { tempFolderPath } from "../utils.ts";
6+
import { isTS, resolveToProjectRoot, tempFolderPath } from "../utils.ts";
77
import { resolve } from "node:path";
88
import { existsSync } from "node:fs";
99
import { pathToFileURL } from "node:url";
@@ -61,15 +61,18 @@ const loadTsConfig = async (_filepath: string, content: string) => {
6161
};
6262

6363
const options: Partial<Options> = {
64-
searchPlaces: ["thyweaver.config.ts", "thyweaver.config.js"],
6564
loaders: {
6665
...defaultLoaders,
6766
".ts": loadTsConfig,
6867
},
6968
};
7069

7170
export const loadConfig = async () => {
72-
const result = await lilconfig("weaver", options).search();
71+
const result = await lilconfig("weaver", options).load(
72+
isTS
73+
? resolveToProjectRoot("thyweaver.config.ts")
74+
: resolveToProjectRoot("thyweaver.config.js"),
75+
);
7376
return result!.config as ThyWevearOptions;
7477
};
7578

packages/core/src/config/config_types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Config as SWCOptions } from "@swc/core";
2+
import type { Command } from "commander";
23

34
export interface AdditionalAsset {
45
/**
@@ -52,7 +53,13 @@ export interface DevServerOptions {
5253
twineDebug: boolean;
5354
}
5455

56+
export interface Plugin {
57+
name: string;
58+
command?: Command;
59+
}
60+
5561
export interface ThyWevearOptions {
62+
plugins?: Plugin[];
5663
devServer?: DevServerOptions;
5764
bundler: BundlerOptions;
5865
}

packages/core/src/config/defaults.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import swc from "./swc_defaults.ts";
33
import postcss from "./postcss_defaults.ts";
44
import { resolve } from "node:path";
55
import { tempFolderPath } from "../utils.ts";
6+
import { isTS } from "../utils.ts";
67

78
export const defaultConfig: ThyWevearOptions = {
89
devServer: {
@@ -18,7 +19,9 @@ export const defaultConfig: ThyWevearOptions = {
1819
filesystem: {
1920
dist: "dist/",
2021
projectFiles: {
21-
entryPoint: "src/assets/app/index.ts",
22+
entryPoint: isTS
23+
? "src/assets/app/index.ts"
24+
: "src/assets/app/index.js",
2225
fontsDir: "src/assets/fonts/",
2326
mediaDir: "src/assets/media/",
2427
vendorFilesDir: "src/assets/vendor/",

packages/core/src/dev_server/main.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { H3, serve, serveStatic } from "h3";
1+
import { createEventStream, H3, serve, serveStatic } from "h3";
22
import { loadConfig } from "../config/config_handler.ts";
33
import { readFile, stat } from "node:fs/promises";
44
import { join } from "node:path";
55
import { devState, resolveToProjectRoot } from "../utils.ts";
6-
6+
import { addStream, broadcast, removeStream } from "./streams.ts";
77
const config = await loadConfig();
88

99
const app = new H3();
@@ -56,7 +56,9 @@ app.use("/media/**", (event) => {
5656
.join("/");
5757

5858
const path = join(
59-
resolveToProjectRoot(config.bundler.filesystem!.projectFiles.mediaDir),
59+
resolveToProjectRoot(
60+
config.bundler.filesystem!.projectFiles!.mediaDir!,
61+
),
6062
parsedId,
6163
);
6264

@@ -71,7 +73,9 @@ app.use("/media/**", (event) => {
7173
.join("/");
7274

7375
const path = join(
74-
resolveToProjectRoot(config.bundler.filesystem!.projectFiles.mediaDir),
76+
resolveToProjectRoot(
77+
config.bundler.filesystem!.projectFiles!.mediaDir!,
78+
),
7579
parsedId,
7680
);
7781

@@ -85,6 +89,20 @@ app.use("/media/**", (event) => {
8589
},
8690
});
8791
});
92+
93+
app.get("/events/", async (event) => {
94+
const eventStream = createEventStream(event);
95+
addStream(eventStream);
96+
97+
await broadcast("Test message");
98+
99+
eventStream.onClosed(() => {
100+
removeStream(eventStream);
101+
});
102+
103+
return eventStream.send();
104+
});
105+
88106
const startServer = () => {
89107
return serve(app, {
90108
port: config.devServer!.port,

0 commit comments

Comments
 (0)