@asterflow/fs 1.0.2 → 1.0.3
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 +2 -2
- package/dist/cjs/index.cjs +66 -38
- package/dist/mjs/index.js +51 -24
- package/dist/types/index.d.ts +14 -20
- package/package.json +5 -11
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ In your main application file, import and register the `fsRouting` plugin.
|
|
|
76
76
|
**`src/index.ts`**
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
|
-
import { AsterFlow } from '
|
|
79
|
+
import { AsterFlow } from 'asterflow';
|
|
80
80
|
import { fsRouting } from '@asterflow/fs';
|
|
81
81
|
import { join } from 'path';
|
|
82
82
|
|
|
@@ -112,7 +112,7 @@ The plugin transforms file paths into URL routes based on the following rules:
|
|
|
112
112
|
|
|
113
113
|
## 🔗 Related Packages
|
|
114
114
|
|
|
115
|
-
- [
|
|
115
|
+
- [asterflow](https://www.npmjs.com/package/asterflow) - The core of the AsterFlow framework.
|
|
116
116
|
- [@asterflow/plugin](https://www.npmjs.com/package/@asterflow/plugin) - The main plugin system.
|
|
117
117
|
- [@asterflow/router](https://www.npmjs.com/package/@asterflow/router) - The type-safe routing system used by this plugin.
|
|
118
118
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,64 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var p = Object.defineProperty;
|
|
3
3
|
var h = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
for (var
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
if (
|
|
11
|
-
for (let s of
|
|
12
|
-
!
|
|
4
|
+
var w = Object.getOwnPropertyNames;
|
|
5
|
+
var R = Object.prototype.hasOwnProperty;
|
|
6
|
+
var v = (t, o) => {
|
|
7
|
+
for (var r in o)
|
|
8
|
+
p(t, r, { get: o[r], enumerable: !0 });
|
|
9
|
+
}, F = (t, o, r, e) => {
|
|
10
|
+
if (o && typeof o == "object" || typeof o == "function")
|
|
11
|
+
for (let s of w(o))
|
|
12
|
+
!R.call(t, s) && s !== r && p(t, s, { get: () => o[s], enumerable: !(e = h(o, s)) || e.enumerable });
|
|
13
13
|
return t;
|
|
14
14
|
};
|
|
15
|
-
var j = (t) =>
|
|
15
|
+
var j = (t) => F(p({}, "__esModule", { value: !0 }), t);
|
|
16
16
|
|
|
17
17
|
// plugins/fs/src/index.ts
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
default: () =>
|
|
18
|
+
var P = {};
|
|
19
|
+
v(P, {
|
|
20
|
+
default: () => T,
|
|
21
21
|
fsRoutingPlugin: () => y,
|
|
22
|
-
getFilesRecursively: () =>
|
|
23
|
-
transformPathToUrl: () =>
|
|
22
|
+
getFilesRecursively: () => n,
|
|
23
|
+
transformPathToUrl: () => u
|
|
24
24
|
});
|
|
25
|
-
module.exports = j(
|
|
26
|
-
var
|
|
25
|
+
module.exports = j(P);
|
|
26
|
+
var x = require("@asterflow/plugin"), a = require("@asterflow/router");
|
|
27
27
|
|
|
28
28
|
// plugins/fs/package.json
|
|
29
|
-
var
|
|
29
|
+
var f = "1.0.3";
|
|
30
30
|
|
|
31
31
|
// plugins/fs/src/utils/format.ts
|
|
32
|
-
var
|
|
33
|
-
function
|
|
34
|
-
let
|
|
35
|
-
return
|
|
32
|
+
var d = require("path");
|
|
33
|
+
function u(t, o) {
|
|
34
|
+
let e = (0, d.relative)(o, t).replace(/\.(ts|js)$/, "");
|
|
35
|
+
return e.endsWith("/index") ? e = e.slice(0, -6) : e === "index" && (e = ""), e = e.replace(/\$/g, ":"), `/${e}`;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// plugins/fs/src/utils/glob.ts
|
|
39
|
-
var
|
|
40
|
-
async function
|
|
41
|
-
let
|
|
39
|
+
var g = require("fs/promises"), m = require("path");
|
|
40
|
+
async function n(t) {
|
|
41
|
+
let o = await (0, g.readdir)(t, { withFileTypes: !0 });
|
|
42
42
|
return (await Promise.all(
|
|
43
|
-
|
|
44
|
-
let s = (0, m.join)(t,
|
|
45
|
-
return
|
|
43
|
+
o.map(async (e) => {
|
|
44
|
+
let s = (0, m.join)(t, e.name);
|
|
45
|
+
return e.isDirectory() ? n(s) : s;
|
|
46
46
|
})
|
|
47
47
|
)).flat();
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// plugins/fs/src/utils/log.ts
|
|
51
|
+
var l = {
|
|
52
|
+
reset: "\x1B[0m",
|
|
53
|
+
red: "\x1B[31m",
|
|
54
|
+
yellow: "\x1B[33m",
|
|
55
|
+
cyan: "\x1B[36m"
|
|
56
|
+
};
|
|
57
|
+
function c(t, o) {
|
|
58
|
+
console.warn(`${l.yellow}%s %s${l.reset}`, "[AsterFlow]", t), console.group();
|
|
59
|
+
for (let [r, e] of Object.entries(o))
|
|
60
|
+
console.log(`${l.cyan}%s:${l.reset} %s`, r, e);
|
|
61
|
+
console.groupEnd(), console.log();
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
// plugins/fs/src/index.ts
|
|
51
|
-
var y =
|
|
52
|
-
async registerRoutes(
|
|
53
|
-
if (
|
|
54
|
-
for (let
|
|
55
|
-
let
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
var y = x.Plugin.create({ name: "fs-routing" }).decorate("creator", "Ashu11-A").decorate("version", f).config({ path: "" }).derive("files", async (t) => await n(t.path)).extends((t, o) => ({
|
|
66
|
+
async registerRoutes(r) {
|
|
67
|
+
if (r.files.length !== 0)
|
|
68
|
+
for (let e of r.files) {
|
|
69
|
+
let i = (await import(e)).default;
|
|
70
|
+
if (!i) {
|
|
71
|
+
c("File Skipped: No Default Export", {
|
|
72
|
+
File: e,
|
|
73
|
+
Reason: "The file does not contain any default exported routes (export default).",
|
|
74
|
+
Solution: 'Ensure the file has a "export default new Router()" or similar.'
|
|
75
|
+
});
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (!(i instanceof a.Method || i instanceof a.Router)) {
|
|
79
|
+
c("File Skipped: Invalid Export Type", {
|
|
80
|
+
File: e,
|
|
81
|
+
"Exported Type": typeof i,
|
|
82
|
+
Reason: "The file does not export a known class instance (e.g., Router, Method)."
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
i.path = u(e, r.path), t.controller(i);
|
|
59
87
|
}
|
|
60
88
|
}
|
|
61
|
-
})).on("beforeInitialize", async (t,
|
|
89
|
+
})).on("beforeInitialize", async (t, o) => await t.registerRoutes(o)), T = y;
|
|
62
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
91
|
0 && (module.exports = {
|
|
64
92
|
fsRoutingPlugin,
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,46 +1,73 @@
|
|
|
1
1
|
// plugins/fs/src/index.ts
|
|
2
|
-
import { Plugin as
|
|
3
|
-
import { Method as
|
|
4
|
-
import { Analyze as h } from "@asterflow/url-parser";
|
|
2
|
+
import { Plugin as x } from "@asterflow/plugin";
|
|
3
|
+
import { Method as y, Router as h } from "@asterflow/router";
|
|
5
4
|
|
|
6
5
|
// plugins/fs/package.json
|
|
7
|
-
var
|
|
6
|
+
var p = "1.0.3";
|
|
8
7
|
|
|
9
8
|
// plugins/fs/src/utils/format.ts
|
|
10
|
-
import { relative as
|
|
11
|
-
function
|
|
12
|
-
let e =
|
|
9
|
+
import { relative as d } from "path";
|
|
10
|
+
function u(t, o) {
|
|
11
|
+
let e = d(o, t).replace(/\.(ts|js)$/, "");
|
|
13
12
|
return e.endsWith("/index") ? e = e.slice(0, -6) : e === "index" && (e = ""), e = e.replace(/\$/g, ":"), `/${e}`;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
// plugins/fs/src/utils/glob.ts
|
|
17
|
-
import { readdir as
|
|
16
|
+
import { readdir as g } from "fs/promises";
|
|
18
17
|
import { join as m } from "path";
|
|
19
|
-
async function
|
|
20
|
-
let
|
|
18
|
+
async function l(t) {
|
|
19
|
+
let o = await g(t, { withFileTypes: !0 });
|
|
21
20
|
return (await Promise.all(
|
|
22
|
-
|
|
23
|
-
let
|
|
24
|
-
return e.isDirectory() ?
|
|
21
|
+
o.map(async (e) => {
|
|
22
|
+
let n = m(t, e.name);
|
|
23
|
+
return e.isDirectory() ? l(n) : n;
|
|
25
24
|
})
|
|
26
25
|
)).flat();
|
|
27
26
|
}
|
|
28
27
|
|
|
28
|
+
// plugins/fs/src/utils/log.ts
|
|
29
|
+
var i = {
|
|
30
|
+
reset: "\x1B[0m",
|
|
31
|
+
red: "\x1B[31m",
|
|
32
|
+
yellow: "\x1B[33m",
|
|
33
|
+
cyan: "\x1B[36m"
|
|
34
|
+
};
|
|
35
|
+
function a(t, o) {
|
|
36
|
+
console.warn(`${i.yellow}%s %s${i.reset}`, "[AsterFlow]", t), console.group();
|
|
37
|
+
for (let [r, e] of Object.entries(o))
|
|
38
|
+
console.log(`${i.cyan}%s:${i.reset} %s`, r, e);
|
|
39
|
+
console.groupEnd(), console.log();
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
// plugins/fs/src/index.ts
|
|
30
|
-
var
|
|
43
|
+
var w = x.create({ name: "fs-routing" }).decorate("creator", "Ashu11-A").decorate("version", p).config({ path: "" }).derive("files", async (t) => await l(t.path)).extends((t, o) => ({
|
|
31
44
|
async registerRoutes(r) {
|
|
32
45
|
if (r.files.length !== 0)
|
|
33
|
-
for (let
|
|
34
|
-
let s = (await import(
|
|
35
|
-
if (!s
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
for (let e of r.files) {
|
|
47
|
+
let s = (await import(e)).default;
|
|
48
|
+
if (!s) {
|
|
49
|
+
a("File Skipped: No Default Export", {
|
|
50
|
+
File: e,
|
|
51
|
+
Reason: "The file does not contain any default exported routes (export default).",
|
|
52
|
+
Solution: 'Ensure the file has a "export default new Router()" or similar.'
|
|
53
|
+
});
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!(s instanceof y || s instanceof h)) {
|
|
57
|
+
a("File Skipped: Invalid Export Type", {
|
|
58
|
+
File: e,
|
|
59
|
+
"Exported Type": typeof s,
|
|
60
|
+
Reason: "The file does not export a known class instance (e.g., Router, Method)."
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
s.path = u(e, r.path), t.controller(s);
|
|
38
65
|
}
|
|
39
66
|
}
|
|
40
|
-
})).on("beforeInitialize", async (t,
|
|
67
|
+
})).on("beforeInitialize", async (t, o) => await t.registerRoutes(o)), M = w;
|
|
41
68
|
export {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
M as default,
|
|
70
|
+
w as fsRoutingPlugin,
|
|
71
|
+
l as getFilesRecursively,
|
|
72
|
+
u as transformPathToUrl
|
|
46
73
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,32 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
import { Plugin } from '@asterflow/plugin';
|
|
4
4
|
|
|
5
|
-
export declare const fsRoutingPlugin: Plugin<"fs-routing", import("
|
|
6
|
-
], import("@asterflow/adapter").Adapter<import("@asterflow/adapter").Runtime.Node>, {}>, {
|
|
5
|
+
export declare const fsRoutingPlugin: Plugin<"fs-routing", import("asterflow").AnyAsterflow, {
|
|
7
6
|
path: string;
|
|
7
|
+
defaultConfig: {
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
8
10
|
}, {
|
|
9
11
|
creator: string;
|
|
10
|
-
} & {
|
|
11
12
|
version: string;
|
|
12
|
-
}
|
|
13
|
+
}, {
|
|
13
14
|
files: string[];
|
|
14
|
-
}, Omit<{}, Event> & {
|
|
15
|
-
beforeInitialize: [
|
|
16
|
-
(instance: import("@asterflow/core").IAsterflow<import("@asterflow/core").AnyReminist, {}, [
|
|
17
|
-
], import("@asterflow/adapter").Adapter<import("@asterflow/adapter").Runtime.Node>, {}> & {
|
|
18
|
-
registerRoutes(context: FSRoutingContext): Promise<void>;
|
|
19
|
-
}, context: {
|
|
20
|
-
creator: string;
|
|
21
|
-
} & {
|
|
22
|
-
version: string;
|
|
23
|
-
} & {
|
|
24
|
-
files: string[];
|
|
25
|
-
} & {
|
|
26
|
-
path: string;
|
|
27
|
-
}) => Promise<void>
|
|
28
|
-
];
|
|
29
15
|
}, {
|
|
30
|
-
registerRoutes(context:
|
|
16
|
+
registerRoutes: (context: {
|
|
17
|
+
creator: string;
|
|
18
|
+
version: string;
|
|
19
|
+
path: string;
|
|
20
|
+
defaultConfig: {
|
|
21
|
+
path: string;
|
|
22
|
+
};
|
|
23
|
+
files: string[];
|
|
24
|
+
}) => Promise<void>;
|
|
31
25
|
}>;
|
|
32
26
|
/**
|
|
33
27
|
* Recursively lists files from a starting directory.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asterflow/fs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "dist/cjs/index.cjs",
|
|
5
5
|
"module": "dist/mjs/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -26,15 +26,9 @@
|
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=20"
|
|
28
28
|
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"@asterflow/core": "^1.0.7",
|
|
31
|
-
"@types/bun": "latest"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"typescript": "^5.8.3"
|
|
35
|
-
},
|
|
36
29
|
"dependencies": {
|
|
37
|
-
"@asterflow/
|
|
38
|
-
"@asterflow/
|
|
30
|
+
"@asterflow/plugin": "^1.0.5",
|
|
31
|
+
"@asterflow/router": "^1.0.9",
|
|
32
|
+
"@asterflow/url-parser": "^2.0.2"
|
|
39
33
|
}
|
|
40
|
-
}
|
|
34
|
+
}
|