vector-framework 0.9.1 → 0.9.2
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/dist/cli/index.js +23 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/cli.js +83 -234
- package/package.json +2 -2
- package/src/cli/index.ts +23 -10
package/dist/cli/index.js
CHANGED
|
@@ -3,8 +3,10 @@ import { watch } from "node:fs";
|
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
import { getVectorInstance } from "../core/vector";
|
|
5
5
|
import { ConfigLoader } from "../core/config-loader";
|
|
6
|
+
// Compatibility layer for both Node and Bun
|
|
7
|
+
const args = typeof Bun !== 'undefined' ? Bun.argv.slice(2) : process.argv.slice(2);
|
|
6
8
|
const { values, positionals } = parseArgs({
|
|
7
|
-
args
|
|
9
|
+
args,
|
|
8
10
|
options: {
|
|
9
11
|
port: {
|
|
10
12
|
type: "string",
|
|
@@ -161,15 +163,26 @@ async function runBuild() {
|
|
|
161
163
|
const routes = await scanner.scan();
|
|
162
164
|
await generator.generate(routes);
|
|
163
165
|
console.log(` Generated ${routes.length} routes`);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
166
|
+
// Use spawn based on runtime
|
|
167
|
+
if (typeof Bun !== 'undefined') {
|
|
168
|
+
const buildProcess = Bun.spawn([
|
|
169
|
+
"bun",
|
|
170
|
+
"build",
|
|
171
|
+
"src/index.ts",
|
|
172
|
+
"--outdir",
|
|
173
|
+
"dist",
|
|
174
|
+
"--minify",
|
|
175
|
+
]);
|
|
176
|
+
await buildProcess.exited;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// For Node.js, use child_process
|
|
180
|
+
const { spawnSync } = await import('child_process');
|
|
181
|
+
spawnSync('bun', ['build', 'src/index.ts', '--outdir', 'dist', '--minify'], {
|
|
182
|
+
stdio: 'inherit',
|
|
183
|
+
shell: true
|
|
184
|
+
});
|
|
185
|
+
}
|
|
173
186
|
console.log("\n ✓ Build complete\n");
|
|
174
187
|
}
|
|
175
188
|
catch (error) {
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,4CAA4C;AAC5C,MAAM,IAAI,GAAG,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEpF,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;IACxC,IAAI;IACJ,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,MAAM;SAChB;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,WAAW;SACrB;QACD,MAAM,EAAE;YACN,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G,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,QAAQ,OAAO,EAAE,CAAC;IAChB,KAAK,KAAK;QACR,MAAM,MAAM,EAAE,CAAC;QACf,MAAM;IACR,KAAK,OAAO;QACV,MAAM,QAAQ,EAAE,CAAC;QACjB,MAAM;IACR,KAAK,OAAO;QACV,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC;QACpC,MAAM,MAAM,EAAE,CAAC;QACf,MAAM;IACR;QACE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;CAcf,CAAC,CAAC;QACC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
5
19
|
var __export = (target, all) => {
|
|
6
20
|
for (var name in all)
|
|
7
21
|
__defProp(target, name, {
|
|
@@ -12,7 +26,7 @@ var __export = (target, all) => {
|
|
|
12
26
|
});
|
|
13
27
|
};
|
|
14
28
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
15
|
-
var __require =
|
|
29
|
+
var __require = import.meta.require;
|
|
16
30
|
|
|
17
31
|
// src/auth/protected.ts
|
|
18
32
|
class AuthManager {
|
|
@@ -219,8 +233,12 @@ var init_manager = __esm(() => {
|
|
|
219
233
|
});
|
|
220
234
|
|
|
221
235
|
// src/dev/route-generator.ts
|
|
222
|
-
|
|
223
|
-
|
|
236
|
+
var exports_route_generator = {};
|
|
237
|
+
__export(exports_route_generator, {
|
|
238
|
+
RouteGenerator: () => RouteGenerator
|
|
239
|
+
});
|
|
240
|
+
import { promises as fs } from "fs";
|
|
241
|
+
import { dirname, relative } from "path";
|
|
224
242
|
|
|
225
243
|
class RouteGenerator {
|
|
226
244
|
outputPath;
|
|
@@ -298,8 +316,12 @@ ${routeEntries.join(`,
|
|
|
298
316
|
var init_route_generator = () => {};
|
|
299
317
|
|
|
300
318
|
// src/dev/route-scanner.ts
|
|
301
|
-
|
|
302
|
-
|
|
319
|
+
var exports_route_scanner = {};
|
|
320
|
+
__export(exports_route_scanner, {
|
|
321
|
+
RouteScanner: () => RouteScanner
|
|
322
|
+
});
|
|
323
|
+
import { existsSync, promises as fs2 } from "fs";
|
|
324
|
+
import { join, relative as relative2, resolve, sep } from "path";
|
|
303
325
|
|
|
304
326
|
class RouteScanner {
|
|
305
327
|
routesDir;
|
|
@@ -309,19 +331,19 @@ class RouteScanner {
|
|
|
309
331
|
async scan() {
|
|
310
332
|
const routes = [];
|
|
311
333
|
if (!existsSync(this.routesDir)) {
|
|
312
|
-
console.log(`
|
|
313
|
-
console.log("
|
|
334
|
+
console.log(` \u2192 Routes directory not found: ${this.routesDir}`);
|
|
335
|
+
console.log(" \u2192 No routes will be auto-discovered");
|
|
314
336
|
return [];
|
|
315
337
|
}
|
|
316
338
|
try {
|
|
317
|
-
console.log(`
|
|
339
|
+
console.log(` \u2192 Scanning routes from: ${this.routesDir}`);
|
|
318
340
|
await this.scanDirectory(this.routesDir, routes);
|
|
319
341
|
if (routes.length > 0) {
|
|
320
|
-
console.log(`
|
|
342
|
+
console.log(` \u2713 Found ${routes.length} route${routes.length === 1 ? "" : "s"}`);
|
|
321
343
|
}
|
|
322
344
|
} catch (error) {
|
|
323
345
|
if (error.code === "ENOENT") {
|
|
324
|
-
console.warn(`
|
|
346
|
+
console.warn(` \u2717 Routes directory not accessible: ${this.routesDir}`);
|
|
325
347
|
return [];
|
|
326
348
|
}
|
|
327
349
|
throw error;
|
|
@@ -794,7 +816,7 @@ class VectorServer {
|
|
|
794
816
|
return new Response("Internal Server Error", { status: 500 });
|
|
795
817
|
}
|
|
796
818
|
});
|
|
797
|
-
console.log(
|
|
819
|
+
console.log(`\u2192 Vector server running at http://${hostname}:${port}`);
|
|
798
820
|
return this.server;
|
|
799
821
|
}
|
|
800
822
|
stop() {
|
|
@@ -823,202 +845,7 @@ var init_server = __esm(() => {
|
|
|
823
845
|
init_itty_router();
|
|
824
846
|
});
|
|
825
847
|
|
|
826
|
-
// src/dev/route-scanner.ts
|
|
827
|
-
var exports_route_scanner = {};
|
|
828
|
-
__export(exports_route_scanner, {
|
|
829
|
-
RouteScanner: () => RouteScanner2
|
|
830
|
-
});
|
|
831
|
-
import { existsSync as existsSync3, promises as fs3 } from "node:fs";
|
|
832
|
-
import { join as join2, relative as relative3, resolve as resolve3, sep as sep2 } from "node:path";
|
|
833
|
-
|
|
834
|
-
class RouteScanner2 {
|
|
835
|
-
routesDir;
|
|
836
|
-
constructor(routesDir = "./routes") {
|
|
837
|
-
this.routesDir = resolve3(process.cwd(), routesDir);
|
|
838
|
-
}
|
|
839
|
-
async scan() {
|
|
840
|
-
const routes = [];
|
|
841
|
-
if (!existsSync3(this.routesDir)) {
|
|
842
|
-
console.log(` → Routes directory not found: ${this.routesDir}`);
|
|
843
|
-
console.log(" → No routes will be auto-discovered");
|
|
844
|
-
return [];
|
|
845
|
-
}
|
|
846
|
-
try {
|
|
847
|
-
console.log(` → Scanning routes from: ${this.routesDir}`);
|
|
848
|
-
await this.scanDirectory(this.routesDir, routes);
|
|
849
|
-
if (routes.length > 0) {
|
|
850
|
-
console.log(` ✓ Found ${routes.length} route${routes.length === 1 ? "" : "s"}`);
|
|
851
|
-
}
|
|
852
|
-
} catch (error) {
|
|
853
|
-
if (error.code === "ENOENT") {
|
|
854
|
-
console.warn(` ✗ Routes directory not accessible: ${this.routesDir}`);
|
|
855
|
-
return [];
|
|
856
|
-
}
|
|
857
|
-
throw error;
|
|
858
|
-
}
|
|
859
|
-
return routes;
|
|
860
|
-
}
|
|
861
|
-
async scanDirectory(dir, routes, basePath = "") {
|
|
862
|
-
const entries = await fs3.readdir(dir);
|
|
863
|
-
for (const entry of entries) {
|
|
864
|
-
const fullPath = join2(dir, entry);
|
|
865
|
-
const stats = await fs3.stat(fullPath);
|
|
866
|
-
if (stats.isDirectory()) {
|
|
867
|
-
const newBasePath = basePath ? `${basePath}/${entry}` : entry;
|
|
868
|
-
await this.scanDirectory(fullPath, routes, newBasePath);
|
|
869
|
-
} else if (entry.endsWith(".ts") || entry.endsWith(".js")) {
|
|
870
|
-
const routePath = relative3(this.routesDir, fullPath).replace(/\.(ts|js)$/, "").split(sep2).join("/");
|
|
871
|
-
try {
|
|
872
|
-
const importPath = process.platform === "win32" ? `file:///${fullPath.replace(/\\/g, "/")}` : fullPath;
|
|
873
|
-
const module = await import(importPath);
|
|
874
|
-
if (module.default && typeof module.default === "function") {
|
|
875
|
-
routes.push({
|
|
876
|
-
name: "default",
|
|
877
|
-
path: fullPath,
|
|
878
|
-
method: "GET",
|
|
879
|
-
options: {
|
|
880
|
-
method: "GET",
|
|
881
|
-
path: `/${routePath}`,
|
|
882
|
-
expose: true
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
for (const [name, value] of Object.entries(module)) {
|
|
887
|
-
if (name === "default")
|
|
888
|
-
continue;
|
|
889
|
-
if (value && typeof value === "object" && "entry" in value && "options" in value && "handler" in value) {
|
|
890
|
-
const routeDef = value;
|
|
891
|
-
routes.push({
|
|
892
|
-
name,
|
|
893
|
-
path: fullPath,
|
|
894
|
-
method: routeDef.options.method,
|
|
895
|
-
options: routeDef.options
|
|
896
|
-
});
|
|
897
|
-
} else if (Array.isArray(value) && value.length >= 4) {
|
|
898
|
-
const [method, , , path] = value;
|
|
899
|
-
routes.push({
|
|
900
|
-
name,
|
|
901
|
-
path: fullPath,
|
|
902
|
-
method,
|
|
903
|
-
options: {
|
|
904
|
-
method,
|
|
905
|
-
path,
|
|
906
|
-
expose: true
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
} catch (error) {
|
|
912
|
-
console.error(`Failed to load route from ${fullPath}:`, error);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
enableWatch(callback) {
|
|
918
|
-
if (typeof Bun !== "undefined" && Bun.env.NODE_ENV === "development") {
|
|
919
|
-
console.log(`Watching for route changes in ${this.routesDir}`);
|
|
920
|
-
setInterval(async () => {
|
|
921
|
-
await callback();
|
|
922
|
-
}, 1000);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
var init_route_scanner2 = () => {};
|
|
927
|
-
|
|
928
|
-
// src/dev/route-generator.ts
|
|
929
|
-
var exports_route_generator = {};
|
|
930
|
-
__export(exports_route_generator, {
|
|
931
|
-
RouteGenerator: () => RouteGenerator2
|
|
932
|
-
});
|
|
933
|
-
import { promises as fs4 } from "node:fs";
|
|
934
|
-
import { dirname as dirname2, relative as relative4 } from "node:path";
|
|
935
|
-
|
|
936
|
-
class RouteGenerator2 {
|
|
937
|
-
outputPath;
|
|
938
|
-
constructor(outputPath = "./.vector/routes.generated.ts") {
|
|
939
|
-
this.outputPath = outputPath;
|
|
940
|
-
}
|
|
941
|
-
async generate(routes) {
|
|
942
|
-
const outputDir = dirname2(this.outputPath);
|
|
943
|
-
await fs4.mkdir(outputDir, { recursive: true });
|
|
944
|
-
const imports = [];
|
|
945
|
-
const groupedByFile = new Map;
|
|
946
|
-
for (const route of routes) {
|
|
947
|
-
if (!groupedByFile.has(route.path)) {
|
|
948
|
-
groupedByFile.set(route.path, []);
|
|
949
|
-
}
|
|
950
|
-
groupedByFile.get(route.path).push(route);
|
|
951
|
-
}
|
|
952
|
-
let importIndex = 0;
|
|
953
|
-
const routeEntries = [];
|
|
954
|
-
for (const [filePath, fileRoutes] of groupedByFile) {
|
|
955
|
-
const relativePath = relative4(dirname2(this.outputPath), filePath).replace(/\\/g, "/").replace(/\.(ts|js)$/, "");
|
|
956
|
-
const importName = `route_${importIndex++}`;
|
|
957
|
-
const namedImports = fileRoutes.filter((r2) => r2.name !== "default").map((r2) => r2.name);
|
|
958
|
-
if (fileRoutes.some((r2) => r2.name === "default")) {
|
|
959
|
-
if (namedImports.length > 0) {
|
|
960
|
-
imports.push(`import ${importName}, { ${namedImports.join(", ")} } from '${relativePath}';`);
|
|
961
|
-
} else {
|
|
962
|
-
imports.push(`import ${importName} from '${relativePath}';`);
|
|
963
|
-
}
|
|
964
|
-
} else if (namedImports.length > 0) {
|
|
965
|
-
imports.push(`import { ${namedImports.join(", ")} } from '${relativePath}';`);
|
|
966
|
-
}
|
|
967
|
-
for (const route of fileRoutes) {
|
|
968
|
-
const routeVar = route.name === "default" ? importName : route.name;
|
|
969
|
-
routeEntries.push(` ${routeVar},`);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
const content = `// This file is auto-generated. Do not edit manually.
|
|
973
|
-
// Generated at: ${new Date().toISOString()}
|
|
974
|
-
|
|
975
|
-
${imports.join(`
|
|
976
|
-
`)}
|
|
977
|
-
|
|
978
|
-
export const routes = [
|
|
979
|
-
${routeEntries.join(`
|
|
980
|
-
`)}
|
|
981
|
-
];
|
|
982
|
-
|
|
983
|
-
export default routes;
|
|
984
|
-
`;
|
|
985
|
-
await fs4.writeFile(this.outputPath, content, "utf-8");
|
|
986
|
-
console.log(`Generated routes file: ${this.outputPath}`);
|
|
987
|
-
}
|
|
988
|
-
async generateDynamic(routes) {
|
|
989
|
-
const routeEntries = [];
|
|
990
|
-
for (const route of routes) {
|
|
991
|
-
const routeObj = JSON.stringify({
|
|
992
|
-
method: route.method,
|
|
993
|
-
path: route.options.path,
|
|
994
|
-
options: route.options
|
|
995
|
-
});
|
|
996
|
-
routeEntries.push(` await import('${route.path}').then(m => ({
|
|
997
|
-
...${routeObj},
|
|
998
|
-
handler: m.${route.name === "default" ? "default" : route.name}
|
|
999
|
-
}))`);
|
|
1000
|
-
}
|
|
1001
|
-
return `export const loadRoutes = async () => {
|
|
1002
|
-
return Promise.all([
|
|
1003
|
-
${routeEntries.join(`,
|
|
1004
|
-
`)}
|
|
1005
|
-
]);
|
|
1006
|
-
};`;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
var init_route_generator2 = () => {};
|
|
1010
|
-
|
|
1011
|
-
// src/cli/index.ts
|
|
1012
|
-
import { watch } from "fs";
|
|
1013
|
-
import { parseArgs } from "util";
|
|
1014
|
-
|
|
1015
848
|
// src/core/vector.ts
|
|
1016
|
-
init_manager();
|
|
1017
|
-
init_route_generator();
|
|
1018
|
-
init_route_scanner();
|
|
1019
|
-
init_router();
|
|
1020
|
-
init_server();
|
|
1021
|
-
|
|
1022
849
|
class Vector {
|
|
1023
850
|
static instance;
|
|
1024
851
|
router;
|
|
@@ -1113,7 +940,7 @@ class Vector {
|
|
|
1113
940
|
}
|
|
1114
941
|
}
|
|
1115
942
|
this.router.sortRoutes();
|
|
1116
|
-
console.log(
|
|
943
|
+
console.log(`\u2705 Loaded ${routes.length} routes from ${routesDir}`);
|
|
1117
944
|
}
|
|
1118
945
|
} catch (error) {
|
|
1119
946
|
if (error.code !== "ENOENT" && error.code !== "ENOTDIR") {
|
|
@@ -1146,9 +973,9 @@ class Vector {
|
|
|
1146
973
|
}
|
|
1147
974
|
logRouteLoaded(route) {
|
|
1148
975
|
if (Array.isArray(route)) {
|
|
1149
|
-
console.log(`
|
|
976
|
+
console.log(` \u2713 Loaded route: ${route[0]} ${route[3] || route[1]}`);
|
|
1150
977
|
} else {
|
|
1151
|
-
console.log(`
|
|
978
|
+
console.log(` \u2713 Loaded route: ${route.method} ${route.path}`);
|
|
1152
979
|
}
|
|
1153
980
|
}
|
|
1154
981
|
stop() {
|
|
@@ -1174,11 +1001,24 @@ class Vector {
|
|
|
1174
1001
|
Vector.instance = null;
|
|
1175
1002
|
}
|
|
1176
1003
|
}
|
|
1177
|
-
var getVectorInstance
|
|
1004
|
+
var getVectorInstance;
|
|
1005
|
+
var init_vector = __esm(() => {
|
|
1006
|
+
init_manager();
|
|
1007
|
+
init_route_generator();
|
|
1008
|
+
init_route_scanner();
|
|
1009
|
+
init_router();
|
|
1010
|
+
init_server();
|
|
1011
|
+
getVectorInstance = Vector.getInstance;
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
// src/cli/index.ts
|
|
1015
|
+
init_vector();
|
|
1016
|
+
import { watch } from "fs";
|
|
1017
|
+
import { parseArgs } from "util";
|
|
1178
1018
|
|
|
1179
1019
|
// src/core/config-loader.ts
|
|
1180
|
-
import { existsSync as existsSync2 } from "
|
|
1181
|
-
import { resolve as resolve2 } from "
|
|
1020
|
+
import { existsSync as existsSync2 } from "fs";
|
|
1021
|
+
import { resolve as resolve2 } from "path";
|
|
1182
1022
|
|
|
1183
1023
|
class ConfigLoader {
|
|
1184
1024
|
configPath;
|
|
@@ -1190,20 +1030,20 @@ class ConfigLoader {
|
|
|
1190
1030
|
async load() {
|
|
1191
1031
|
if (existsSync2(this.configPath)) {
|
|
1192
1032
|
try {
|
|
1193
|
-
console.log(
|
|
1033
|
+
console.log(`\u2192 Loading config from: ${this.configPath}`);
|
|
1194
1034
|
const userConfigPath = toFileUrl(this.configPath);
|
|
1195
1035
|
const userConfig = await import(userConfigPath);
|
|
1196
1036
|
this.config = userConfig.default || userConfig;
|
|
1197
1037
|
this.configSource = "user";
|
|
1198
|
-
console.log("
|
|
1038
|
+
console.log(" \u2713 User config loaded successfully");
|
|
1199
1039
|
} catch (error) {
|
|
1200
|
-
console.error(`
|
|
1201
|
-
console.log("
|
|
1040
|
+
console.error(` \u2717 Failed to load config from ${this.configPath}:`, error);
|
|
1041
|
+
console.log(" \u2192 Using default configuration");
|
|
1202
1042
|
this.config = {};
|
|
1203
1043
|
}
|
|
1204
1044
|
} else {
|
|
1205
|
-
console.log(`
|
|
1206
|
-
console.log("
|
|
1045
|
+
console.log(` \u2192 No config file found at: ${this.configPath}`);
|
|
1046
|
+
console.log(" \u2192 Using default configuration");
|
|
1207
1047
|
this.config = {};
|
|
1208
1048
|
}
|
|
1209
1049
|
return await this.buildLegacyConfig();
|
|
@@ -1331,8 +1171,9 @@ class ConfigLoader {
|
|
|
1331
1171
|
}
|
|
1332
1172
|
|
|
1333
1173
|
// src/cli/index.ts
|
|
1174
|
+
var args = typeof Bun !== "undefined" ? Bun.argv.slice(2) : process.argv.slice(2);
|
|
1334
1175
|
var { values, positionals } = parseArgs({
|
|
1335
|
-
args
|
|
1176
|
+
args,
|
|
1336
1177
|
options: {
|
|
1337
1178
|
port: {
|
|
1338
1179
|
type: "string",
|
|
@@ -1467,22 +1308,30 @@ async function runBuild() {
|
|
|
1467
1308
|
\u2192 Building Vector application
|
|
1468
1309
|
`);
|
|
1469
1310
|
try {
|
|
1470
|
-
const { RouteScanner:
|
|
1471
|
-
const { RouteGenerator:
|
|
1472
|
-
const scanner = new
|
|
1473
|
-
const generator = new
|
|
1311
|
+
const { RouteScanner: RouteScanner2 } = await Promise.resolve().then(() => (init_route_scanner(), exports_route_scanner));
|
|
1312
|
+
const { RouteGenerator: RouteGenerator2 } = await Promise.resolve().then(() => (init_route_generator(), exports_route_generator));
|
|
1313
|
+
const scanner = new RouteScanner2(values.routes);
|
|
1314
|
+
const generator = new RouteGenerator2;
|
|
1474
1315
|
const routes = await scanner.scan();
|
|
1475
1316
|
await generator.generate(routes);
|
|
1476
1317
|
console.log(` Generated ${routes.length} routes`);
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1318
|
+
if (typeof Bun !== "undefined") {
|
|
1319
|
+
const buildProcess = Bun.spawn([
|
|
1320
|
+
"bun",
|
|
1321
|
+
"build",
|
|
1322
|
+
"src/index.ts",
|
|
1323
|
+
"--outdir",
|
|
1324
|
+
"dist",
|
|
1325
|
+
"--minify"
|
|
1326
|
+
]);
|
|
1327
|
+
await buildProcess.exited;
|
|
1328
|
+
} else {
|
|
1329
|
+
const { spawnSync } = await import("child_process");
|
|
1330
|
+
spawnSync("bun", ["build", "src/index.ts", "--outdir", "dist", "--minify"], {
|
|
1331
|
+
stdio: "inherit",
|
|
1332
|
+
shell: true
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1486
1335
|
console.log(`
|
|
1487
1336
|
\u2713 Build complete
|
|
1488
1337
|
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vector-framework",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"author": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"build:clean": "rm -rf dist",
|
|
82
82
|
"build:ts": "tsc",
|
|
83
83
|
"build:bundle": "bun build src/index.ts --format esm --minify --outfile dist/index.mjs && bun build src/index.ts --format cjs --minify --outfile dist/index.js",
|
|
84
|
-
"build:cli": "bun build src/cli/index.ts --target
|
|
84
|
+
"build:cli": "bun build src/cli/index.ts --target bun --outfile dist/cli.js",
|
|
85
85
|
"test": "bun test tests/api-error.test.ts tests/cache.test.ts tests/middleware.test.ts tests/middleware-integration.test.ts tests/router.test.ts",
|
|
86
86
|
"test:unit": "bun test tests/*.test.ts",
|
|
87
87
|
"test:watch": "bun test --watch tests/*.test.ts",
|
package/src/cli/index.ts
CHANGED
|
@@ -5,8 +5,11 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
import { getVectorInstance } from "../core/vector";
|
|
6
6
|
import { ConfigLoader } from "../core/config-loader";
|
|
7
7
|
|
|
8
|
+
// Compatibility layer for both Node and Bun
|
|
9
|
+
const args = typeof Bun !== 'undefined' ? Bun.argv.slice(2) : process.argv.slice(2);
|
|
10
|
+
|
|
8
11
|
const { values, positionals } = parseArgs({
|
|
9
|
-
args
|
|
12
|
+
args,
|
|
10
13
|
options: {
|
|
11
14
|
port: {
|
|
12
15
|
type: "string",
|
|
@@ -195,15 +198,25 @@ async function runBuild() {
|
|
|
195
198
|
|
|
196
199
|
console.log(` Generated ${routes.length} routes`);
|
|
197
200
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
// Use spawn based on runtime
|
|
202
|
+
if (typeof Bun !== 'undefined') {
|
|
203
|
+
const buildProcess = Bun.spawn([
|
|
204
|
+
"bun",
|
|
205
|
+
"build",
|
|
206
|
+
"src/index.ts",
|
|
207
|
+
"--outdir",
|
|
208
|
+
"dist",
|
|
209
|
+
"--minify",
|
|
210
|
+
]);
|
|
211
|
+
await buildProcess.exited;
|
|
212
|
+
} else {
|
|
213
|
+
// For Node.js, use child_process
|
|
214
|
+
const { spawnSync } = await import('child_process');
|
|
215
|
+
spawnSync('bun', ['build', 'src/index.ts', '--outdir', 'dist', '--minify'], {
|
|
216
|
+
stdio: 'inherit',
|
|
217
|
+
shell: true
|
|
218
|
+
});
|
|
219
|
+
}
|
|
207
220
|
|
|
208
221
|
console.log("\n ✓ Build complete\n");
|
|
209
222
|
} catch (error) {
|