rasengan 1.0.0-beta.5 → 1.0.0-beta.50
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/README.md +36 -0
- package/lib/esm/cli/dirname.js +14 -0
- package/lib/esm/cli/index.js +138 -0
- package/lib/esm/config/index.js +2 -0
- package/lib/esm/config/utils/define-config.js +179 -0
- package/lib/esm/config/utils/index.js +3 -0
- package/lib/esm/config/utils/load-modules.js +114 -0
- package/lib/esm/config/utils/path.js +32 -0
- package/lib/esm/core/components/index.js +150 -0
- package/lib/esm/core/index.js +1 -0
- package/lib/esm/decorators/index.js +1 -0
- package/lib/esm/decorators/route.js +20 -0
- package/lib/esm/decorators/router.js +34 -0
- package/lib/esm/entries/entry-client.js +7 -0
- package/lib/esm/entries/entry-server-stream.js +112 -0
- package/lib/esm/entries/entry-server.js +92 -0
- package/lib/{index.js → esm/index.js} +1 -2
- package/lib/esm/routing/components/index.js +112 -0
- package/lib/esm/routing/index.js +5 -0
- package/lib/esm/routing/interfaces.js +91 -0
- package/lib/esm/routing/utils/define-router.js +49 -0
- package/lib/esm/routing/utils/generate-metadata.js +86 -0
- package/lib/esm/routing/utils/generate-routes.js +278 -0
- package/lib/esm/routing/utils/index.js +3 -0
- package/lib/esm/scripts/copy-extra-files.js +29 -0
- package/lib/esm/scripts/generate-package-json.js +23 -0
- package/lib/esm/scripts/prepare-prod.js +26 -0
- package/lib/esm/scripts/refresh-hack.js +5 -0
- package/lib/esm/scripts/utils/check-os.js +7 -0
- package/lib/esm/scripts/utils/copy.js +16 -0
- package/lib/esm/server/functions/netlify/netlify/functions/api.js +232 -0
- package/lib/esm/server/functions/netlify/netlify.toml +26 -0
- package/lib/esm/server/functions/vercel/api/index.js +195 -0
- package/lib/esm/server/functions/vercel/vercel.json +16 -0
- package/lib/{server → esm/server}/utils/createFetchRequest.js +14 -9
- package/lib/esm/server/utils/createReadableStream.js +103 -0
- package/lib/{server → esm/server}/utils/getIp.js +6 -6
- package/lib/{server → esm/server}/utils/handleError.js +1 -13
- package/lib/esm/server/utils/handleRequest.js +213 -0
- package/lib/{server → esm/server}/utils/index.js +2 -1
- package/lib/esm/server/utils/log.js +121 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -0
- package/lib/tsconfig.types.tsbuildinfo +1 -0
- package/lib/types/cli/dirname.d.ts +2 -0
- package/lib/types/config/index.d.ts +2 -0
- package/lib/{config → types/config}/type.d.ts +27 -1
- package/lib/types/config/utils/define-config.d.ts +7 -0
- package/lib/types/config/utils/index.d.ts +3 -0
- package/lib/types/config/utils/load-modules.d.ts +22 -0
- package/lib/types/config/utils/path.d.ts +12 -0
- package/lib/types/core/components/index.d.ts +53 -0
- package/lib/types/core/index.d.ts +2 -0
- package/lib/types/core/types.d.ts +160 -0
- package/lib/{decorators → types/decorators}/route.d.ts +2 -1
- package/lib/{decorators → types/decorators}/router.d.ts +2 -1
- package/lib/{decorators → types/decorators}/types.d.ts +7 -3
- package/lib/types/entries/entry-server-stream.d.ts +4 -0
- package/lib/types/entries/entry-server.d.ts +13 -0
- package/lib/types/hooks/index.d.ts +0 -0
- package/lib/{index.d.ts → types/index.d.ts} +1 -1
- package/lib/{routing → types/routing}/components/index.d.ts +13 -4
- package/lib/types/routing/index.d.ts +6 -0
- package/lib/{routing → types/routing}/interfaces.d.ts +1 -2
- package/lib/types/routing/types.d.ts +88 -0
- package/lib/types/routing/utils/define-router.d.ts +8 -0
- package/lib/types/routing/utils/generate-metadata.d.ts +6 -0
- package/lib/types/routing/utils/generate-routes.d.ts +12 -0
- package/lib/types/routing/utils/index.d.ts +3 -0
- package/lib/types/scripts/copy-extra-files.d.ts +1 -0
- package/lib/types/scripts/generate-package-json.d.ts +1 -0
- package/lib/types/scripts/prepare-prod.d.ts +1 -0
- package/lib/types/scripts/refresh-hack.d.ts +1 -0
- package/lib/types/scripts/utils/check-os.d.ts +1 -0
- package/lib/types/scripts/utils/copy.d.ts +1 -0
- package/lib/types/server/functions/netlify/netlify/functions/api.d.ts +3 -0
- package/lib/{server/functions/vercel/_rasengan/server → types/server/functions/vercel/api}/index.d.ts +1 -1
- package/lib/{server → types/server}/utils/createFetchRequest.d.ts +1 -1
- package/lib/types/server/utils/createReadableStream.d.ts +11 -0
- package/lib/types/server/utils/handleRequest.d.ts +1 -0
- package/lib/{server → types/server}/utils/index.d.ts +2 -1
- package/lib/{server → types/server}/utils/log.d.ts +2 -1
- package/package.json +62 -23
- package/server.js +221 -208
- package/tsconfig.base.json +29 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +8 -0
- package/tsconfig.json +23 -20
- package/tsconfig.types.json +10 -0
- package/types/client.d.ts +27 -0
- package/vite.config.ts +103 -57
- package/lib/cli/dirname.d.ts +0 -2
- package/lib/cli/dirname.js +0 -5
- package/lib/cli/index.js +0 -100
- package/lib/config/index.d.ts +0 -58
- package/lib/config/index.js +0 -106
- package/lib/core/components/index.d.ts +0 -22
- package/lib/core/components/index.js +0 -59
- package/lib/core/index.d.ts +0 -2
- package/lib/core/index.js +0 -1
- package/lib/core/interfaces.d.ts +0 -76
- package/lib/core/interfaces.js +0 -90
- package/lib/core/types.d.ts +0 -45
- package/lib/decorators/index.d.ts +0 -2
- package/lib/decorators/index.js +0 -2
- package/lib/decorators/route.js +0 -24
- package/lib/decorators/router.js +0 -23
- package/lib/entries/entry-client.js +0 -14
- package/lib/entries/entry-server.d.ts +0 -6
- package/lib/entries/entry-server.js +0 -19
- package/lib/routing/components/index.js +0 -68
- package/lib/routing/index.d.ts +0 -3
- package/lib/routing/index.js +0 -3
- package/lib/routing/interfaces.js +0 -87
- package/lib/routing/types.d.ts +0 -4
- package/lib/routing/utils/index.d.ts +0 -40
- package/lib/routing/utils/index.js +0 -255
- package/lib/server/functions/vercel/_rasengan/server/index.js +0 -91
- package/lib/server/functions/vercel/api/index.d.ts +0 -2
- package/lib/server/functions/vercel/api/index.js +0 -91
- package/lib/server/functions/vercel/vercel.json +0 -12
- package/lib/server/utils/log.js +0 -68
- package/tsconfig.lib.json +0 -41
- package/tsconfig.node.json +0 -11
- package/types/image.d.ts +0 -44
- /package/lib/{config → esm/config}/type.js +0 -0
- /package/lib/{core → esm/core}/types.js +0 -0
- /package/lib/{decorators → esm/decorators}/types.js +0 -0
- /package/lib/{hooks → esm/hooks}/index.js +0 -0
- /package/lib/{routing → esm/routing}/types.js +0 -0
- /package/lib/{cli → types/cli}/index.d.ts +0 -0
- /package/lib/{hooks → types/decorators}/index.d.ts +0 -0
- /package/lib/{entries → types/entries}/entry-client.d.ts +0 -0
- /package/lib/{server → types/server}/utils/getIp.d.ts +0 -0
- /package/lib/{server → types/server}/utils/handleError.d.ts +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[](https://rasengan.dev)
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/rasengan)
|
|
4
|
+
[](https://www.npmjs.com/package/rasengan)
|
|
5
|
+
[](https://github.com/rasengan-dev/rasenganjs/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
## Getting Started
|
|
8
|
+
|
|
9
|
+
Based on modern tools, Rasengan.js will help you to create **high-quality web applications** with the benefit of React Components. It's a simple and easy-to-use framework that will help you to create a **beautiful and responsive web application**.
|
|
10
|
+
|
|
11
|
+
- Visit the [Rasengan.js Showcase](https://rasengan.dev/showcase) to see more sites built with Rasengan.js.
|
|
12
|
+
- Visit the [Rasengan.js Blog](https://rasengan.dev/blog) to get all news related to Rasengan.js.
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
|
|
16
|
+
Visit [https://rasengan.dev/docs](https://rasengan.dev/docs) to view the full documentation.
|
|
17
|
+
|
|
18
|
+
## Community
|
|
19
|
+
|
|
20
|
+
The Rasengan.js community can be found on [GitHub Discussions](https://github.com/rasengan-dev/rasenganjs/discussions) where you can ask questions, voice ideas, and share your projects with other people.
|
|
21
|
+
|
|
22
|
+
We also have a [Twitter](https://twitter.com/rasenganjs) account where you can follow us to get the latest news about Rasengan.js.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Rasengan.js is [MIT licensed](https://github.com/rasengan-dev/rasenganjs/blob/main/LICENSE).
|
|
27
|
+
|
|
28
|
+
## Contributing
|
|
29
|
+
|
|
30
|
+
We are open to all contributions. If you want to contribute to Rasengan.js, please read the [Contributing Guide](https://github.com/rasengan-dev/rasenganjs/blob/main/CONTRIBUTING.md) to get started.
|
|
31
|
+
|
|
32
|
+
## Authors
|
|
33
|
+
|
|
34
|
+
Here are the authors of Rasengan.js, the people who are at the origin of this great framework:
|
|
35
|
+
|
|
36
|
+
- Dilane Kombou ([**@dilanekombou**](https://twitter.com/dilanekombou))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
function getDirname() {
|
|
4
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
5
|
+
return __dirname;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
var __filename_1 = fileURLToPath(import.meta.url);
|
|
10
|
+
var __dirname_1 = dirname(__filename_1);
|
|
11
|
+
return __dirname_1;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export default getDirname();
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
import chalk from "chalk";
|
|
50
|
+
import { Command } from "commander";
|
|
51
|
+
import { execa } from "execa";
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
import path from "node:path";
|
|
54
|
+
import { resolvePath } from "../config/index.js";
|
|
55
|
+
var program = new Command();
|
|
56
|
+
program
|
|
57
|
+
.name(chalk.blue("rasengan"))
|
|
58
|
+
.version("1.0.0", "-v, --version", "Output the current version number");
|
|
59
|
+
// Handle the dev command
|
|
60
|
+
program
|
|
61
|
+
.command("dev")
|
|
62
|
+
.option("-p <port>")
|
|
63
|
+
.description("Start development server")
|
|
64
|
+
.action(function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
65
|
+
var convertedPort;
|
|
66
|
+
var port = _b.p;
|
|
67
|
+
return __generator(this, function (_c) {
|
|
68
|
+
convertedPort = Number(port);
|
|
69
|
+
// Checking port
|
|
70
|
+
if (port &&
|
|
71
|
+
(isNaN(convertedPort) || convertedPort < 0 || convertedPort > 65535)) {
|
|
72
|
+
console.log("");
|
|
73
|
+
console.log(chalk.red("Please provide a valid port number between 0-65535"));
|
|
74
|
+
console.log("");
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
execa("node", ["node_modules/rasengan/server"], {
|
|
78
|
+
stdio: "inherit",
|
|
79
|
+
env: __assign(__assign({}, process.env), { PORT: convertedPort ? convertedPort.toString() : undefined }),
|
|
80
|
+
});
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
});
|
|
83
|
+
}); });
|
|
84
|
+
// Handle the build command
|
|
85
|
+
program
|
|
86
|
+
.command("build")
|
|
87
|
+
.description("Build the project")
|
|
88
|
+
.action(function () {
|
|
89
|
+
execa("npm", ["run", "build"], {
|
|
90
|
+
cwd: "node_modules/rasengan",
|
|
91
|
+
stdio: "inherit", // Pipe child process output to the parent process
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
// Handle the prebuild command
|
|
95
|
+
program
|
|
96
|
+
.command("prepare")
|
|
97
|
+
.description("Prepare the project")
|
|
98
|
+
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
99
|
+
var configPath, appConfig, server, hostingStrategy;
|
|
100
|
+
var _a, _b;
|
|
101
|
+
return __generator(this, function (_c) {
|
|
102
|
+
switch (_c.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
// Displaying the message
|
|
105
|
+
console.log("");
|
|
106
|
+
console.log(chalk.blue("Preparing your project for production..."));
|
|
107
|
+
console.log("");
|
|
108
|
+
configPath = resolvePath(path.join(process.cwd(), "rasengan.config.js"));
|
|
109
|
+
return [4 /*yield*/, import(configPath)];
|
|
110
|
+
case 1:
|
|
111
|
+
appConfig = (_c.sent()).default;
|
|
112
|
+
return [4 /*yield*/, appConfig];
|
|
113
|
+
case 2:
|
|
114
|
+
server = (_c.sent()).server;
|
|
115
|
+
hostingStrategy = (_b = (_a = server === null || server === void 0 ? void 0 : server.production) === null || _a === void 0 ? void 0 : _a.hosting) !== null && _b !== void 0 ? _b : "custom";
|
|
116
|
+
execa("node", ["node_modules/rasengan/lib/esm/scripts/prepare-prod"], {
|
|
117
|
+
stdio: "inherit",
|
|
118
|
+
// cwd: "node_modules/rasengan/lib/esm/scripts",
|
|
119
|
+
env: __assign(__assign({}, process.env), { HOSTING_STRATEGY: hostingStrategy })
|
|
120
|
+
});
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); });
|
|
125
|
+
// Handle the start command
|
|
126
|
+
program
|
|
127
|
+
.command("start")
|
|
128
|
+
.description("Start the project in production mode")
|
|
129
|
+
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
execa("npm", ["run", "preview"], {
|
|
132
|
+
cwd: "node_modules/rasengan",
|
|
133
|
+
stdio: "inherit", // Pipe child process output to the parent process
|
|
134
|
+
});
|
|
135
|
+
return [2 /*return*/];
|
|
136
|
+
});
|
|
137
|
+
}); });
|
|
138
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
+
if (ar || !(i in from)) {
|
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
+
ar[i] = from[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Function to define the config for the app
|
|
48
|
+
* It will be used by vite.config.ts and other files in other to configure the app
|
|
49
|
+
* @param {AppConfig | AppConfigFunction | AppConfigFunctionAsync} loadedConfig
|
|
50
|
+
*/
|
|
51
|
+
export var defineConfig = function (loadedConfig) { return __awaiter(void 0, void 0, void 0, function () {
|
|
52
|
+
var config, result, server, vite, defaultViteConfig, defaultServerConfig, config_1;
|
|
53
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
54
|
+
return __generator(this, function (_k) {
|
|
55
|
+
switch (_k.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
if (!(typeof loadedConfig === "function")) return [3 /*break*/, 4];
|
|
58
|
+
result = loadedConfig();
|
|
59
|
+
if (!(result instanceof Promise)) return [3 /*break*/, 2];
|
|
60
|
+
return [4 /*yield*/, result];
|
|
61
|
+
case 1:
|
|
62
|
+
config = _k.sent(); // Await the promise result (AppConfigFunctionAsync)
|
|
63
|
+
return [3 /*break*/, 3];
|
|
64
|
+
case 2:
|
|
65
|
+
config = result; // Synchronous function result (AppConfigFunction)
|
|
66
|
+
_k.label = 3;
|
|
67
|
+
case 3: return [3 /*break*/, 5];
|
|
68
|
+
case 4:
|
|
69
|
+
config = loadedConfig;
|
|
70
|
+
_k.label = 5;
|
|
71
|
+
case 5:
|
|
72
|
+
server = config.server, vite = config.vite;
|
|
73
|
+
defaultViteConfig = {
|
|
74
|
+
plugins: (vite === null || vite === void 0 ? void 0 : vite.plugins) || [],
|
|
75
|
+
optimizeDeps: {
|
|
76
|
+
exclude: ((_a = vite === null || vite === void 0 ? void 0 : vite.optimizeDeps) === null || _a === void 0 ? void 0 : _a.exclude) || [],
|
|
77
|
+
include: ((_b = vite === null || vite === void 0 ? void 0 : vite.optimizeDeps) === null || _b === void 0 ? void 0 : _b.include) || [],
|
|
78
|
+
},
|
|
79
|
+
css: {
|
|
80
|
+
postcss: ((_c = vite === null || vite === void 0 ? void 0 : vite.css) === null || _c === void 0 ? void 0 : _c.postcss) || undefined,
|
|
81
|
+
},
|
|
82
|
+
build: {
|
|
83
|
+
external: ((_d = vite === null || vite === void 0 ? void 0 : vite.build) === null || _d === void 0 ? void 0 : _d.external) || [],
|
|
84
|
+
},
|
|
85
|
+
resolve: {
|
|
86
|
+
symbole: ((_e = vite === null || vite === void 0 ? void 0 : vite.resolve) === null || _e === void 0 ? void 0 : _e.symbole) || "@",
|
|
87
|
+
alias: ((_f = vite === null || vite === void 0 ? void 0 : vite.resolve) === null || _f === void 0 ? void 0 : _f.alias) || [],
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
defaultServerConfig = {
|
|
91
|
+
development: {
|
|
92
|
+
port: ((_g = server === null || server === void 0 ? void 0 : server.development) === null || _g === void 0 ? void 0 : _g.port) || undefined,
|
|
93
|
+
open: ((_h = server === null || server === void 0 ? void 0 : server.development) === null || _h === void 0 ? void 0 : _h.open) || false,
|
|
94
|
+
},
|
|
95
|
+
production: {
|
|
96
|
+
hosting: ((_j = server === null || server === void 0 ? void 0 : server.production) === null || _j === void 0 ? void 0 : _j.hosting) || "custom",
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
config_1 = {
|
|
101
|
+
server: defaultServerConfig,
|
|
102
|
+
vite: {
|
|
103
|
+
plugins: defaultViteConfig.plugins,
|
|
104
|
+
optimizeDeps: {
|
|
105
|
+
exclude: __spreadArray([
|
|
106
|
+
"node:http",
|
|
107
|
+
"node-fetch"
|
|
108
|
+
], defaultViteConfig.optimizeDeps.exclude, true),
|
|
109
|
+
include: __spreadArray([
|
|
110
|
+
"react-fast-compare",
|
|
111
|
+
"invariant",
|
|
112
|
+
"shallowequal",
|
|
113
|
+
"react-dom/client",
|
|
114
|
+
"react-dom",
|
|
115
|
+
"react",
|
|
116
|
+
"react-router-dom",
|
|
117
|
+
"react-helmet-async"
|
|
118
|
+
], defaultViteConfig.optimizeDeps.include, true),
|
|
119
|
+
},
|
|
120
|
+
css: {
|
|
121
|
+
postcss: defaultViteConfig.css.postcss,
|
|
122
|
+
},
|
|
123
|
+
build: {
|
|
124
|
+
external: defaultViteConfig.build.external,
|
|
125
|
+
},
|
|
126
|
+
resolve: {
|
|
127
|
+
// concat two arrays
|
|
128
|
+
alias: __spreadArray([
|
|
129
|
+
{
|
|
130
|
+
find: defaultViteConfig.resolve.symbole,
|
|
131
|
+
replacement: "./src",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
find: "path",
|
|
135
|
+
replacement: "node_modules/path-browserify",
|
|
136
|
+
}
|
|
137
|
+
], defaultViteConfig.resolve.alias, true),
|
|
138
|
+
},
|
|
139
|
+
appType: "custom",
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
return [2 /*return*/, config_1];
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return [2 /*return*/, {
|
|
146
|
+
vite: {
|
|
147
|
+
optimizeDeps: {
|
|
148
|
+
exclude: ["node:http", "node-fetch"],
|
|
149
|
+
include: [
|
|
150
|
+
"react-fast-compare",
|
|
151
|
+
"invariant",
|
|
152
|
+
"shallowequal",
|
|
153
|
+
"react-dom/client",
|
|
154
|
+
"react-dom",
|
|
155
|
+
"react",
|
|
156
|
+
"react-router-dom",
|
|
157
|
+
"react-helmet-async",
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
appType: "custom",
|
|
161
|
+
resolve: {
|
|
162
|
+
alias: [
|
|
163
|
+
{
|
|
164
|
+
find: "@",
|
|
165
|
+
replacement: "./src",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
find: "path",
|
|
169
|
+
replacement: "node_modules/path-browserify",
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
}];
|
|
175
|
+
}
|
|
176
|
+
return [2 /*return*/];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}); };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Asynchronously loads a module from a file path.
|
|
39
|
+
*
|
|
40
|
+
* @param path - The path to the module.
|
|
41
|
+
* @returns The loaded module.
|
|
42
|
+
*/
|
|
43
|
+
export var loadModule = function (path) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
+
var module_1, error_1;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
_a.trys.push([0, 2, , 3]);
|
|
49
|
+
return [4 /*yield*/, import(path)];
|
|
50
|
+
case 1:
|
|
51
|
+
module_1 = _a.sent();
|
|
52
|
+
return [2 /*return*/, module_1];
|
|
53
|
+
case 2:
|
|
54
|
+
error_1 = _a.sent();
|
|
55
|
+
throw new Error(error_1);
|
|
56
|
+
case 3: return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); };
|
|
60
|
+
/**
|
|
61
|
+
* Asynchronously loads a module from a file path only in the server-side environment.
|
|
62
|
+
*
|
|
63
|
+
* @param path - The path to the module.
|
|
64
|
+
* @returns The loaded module.
|
|
65
|
+
*/
|
|
66
|
+
export var loadModuleSSR = function (path) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var module_2, error_2;
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
_a.trys.push([0, 3, , 4]);
|
|
72
|
+
if (!(typeof window === "undefined")) return [3 /*break*/, 2];
|
|
73
|
+
return [4 /*yield*/, loadModule(path)];
|
|
74
|
+
case 1:
|
|
75
|
+
module_2 = _a.sent();
|
|
76
|
+
return [2 /*return*/, module_2];
|
|
77
|
+
case 2: return [2 /*return*/, {}];
|
|
78
|
+
case 3:
|
|
79
|
+
error_2 = _a.sent();
|
|
80
|
+
throw new Error(error_2);
|
|
81
|
+
case 4: return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); };
|
|
85
|
+
/**
|
|
86
|
+
* Asynchronously loads a module from a file path relative to the project root directory.
|
|
87
|
+
*
|
|
88
|
+
* This function checks the current environment (production or development) and adjusts the file path accordingly. It then resolves the file path to a valid URL format based on the operating system.
|
|
89
|
+
*
|
|
90
|
+
* @param filename - The name of the file to be loaded.
|
|
91
|
+
* @returns The loaded module.
|
|
92
|
+
*/
|
|
93
|
+
// export const loadAsyncFromRoot = async (filename: string) => {
|
|
94
|
+
// try {
|
|
95
|
+
// const isProduction = process.env.NODE_ENV === "production";
|
|
96
|
+
// let __pathToRoot = "";
|
|
97
|
+
// if (!isProduction) {
|
|
98
|
+
// __pathToRoot = process.cwd();
|
|
99
|
+
// } else {
|
|
100
|
+
// __pathToRoot = path.join(process.cwd(), "./../../");
|
|
101
|
+
// }
|
|
102
|
+
// const filePath = resolvePath(path.join(__pathToRoot, filename));
|
|
103
|
+
// const file = await import(`./${filePath}`);
|
|
104
|
+
// return file;
|
|
105
|
+
// } catch (error) {
|
|
106
|
+
// console.error(error);
|
|
107
|
+
// return {};
|
|
108
|
+
// }
|
|
109
|
+
// }
|
|
110
|
+
// export const getDirname = (url: string) => {
|
|
111
|
+
// // Get directory name
|
|
112
|
+
// const __dirname = dirname(fileURLToPath(url));
|
|
113
|
+
// return __dirname;
|
|
114
|
+
// }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to adapt the path for dev and prod
|
|
3
|
+
* @param {string | Array<string>} paths
|
|
4
|
+
*/
|
|
5
|
+
export var adaptPath = function (paths) {
|
|
6
|
+
// Check if we are in dev mode or prod
|
|
7
|
+
var isProduction = process.env.NODE_ENV === "production";
|
|
8
|
+
var prefix = isProduction ? "./../../" : "";
|
|
9
|
+
// Chech if the path is an array
|
|
10
|
+
var isArray = Array.isArray(paths);
|
|
11
|
+
// If the path is an array
|
|
12
|
+
if (isArray) {
|
|
13
|
+
return paths.map(function (path) { return "".concat(process.cwd(), "/").concat(prefix).concat(path); });
|
|
14
|
+
}
|
|
15
|
+
// If the path is a string
|
|
16
|
+
return "".concat(process.cwd(), "/").concat(prefix).concat(paths);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Adapts the provided file path to a valid URL format based on the operating system.
|
|
20
|
+
*
|
|
21
|
+
* @param path - The file path to be adapted.
|
|
22
|
+
* @returns The adapted file path in a valid URL format.
|
|
23
|
+
*/
|
|
24
|
+
export var resolvePath = function (path) {
|
|
25
|
+
// Check the OS
|
|
26
|
+
var isWindows = process.platform === "win32";
|
|
27
|
+
// Adapt the path
|
|
28
|
+
if (isWindows) {
|
|
29
|
+
return "file:///".concat(path);
|
|
30
|
+
}
|
|
31
|
+
return path;
|
|
32
|
+
};
|