@mauroandre/velojs 0.0.38 → 0.0.40
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/agent/skills/velojs-project-graph/SKILL.md +122 -0
- package/dist/cli.js +49 -33
- package/dist/graph-viewer.d.ts +13 -0
- package/dist/graph-viewer.js +378 -0
- package/dist/graph.d.ts +37 -0
- package/dist/graph.js +202 -0
- package/dist/init.js +16 -7
- package/dist/vite.js +279 -248
- package/package.json +1 -1
package/dist/graph.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import y from "node:fs";
|
|
2
|
+
import E from "node:path";
|
|
3
|
+
import { parse as T } from "@babel/parser";
|
|
4
|
+
import w from "@babel/traverse";
|
|
5
|
+
import * as a from "@babel/types";
|
|
6
|
+
const g = typeof w == "function" ? w : w.default, W = /export\s+(const|function)\s+Component/, _ = /export\s+(const|function)\s+loader/, b = /export\s+const\s+action_(\w+)/g, k = /export\s+const\s+stream_(\w+)/g, M = /export\s+const\s+socket_(\w+)/g;
|
|
7
|
+
function A(i) {
|
|
8
|
+
let e;
|
|
9
|
+
try {
|
|
10
|
+
e = y.readFileSync(i, "utf-8");
|
|
11
|
+
} catch {
|
|
12
|
+
return {
|
|
13
|
+
hasComponent: !1,
|
|
14
|
+
hasLoader: !1,
|
|
15
|
+
actions: [],
|
|
16
|
+
streams: [],
|
|
17
|
+
sockets: []
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const s = [];
|
|
21
|
+
let o;
|
|
22
|
+
const u = new RegExp(b.source, "g");
|
|
23
|
+
for (; (o = u.exec(e)) !== null; )
|
|
24
|
+
s.push(o[1]);
|
|
25
|
+
const t = [], c = new RegExp(k.source, "g");
|
|
26
|
+
for (; (o = c.exec(e)) !== null; )
|
|
27
|
+
t.push(o[1]);
|
|
28
|
+
const n = [], r = new RegExp(M.source, "g");
|
|
29
|
+
for (; (o = r.exec(e)) !== null; )
|
|
30
|
+
n.push(o[1]);
|
|
31
|
+
return {
|
|
32
|
+
hasComponent: W.test(e),
|
|
33
|
+
hasLoader: _.test(e),
|
|
34
|
+
actions: s,
|
|
35
|
+
streams: t,
|
|
36
|
+
sockets: n
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function C(i) {
|
|
40
|
+
const e = T(i, {
|
|
41
|
+
sourceType: "module",
|
|
42
|
+
plugins: ["typescript", "jsx"]
|
|
43
|
+
}), s = /* @__PURE__ */ new Map();
|
|
44
|
+
g(e, {
|
|
45
|
+
ImportDeclaration(u) {
|
|
46
|
+
const t = u.node.source.value;
|
|
47
|
+
for (const c of u.node.specifiers)
|
|
48
|
+
a.isImportNamespaceSpecifier(c) && s.set(c.local.name, t);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
let o = null;
|
|
52
|
+
return g(e, {
|
|
53
|
+
ExportDefaultDeclaration(u) {
|
|
54
|
+
const t = u.node.declaration;
|
|
55
|
+
a.isArrayExpression(t) ? o = t : (a.isTSSatisfiesExpression(t) || a.isTSAsExpression(t)) && a.isArrayExpression(t.expression) && (o = t.expression);
|
|
56
|
+
}
|
|
57
|
+
}), { imports: s, arrayNode: o };
|
|
58
|
+
}
|
|
59
|
+
function L(i, e) {
|
|
60
|
+
if (!i) return null;
|
|
61
|
+
const s = e.get(i);
|
|
62
|
+
return s ? s.replace(/^\.\//, "").replace(/\.(tsx?|jsx?|js)$/, "") : null;
|
|
63
|
+
}
|
|
64
|
+
function O(i, e, s) {
|
|
65
|
+
const o = [];
|
|
66
|
+
for (const u of i) {
|
|
67
|
+
if (!a.isObjectExpression(u)) continue;
|
|
68
|
+
let t = "", c = e, n = null, r = null, d = !1;
|
|
69
|
+
const x = [], m = u.properties.filter(
|
|
70
|
+
(l) => a.isObjectProperty(l)
|
|
71
|
+
);
|
|
72
|
+
for (const l of m) {
|
|
73
|
+
const j = l.key, I = a.isIdentifier(j) ? j.name : null;
|
|
74
|
+
if (I === "path" && a.isStringLiteral(l.value) && (t = l.value.value, t && !t.startsWith("/") ? c = e + "/" + t : c = e + t), I === "module" && a.isIdentifier(l.value) && (n = l.value.name), I === "children" && a.isArrayExpression(l.value) && (r = l.value), I === "isRoot" && a.isBooleanLiteral(l.value) && (d = l.value.value), I === "middlewares" && a.isArrayExpression(l.value))
|
|
75
|
+
for (const R of l.value.elements)
|
|
76
|
+
R && a.isIdentifier(R) && x.push(R.name);
|
|
77
|
+
}
|
|
78
|
+
const f = L(n, s), h = !r && t === "/" ? e || "/" : c, p = r ? O(r.elements, c, s) : [];
|
|
79
|
+
o.push({
|
|
80
|
+
moduleId: f,
|
|
81
|
+
fullPath: f ? h : null,
|
|
82
|
+
path: f ? t : null,
|
|
83
|
+
isRoot: d,
|
|
84
|
+
middlewares: x,
|
|
85
|
+
children: p
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return o;
|
|
89
|
+
}
|
|
90
|
+
function D(i) {
|
|
91
|
+
const { imports: e, arrayNode: s } = C(i);
|
|
92
|
+
return s ? O(s.elements, "", e) : [];
|
|
93
|
+
}
|
|
94
|
+
const S = [".tsx", ".ts", ".jsx", ".js"];
|
|
95
|
+
function F(i, e, s) {
|
|
96
|
+
if (e.startsWith(".") && (e.endsWith(".js") || e.endsWith(".jsx") || e.endsWith(".ts") || e.endsWith(".tsx"))) {
|
|
97
|
+
const o = E.dirname(i), t = E.resolve(o, e).replace(/\.(tsx?|jsx?|js)$/, "");
|
|
98
|
+
for (const n of S) {
|
|
99
|
+
const r = t + n;
|
|
100
|
+
if (y.existsSync(r)) return r;
|
|
101
|
+
}
|
|
102
|
+
const c = [t];
|
|
103
|
+
for (const n of c)
|
|
104
|
+
if (y.existsSync(n) && y.statSync(n).isDirectory())
|
|
105
|
+
for (const r of S) {
|
|
106
|
+
const d = E.join(n, "index" + r);
|
|
107
|
+
if (y.existsSync(d)) return d;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
function N(i, e) {
|
|
114
|
+
const s = E.relative(e, i);
|
|
115
|
+
return s.startsWith("..") ? null : s.replace(/\.(tsx?|jsx?|js)$/, "");
|
|
116
|
+
}
|
|
117
|
+
function B(i, e) {
|
|
118
|
+
const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set();
|
|
119
|
+
function u(t) {
|
|
120
|
+
if (o.has(t)) return;
|
|
121
|
+
o.add(t);
|
|
122
|
+
const c = N(t, e);
|
|
123
|
+
if (!c) return;
|
|
124
|
+
let n;
|
|
125
|
+
try {
|
|
126
|
+
n = y.readFileSync(t, "utf-8");
|
|
127
|
+
} catch {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const r = [], d = T(n, {
|
|
131
|
+
sourceType: "module",
|
|
132
|
+
plugins: ["typescript", "jsx"]
|
|
133
|
+
});
|
|
134
|
+
g(d, {
|
|
135
|
+
ImportDeclaration(x) {
|
|
136
|
+
const m = x.node.source.value;
|
|
137
|
+
if (m.startsWith(".")) {
|
|
138
|
+
const f = F(
|
|
139
|
+
t,
|
|
140
|
+
m
|
|
141
|
+
);
|
|
142
|
+
if (f) {
|
|
143
|
+
const v = N(
|
|
144
|
+
f,
|
|
145
|
+
e
|
|
146
|
+
);
|
|
147
|
+
v && (r.push(v), u(f));
|
|
148
|
+
}
|
|
149
|
+
} else
|
|
150
|
+
r.push(m);
|
|
151
|
+
}
|
|
152
|
+
}), s.set(c, { file: t, imports: [...new Set(r)] });
|
|
153
|
+
}
|
|
154
|
+
return u(i), { modules: s };
|
|
155
|
+
}
|
|
156
|
+
function q(i) {
|
|
157
|
+
const e = E.join(i, "routes.tsx");
|
|
158
|
+
let s;
|
|
159
|
+
try {
|
|
160
|
+
s = y.readFileSync(e, "utf-8");
|
|
161
|
+
} catch {
|
|
162
|
+
return { routes: [], modules: {} };
|
|
163
|
+
}
|
|
164
|
+
const o = D(s), { modules: u } = B(
|
|
165
|
+
e,
|
|
166
|
+
i
|
|
167
|
+
), t = {}, c = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const [n, r] of u) {
|
|
169
|
+
let d = "unknown";
|
|
170
|
+
const x = (h) => {
|
|
171
|
+
for (const p of h) {
|
|
172
|
+
if (p.moduleId === n)
|
|
173
|
+
return p.isRoot ? "root" : p.children.length > 0 ? "layout" : "page";
|
|
174
|
+
const l = x(p.children);
|
|
175
|
+
if (l) return l;
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}, m = x(o);
|
|
179
|
+
m && (d = m);
|
|
180
|
+
const f = r.file, v = A(f);
|
|
181
|
+
for (const h of r.imports) {
|
|
182
|
+
c.has(h) || c.set(h, []);
|
|
183
|
+
const p = c.get(h);
|
|
184
|
+
p.includes(n) || p.push(n);
|
|
185
|
+
}
|
|
186
|
+
t[n] = {
|
|
187
|
+
file: E.relative(process.cwd(), f),
|
|
188
|
+
kind: d,
|
|
189
|
+
exports: v,
|
|
190
|
+
imports: r.imports,
|
|
191
|
+
importedBy: []
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
for (const [n, r] of Object.entries(t))
|
|
195
|
+
r.importedBy = c.get(n) ?? [];
|
|
196
|
+
return { routes: o, modules: t };
|
|
197
|
+
}
|
|
198
|
+
export {
|
|
199
|
+
q as buildGraph,
|
|
200
|
+
D as buildRouteTree,
|
|
201
|
+
A as detectExports
|
|
202
|
+
};
|
package/dist/init.js
CHANGED
|
@@ -7,6 +7,15 @@ function m() {
|
|
|
7
7
|
return JSON.parse(t.readFileSync(e, "utf-8")).version;
|
|
8
8
|
}
|
|
9
9
|
const u = {
|
|
10
|
+
".gitignore": `# Dependencies
|
|
11
|
+
node_modules/
|
|
12
|
+
|
|
13
|
+
# Build output
|
|
14
|
+
dist/
|
|
15
|
+
|
|
16
|
+
# Project graph
|
|
17
|
+
.velojs/
|
|
18
|
+
`,
|
|
10
19
|
"package.json": `{
|
|
11
20
|
"name": "my-velojs-app",
|
|
12
21
|
"version": "0.1.0",
|
|
@@ -139,22 +148,22 @@ a:hover {
|
|
|
139
148
|
`
|
|
140
149
|
};
|
|
141
150
|
async function x(o) {
|
|
142
|
-
const e = o ? s.resolve(process.cwd(), o) : process.cwd(),
|
|
151
|
+
const e = o ? s.resolve(process.cwd(), o) : process.cwd(), n = s.basename(e);
|
|
143
152
|
t.existsSync(e) ? t.readdirSync(e).filter(
|
|
144
|
-
(
|
|
153
|
+
(r) => !r.startsWith(".") && r !== "node_modules"
|
|
145
154
|
).length > 0 && (console.error(
|
|
146
|
-
`Error: Directory "${
|
|
155
|
+
`Error: Directory "${n}" is not empty. Use an empty directory.`
|
|
147
156
|
), process.exit(1)) : t.mkdirSync(e, { recursive: !0 });
|
|
148
|
-
for (const [a,
|
|
157
|
+
for (const [a, r] of Object.entries(u)) {
|
|
149
158
|
const p = s.join(e, a), l = s.dirname(p);
|
|
150
159
|
t.existsSync(l) || t.mkdirSync(l, { recursive: !0 });
|
|
151
|
-
const c = a === "package.json" ?
|
|
160
|
+
const c = a === "package.json" ? r.replace("my-velojs-app", n) : r;
|
|
152
161
|
t.writeFileSync(p, c);
|
|
153
162
|
}
|
|
154
163
|
console.log(`
|
|
155
|
-
Project created in ${o ?
|
|
164
|
+
Project created in ${o ? n : "current directory"}!
|
|
156
165
|
`), console.log(`Next steps:
|
|
157
|
-
`), o && console.log(` cd ${
|
|
166
|
+
`), o && console.log(` cd ${n}`), console.log(" npm install"), console.log(` npx velojs dev
|
|
158
167
|
`);
|
|
159
168
|
}
|
|
160
169
|
export {
|