rasengan 1.0.0-beta.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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/lib/cli/dirname.d.ts +2 -0
  3. package/lib/cli/dirname.js +6 -0
  4. package/lib/cli/dirname.js.map +1 -0
  5. package/lib/cli/index.d.ts +2 -0
  6. package/lib/cli/index.js +101 -0
  7. package/lib/cli/index.js.map +1 -0
  8. package/lib/config/index.d.ts +39 -0
  9. package/lib/config/index.js +57 -0
  10. package/lib/config/index.js.map +1 -0
  11. package/lib/config/type.d.ts +68 -0
  12. package/lib/config/type.js +2 -0
  13. package/lib/config/type.js.map +1 -0
  14. package/lib/core/components/index.d.ts +26 -0
  15. package/lib/core/components/index.js +72 -0
  16. package/lib/core/components/index.js.map +1 -0
  17. package/lib/core/index.d.ts +2 -0
  18. package/lib/core/index.js +2 -0
  19. package/lib/core/index.js.map +1 -0
  20. package/lib/core/interfaces.d.ts +76 -0
  21. package/lib/core/interfaces.js +91 -0
  22. package/lib/core/interfaces.js.map +1 -0
  23. package/lib/core/types.d.ts +45 -0
  24. package/lib/core/types.js +2 -0
  25. package/lib/core/types.js.map +1 -0
  26. package/lib/decorators/index.d.ts +2 -0
  27. package/lib/decorators/index.js +3 -0
  28. package/lib/decorators/index.js.map +1 -0
  29. package/lib/decorators/route.d.ts +7 -0
  30. package/lib/decorators/route.js +25 -0
  31. package/lib/decorators/route.js.map +1 -0
  32. package/lib/decorators/router.d.ts +7 -0
  33. package/lib/decorators/router.js +24 -0
  34. package/lib/decorators/router.js.map +1 -0
  35. package/lib/decorators/types.d.ts +47 -0
  36. package/lib/decorators/types.js +2 -0
  37. package/lib/decorators/types.js.map +1 -0
  38. package/lib/entries/entry-client.d.ts +1 -0
  39. package/lib/entries/entry-client.js +15 -0
  40. package/lib/entries/entry-client.js.map +1 -0
  41. package/lib/entries/entry-server.d.ts +6 -0
  42. package/lib/entries/entry-server.js +20 -0
  43. package/lib/entries/entry-server.js.map +1 -0
  44. package/lib/hooks/index.d.ts +0 -0
  45. package/lib/hooks/index.js +1 -0
  46. package/lib/hooks/index.js.map +1 -0
  47. package/lib/index.d.ts +6 -0
  48. package/lib/index.js +10 -0
  49. package/lib/index.js.map +1 -0
  50. package/lib/routing/components/index.d.ts +32 -0
  51. package/lib/routing/components/index.js +69 -0
  52. package/lib/routing/components/index.js.map +1 -0
  53. package/lib/routing/index.d.ts +3 -0
  54. package/lib/routing/index.js +4 -0
  55. package/lib/routing/index.js.map +1 -0
  56. package/lib/routing/interfaces.d.ts +67 -0
  57. package/lib/routing/interfaces.js +88 -0
  58. package/lib/routing/interfaces.js.map +1 -0
  59. package/lib/routing/types.d.ts +4 -0
  60. package/lib/routing/types.js +2 -0
  61. package/lib/routing/types.js.map +1 -0
  62. package/lib/routing/utils/index.d.ts +40 -0
  63. package/lib/routing/utils/index.js +256 -0
  64. package/lib/routing/utils/index.js.map +1 -0
  65. package/lib/server/functions/vercel/api/index.d.ts +2 -0
  66. package/lib/server/functions/vercel/api/index.js +91 -0
  67. package/lib/server/functions/vercel/api/index.js.map +1 -0
  68. package/lib/server/functions/vercel/vercel.json +12 -0
  69. package/lib/server/utils/createFetchRequest.d.ts +5 -0
  70. package/lib/server/utils/createFetchRequest.js +34 -0
  71. package/lib/server/utils/createFetchRequest.js.map +1 -0
  72. package/lib/server/utils/getIp.d.ts +1 -0
  73. package/lib/server/utils/getIp.js +30 -0
  74. package/lib/server/utils/getIp.js.map +1 -0
  75. package/lib/server/utils/handleError.d.ts +2 -0
  76. package/lib/server/utils/handleError.js +28 -0
  77. package/lib/server/utils/handleError.js.map +1 -0
  78. package/lib/server/utils/index.d.ts +5 -0
  79. package/lib/server/utils/index.js +8 -0
  80. package/lib/server/utils/index.js.map +1 -0
  81. package/lib/server/utils/log.d.ts +6 -0
  82. package/lib/server/utils/log.js +69 -0
  83. package/lib/server/utils/log.js.map +1 -0
  84. package/package.json +75 -0
  85. package/server.js +229 -0
  86. package/src/cli/dirname.ts +7 -0
  87. package/src/cli/index.ts +134 -0
  88. package/src/config/index.ts +67 -0
  89. package/src/config/type.ts +76 -0
  90. package/src/core/components/index.tsx +111 -0
  91. package/src/core/index.ts +14 -0
  92. package/src/core/interfaces.tsx +129 -0
  93. package/src/core/types.ts +43 -0
  94. package/src/decorators/index.ts +2 -0
  95. package/src/decorators/route.ts +32 -0
  96. package/src/decorators/router.ts +30 -0
  97. package/src/decorators/types.ts +54 -0
  98. package/src/entries/entry-client.tsx +33 -0
  99. package/src/entries/entry-server.tsx +50 -0
  100. package/src/hooks/index.ts +0 -0
  101. package/src/index.ts +11 -0
  102. package/src/routing/components/index.tsx +125 -0
  103. package/src/routing/index.ts +23 -0
  104. package/src/routing/interfaces.ts +105 -0
  105. package/src/routing/types.ts +3 -0
  106. package/src/routing/utils/index.tsx +342 -0
  107. package/src/server/functions/vercel/api/index.ts +122 -0
  108. package/src/server/functions/vercel/vercel.json +12 -0
  109. package/src/server/utils/createFetchRequest.ts +40 -0
  110. package/src/server/utils/getIp.ts +37 -0
  111. package/src/server/utils/handleError.ts +36 -0
  112. package/src/server/utils/index.ts +15 -0
  113. package/src/server/utils/log.ts +115 -0
  114. package/src/vite-env.d.ts +1 -0
  115. package/tsconfig.json +30 -0
  116. package/tsconfig.lib.json +41 -0
  117. package/tsconfig.node.json +11 -0
  118. package/vite.config.ts +45 -0
@@ -0,0 +1,115 @@
1
+ import chalk from "chalk";
2
+ import ora from "ora";
3
+ import fs from "fs/promises";
4
+ // @ts-ignore
5
+ import keypress from "keypress";
6
+ import { getIP } from "./index.js";
7
+
8
+ /**
9
+ * Log server info after the server is started
10
+ * @param {number} port The port the server is running on
11
+ * @param {boolean} isProduction Whether the server is running in production mode
12
+ */
13
+ export async function logServerInfo(port: number, isProduction: boolean) {
14
+ // Constants
15
+ const arrowRight = "\u2192";
16
+
17
+ // Spinner
18
+ console.log("");
19
+ const spinner = ora({
20
+ text: `Starting server in ${
21
+ isProduction ? "production" : "development"
22
+ } mode...`,
23
+ color: "blue",
24
+ spinner: "dots",
25
+ }).start();
26
+
27
+ // Getting the package.json file
28
+ let packageJson;
29
+ if (!isProduction) {
30
+ packageJson = await fs.readFile(
31
+ "node_modules/rasengan/package.json",
32
+ "utf-8"
33
+ );
34
+ } else {
35
+ packageJson = await fs.readFile("package.json", "utf-8");
36
+ }
37
+
38
+ // Parsing the package.json file
39
+ const parsedPackageJson = JSON.parse(packageJson);
40
+
41
+ spinner.succeed(
42
+ `${chalk.bold.blue(
43
+ `Rasengan v${parsedPackageJson["version"]}`
44
+ )} is running 🚀`
45
+ );
46
+
47
+ console.log("\n\n");
48
+
49
+ process.stdout.write(
50
+ `${chalk.bold.green(arrowRight)} ${chalk.bold("Local:")} ${chalk.blue(
51
+ `http://localhost:${chalk.bold(port)}`
52
+ )}`
53
+ );
54
+ console.log("");
55
+
56
+ // Get the IP address of the machine
57
+ const ipAddress = getIP();
58
+
59
+ if (ipAddress) {
60
+ process.stdout.write(
61
+ `${chalk.bold.green(arrowRight)} ${chalk.bold("Network:")} ${chalk.blue(
62
+ `http://${getIP()}:${chalk.bold(port)}`
63
+ )}\n`
64
+ );
65
+ }
66
+
67
+ // Display options
68
+ process.stdout.write(
69
+ `${chalk.bold.green(arrowRight)} ${chalk.gray("Use")} ${chalk.bold(
70
+ "-p <PORT>"
71
+ )} ${chalk.gray("to specify a custom port")}\n`
72
+ );
73
+ process.stdout.write(
74
+ `${chalk.bold.green(arrowRight)} ${chalk.gray("Press")} ${chalk.bold(
75
+ "c"
76
+ )} ${chalk.gray("to clear")}\n`
77
+ );
78
+ process.stdout.write(
79
+ `${chalk.bold.green(arrowRight)} ${chalk.gray("Press")} ${chalk.bold(
80
+ "ctrl + c"
81
+ )} ${chalk.gray("to close the server")}\n`
82
+ );
83
+
84
+ console.log("\n");
85
+
86
+ // Enable keypress events on the process.stdin stream
87
+ keypress(process.stdin);
88
+
89
+ // Listen on user keyboard input on the terminal
90
+ process.stdin.on("keypress", (_: string, key: any) => {
91
+ // Check if the key pressed is 'c'
92
+ if (key) {
93
+ if (key.name === "c" && key.ctrl) {
94
+ console.log(
95
+ `${chalk.green("ctrl + c")} ${chalk.gray("pressed: ")} ${chalk.blue(
96
+ "Closing server... \n\n"
97
+ )}`
98
+ );
99
+ process.exit(0);
100
+ } else if (key.name === "c" && !key.ctrl && !key.meta && !key.shift) {
101
+ // Clear terminal
102
+ process.stdout.write("\x1Bc");
103
+
104
+ logServerInfo(port, isProduction);
105
+ }
106
+ }
107
+ });
108
+
109
+ // Allow the process to exit when Ctrl+C is pressed
110
+ process.stdin.setRawMode(true);
111
+ process.stdin.resume();
112
+
113
+ // Set a higher limit for the number of listeners
114
+ process.stdin.setMaxListeners(100);
115
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react-jsx",
16
+ "composite": true,
17
+
18
+ /* Linting */
19
+ "strict": true,
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+
24
+ /* Plugins */
25
+ "plugins": [{ "name": "typescript-plugin-css-modules" }],
26
+ },
27
+ "include": ["src", "server.js", "types"],
28
+
29
+ "references": [{ "path": "./tsconfig.node.json" }]
30
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "lib",
4
+ "rootDir": "src",
5
+ "target": "ESNext",
6
+ "lib": [
7
+ "ES2015",
8
+ "ESNext",
9
+ "dom",
10
+ "dom.iterable",
11
+ "esnext"
12
+ ],
13
+ "allowJs": true,
14
+ "skipLibCheck": true,
15
+ "esModuleInterop": true,
16
+ "allowSyntheticDefaultImports": true,
17
+ "strict": false,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "noFallthroughCasesInSwitch": true,
20
+ "module": "ESNext",
21
+ "moduleResolution": "node",
22
+ "resolveJsonModule": true,
23
+ "isolatedModules": true,
24
+ "noEmit": false,
25
+ "jsx": "react-jsx",
26
+ "declaration": true,
27
+ "sourceMap": true,
28
+
29
+ /* Plugins */
30
+ "plugins": [{ "name": "typescript-plugin-css-modules" }],
31
+
32
+ /* Types */
33
+ "typeRoots": ["node_modules/@types", "types"]
34
+ },
35
+ "include": [
36
+ "src",
37
+ "types",
38
+ "src/**/*.json",
39
+ ],
40
+ "exclude": ["node_modules", "lib"]
41
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true,
8
+ "jsx": "preserve"
9
+ },
10
+ "include": ["vite.config.ts", "src/entries/entry-server.tsx", "src/vite-env.d.ts"]
11
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+
4
+ // Load rasengan config file
5
+ // @ts-ignore
6
+ import config from "./../../rasengan.config.js";
7
+
8
+ // Extract vite config
9
+ const { vite } = config;
10
+
11
+ export default defineConfig({
12
+ plugins: [react(), ...vite?.plugins],
13
+
14
+ // define index.html location
15
+ root: "./../../",
16
+ optimizeDeps: {
17
+ exclude: [
18
+ "node:http",
19
+ "node-fetch",
20
+ ...vite?.optimizeDeps?.exclude,
21
+ ],
22
+ },
23
+
24
+ build: {
25
+ sourcemap: true,
26
+ rollupOptions: {
27
+ external: vite?.build?.external,
28
+ },
29
+ },
30
+
31
+ ssr: {
32
+ // Ignore CSS files
33
+ noExternal: [/\.css$/],
34
+ },
35
+
36
+ css: {
37
+ modules: {
38
+ localsConvention: "camelCaseOnly",
39
+ },
40
+
41
+ postcss: vite?.css?.postcss,
42
+ },
43
+
44
+ appType: vite.appType,
45
+ });