@dreamkit/dev 0.0.1
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/LICENSE +21 -0
- package/README.md +22 -0
- package/lib/DreamkitDevServer.d.ts +27 -0
- package/lib/DreamkitDevServer.d.ts.map +1 -0
- package/lib/DreamkitDevServer.js +127 -0
- package/lib/actions/generate.d.ts +6 -0
- package/lib/actions/generate.d.ts.map +1 -0
- package/lib/actions/generate.js +62 -0
- package/lib/adapters/solid-start.d.ts +8 -0
- package/lib/adapters/solid-start.d.ts.map +1 -0
- package/lib/adapters/solid-start.js +173 -0
- package/lib/bin.d.ts +4 -0
- package/lib/bin.d.ts.map +1 -0
- package/lib/bin.js +37 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +1 -0
- package/lib/options.d.ts +18 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +8 -0
- package/lib/plugins/dreamkit.d.ts +4 -0
- package/lib/plugins/dreamkit.d.ts.map +1 -0
- package/lib/plugins/dreamkit.js +48 -0
- package/lib/transforms/delete-dead-code.d.ts +6 -0
- package/lib/transforms/delete-dead-code.d.ts.map +1 -0
- package/lib/transforms/delete-dead-code.js +79 -0
- package/lib/transforms/export-default.d.ts +4 -0
- package/lib/transforms/export-default.d.ts.map +1 -0
- package/lib/transforms/export-default.js +10 -0
- package/lib/transforms/fix-use-data.d.ts +3 -0
- package/lib/transforms/fix-use-data.d.ts.map +1 -0
- package/lib/transforms/fix-use-data.js +49 -0
- package/lib/transforms/no-export.d.ts +4 -0
- package/lib/transforms/no-export.d.ts.map +1 -0
- package/lib/transforms/no-export.js +19 -0
- package/lib/transforms/pick-export.d.ts +4 -0
- package/lib/transforms/pick-export.d.ts.map +1 -0
- package/lib/transforms/pick-export.js +55 -0
- package/lib/transforms/replace-import-spec.d.ts +8 -0
- package/lib/transforms/replace-import-spec.d.ts.map +1 -0
- package/lib/transforms/replace-import-spec.js +26 -0
- package/lib/transforms/to-solid-route.d.ts +4 -0
- package/lib/transforms/to-solid-route.d.ts.map +1 -0
- package/lib/transforms/to-solid-route.js +117 -0
- package/lib/utils/ast.d.ts +17 -0
- package/lib/utils/ast.d.ts.map +1 -0
- package/lib/utils/ast.js +78 -0
- package/lib/utils/babel.d.ts +7 -0
- package/lib/utils/babel.d.ts.map +1 -0
- package/lib/utils/babel.js +6 -0
- package/lib/utils/fs.d.ts +5 -0
- package/lib/utils/fs.d.ts.map +1 -0
- package/lib/utils/fs.js +24 -0
- package/lib/utils/log.d.ts +3 -0
- package/lib/utils/log.d.ts.map +1 -0
- package/lib/utils/log.js +2 -0
- package/lib/utils/object.d.ts +4 -0
- package/lib/utils/object.d.ts.map +1 -0
- package/lib/utils/object.js +20 -0
- package/lib/utils/path.d.ts +6 -0
- package/lib/utils/path.d.ts.map +1 -0
- package/lib/utils/path.js +19 -0
- package/lib/utils/router.d.ts +7 -0
- package/lib/utils/router.d.ts.map +1 -0
- package/lib/utils/router.js +37 -0
- package/lib/utils/runtime.d.ts +3 -0
- package/lib/utils/runtime.d.ts.map +1 -0
- package/lib/utils/runtime.js +19 -0
- package/lib/utils/shaking.d.ts +24 -0
- package/lib/utils/shaking.d.ts.map +1 -0
- package/lib/utils/shaking.js +81 -0
- package/lib/utils/string.d.ts +2 -0
- package/lib/utils/string.d.ts.map +1 -0
- package/lib/utils/string.js +3 -0
- package/lib/utils/timeout.d.ts +2 -0
- package/lib/utils/timeout.d.ts.map +1 -0
- package/lib/utils/timeout.js +14 -0
- package/lib/utils/transform.d.ts +25 -0
- package/lib/utils/transform.d.ts.map +1 -0
- package/lib/utils/transform.js +44 -0
- package/lib/utils/typescript.d.ts +14 -0
- package/lib/utils/typescript.d.ts.map +1 -0
- package/lib/utils/typescript.js +78 -0
- package/lib/utils/vinxi.d.ts +26 -0
- package/lib/utils/vinxi.d.ts.map +1 -0
- package/lib/utils/vinxi.js +55 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Juanra GM <juanrgm724@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @dreamkit/dev
|
|
2
|
+
|
|
3
|
+
> Development tools for DreamKit.
|
|
4
|
+
|
|
5
|
+
[![workflow-badge]](https://github.com/swordev/dreamkit/actions/workflows/ci.yaml) [![npm-badge]](https://www.npmjs.com/package/@dreamkit/dev)
|
|
6
|
+
|
|
7
|
+
[workflow-badge]: https://img.shields.io/github/actions/workflow/status/swordev/dreamkit/ci.yaml?branch=main
|
|
8
|
+
[npm-badge]: https://img.shields.io/npm/v/@dreamkit/dev?label=@dreamkit/dev
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @dreamkit/dev
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Documentation
|
|
17
|
+
|
|
18
|
+
https://dreamkit.dev
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
Distributed under the MIT License. See LICENSE for more information.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DreamkitPluginOptions, OutDreamkitPluginOptions } from "./options.js";
|
|
2
|
+
import { VirtualShaking } from "./utils/shaking.js";
|
|
3
|
+
import { App, Route } from "@dreamkit/app";
|
|
4
|
+
import { ViteDevServer } from "vite";
|
|
5
|
+
import { ViteRuntime } from "vite/runtime";
|
|
6
|
+
export type DreamkitDevExternalOptions = {
|
|
7
|
+
root: string;
|
|
8
|
+
routeDir: string;
|
|
9
|
+
};
|
|
10
|
+
export type DreamkitDevInOptions = DreamkitPluginOptions & DreamkitDevExternalOptions;
|
|
11
|
+
export type DreamkitDevOptions = OutDreamkitPluginOptions & DreamkitDevExternalOptions;
|
|
12
|
+
export declare class DreamkitDevServer {
|
|
13
|
+
readonly app: App;
|
|
14
|
+
readonly entry: VirtualShaking;
|
|
15
|
+
protected runtimeServer: ViteDevServer | undefined;
|
|
16
|
+
protected runtime: ViteRuntime | undefined;
|
|
17
|
+
readonly options: DreamkitDevOptions;
|
|
18
|
+
constructor(inOptions: DreamkitDevInOptions);
|
|
19
|
+
fetch(path: string): Promise<any>;
|
|
20
|
+
fetchDefault<T>(path: string): Promise<T>;
|
|
21
|
+
fetchRoute(path: string): Promise<Route>;
|
|
22
|
+
findRouteObjects(): Promise<Record<string, any>>;
|
|
23
|
+
fetchEntryObjects(): Promise<Record<string, any>>;
|
|
24
|
+
prepare(includeRouteFileObjects?: boolean): Promise<void>;
|
|
25
|
+
stop(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=DreamkitDevServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DreamkitDevServer.d.ts","sourceRoot":"","sources":["../src/DreamkitDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,GAAG,EAAW,KAAK,EAAU,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAmC,aAAa,EAAE,MAAM,MAAM,CAAC;AAGtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GACtD,0BAA0B,CAAC;AAC7B,MAAM,MAAM,kBAAkB,GAAG,wBAAwB,GACvD,0BAA0B,CAAC;AAE7B,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IACnD,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;gBACzB,SAAS,EAAE,oBAAoB;IA6BrC,KAAK,CAAC,IAAI,EAAE,MAAM;IAKlB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAKxC,gBAAgB;IAyBhB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAIjD,OAAO,CAAC,uBAAuB,UAAO;IAkCtC,IAAI;CAIX"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { dreamkitPluginOptions, } from "./options.js";
|
|
2
|
+
import { generateIfChanges } from "./utils/ast.js";
|
|
3
|
+
import { log } from "./utils/log.js";
|
|
4
|
+
import { resolvePath } from "./utils/path.js";
|
|
5
|
+
import { findFileRoutes } from "./utils/router.js";
|
|
6
|
+
import { VirtualShaking } from "./utils/shaking.js";
|
|
7
|
+
import { createTransformUrl, transformCodeByUrl } from "./utils/transform.js";
|
|
8
|
+
import { App, isRoute, $route } from "@dreamkit/app";
|
|
9
|
+
import { existsSync } from "fs";
|
|
10
|
+
import { createServer, createViteRuntime } from "vite";
|
|
11
|
+
import solidPlugin from "vite-plugin-solid";
|
|
12
|
+
import tsconfigPlugin from "vite-tsconfig-paths";
|
|
13
|
+
export class DreamkitDevServer {
|
|
14
|
+
app;
|
|
15
|
+
entry;
|
|
16
|
+
runtimeServer;
|
|
17
|
+
runtime;
|
|
18
|
+
options;
|
|
19
|
+
constructor(inOptions) {
|
|
20
|
+
this.app = new App();
|
|
21
|
+
const options = (this.options = {
|
|
22
|
+
...dreamkitPluginOptions,
|
|
23
|
+
...inOptions,
|
|
24
|
+
});
|
|
25
|
+
const vars = { defaults: options.root, root: options.root };
|
|
26
|
+
options.entry = resolvePath(options.entry, vars);
|
|
27
|
+
options.metaGlobalOutput = resolvePath(options.metaGlobalOutput, vars);
|
|
28
|
+
options.metaLocalOutput = resolvePath(options.metaLocalOutput, vars);
|
|
29
|
+
this.entry = new VirtualShaking({
|
|
30
|
+
entry: options.entry,
|
|
31
|
+
onChange: async (changes) => {
|
|
32
|
+
log("entry changes", changes);
|
|
33
|
+
const nextObjects = await this.fetchEntryObjects();
|
|
34
|
+
const add = {};
|
|
35
|
+
const remove = [];
|
|
36
|
+
for (const change of changes) {
|
|
37
|
+
if (change.action === "update" || change.action === "delete")
|
|
38
|
+
if (this.app.objects.has(change.name))
|
|
39
|
+
remove.push(change.name);
|
|
40
|
+
if (change.action === "create" || change.action === "update")
|
|
41
|
+
add[change.name] = nextObjects[change.name];
|
|
42
|
+
}
|
|
43
|
+
await this.app.remove(remove);
|
|
44
|
+
await this.app.add(add);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async fetch(path) {
|
|
49
|
+
//const mod = $server.moduleGraph.getModuleById(shaking.entry);
|
|
50
|
+
//if (mod) $server.moduleGraph.invalidateModule(mod);
|
|
51
|
+
return await this.runtime.executeUrl(`${path}?${Date.now()}`);
|
|
52
|
+
}
|
|
53
|
+
async fetchDefault(path) {
|
|
54
|
+
const result = await this.fetch(path);
|
|
55
|
+
return result.default;
|
|
56
|
+
}
|
|
57
|
+
async fetchRoute(path) {
|
|
58
|
+
const url = createTransformUrl(path, { toSolidRoute: true });
|
|
59
|
+
const result = await this.fetch(url);
|
|
60
|
+
return result.default;
|
|
61
|
+
}
|
|
62
|
+
async findRouteObjects() {
|
|
63
|
+
const files = await findFileRoutes(this.options.routeDir);
|
|
64
|
+
const objects = {};
|
|
65
|
+
for (const item of files) {
|
|
66
|
+
const items = await this.fetch(item.filePath);
|
|
67
|
+
for (const moduleKey in items) {
|
|
68
|
+
const value = items[moduleKey];
|
|
69
|
+
const objectId = moduleKey === "default" ? item.path : `${item.path}:${moduleKey}`;
|
|
70
|
+
if (moduleKey === "default") {
|
|
71
|
+
if (isRoute(value)) {
|
|
72
|
+
objects[objectId] = value.$options.path
|
|
73
|
+
? $route
|
|
74
|
+
: $route["clone"]({
|
|
75
|
+
...value.$options,
|
|
76
|
+
path: item.path,
|
|
77
|
+
}).create(value.$options.component);
|
|
78
|
+
}
|
|
79
|
+
else if (typeof value === "function") {
|
|
80
|
+
objects[objectId] = $route.path(item.path).create(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return objects;
|
|
86
|
+
}
|
|
87
|
+
async fetchEntryObjects() {
|
|
88
|
+
if (existsSync(this.entry.path))
|
|
89
|
+
return await this.fetch(this.entry.path);
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
async prepare(includeRouteFileObjects = true) {
|
|
93
|
+
this.runtimeServer = await createServer({
|
|
94
|
+
root: this.options.root,
|
|
95
|
+
server: { middlewareMode: true },
|
|
96
|
+
plugins: [
|
|
97
|
+
tsconfigPlugin({}),
|
|
98
|
+
{
|
|
99
|
+
name: "dk:virtual-shaking",
|
|
100
|
+
enforce: "pre",
|
|
101
|
+
load: (id) => this.entry.tryLoad(id),
|
|
102
|
+
transform(code, id) {
|
|
103
|
+
const ast = transformCodeByUrl(id, code);
|
|
104
|
+
return generateIfChanges(ast);
|
|
105
|
+
},
|
|
106
|
+
handleHotUpdate: async ({ file, read, modules }) => {
|
|
107
|
+
return this.entry.tryUpdate(file, read, modules);
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
solidPlugin({ ssr: true }),
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
this.runtime = await createViteRuntime(this.runtimeServer, {
|
|
114
|
+
hmr: { logger: false },
|
|
115
|
+
});
|
|
116
|
+
this.entry.init();
|
|
117
|
+
const objects = {
|
|
118
|
+
...(await this.fetchEntryObjects()),
|
|
119
|
+
...(includeRouteFileObjects && (await this.findRouteObjects())),
|
|
120
|
+
};
|
|
121
|
+
await this.app.add(objects);
|
|
122
|
+
}
|
|
123
|
+
async stop() {
|
|
124
|
+
await this.runtimeServer?.close();
|
|
125
|
+
await this.runtime?.destroy();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/actions/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAY5D,wBAAsB,QAAQ,CAAC,MAAM,EAAE,iBAAiB;;;GAwDvD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { writeFileIfDifferent } from "../utils/fs.js";
|
|
2
|
+
import { createInterface, createModuleDeclaration, createType, } from "../utils/typescript.js";
|
|
3
|
+
import { mkdir } from "fs/promises";
|
|
4
|
+
import { dirname } from "path";
|
|
5
|
+
export async function generate(server) {
|
|
6
|
+
const options = server.options;
|
|
7
|
+
const output = options.metaFormat === "global"
|
|
8
|
+
? options.metaGlobalOutput
|
|
9
|
+
: options.metaLocalOutput;
|
|
10
|
+
const routeDef = [...server.app.routes]
|
|
11
|
+
.map((route) => ({
|
|
12
|
+
path: route.$options.path ?? "",
|
|
13
|
+
params: route.$options.params,
|
|
14
|
+
}))
|
|
15
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
16
|
+
const typeRoutes = await generateDefinition(routeDef);
|
|
17
|
+
let contents;
|
|
18
|
+
if (options.metaFormat === "global") {
|
|
19
|
+
const declarations = {
|
|
20
|
+
["dreamkit/presets/global.override.js"]: createInterface("Routing", typeRoutes, 1),
|
|
21
|
+
};
|
|
22
|
+
contents =
|
|
23
|
+
Object.entries(declarations)
|
|
24
|
+
.map(([source, body]) => `// prettier-ignore\n` + createModuleDeclaration(source, [body]))
|
|
25
|
+
.join("\n\n") + "\n";
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
contents = [
|
|
29
|
+
`// prettier-ignore`,
|
|
30
|
+
`import { BaseRequestUrl, defineLink, defineRoutePath } from "dreamkit/presets/custom-global.js";`,
|
|
31
|
+
"",
|
|
32
|
+
...(options.metaLocalExports
|
|
33
|
+
? [
|
|
34
|
+
'export * from "dreamkit/presets/common.js";',
|
|
35
|
+
'export * from "dreamkit/presets/solid.js";',
|
|
36
|
+
]
|
|
37
|
+
: []),
|
|
38
|
+
createInterface("Routing", typeRoutes, 0),
|
|
39
|
+
"export const routePath = defineRoutePath<Routing>();",
|
|
40
|
+
"export const Link = defineLink<Routing>();",
|
|
41
|
+
"export class RequestUrl extends BaseRequestUrl<Routing> {}",
|
|
42
|
+
].join("\n");
|
|
43
|
+
}
|
|
44
|
+
await mkdir(dirname(output), { recursive: true });
|
|
45
|
+
const changed = await writeFileIfDifferent(output, contents);
|
|
46
|
+
return {
|
|
47
|
+
output,
|
|
48
|
+
changed,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function generateDefinition(routes) {
|
|
52
|
+
const result = {};
|
|
53
|
+
for (const route of routes) {
|
|
54
|
+
if (route.path.includes("*404"))
|
|
55
|
+
continue;
|
|
56
|
+
const params = route.params;
|
|
57
|
+
result[route.path] = Object.keys(params?.options.props || {}).length
|
|
58
|
+
? createType(params)
|
|
59
|
+
: "never";
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DreamkitDevInOptions } from "../DreamkitDevServer.js";
|
|
2
|
+
import { DreamkitPluginOptions } from "../options.js";
|
|
3
|
+
import { App } from "vinxi";
|
|
4
|
+
export declare function fetchDreamkitDevOptions(options: {
|
|
5
|
+
root: string;
|
|
6
|
+
}): Promise<DreamkitDevInOptions>;
|
|
7
|
+
export declare function createDreamkitDevServer(vinxiApp: App, inOptions?: DreamkitPluginOptions): void;
|
|
8
|
+
//# sourceMappingURL=solid-start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solid-start.d.ts","sourceRoot":"","sources":["../../src/adapters/solid-start.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAErB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAYtD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAM5B,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAsDhC;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,GAAG,EACb,SAAS,GAAE,qBAA0B,QAuItC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { DreamkitDevServer, } from "../DreamkitDevServer.js";
|
|
2
|
+
import { generate } from "../actions/generate.js";
|
|
3
|
+
import { generateIfChanges } from "../utils/ast.js";
|
|
4
|
+
import { execute } from "../utils/runtime.js";
|
|
5
|
+
import { createDelayedFunction } from "../utils/timeout.js";
|
|
6
|
+
import { transformCode } from "../utils/transform.js";
|
|
7
|
+
import { onChangeVinxiRoutes, } from "../utils/vinxi.js";
|
|
8
|
+
import { isRoute, $route } from "@dreamkit/app";
|
|
9
|
+
import { join, resolve } from "path";
|
|
10
|
+
const isEntryRoute = (id, value) => !id.startsWith("/") && isRoute(value);
|
|
11
|
+
export async function fetchDreamkitDevOptions(options) {
|
|
12
|
+
const entry = join(options.root, "app.config.ts").replaceAll("\\", "/");
|
|
13
|
+
const dummyDefineConfigSource = "virtual:config";
|
|
14
|
+
const result = await execute(entry, [
|
|
15
|
+
{
|
|
16
|
+
name: "dk:options",
|
|
17
|
+
resolveId(source) {
|
|
18
|
+
if (source === dummyDefineConfigSource)
|
|
19
|
+
return `\0${source}`;
|
|
20
|
+
},
|
|
21
|
+
load(id, options) {
|
|
22
|
+
if (id === `\0${dummyDefineConfigSource}`) {
|
|
23
|
+
return {
|
|
24
|
+
code: "export const defineConfig = (value) => value",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
transform(code, file) {
|
|
29
|
+
if (file === entry) {
|
|
30
|
+
const ast = transformCode(code, {
|
|
31
|
+
replaceImportSpec: {
|
|
32
|
+
source: "@solidjs/start/config",
|
|
33
|
+
spec: "defineConfig",
|
|
34
|
+
newSource: dummyDefineConfigSource,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return generateIfChanges(ast);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
const vinxiApp = result.default;
|
|
43
|
+
const dreamkitPlugin = vinxiApp.vite?.plugins?.find((plugin) => plugin.name === "dreamkit");
|
|
44
|
+
if (!dreamkitPlugin)
|
|
45
|
+
throw new Error("'dreamkit' plugin not found");
|
|
46
|
+
return {
|
|
47
|
+
root: options.root,
|
|
48
|
+
routeDir: join(options.root, vinxiApp.appRoot ?? "src", vinxiApp.routeDir ?? "routes"),
|
|
49
|
+
...dreamkitPlugin.dreamkitOptions,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function createDreamkitDevServer(vinxiApp, inOptions = {}) {
|
|
53
|
+
const ssrRouter = vinxiApp.config.routers.find((config) => config.name === "ssr").internals.routes;
|
|
54
|
+
const server = new DreamkitDevServer({
|
|
55
|
+
root: resolve(vinxiApp.config.root ?? "."),
|
|
56
|
+
routeDir: ssrRouter.config.dir,
|
|
57
|
+
...inOptions,
|
|
58
|
+
});
|
|
59
|
+
async function onBuildStart() {
|
|
60
|
+
await server.prepare(false);
|
|
61
|
+
for (const router of vinxiApp.config.routers) {
|
|
62
|
+
if (router.name === "ssr" || router.name === "client") {
|
|
63
|
+
const internalRouter = router.internals.routes;
|
|
64
|
+
const routes = (await internalRouter?.getRoutes()) || [];
|
|
65
|
+
for (const vinxiRoute of routes) {
|
|
66
|
+
const routeObject = await server.fetchDefault(vinxiRoute.filePath);
|
|
67
|
+
if (isRoute(routeObject))
|
|
68
|
+
vinxiRoute.$$route = {
|
|
69
|
+
pick: ["route"],
|
|
70
|
+
src: vinxiRoute.filePath,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function onBuildEnd() {
|
|
77
|
+
await server.stop();
|
|
78
|
+
}
|
|
79
|
+
async function onDevStart() {
|
|
80
|
+
await server.prepare(true);
|
|
81
|
+
for (const router of vinxiApp.config.routers) {
|
|
82
|
+
const internalRouter = router.internals.routes;
|
|
83
|
+
if (internalRouter) {
|
|
84
|
+
onChangeVinxiRoutes(internalRouter, async (action, vinxiRoute) => {
|
|
85
|
+
const isVinxiRouterPage = vinxiRoute.page &&
|
|
86
|
+
!vinxiRoute._dreamkitEntryId &&
|
|
87
|
+
(router.name === "ssr" || router.name === "client");
|
|
88
|
+
if (!isVinxiRouterPage)
|
|
89
|
+
return;
|
|
90
|
+
const id = vinxiRoute.path;
|
|
91
|
+
if (action === "remove") {
|
|
92
|
+
if (router.name === "ssr" && server.app.objects.has(id))
|
|
93
|
+
await server.app.remove([id]);
|
|
94
|
+
}
|
|
95
|
+
else if (action === "add" || action === "update") {
|
|
96
|
+
const routeObject = await server.fetchDefault(vinxiRoute.filePath);
|
|
97
|
+
if (isRoute(routeObject))
|
|
98
|
+
vinxiRoute.$$route = {
|
|
99
|
+
pick: ["route"],
|
|
100
|
+
src: vinxiRoute.filePath,
|
|
101
|
+
};
|
|
102
|
+
if (router.name === "ssr") {
|
|
103
|
+
await server.app.add({
|
|
104
|
+
[id]: $route["clone"]({ filePath: vinxiRoute.filePath })
|
|
105
|
+
.params(isRoute(routeObject)
|
|
106
|
+
? routeObject.$options.params?.props || {}
|
|
107
|
+
: {})
|
|
108
|
+
.path(vinxiRoute.path)
|
|
109
|
+
.create(() => { }),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const tryGenerate = createDelayedFunction(() => generate(server), 300);
|
|
117
|
+
server.app
|
|
118
|
+
.on("change", (data) => {
|
|
119
|
+
if (isRoute(data.value)) {
|
|
120
|
+
tryGenerate();
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.on("add", async ({ id, value }) => {
|
|
124
|
+
if (isEntryRoute(id, value)) {
|
|
125
|
+
for (const config of vinxiApp.config.routers) {
|
|
126
|
+
if (config.name === "ssr" || config.name === "client") {
|
|
127
|
+
const routes = config.internals.routes;
|
|
128
|
+
const vinxiRoute = {
|
|
129
|
+
_dreamkitEntryId: id,
|
|
130
|
+
page: true,
|
|
131
|
+
$component: {
|
|
132
|
+
src: `${server.entry.path}?dk-pick-entry=${id}&pick=default&`,
|
|
133
|
+
pick: ["default", "$css"],
|
|
134
|
+
},
|
|
135
|
+
$$route: {
|
|
136
|
+
src: `${server.entry.path}?dk-pick-entry=${id}&pick=route&`,
|
|
137
|
+
pick: ["route"],
|
|
138
|
+
},
|
|
139
|
+
path: value.$options.path ?? "",
|
|
140
|
+
filePath: server.entry.path,
|
|
141
|
+
};
|
|
142
|
+
if (!value.$options.path) {
|
|
143
|
+
console.warn("Missing route path", { id });
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
routes._addRoute(vinxiRoute);
|
|
147
|
+
routes.dispatchEvent(new CustomEvent("reload", {
|
|
148
|
+
detail: { route: vinxiRoute, dreamkitRoute: true },
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
.on("remove", ({ id, value }) => {
|
|
155
|
+
if (isEntryRoute(id, value)) {
|
|
156
|
+
for (const config of vinxiApp.config.routers) {
|
|
157
|
+
if (config.name === "ssr" || config.name === "client") {
|
|
158
|
+
const routes = config.internals.routes;
|
|
159
|
+
routes.routes = routes.routes.filter((r) => r._id !== id);
|
|
160
|
+
routes.dispatchEvent(new CustomEvent("reload", {
|
|
161
|
+
detail: { dreamkitRoute: true },
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
vinxiApp.hooks.hook("app:build:router:start", onBuildStart);
|
|
169
|
+
vinxiApp.hooks.hook("app:build:router:vite:end", onBuildEnd);
|
|
170
|
+
vinxiApp.hooks.hook("app:build:nitro:start", onBuildStart);
|
|
171
|
+
vinxiApp.hooks.hook("app:build:nitro:end", onBuildEnd);
|
|
172
|
+
vinxiApp.hooks.hook("app:dev:start", onDevStart);
|
|
173
|
+
}
|
package/lib/bin.d.ts
ADDED
package/lib/bin.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/lib/bin.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DreamkitDevServer } from "./DreamkitDevServer.js";
|
|
2
|
+
import { generate } from "./actions/generate.js";
|
|
3
|
+
import { fetchDreamkitDevOptions } from "./adapters/solid-start.js";
|
|
4
|
+
import { createCommand } from "commander";
|
|
5
|
+
import { relative, resolve } from "path";
|
|
6
|
+
const program = createCommand();
|
|
7
|
+
function globalOptions() {
|
|
8
|
+
const global = program.optsWithGlobals();
|
|
9
|
+
return {
|
|
10
|
+
...global,
|
|
11
|
+
root: resolve(global.cwd).replaceAll("\\", "/"),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
program.option("--cwd [dir]", "working dir", ".");
|
|
15
|
+
program
|
|
16
|
+
.command("generate")
|
|
17
|
+
.alias("gen")
|
|
18
|
+
.action(async () => {
|
|
19
|
+
const global = globalOptions();
|
|
20
|
+
const options = await fetchDreamkitDevOptions({
|
|
21
|
+
root: global.root,
|
|
22
|
+
});
|
|
23
|
+
const server = new DreamkitDevServer(options);
|
|
24
|
+
try {
|
|
25
|
+
await server.prepare();
|
|
26
|
+
const result = await generate(server);
|
|
27
|
+
const outputPath = relative(process.cwd(), result.output).replaceAll("\\", "/");
|
|
28
|
+
console.info([
|
|
29
|
+
`Generated: ${outputPath}`,
|
|
30
|
+
!result.changed ? " (no changes)" : "",
|
|
31
|
+
].join(""));
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await server.stop();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
program.parse(process.argv);
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { dreamkitPlugin } from "./plugins/dreamkit.js";
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type DreamkitPluginOptions = {
|
|
2
|
+
entry?: string;
|
|
3
|
+
metaFormat?: "global" | "local";
|
|
4
|
+
metaRouting?: boolean;
|
|
5
|
+
metaGlobalOutput?: string;
|
|
6
|
+
metaLocalExports?: boolean;
|
|
7
|
+
metaLocalOutput?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const dreamkitPluginOptions: {
|
|
10
|
+
metaFormat: "global";
|
|
11
|
+
metaRouting: true;
|
|
12
|
+
entry: string;
|
|
13
|
+
metaGlobalOutput: string;
|
|
14
|
+
metaLocalOutput: string;
|
|
15
|
+
metaLocalExports: true;
|
|
16
|
+
};
|
|
17
|
+
export type OutDreamkitPluginOptions = Required<Pick<DreamkitPluginOptions, keyof typeof dreamkitPluginOptions>> & Omit<DreamkitPluginOptions, keyof typeof dreamkitPluginOptions>;
|
|
18
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAChC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;;;;CAOD,CAAC;AAElC,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAC7C,IAAI,CAAC,qBAAqB,EAAE,MAAM,OAAO,qBAAqB,CAAC,CAChE,GACC,IAAI,CAAC,qBAAqB,EAAE,MAAM,OAAO,qBAAqB,CAAC,CAAC"}
|
package/lib/options.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dreamkit.d.ts","sourceRoot":"","sources":["../../src/plugins/dreamkit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,wBAAgB,cAAc,CAAC,SAAS,GAAE,qBAA0B,GAAG,MAAM,CA+C5E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createDreamkitDevServer } from "../adapters/solid-start.js";
|
|
2
|
+
import { generateIfChanges } from "../utils/ast.js";
|
|
3
|
+
import { transformCode } from "../utils/transform.js";
|
|
4
|
+
import { onVinxiApp } from "../utils/vinxi.js";
|
|
5
|
+
export function dreamkitPlugin(inOptions = {}) {
|
|
6
|
+
let isSolidStart = false;
|
|
7
|
+
const cleanup = onVinxiApp((app) => createDreamkitDevServer(app, inOptions));
|
|
8
|
+
return {
|
|
9
|
+
name: "dreamkit",
|
|
10
|
+
enforce: "pre",
|
|
11
|
+
["dreamkitOptions"]: inOptions,
|
|
12
|
+
config(config) {
|
|
13
|
+
isSolidStart = !!config.app;
|
|
14
|
+
if (!isSolidStart)
|
|
15
|
+
cleanup();
|
|
16
|
+
},
|
|
17
|
+
configResolved(config) {
|
|
18
|
+
if (isSolidStart)
|
|
19
|
+
config.plugins = config.plugins?.filter((plugin) => plugin.name !== "tree-shake");
|
|
20
|
+
},
|
|
21
|
+
async transform(code, id) {
|
|
22
|
+
const [, searchString] = id.split("?");
|
|
23
|
+
const searchParams = new URLSearchParams(searchString);
|
|
24
|
+
const dreamkitPickEntry = searchParams.get("dk-pick-entry");
|
|
25
|
+
const picks = searchParams.getAll("pick");
|
|
26
|
+
const transforms = [];
|
|
27
|
+
if (dreamkitPickEntry) {
|
|
28
|
+
transforms.push({
|
|
29
|
+
pickExport: [dreamkitPickEntry],
|
|
30
|
+
noExport: [dreamkitPickEntry],
|
|
31
|
+
exportDefault: dreamkitPickEntry,
|
|
32
|
+
toSolidRoute: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (picks.length) {
|
|
36
|
+
transforms.push({
|
|
37
|
+
...(!transforms.some((v) => v.toSolidRoute) && {
|
|
38
|
+
toSolidRoute: true,
|
|
39
|
+
}),
|
|
40
|
+
pickExport: picks,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const ast = transformCode(code, ...transforms);
|
|
44
|
+
const result = generateIfChanges(ast);
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-dead-code.d.ts","sourceRoot":"","sources":["../../src/transforms/delete-dead-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKlD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,QA6DlD"}
|