zudoku 0.1.1-dev.20 → 0.1.1-dev.22

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 (131) hide show
  1. package/dist/cli/common/logger.js +3 -1
  2. package/dist/cli/common/logger.js.map +1 -1
  3. package/dist/cli/common/outdated.js +4 -4
  4. package/dist/cli/common/outdated.js.map +1 -1
  5. package/dist/cli/common/output.js +4 -4
  6. package/dist/cli/common/output.js.map +1 -1
  7. package/dist/cli/common/utils/box.js +2 -2
  8. package/dist/cli/common/utils/box.js.map +1 -1
  9. package/dist/config/config.d.ts +1 -0
  10. package/dist/lib/authentication/clerk.d.ts +2 -1
  11. package/dist/lib/authentication/clerk.js +2 -1
  12. package/dist/lib/authentication/clerk.js.map +1 -1
  13. package/dist/lib/{DevPortal.d.ts → components/DevPortal.d.ts} +5 -5
  14. package/dist/lib/{DevPortal.js → components/DevPortal.js} +7 -7
  15. package/dist/lib/components/DevPortal.js.map +1 -0
  16. package/dist/lib/{Heading.js → components/Heading.js} +2 -2
  17. package/dist/lib/components/Heading.js.map +1 -0
  18. package/dist/lib/components/Link.d.ts +1 -0
  19. package/dist/lib/components/Link.js +2 -0
  20. package/dist/lib/components/Link.js.map +1 -0
  21. package/dist/lib/{Router.d.ts → components/Router.d.ts} +1 -1
  22. package/dist/lib/{Router.js → components/Router.js} +2 -2
  23. package/dist/lib/components/Router.js.map +1 -0
  24. package/dist/lib/components/index.d.ts +3 -0
  25. package/dist/lib/components/index.js +4 -0
  26. package/dist/lib/components/index.js.map +1 -0
  27. package/dist/lib/core/DevPortalContext.d.ts +1 -1
  28. package/dist/lib/core/DevPortalContext.js.map +1 -1
  29. package/dist/lib/plugins/api-key/index.js +1 -1
  30. package/dist/lib/plugins/api-key/index.js.map +1 -1
  31. package/dist/lib/plugins/index.d.ts +4 -0
  32. package/dist/lib/plugins/index.js +6 -0
  33. package/dist/lib/plugins/index.js.map +1 -0
  34. package/dist/lib/plugins/markdown/MdxPage.js +1 -1
  35. package/dist/lib/plugins/markdown/MdxPage.js.map +1 -1
  36. package/dist/lib/plugins/markdown/generateRoutes.js +1 -1
  37. package/dist/lib/plugins/markdown/generateRoutes.js.map +1 -1
  38. package/dist/lib/plugins/openapi/OperationList.js +2 -2
  39. package/dist/lib/plugins/openapi/OperationList.js.map +1 -1
  40. package/dist/lib/plugins/openapi/OperationListItem.js +1 -1
  41. package/dist/lib/plugins/openapi/OperationListItem.js.map +1 -1
  42. package/dist/lib/plugins/openapi/ParameterList.js +1 -1
  43. package/dist/lib/plugins/openapi/ParameterList.js.map +1 -1
  44. package/dist/lib/plugins/openapi/index.js +1 -1
  45. package/dist/lib/plugins/openapi/index.js.map +1 -1
  46. package/dist/lib/plugins/openapi-worker.d.ts +1 -0
  47. package/dist/lib/plugins/openapi-worker.js +2 -0
  48. package/dist/lib/plugins/openapi-worker.js.map +1 -0
  49. package/dist/lib/ui/Button.d.ts +1 -1
  50. package/dist/lib/util/MdxComponents.js +1 -1
  51. package/dist/lib/util/MdxComponents.js.map +1 -1
  52. package/dist/vite/config.js +16 -12
  53. package/dist/vite/config.js.map +1 -1
  54. package/dist/vite/plugin-auth.js +2 -2
  55. package/dist/vite/plugin-auth.js.map +1 -1
  56. package/dist/vite/plugin-component.d.ts +2 -1
  57. package/dist/vite/plugin-component.js +14 -5
  58. package/dist/vite/plugin-component.js.map +1 -1
  59. package/lib/{DevPortal-DqcnbwLT.js → DevPortal-ChiyAyW7.js} +7348 -7347
  60. package/lib/{zudoku.auth.js → zudoku.auth-clerk.js} +6 -8
  61. package/lib/zudoku.components.js +1 -1
  62. package/lib/zudoku.plugins.js +2 -2
  63. package/package.json +11 -11
  64. package/src/lib/authentication/clerk.ts +3 -5
  65. package/src/lib/{DevPortal.tsx → components/DevPortal.tsx} +16 -13
  66. package/src/lib/{Heading.tsx → components/Heading.tsx} +2 -2
  67. package/src/lib/components/Link.tsx +1 -0
  68. package/src/lib/{Router.tsx → components/Router.tsx} +2 -2
  69. package/src/lib/components/index.ts +3 -0
  70. package/src/lib/core/DevPortalContext.ts +4 -1
  71. package/src/lib/plugins/api-key/index.tsx +1 -1
  72. package/src/lib/plugins/index.ts +5 -0
  73. package/src/lib/plugins/markdown/MdxPage.tsx +1 -1
  74. package/src/lib/plugins/markdown/generateRoutes.tsx +1 -1
  75. package/src/lib/plugins/openapi/OperationList.tsx +3 -3
  76. package/src/lib/plugins/openapi/OperationListItem.tsx +1 -1
  77. package/src/lib/plugins/openapi/ParameterList.tsx +1 -1
  78. package/src/lib/plugins/openapi/index.tsx +1 -1
  79. package/src/lib/plugins/openapi-worker.ts +1 -0
  80. package/src/lib/util/MdxComponents.tsx +1 -1
  81. package/dist/lib/DevPortal.js.map +0 -1
  82. package/dist/lib/Heading.js.map +0 -1
  83. package/dist/lib/Router.js.map +0 -1
  84. package/dist/lib/auth.d.ts +0 -1
  85. package/dist/lib/auth.js +0 -2
  86. package/dist/lib/auth.js.map +0 -1
  87. package/dist/lib/components.d.ts +0 -3
  88. package/dist/lib/components.js +0 -4
  89. package/dist/lib/components.js.map +0 -1
  90. package/dist/lib/plugins.d.ts +0 -4
  91. package/dist/lib/plugins.js +0 -6
  92. package/dist/lib/plugins.js.map +0 -1
  93. package/src/cli/build/handler.ts +0 -14
  94. package/src/cli/cli.ts +0 -77
  95. package/src/cli/cmds/build.ts +0 -24
  96. package/src/cli/cmds/dev.ts +0 -29
  97. package/src/cli/common/analytics/lib.ts +0 -89
  98. package/src/cli/common/constants.ts +0 -10
  99. package/src/cli/common/logger.ts +0 -5
  100. package/src/cli/common/machine-id/lib.ts +0 -85
  101. package/src/cli/common/outdated.ts +0 -102
  102. package/src/cli/common/output.ts +0 -86
  103. package/src/cli/common/utils/box.license.txt +0 -202
  104. package/src/cli/common/utils/box.ts +0 -116
  105. package/src/cli/common/utils/ports.ts +0 -21
  106. package/src/cli/common/validators/lib.ts +0 -43
  107. package/src/cli/common/xdg/lib.ts +0 -36
  108. package/src/cli/dev/handler.ts +0 -42
  109. package/src/config/config.ts +0 -56
  110. package/src/index.ts +0 -8
  111. package/src/lib/auth.ts +0 -1
  112. package/src/lib/components.ts +0 -3
  113. package/src/lib/plugins.ts +0 -5
  114. package/src/ts.ts +0 -94
  115. package/src/types.d.ts +0 -24
  116. package/src/vite/build.ts +0 -33
  117. package/src/vite/config.test.ts +0 -10
  118. package/src/vite/config.ts +0 -183
  119. package/src/vite/dev-server.ts +0 -64
  120. package/src/vite/html.ts +0 -37
  121. package/src/vite/plugin-api.ts +0 -57
  122. package/src/vite/plugin-auth.ts +0 -32
  123. package/src/vite/plugin-component.ts +0 -26
  124. package/src/vite/plugin-config.ts +0 -31
  125. package/src/vite/plugin-docs.test.ts +0 -32
  126. package/src/vite/plugin-docs.ts +0 -52
  127. package/src/vite/plugin-html.ts +0 -50
  128. package/src/vite/plugin-mdx.ts +0 -74
  129. package/src/vite/plugin-metadata.ts +0 -30
  130. package/src/vite/plugin.ts +0 -23
  131. /package/dist/lib/{Heading.d.ts → components/Heading.d.ts} +0 -0
@@ -1,36 +0,0 @@
1
- import { homedir } from "node:os";
2
- import path from "node:path";
3
- import { CLI_XDG_FOLDER_NAME } from "../constants.js";
4
-
5
- function defineDirectoryWithFallback(xdgName: string, fallback: string) {
6
- if (process.env[xdgName]) {
7
- return process.env[xdgName] as string;
8
- } else {
9
- return path.join(homedir(), fallback);
10
- }
11
- }
12
-
13
- export const XDG_CONFIG_HOME = defineDirectoryWithFallback(
14
- "XDG_CONFIG_HOME",
15
- ".config",
16
- );
17
- export const XDG_DATA_HOME = defineDirectoryWithFallback(
18
- "XDG_DATA_HOME",
19
- ".local/share",
20
- );
21
- export const XDG_STATE_HOME = defineDirectoryWithFallback(
22
- "XDG_DATA_HOME",
23
- ".local/state",
24
- );
25
- export const ZUPLO_XDG_CONFIG_HOME = path.join(
26
- XDG_CONFIG_HOME,
27
- CLI_XDG_FOLDER_NAME,
28
- );
29
- export const ZUPLO_XDG_DATA_HOME = path.join(
30
- XDG_DATA_HOME,
31
- CLI_XDG_FOLDER_NAME,
32
- );
33
- export const ZUPLO_XDG_STATE_HOME = path.join(
34
- XDG_STATE_HOME,
35
- CLI_XDG_FOLDER_NAME,
36
- );
@@ -1,42 +0,0 @@
1
- import { DevServer } from "../../vite/dev-server.js";
2
- import { printDiagnosticsToConsole } from "../common/output.js";
3
- import { isPortAvailable } from "../common/utils/ports.js";
4
-
5
- export interface Arguments {
6
- dir: string;
7
- port?: number;
8
- }
9
-
10
- export async function dev(argv: Arguments) {
11
- const host = "localhost";
12
- let port = argv.port;
13
- if (!port) {
14
- port = 9000;
15
- while (!(await isPortAvailable(host, port)) && port < 9800) {
16
- port++;
17
- }
18
- }
19
- const server = new DevServer({ ...argv, port });
20
-
21
- await server.start();
22
-
23
- printDiagnosticsToConsole("Started local development setup");
24
- printDiagnosticsToConsole("Ctrl+C to exit");
25
- printDiagnosticsToConsole("");
26
- printDiagnosticsToConsole(`🚀 Zudoku Portal: http://${host}:${port}`);
27
- printDiagnosticsToConsole("");
28
- printDiagnosticsToConsole("");
29
-
30
- return new Promise<void>((resolve) => {
31
- async function exit() {
32
- printDiagnosticsToConsole("Closing local development setup");
33
-
34
- await server.stop();
35
-
36
- resolve();
37
- }
38
-
39
- process.on("SIGTERM", exit);
40
- process.on("SIGINT", exit);
41
- });
42
- }
@@ -1,56 +0,0 @@
1
- import { Options } from "@mdx-js/rollup";
2
- import { NavigationItem } from "../lib/core/DevPortalContext.js";
3
- import { OasPluginConfig } from "../lib/plugins/openapi/index.js";
4
- import { type MdxComponentsType } from "../lib/util/MdxComponents.js";
5
-
6
- export interface ZudokuConfig {
7
- ui?: UIConfig;
8
- mdx?: {
9
- components?: MdxComponentsType;
10
- };
11
-
12
- authentication?: AuthenticationConfig;
13
-
14
- navigation?: NavigationItem[];
15
-
16
- docs?: DocsConfig;
17
- apis?: ApiConfig | ApiConfig[];
18
-
19
- build?: {
20
- remarkPlugins?: Options["remarkPlugins"];
21
- rehypePlugins?: Options["rehypePlugins"];
22
- };
23
- }
24
-
25
- export interface ZudokuPluginOptions extends ZudokuConfig {
26
- rootDir: string;
27
- }
28
-
29
- export interface UIConfig {
30
- /**
31
- * The site title
32
- */
33
- headerTitle?: string;
34
- pageTitle?: string;
35
- // description: string;
36
- logo?: string;
37
-
38
- metadata?: MetadataConfig;
39
- }
40
-
41
- export interface MetadataConfig {
42
- favicon?: string;
43
- }
44
-
45
- export interface DocsConfig {
46
- files?: string;
47
- }
48
-
49
- export type ApiConfig = OasPluginConfig;
50
-
51
- export interface ClerkAuthenticationConfig {
52
- type: "clerk";
53
- clerkPubKey: string;
54
- }
55
-
56
- export type AuthenticationConfig = ClerkAuthenticationConfig;
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- // Config
2
- export type { ZudokuConfig } from "./config/config.js";
3
- export type {
4
- NavigationCategory,
5
- NavigationCategoryItem,
6
- NavigationItem,
7
- } from "./lib/core/DevPortalContext.js";
8
- export type { MDXImport } from "./lib/plugins/markdown/index.js";
package/src/lib/auth.ts DELETED
@@ -1 +0,0 @@
1
- export { clerkAuth } from "./authentication/clerk.js";
@@ -1,3 +0,0 @@
1
- export { DynamicIcon } from "./components/DynamicIcon.js";
2
- export { Link } from "./core/router.js";
3
- export { DevPortal } from "./DevPortal.js";
@@ -1,5 +0,0 @@
1
- // Plugins
2
- export { apiKeyPlugin } from "./plugins/api-key/index.js";
3
- export { markdownPlugin } from "./plugins/markdown/index.js";
4
- export { openApiPlugin } from "./plugins/openapi/index.js";
5
- export { redirectPlugin } from "./plugins/redirect/index.js";
package/src/ts.ts DELETED
@@ -1,94 +0,0 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- /**
5
- * Function to check if a TypeScript string is valid
6
- * Used for tests
7
- */
8
- export async function checkTypescriptString(code: string) {
9
- const rootDir = process.cwd();
10
- const inMemoryFileName = path.join(rootDir, "/src/temp.ts");
11
- const configPath = ts.findConfigFile(
12
- rootDir,
13
- ts.sys.fileExists,
14
- "tsconfig.json",
15
- );
16
- if (!configPath) {
17
- throw new Error("Could not find a valid tsconfig.json");
18
- }
19
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
20
- const parsedCommandLine = ts.parseJsonConfigFileContent(
21
- configFile.config,
22
- ts.sys,
23
- path.dirname(configPath),
24
- );
25
-
26
- // Custom compiler host to handle in-memory file and delegate to default host for others
27
- const compilerHost: ts.CompilerHost = {
28
- ...ts.createCompilerHost(parsedCommandLine.options),
29
- getSourceFile: (
30
- fileName,
31
- languageVersion,
32
- onError,
33
- shouldCreateNewSourceFile,
34
- ) => {
35
- if (fileName === inMemoryFileName) {
36
- return ts.createSourceFile(fileName, code, languageVersion, true);
37
- }
38
- return ts
39
- .createCompilerHost(parsedCommandLine.options)
40
- .getSourceFile(
41
- fileName,
42
- languageVersion,
43
- onError,
44
- shouldCreateNewSourceFile,
45
- );
46
- },
47
- fileExists: (fileName) => {
48
- if (fileName === inMemoryFileName) {
49
- return true;
50
- }
51
- return ts.sys.fileExists(fileName);
52
- },
53
- readFile: (fileName) => {
54
- if (fileName === inMemoryFileName) {
55
- return code;
56
- }
57
- return ts.sys.readFile(fileName);
58
- },
59
- };
60
-
61
- // Create a source file in memory
62
- const sourceFile = ts.createSourceFile("tempFile.ts", code, 99, true);
63
-
64
- // Create a program using the in-memory source file
65
- const program = ts.createProgram({
66
- rootNames: parsedCommandLine.fileNames.concat(inMemoryFileName),
67
- options: parsedCommandLine.options,
68
- host: compilerHost,
69
- });
70
-
71
- // Get all diagnostics for the program, which includes syntax and semantic errors
72
- const diagnostics = ts.getPreEmitDiagnostics(program);
73
-
74
- diagnostics.forEach((diagnostic) => {
75
- if (diagnostic.file) {
76
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(
77
- diagnostic.start!,
78
- );
79
- const message = ts.flattenDiagnosticMessageText(
80
- diagnostic.messageText,
81
- "\n",
82
- );
83
- console.log(
84
- `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`,
85
- );
86
- } else {
87
- console.log(
88
- ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
89
- );
90
- }
91
- });
92
-
93
- return diagnostics;
94
- }
package/src/types.d.ts DELETED
@@ -1,24 +0,0 @@
1
- declare module "slugify" {
2
- declare function slugify(
3
- string: string,
4
- options?:
5
- | {
6
- replacement?: string;
7
- remove?: RegExp;
8
- lower?: boolean;
9
- strict?: boolean;
10
- locale?: string;
11
- trim?: boolean;
12
- }
13
- | string,
14
- ): string;
15
-
16
- export default slugify;
17
- }
18
-
19
- declare module "virtual:zudoku-docs-plugins";
20
- declare module "virtual:zudoku-api-plugins";
21
- declare module "virtual:zudoku-config";
22
- declare module "virtual:zudoku-auth";
23
- declare module "virtual:zudoku-component";
24
- declare module "zudoku/open-api-worker";
package/src/vite/build.ts DELETED
@@ -1,33 +0,0 @@
1
- import { writeFile } from "fs/promises";
2
- import { build as viteBuild } from "vite";
3
- import { getViteConfig } from "./config.js";
4
- import { getBuildHtml } from "./html.js";
5
-
6
- export async function runBuild(options: { dir: string }) {
7
- const viteConfig = await getViteConfig({ dir: options.dir, mode: "build" });
8
-
9
- const result = await viteBuild(viteConfig);
10
-
11
- if (Array.isArray(result)) {
12
- throw new Error("Build failed");
13
- }
14
-
15
- if ("output" in result) {
16
- const jsEntry = result.output.find(
17
- (o) => "isEntry" in o && o.isEntry,
18
- )?.fileName;
19
- const cssEntry = result.output.find((o) =>
20
- o.fileName.endsWith(".css"),
21
- )?.fileName;
22
-
23
- const html = getBuildHtml({
24
- jsEntry: `/${jsEntry}`,
25
- cssEntry: `/${cssEntry}`,
26
- });
27
-
28
- await writeFile(`${options.dir}/dist/index.html`, html, "utf-8");
29
- return;
30
- }
31
-
32
- throw new Error("Build failed");
33
- }
@@ -1,10 +0,0 @@
1
- import assert from "node:assert";
2
- import path from "node:path";
3
- import test from "node:test";
4
- import { loadConfig } from "./config.js";
5
-
6
- test("Should correctly load zudoku.config.ts file", async (t) => {
7
- const rootPath = path.resolve("../../samples/with-config/");
8
- const config = await loadConfig(rootPath, "zudoku.config.ts");
9
- assert.equal(config.default.ui.headerTitle, "My Portal");
10
- });
@@ -1,183 +0,0 @@
1
- import autoprefixer from "autoprefixer";
2
- import esbuild from "esbuild";
3
- import { stat } from "node:fs/promises";
4
- import path from "node:path";
5
- import tailwindcss from "tailwindcss";
6
- import { InlineConfig, LogLevel } from "vite";
7
- import tailwindConfig from "../app/tailwind.js";
8
- import { logger } from "../cli/common/logger.js";
9
- import { isPortAvailable } from "../cli/common/utils/ports.js";
10
- import { ZudokuConfig } from "../config/config.js";
11
- import viteComponentPlugin from "./plugin-component.js";
12
- import vitePlugin from "./plugin.js";
13
-
14
- const extensions = ["js", "jsx", "ts", "tsx", "mjs"];
15
-
16
- export interface ZudokuViteConfig extends InlineConfig {
17
- root: string;
18
- }
19
-
20
- const fileExists = (path: string) =>
21
- stat(path)
22
- .then(() => true)
23
- .catch(() => false);
24
-
25
- export async function loadZuploConfig(rootDir: string): Promise<ZudokuConfig> {
26
- for (const ext of extensions) {
27
- const fileName = `zudoku.config.${ext}`;
28
- const configPath = path.join(rootDir, fileName);
29
-
30
- try {
31
- if (await fileExists(configPath)) {
32
- logger.info(`Loading zudoku.config file: ${configPath}`);
33
- const config = await loadConfig(rootDir, fileName);
34
- return config.default as ZudokuConfig;
35
- }
36
- } catch (e) {
37
- logger.error(e);
38
- }
39
- }
40
-
41
- // Default config
42
- logger.warn("No zudoku.config file found");
43
- return {};
44
- }
45
-
46
- function getModuleDir() {
47
- // NOTE: This is relative to the /dist folder because the dev server
48
- // runs the compiled JS files, but vite uses the raw TS files
49
- return new URL("../../", import.meta.url).pathname;
50
- }
51
-
52
- export function getAppMainTsxPath() {
53
- const modDir = getModuleDir();
54
- return path.join(modDir, "src", "app", "main.tsx");
55
- }
56
-
57
- export async function getViteConfig({
58
- dir,
59
- mode,
60
- }: {
61
- dir: string;
62
- mode: "dev" | "build";
63
- }): Promise<ZudokuViteConfig> {
64
- const rootDir = path.resolve(process.cwd(), dir);
65
- const moduleDir = getModuleDir();
66
- const config = await loadZuploConfig(rootDir);
67
-
68
- let websocketPort = 9800;
69
- while (
70
- !(await isPortAvailable("localhost", websocketPort)) &&
71
- websocketPort < 9999
72
- ) {
73
- websocketPort++;
74
- }
75
-
76
- const viteConfig: ZudokuViteConfig = {
77
- root: rootDir,
78
- appType: "custom",
79
- configFile: false,
80
- clearScreen: false,
81
- logLevel: (process.env.LOG_LEVEL || "info") as LogLevel,
82
- customLogger: logger,
83
- envPrefix: "PUBLIC_",
84
- worker: {
85
- format: "es",
86
- },
87
- server: {
88
- middlewareMode: true,
89
- open: true,
90
- hmr: {
91
- port: websocketPort,
92
- },
93
- watch: {
94
- ignored: [
95
- `${rootDir}/dist`,
96
- `${rootDir}/lib`,
97
- `${rootDir}/.git`,
98
- `${rootDir}/node_modules`,
99
- `${rootDir}/zuplo.config.ts`,
100
- ],
101
- },
102
- // sourcemapIgnoreList: (sourcePath) => {
103
- // return (
104
- // sourcePath.includes("node_modules/openapi-types/") ||
105
- // sourcePath.includes("node_modules/value-or-promise/")
106
- // );
107
- // },
108
- },
109
- build: {
110
- outDir: path.resolve(rootDir, "dist"),
111
- rollupOptions: {
112
- // external: ["@mdx-js/react"],
113
- input: mode === "build" ? "zudoku/app/main.tsx" : undefined,
114
- },
115
- },
116
- optimizeDeps: {
117
- entries: [getAppMainTsxPath()],
118
- exclude: ["zudoku/open-api-worker"],
119
- include: [
120
- "hast-util-to-jsx-runtime > style-to-object",
121
- "debug",
122
- "extend",
123
- "stringify-object",
124
- "url",
125
- "@zudoku/httpsnippet > qs",
126
- "react-fast-compare",
127
- "invariant",
128
- "shallowequal",
129
- "slugify",
130
- "zustand",
131
- ],
132
- },
133
- plugins: [vitePlugin({ ...config, rootDir }), viteComponentPlugin()],
134
- css: {
135
- postcss: {
136
- plugins: [
137
- tailwindcss({
138
- ...tailwindConfig,
139
- content: [
140
- `${moduleDir}/src/**/*.{js,ts,jsx,tsx,md,mdx}`,
141
- // Tailwind seems to crash if it tries to parse compiled .js files
142
- // as a workaround, we will just ship the source file and use those
143
- // `${moduleDir}/lib/**/*.{js,ts,jsx,tsx,md,mdx}`,
144
- `${rootDir}/src/**/*.{js,ts,jsx,tsx,md,mdx}`,
145
- ],
146
- }),
147
- autoprefixer,
148
- ],
149
- },
150
- },
151
- };
152
-
153
- return viteConfig;
154
- }
155
-
156
- export async function loadConfig(rootPath: string, fileName: string) {
157
- const compiledFilepath = path.join(
158
- rootPath,
159
- "node_modules",
160
- ".zudoku",
161
- "zudoku.config.mjs",
162
- );
163
- const filepath = path.join(rootPath, fileName);
164
- try {
165
- await esbuild.build({
166
- entryPoints: [filepath],
167
- bundle: true,
168
- keepNames: true,
169
- treeShaking: true,
170
- minifyIdentifiers: false,
171
- minifySyntax: false,
172
- minifyWhitespace: false,
173
- platform: "node",
174
- target: "es2022",
175
- format: "esm",
176
- outfile: compiledFilepath,
177
- });
178
- } catch (error) {
179
- error.message = `TypeScript Error in ${filepath}:\n${error.message}`;
180
- throw error;
181
- }
182
- return await import(compiledFilepath);
183
- }
@@ -1,64 +0,0 @@
1
- import express from "express";
2
- import { Server } from "node:http";
3
- import { createServer as createViteServer } from "vite";
4
-
5
- import { createGraphQLServer } from "../lib/oas/graphql/index.js";
6
- import { getAppMainTsxPath, getViteConfig } from "./config.js";
7
- import { getDevHtml } from "./html.js";
8
-
9
- export class DevServer {
10
- private server: Server | undefined;
11
-
12
- constructor(private options: { port: number; dir: string }) {}
13
-
14
- async start() {
15
- const app = express();
16
-
17
- const viteConfig = await getViteConfig({
18
- dir: this.options.dir,
19
- mode: "dev",
20
- });
21
-
22
- const vite = await createViteServer(viteConfig);
23
-
24
- const graphql = createGraphQLServer({
25
- graphqlEndpoint: "/__z/graphql",
26
- });
27
-
28
- app.use(graphql.graphqlEndpoint, graphql);
29
- app.use(vite.middlewares);
30
-
31
- app.use("*", async (req, res) => {
32
- try {
33
- const entryJs = getAppMainTsxPath();
34
- const rawHtml = getDevHtml(entryJs);
35
- const indexHtml = await vite.transformIndexHtml(req.url, rawHtml);
36
-
37
- // Send the transformed index.html back to the client
38
- res.status(200).set({ "Content-Type": "text/html" }).end(indexHtml);
39
- } catch (e) {
40
- vite.ssrFixStacktrace(e);
41
- console.error(e);
42
- res.status(500).end(e.message);
43
- }
44
- });
45
-
46
- return new Promise<void>((resolve) => {
47
- this.server = app.listen(this.options.port, resolve);
48
- });
49
- }
50
-
51
- async stop() {
52
- if (this.server) {
53
- return new Promise<void>((resolve, reject) => {
54
- this.server!.close((err) => {
55
- if (err) {
56
- reject(err);
57
- } else {
58
- resolve();
59
- }
60
- });
61
- });
62
- }
63
- }
64
- }
package/src/vite/html.ts DELETED
@@ -1,37 +0,0 @@
1
- export function getDevHtml(jsEntry: string) {
2
- return `<!doctype html>
3
- <html lang="en" class="dark">
4
- <head>
5
- <meta charset="UTF-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- </head>
8
- <body>
9
- <div id="root"></div>
10
- <script type="module" src="${jsEntry}"></script>
11
- </body>
12
- </html>
13
- `;
14
- }
15
-
16
- export function getBuildHtml({
17
- jsEntry,
18
- cssEntry,
19
- }: {
20
- jsEntry: string;
21
- cssEntry: string;
22
- }) {
23
- return `<!doctype html>
24
- <html lang="en">
25
- <head>
26
- <meta charset="UTF-8" />
27
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
28
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
29
- <title>Vite + React + TS</title>
30
- <script type="module" crossorigin src="${jsEntry}"></script>
31
- <link rel="stylesheet" crossorigin href="${cssEntry}">
32
- </head>
33
- <body>
34
- <div id="root"></div>
35
- </body>
36
- </html>`;
37
- }
@@ -1,57 +0,0 @@
1
- import { Plugin } from "vite";
2
- import { ZudokuPluginOptions } from "../config/config.js";
3
- import { getConfigExportCode } from "./plugin-config.js";
4
-
5
- const viteApiPlugin = (config: ZudokuPluginOptions): Plugin => {
6
- const virtualModuleId = "virtual:zudoku-api-plugins";
7
- const resolvedVirtualModuleId = "\0" + virtualModuleId;
8
-
9
- return {
10
- name: "vite-zudoku-api-plugins",
11
- resolveId(id) {
12
- if (id === virtualModuleId) {
13
- return resolvedVirtualModuleId;
14
- }
15
- },
16
- load(id) {
17
- if (id === resolvedVirtualModuleId) {
18
- const code: string[] = [
19
- // IMPORTANT! This path here is important, we MUST resolve
20
- // files here as Typescript from the appDir
21
- getConfigExportCode(config.rootDir),
22
- `import { openApiPlugin } from "zudoku/plugins";`,
23
- `const configuredApiPlugins = [];`,
24
- ];
25
-
26
- if (config?.apis) {
27
- if (Array.isArray(config.apis)) {
28
- config.apis.forEach((c, i) => {
29
- code.push(
30
- ...[
31
- `// @ts-ignore`, // To make tests pass
32
- `configuredApiPlugins.push(openApiPlugin(config.apis?[${i}]));`,
33
- ],
34
- );
35
- });
36
- } else {
37
- code.push(
38
- ...[
39
- `// @ts-ignore`, // To make tests pass
40
- `configuredApiPlugins.push(openApiPlugin(config.apis));`,
41
- ],
42
- );
43
- }
44
- }
45
-
46
- code.push(`export { configuredApiPlugins };`);
47
-
48
- return {
49
- code: code.join("\n"),
50
- map: null,
51
- };
52
- }
53
- },
54
- };
55
- };
56
-
57
- export default viteApiPlugin;