@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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/lib/DreamkitDevServer.d.ts +27 -0
  4. package/lib/DreamkitDevServer.d.ts.map +1 -0
  5. package/lib/DreamkitDevServer.js +127 -0
  6. package/lib/actions/generate.d.ts +6 -0
  7. package/lib/actions/generate.d.ts.map +1 -0
  8. package/lib/actions/generate.js +62 -0
  9. package/lib/adapters/solid-start.d.ts +8 -0
  10. package/lib/adapters/solid-start.d.ts.map +1 -0
  11. package/lib/adapters/solid-start.js +173 -0
  12. package/lib/bin.d.ts +4 -0
  13. package/lib/bin.d.ts.map +1 -0
  14. package/lib/bin.js +37 -0
  15. package/lib/index.d.ts +2 -0
  16. package/lib/index.d.ts.map +1 -0
  17. package/lib/index.js +1 -0
  18. package/lib/options.d.ts +18 -0
  19. package/lib/options.d.ts.map +1 -0
  20. package/lib/options.js +8 -0
  21. package/lib/plugins/dreamkit.d.ts +4 -0
  22. package/lib/plugins/dreamkit.d.ts.map +1 -0
  23. package/lib/plugins/dreamkit.js +48 -0
  24. package/lib/transforms/delete-dead-code.d.ts +6 -0
  25. package/lib/transforms/delete-dead-code.d.ts.map +1 -0
  26. package/lib/transforms/delete-dead-code.js +79 -0
  27. package/lib/transforms/export-default.d.ts +4 -0
  28. package/lib/transforms/export-default.d.ts.map +1 -0
  29. package/lib/transforms/export-default.js +10 -0
  30. package/lib/transforms/fix-use-data.d.ts +3 -0
  31. package/lib/transforms/fix-use-data.d.ts.map +1 -0
  32. package/lib/transforms/fix-use-data.js +49 -0
  33. package/lib/transforms/no-export.d.ts +4 -0
  34. package/lib/transforms/no-export.d.ts.map +1 -0
  35. package/lib/transforms/no-export.js +19 -0
  36. package/lib/transforms/pick-export.d.ts +4 -0
  37. package/lib/transforms/pick-export.d.ts.map +1 -0
  38. package/lib/transforms/pick-export.js +55 -0
  39. package/lib/transforms/replace-import-spec.d.ts +8 -0
  40. package/lib/transforms/replace-import-spec.d.ts.map +1 -0
  41. package/lib/transforms/replace-import-spec.js +26 -0
  42. package/lib/transforms/to-solid-route.d.ts +4 -0
  43. package/lib/transforms/to-solid-route.d.ts.map +1 -0
  44. package/lib/transforms/to-solid-route.js +117 -0
  45. package/lib/utils/ast.d.ts +17 -0
  46. package/lib/utils/ast.d.ts.map +1 -0
  47. package/lib/utils/ast.js +78 -0
  48. package/lib/utils/babel.d.ts +7 -0
  49. package/lib/utils/babel.d.ts.map +1 -0
  50. package/lib/utils/babel.js +6 -0
  51. package/lib/utils/fs.d.ts +5 -0
  52. package/lib/utils/fs.d.ts.map +1 -0
  53. package/lib/utils/fs.js +24 -0
  54. package/lib/utils/log.d.ts +3 -0
  55. package/lib/utils/log.d.ts.map +1 -0
  56. package/lib/utils/log.js +2 -0
  57. package/lib/utils/object.d.ts +4 -0
  58. package/lib/utils/object.d.ts.map +1 -0
  59. package/lib/utils/object.js +20 -0
  60. package/lib/utils/path.d.ts +6 -0
  61. package/lib/utils/path.d.ts.map +1 -0
  62. package/lib/utils/path.js +19 -0
  63. package/lib/utils/router.d.ts +7 -0
  64. package/lib/utils/router.d.ts.map +1 -0
  65. package/lib/utils/router.js +37 -0
  66. package/lib/utils/runtime.d.ts +3 -0
  67. package/lib/utils/runtime.d.ts.map +1 -0
  68. package/lib/utils/runtime.js +19 -0
  69. package/lib/utils/shaking.d.ts +24 -0
  70. package/lib/utils/shaking.d.ts.map +1 -0
  71. package/lib/utils/shaking.js +81 -0
  72. package/lib/utils/string.d.ts +2 -0
  73. package/lib/utils/string.d.ts.map +1 -0
  74. package/lib/utils/string.js +3 -0
  75. package/lib/utils/timeout.d.ts +2 -0
  76. package/lib/utils/timeout.d.ts.map +1 -0
  77. package/lib/utils/timeout.js +14 -0
  78. package/lib/utils/transform.d.ts +25 -0
  79. package/lib/utils/transform.d.ts.map +1 -0
  80. package/lib/utils/transform.js +44 -0
  81. package/lib/utils/typescript.d.ts +14 -0
  82. package/lib/utils/typescript.d.ts.map +1 -0
  83. package/lib/utils/typescript.js +78 -0
  84. package/lib/utils/vinxi.d.ts +26 -0
  85. package/lib/utils/vinxi.d.ts.map +1 -0
  86. package/lib/utils/vinxi.js +55 -0
  87. package/package.json +65 -0
@@ -0,0 +1,19 @@
1
+ import { basename, dirname, isAbsolute, join } from "path";
2
+ export function resolvePath(inPath, vars) {
3
+ let path = inPath;
4
+ for (const name in vars)
5
+ path = path.replace(`{${name}}`, vars[name]);
6
+ return isAbsolute(path) ? path : join(vars.defaults, path);
7
+ }
8
+ export function getExt(path) {
9
+ const name = basename(path);
10
+ const parts = name.split(".");
11
+ return parts.length > 1 ? parts.pop() : undefined;
12
+ }
13
+ export function getVariantPath(path, variant) {
14
+ const dir = dirname(path);
15
+ const name = basename(path);
16
+ const ext = getExt(name);
17
+ const nameWithoutExt = ext ? name.slice(0, -ext.length - 1) : name;
18
+ return join(dir, ext ? `${nameWithoutExt}.${variant}.${ext}` : `${name}.${variant}`);
19
+ }
@@ -0,0 +1,7 @@
1
+ export type Route = {
2
+ filePath: string;
3
+ path: string;
4
+ };
5
+ export declare function getRoutePath(file: string): string;
6
+ export declare function findFileRoutes(cwd: string, extensions?: string[]): Promise<Route[]>;
7
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/utils/router.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAkBxC;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,UAAU,WAA6B,oBAgBxC"}
@@ -0,0 +1,37 @@
1
+ import { analyzeModule } from "./ast.js";
2
+ import { globStream } from "glob";
3
+ import { join } from "path";
4
+ export function getRoutePath(file) {
5
+ const path = file
6
+ .replaceAll("\\", "/")
7
+ .split(".")
8
+ .slice(0, -1)
9
+ .join(".")
10
+ .replace(/index$/, "")
11
+ .replace(/\[([^\/]+)\]/g, (_, m) => {
12
+ if (m.length > 3 && m.startsWith("...")) {
13
+ return `*${m.slice(3)}`;
14
+ }
15
+ if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
16
+ return `:${m.slice(1, -1)}?`;
17
+ }
18
+ return `:${m}`;
19
+ });
20
+ return path.length > 0 ? `/${path}` : "/";
21
+ }
22
+ export async function findFileRoutes(cwd, extensions = ["tsx", "jsx", "js", "ts"]) {
23
+ const filesStream = globStream(`**/*.{${extensions}}`, { cwd });
24
+ const routes = [];
25
+ for await (const file of filesStream) {
26
+ const filePath = join(cwd, file);
27
+ const [_, exports] = await analyzeModule(filePath);
28
+ //const hasDefault = !!exports.find((e) => e.n === "default");
29
+ //if (hasDefault) {
30
+ routes.push({
31
+ filePath,
32
+ path: getRoutePath(file),
33
+ });
34
+ //}
35
+ }
36
+ return routes;
37
+ }
@@ -0,0 +1,3 @@
1
+ import { Plugin } from "vite";
2
+ export declare function execute(path: string, plugins?: Plugin[]): Promise<any>;
3
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/utils/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,MAAM,EAAE,MAAM,MAAM,CAAC;AAG/D,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,gBAcjE"}
@@ -0,0 +1,19 @@
1
+ import { dirname } from "path";
2
+ import { createServer, createViteRuntime } from "vite";
3
+ import solidPlugin from "vite-plugin-solid";
4
+ export async function execute(path, plugins = []) {
5
+ const server = await createServer({
6
+ root: dirname(path),
7
+ plugins: [...plugins, solidPlugin({ ssr: true })],
8
+ });
9
+ const rt = await createViteRuntime(server, {
10
+ hmr: { logger: false },
11
+ });
12
+ try {
13
+ return await rt.executeUrl(path);
14
+ }
15
+ finally {
16
+ await rt.destroy();
17
+ await server.close();
18
+ }
19
+ }
@@ -0,0 +1,24 @@
1
+ import { ModuleNode } from "vite";
2
+ export type Change = {
3
+ name: string;
4
+ action: "create" | "delete" | "update";
5
+ };
6
+ type VirtualShakingOptions = {
7
+ entry: string;
8
+ onChange?: (changes: Change[]) => any;
9
+ };
10
+ export declare class VirtualShaking {
11
+ readonly options: VirtualShakingOptions;
12
+ code: Record<string, string>;
13
+ readonly path: string;
14
+ constructor(options: VirtualShakingOptions);
15
+ protected split(code?: string): Record<string, string>;
16
+ init(): void;
17
+ getEntryExportId(name: string): string;
18
+ tryLoad(id: string): {
19
+ code: string;
20
+ } | undefined;
21
+ tryUpdate(path: string, read: () => string | Promise<string>, modules: ModuleNode[]): Promise<ModuleNode[]>;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=shaking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shaking.d.ts","sourceRoot":"","sources":["../../src/utils/shaking.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAA;CAAE,CAAC;AAE9E,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC;CACvC,CAAC;AAEF,qBAAa,cAAc;IAGb,QAAQ,CAAC,OAAO,EAAE,qBAAqB;IAF5C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACD,OAAO,EAAE,qBAAqB;IAGnD,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM;IAkB7B,IAAI;IAGJ,gBAAgB,CAAC,IAAI,EAAE,MAAM;IAQ7B,OAAO,CAAC,EAAE,EAAE,MAAM;;;IAQZ,SAAS,CACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EACpC,OAAO,EAAE,UAAU,EAAE;CAuBxB"}
@@ -0,0 +1,81 @@
1
+ import { pickExport } from "../transforms/pick-export.js";
2
+ import { findExportedNames, parseFile } from "./ast.js";
3
+ import { generator } from "./babel.js";
4
+ import { getExt } from "./path.js";
5
+ import { createTransformUrl } from "./transform.js";
6
+ import { cloneNode } from "@babel/types";
7
+ import { readFileSync } from "fs";
8
+ export class VirtualShaking {
9
+ options;
10
+ code = {};
11
+ path;
12
+ constructor(options) {
13
+ this.options = options;
14
+ this.path = options.entry.replaceAll("\\", "/");
15
+ }
16
+ split(code) {
17
+ const virtual = {};
18
+ try {
19
+ if (!code)
20
+ code = readFileSync(this.path).toString();
21
+ }
22
+ catch (error) {
23
+ if (error.code !== "ENOENT")
24
+ throw error;
25
+ code = "";
26
+ }
27
+ const ast = parseFile(code);
28
+ const exports = findExportedNames(ast);
29
+ for (const name of exports) {
30
+ const astExport = cloneNode(ast);
31
+ pickExport(astExport, [name]);
32
+ const transform = generator(astExport);
33
+ virtual[name] = transform.code.replace(/\n+/g, "\n");
34
+ }
35
+ return virtual;
36
+ }
37
+ init() {
38
+ this.code = this.split();
39
+ }
40
+ getEntryExportId(name) {
41
+ const ext = getExt(this.path);
42
+ return (createTransformUrl(this.path, {
43
+ pickExport: [name],
44
+ }) + `&ext=${ext}`);
45
+ }
46
+ tryLoad(id) {
47
+ const [path] = id.split("?");
48
+ if (path !== this.path)
49
+ return;
50
+ const pick = new URL(`file://${id}`).searchParams.get("dk-pick");
51
+ if (!pick)
52
+ return;
53
+ const code = this.code[pick];
54
+ return { code };
55
+ }
56
+ async tryUpdate(path, read, modules) {
57
+ if (path !== this.path)
58
+ return modules;
59
+ const prev = this.code || {};
60
+ const next = this.split(await read());
61
+ const newModuleIds = [];
62
+ const changes = [];
63
+ for (const name in next) {
64
+ if (prev[name] !== next[name]) {
65
+ changes.push({
66
+ name,
67
+ action: prev[name] === undefined ? "create" : "update",
68
+ });
69
+ const url = this.getEntryExportId(name);
70
+ newModuleIds.push(url);
71
+ }
72
+ }
73
+ const deleted = Object.keys(prev).filter((name) => !(name in next));
74
+ for (const name of deleted)
75
+ changes.push({ name, action: "delete" });
76
+ if (changes.length)
77
+ this.options.onChange?.(changes);
78
+ this.code = next;
79
+ return modules.filter((m) => newModuleIds.includes(m.id ?? ""));
80
+ }
81
+ }
@@ -0,0 +1,2 @@
1
+ export declare function replaceText(source: string, start: number, end: number, value: string): string;
2
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,UAGd"}
@@ -0,0 +1,3 @@
1
+ export function replaceText(source, start, end, value) {
2
+ return source.slice(0, start) + value + source.slice(end);
3
+ }
@@ -0,0 +1,2 @@
1
+ export declare function createDelayedFunction<T extends (...args: any[]) => any>(func: T, delay?: number, onError?: (error: Error) => void): (...args: Parameters<T>) => void;
2
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/utils/timeout.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACrE,IAAI,EAAE,CAAC,EACP,KAAK,SAAI,EACT,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,aAGf,UAAU,CAAC,CAAC,CAAC,UAU/B"}
@@ -0,0 +1,14 @@
1
+ export function createDelayedFunction(func, delay = 0, onError) {
2
+ let timeout;
3
+ return (...args) => {
4
+ clearTimeout(timeout);
5
+ timeout = setTimeout(async () => {
6
+ try {
7
+ await func(...args);
8
+ }
9
+ catch (error) {
10
+ onError?.(error);
11
+ }
12
+ }, delay);
13
+ };
14
+ }
@@ -0,0 +1,25 @@
1
+ import { exportDefault } from "../transforms/export-default.js";
2
+ import { noExport } from "../transforms/no-export.js";
3
+ import { pickExport } from "../transforms/pick-export.js";
4
+ import { replaceImportSpec } from "../transforms/replace-import-spec.js";
5
+ import { toSolidRoute } from "../transforms/to-solid-route.js";
6
+ import { ParseFileResult } from "./ast.js";
7
+ declare const $transforms: {
8
+ pickExport: typeof pickExport;
9
+ exportDefault: typeof exportDefault;
10
+ noExport: typeof noExport;
11
+ toSolidRoute: typeof toSolidRoute;
12
+ replaceImportSpec: typeof replaceImportSpec;
13
+ };
14
+ export type Transform = {
15
+ [K in keyof typeof $transforms]?: TrueIfUndefined<Parameters<(typeof $transforms)[K]>[1]>;
16
+ };
17
+ export declare function transformCode(code: string, ...input: Transform[]): ParseFileResult | undefined;
18
+ export declare function transformCodeByUrl(id: string, code: string): ParseFileResult | undefined;
19
+ type TrueIfUndefined<T> = [undefined] extends [T] ? true : T;
20
+ export declare function createTransformUrl(id: string, ...transforms: {
21
+ [K in keyof typeof $transforms]?: TrueIfUndefined<Parameters<(typeof $transforms)[K]>[1]>;
22
+ }[]): string;
23
+ export declare function getUrlTransforms(id: string): Transform[];
24
+ export {};
25
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utils/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAa,eAAe,EAAE,MAAM,UAAU,CAAC;AAEtD,QAAA,MAAM,WAAW;;;;;;CAMhB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;KACrB,CAAC,IAAI,MAAM,OAAO,WAAW,CAAC,CAAC,EAAE,eAAe,CAC/C,UAAU,CAAC,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACvC;CACF,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,+BAWhE;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,+BAG1D;AAED,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;AAE7D,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,EACV,GAAG,UAAU,EAAE;KACZ,CAAC,IAAI,MAAM,OAAO,WAAW,CAAC,CAAC,EAAE,eAAe,CAC/C,UAAU,CAAC,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACvC;CACF,EAAE,UAQJ;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,EAAE,CAKxD"}
@@ -0,0 +1,44 @@
1
+ import { exportDefault } from "../transforms/export-default.js";
2
+ import { noExport } from "../transforms/no-export.js";
3
+ import { pickExport } from "../transforms/pick-export.js";
4
+ import { replaceImportSpec } from "../transforms/replace-import-spec.js";
5
+ import { toSolidRoute } from "../transforms/to-solid-route.js";
6
+ import { parseFile } from "./ast.js";
7
+ const $transforms = {
8
+ pickExport,
9
+ exportDefault,
10
+ noExport,
11
+ toSolidRoute,
12
+ replaceImportSpec,
13
+ };
14
+ export function transformCode(code, ...input) {
15
+ let ast;
16
+ for (const item of input) {
17
+ for (let [name, value] of Object.entries(item)) {
18
+ if (name in $transforms) {
19
+ ast = ast || parseFile(code);
20
+ $transforms[name](ast, value);
21
+ }
22
+ }
23
+ }
24
+ return ast;
25
+ }
26
+ export function transformCodeByUrl(id, code) {
27
+ const transforms = getUrlTransforms(id);
28
+ return transformCode(code, ...transforms);
29
+ }
30
+ export function createTransformUrl(id, ...transforms) {
31
+ const url = new URL(id, "file://");
32
+ const prev = getUrlTransforms(id);
33
+ prev.push(...transforms);
34
+ if (prev.length)
35
+ url.searchParams.set("dkt", JSON.stringify(prev));
36
+ const search = prev.length ? `${url.search}&` : url.search;
37
+ return id.split("?")[0] + search;
38
+ }
39
+ export function getUrlTransforms(id) {
40
+ const url = new URL(id, "file://");
41
+ const params = [...url.searchParams.entries()];
42
+ const dkTransforms = url.searchParams.get("dkt") || "[]";
43
+ return JSON.parse(dkTransforms);
44
+ }
@@ -0,0 +1,14 @@
1
+ import { Type } from "@dreamkit/schema";
2
+ export declare class ImportScope extends Map<string, number> {
3
+ create(): ImportSpec;
4
+ }
5
+ export declare class ImportSpec extends Map<string, string> {
6
+ protected scope: Map<string, number>;
7
+ constructor(scope?: Map<string, number>);
8
+ set(key: string, value: string): this;
9
+ }
10
+ export declare function createRecordName(name: string, optional?: boolean): string;
11
+ export declare function createModuleDeclaration(source: string, body: string[], padding?: number): string;
12
+ export declare function createInterface(name: string, props: Record<string, string>, padding?: number): string;
13
+ export declare function createType(type: Type): string;
14
+ //# sourceMappingURL=typescript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/utils/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE/D,qBAAa,WAAY,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAClD,MAAM;CAGP;AAED,qBAAa,UAAW,SAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IACrC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;gBAA1B,KAAK,GAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAa;IAG5D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAQ/B;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,UAKhE;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,SAAI,UAMZ;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,SAAI,UAQZ;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CA8B7C"}
@@ -0,0 +1,78 @@
1
+ export class ImportScope extends Map {
2
+ create() {
3
+ return new ImportSpec(this);
4
+ }
5
+ }
6
+ export class ImportSpec extends Map {
7
+ scope;
8
+ constructor(scope = new Map()) {
9
+ super();
10
+ this.scope = scope;
11
+ }
12
+ set(key, value) {
13
+ const duplications = this.scope.get(key);
14
+ if (duplications) {
15
+ value += duplications.toString();
16
+ this.scope.set(key, duplications + 1);
17
+ }
18
+ return super.set(key, value);
19
+ }
20
+ }
21
+ export function createRecordName(name, optional) {
22
+ const expr = /^([a-z0-9_\$]+)$/.test(name)
23
+ ? name
24
+ : `[${JSON.stringify(name)}]`;
25
+ return optional ? `${expr}?` : expr;
26
+ }
27
+ export function createModuleDeclaration(source, body, padding = 0) {
28
+ const pad = " ".repeat(padding);
29
+ const sourceExpr = JSON.stringify(source);
30
+ const bodyExpr = body.join("\n");
31
+ return `${pad}declare module ${sourceExpr} {\n${bodyExpr}\n${pad}}`;
32
+ }
33
+ export function createInterface(name, props, padding = 0) {
34
+ const pad = " ".repeat(padding);
35
+ const propPad = " ".repeat(padding + 1);
36
+ const body = Object.entries(props)
37
+ .map(([name, value]) => `${propPad}${createRecordName(name)}: ${value};`)
38
+ .join("\n");
39
+ return `${pad}interface ${name} {\n${body}\n${pad}}`;
40
+ }
41
+ export function createType(type) {
42
+ const tsType = (name) => {
43
+ const values = [name];
44
+ if (type.options.nullable)
45
+ values.push("null");
46
+ if (type.options.optional)
47
+ values.push("undefined");
48
+ return values.join(" | ");
49
+ };
50
+ if (type.type === "string") {
51
+ return tsType("string");
52
+ }
53
+ else if (type.type === "number" || type.type === "integer") {
54
+ return tsType("number");
55
+ }
56
+ else if (type.type === "boolean") {
57
+ return tsType("boolean");
58
+ }
59
+ else if (type.type === "object") {
60
+ const objectType = type;
61
+ const props = Object.keys(objectType.options.props || {})
62
+ .map((name) => {
63
+ const prop = objectType.options.props[name];
64
+ const required = !prop.options.optional;
65
+ const nameExpr = createRecordName(name, !required);
66
+ return `${nameExpr}: ${createType(prop)}`;
67
+ })
68
+ .join(", ");
69
+ return `{ ${props} }`;
70
+ }
71
+ else if (type.type === "array") {
72
+ const arrayType = type;
73
+ return tsType(`(${createType(arrayType.items || {})})[]`);
74
+ }
75
+ else {
76
+ return "any";
77
+ }
78
+ }
@@ -0,0 +1,26 @@
1
+ import type { Internals } from "vinxi";
2
+ import type { App } from "vinxi";
3
+ export type VinxiRoute = {
4
+ _dreamkitEntryId?: string;
5
+ page: boolean;
6
+ filePath: string;
7
+ path: string;
8
+ $component: {
9
+ src: string;
10
+ pick: string[];
11
+ };
12
+ $$route?: {
13
+ src: string;
14
+ pick?: string[];
15
+ require?: any;
16
+ import?: any;
17
+ };
18
+ };
19
+ export type BaseFileSystemRouter = Omit<Internals["routes"] & {}, "getRoutes"> & {
20
+ getRoutes(): Promise<VinxiRoute[]>;
21
+ buildRoutes(): Promise<VinxiRoute[]>;
22
+ buildRoutesPromise: Promise<any> | undefined;
23
+ };
24
+ export declare function onVinxiApp(cb: (app: App) => void): () => void;
25
+ export declare function onChangeVinxiRoutes(router: BaseFileSystemRouter, cb: (action: "add" | "update" | "remove", route: VinxiRoute) => any): () => void;
26
+ //# sourceMappingURL=vinxi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vinxi.d.ts","sourceRoot":"","sources":["../../src/utils/vinxi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,MAAM,MAAM,UAAU,GAAG;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE;QACV,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,EAAE,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,MAAM,CAAC,EAAE,GAAG,CAAC;KACd,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,EACxB,WAAW,CACZ,GAAG;IACF,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACnC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACrC,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;CAC9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,cAiBhD;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,oBAAoB,EAC5B,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,EAAE,KAAK,EAAE,UAAU,KAAK,GAAG,cAmCpE"}
@@ -0,0 +1,55 @@
1
+ import { normalize } from "path";
2
+ export function onVinxiApp(cb) {
3
+ Object.defineProperty(globalThis, "app", {
4
+ configurable: true,
5
+ set(value) {
6
+ cb(value);
7
+ Object.defineProperty(globalThis, "app", {
8
+ configurable: true,
9
+ value,
10
+ });
11
+ },
12
+ });
13
+ return () => {
14
+ Object.defineProperty(globalThis, "app", {
15
+ configurable: true,
16
+ value: globalThis.app,
17
+ });
18
+ };
19
+ }
20
+ export function onChangeVinxiRoutes(router, cb) {
21
+ const addRoute = router._addRoute.bind(router);
22
+ const removeRoute = router.removeRoute.bind(router);
23
+ router._addRoute = (route) => {
24
+ const prevRoute = router.routes.find((item) => item.path === route.path);
25
+ const result = cb(prevRoute ? "update" : "add", route);
26
+ if (result instanceof Promise) {
27
+ result.then(() => addRoute(route));
28
+ }
29
+ else {
30
+ addRoute(route);
31
+ }
32
+ };
33
+ router.removeRoute = (src) => {
34
+ src = normalize(src);
35
+ if (router.isRoute(src)) {
36
+ const path = router.toPath(src);
37
+ if (path !== undefined) {
38
+ const route = router.routes.find((r) => r.path === path);
39
+ if (route) {
40
+ const result = cb("remove", route);
41
+ if (result instanceof Promise) {
42
+ result.then(() => removeRoute(route));
43
+ }
44
+ else {
45
+ removeRoute(route);
46
+ }
47
+ }
48
+ }
49
+ }
50
+ };
51
+ return () => {
52
+ router._addRoute = addRoute;
53
+ router.removeRoute = removeRoute;
54
+ };
55
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@dreamkit/dev",
3
+ "version": "0.0.1",
4
+ "description": "Development tools for DreamKit.",
5
+ "homepage": "https://dreamkit.dev",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/swordev/dreamkit/tree/main/packages/dev"
9
+ },
10
+ "license": "MIT",
11
+ "author": "Juanra GM",
12
+ "contributors": [
13
+ {
14
+ "name": "Juanra GM",
15
+ "email": "juanrgm724@gmail.com",
16
+ "url": "https://github.com/juanrgm"
17
+ }
18
+ ],
19
+ "sideEffects": false,
20
+ "type": "module",
21
+ "exports": {
22
+ ".": "./lib/index.js",
23
+ "./bin": "./lib/bin.js"
24
+ },
25
+ "bin": {
26
+ "dk": "./lib/bin.js",
27
+ "dreamkit": "./lib/bin.js"
28
+ },
29
+ "files": [
30
+ "assets",
31
+ "lib"
32
+ ],
33
+ "dependencies": {
34
+ "@babel/generator": "^7.26.2",
35
+ "@babel/parser": "^7.26.2",
36
+ "@babel/traverse": "^7.25.9",
37
+ "@babel/types": "^7.26.0",
38
+ "@types/babel__generator": "^7.6.8",
39
+ "@types/babel__traverse": "^7.20.6",
40
+ "commander": "^12.1.0",
41
+ "debug": "^4.3.7",
42
+ "es-module-lexer": "^1.5.4",
43
+ "esbuild": "^0.24.0",
44
+ "vite-plugin-solid": "^2.10.2",
45
+ "vite-tsconfig-paths": "^5.1.0",
46
+ "@dreamkit/app": "0.0.1",
47
+ "@dreamkit/schema": "0.0.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/debug": "^4.1.12",
51
+ "@types/node": "^22.9.0",
52
+ "glob": "^11.0.0",
53
+ "vinxi": "^0.4.3",
54
+ "vite": "^5.4.10",
55
+ "@dreamkit/tsconfig": "0.0.1"
56
+ },
57
+ "peerDependencies": {
58
+ "@types/node": "^22.7.7",
59
+ "vinxi": "^0.4.3",
60
+ "vite": "^5.4.8"
61
+ },
62
+ "x-dreamkit": {
63
+ "profile": "lib"
64
+ }
65
+ }