Ship Operations console polish, PocketBase social fixtures, and portal join-leads without local DBs or probe scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
3.1 KiB
JavaScript
49 lines
3.1 KiB
JavaScript
/** Source inventory, not a substitute for functional acceptance. */
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import ts from 'typescript';
|
|
|
|
const root = process.cwd();
|
|
const output = path.join(root, 'artifacts/platform-upgrade');
|
|
fs.mkdirSync(output, { recursive: true });
|
|
function files(directory) {
|
|
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
const name = path.join(directory, entry.name);
|
|
if (['node_modules', 'vendor', 'dist', '.next', '__pycache__'].includes(entry.name)) return [];
|
|
return entry.isDirectory() ? files(name) : [name];
|
|
});
|
|
}
|
|
const inventory = { generatedAt: new Date().toISOString(), pages: [], nextInterfaces: [], adminPages: [], fields: [], copy: [], pythonInterfaces: [] };
|
|
for (const dir of ['src', 'apps/com/admin/src']) for (const file of files(path.join(root, dir))) {
|
|
const relative = path.relative(root, file).replaceAll('\\', '/');
|
|
if (!/\.(ts|tsx)$/.test(file)) continue;
|
|
const text = fs.readFileSync(file, 'utf8');
|
|
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
const line = node => source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
|
|
if (/\/page\.tsx$/.test(relative)) inventory.pages.push({ file: relative, route: relative.replace('src/app', '').replace(/\/page\.tsx$/, '') || '/' });
|
|
if (/\/route\.ts$/.test(relative)) inventory.nextInterfaces.push({ file: relative, methods: [...new Set([...text.matchAll(/\b(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g)].map(match => match[1]))] });
|
|
if (relative.startsWith('apps/com/admin/src/pages/')) inventory.adminPages.push(relative);
|
|
function visit(node) {
|
|
if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) {
|
|
const tag = node.tagName.getText(source);
|
|
if (['input', 'select', 'textarea'].includes(tag)) {
|
|
const attributes = Object.fromEntries(node.attributes.properties.filter(ts.isJsxAttribute).map(attr => [attr.name.getText(source), attr.initializer?.getText(source) ?? true]));
|
|
inventory.fields.push({ file: relative, line: line(node), tag, attributes });
|
|
}
|
|
}
|
|
if (ts.isJsxText(node) && node.text.trim()) inventory.copy.push({ file: relative, line: line(node), text: node.text.trim() });
|
|
ts.forEachChild(node, visit);
|
|
}
|
|
visit(source);
|
|
}
|
|
for (const file of files(path.join(root, 'apps/api')).filter(file => file.endsWith('.py'))) {
|
|
const text = fs.readFileSync(file, 'utf8');
|
|
for (const match of text.matchAll(/@(\w+)\.(get|post|put|patch|delete|websocket)\(\s*["']([^"']+)/g)) {
|
|
inventory.pythonInterfaces.push({ file: path.relative(root, file).replaceAll('\\', '/'), line: text.slice(0, match.index).split('\n').length, method: match[2].toUpperCase(), path: match[3] });
|
|
}
|
|
}
|
|
fs.writeFileSync(path.join(output, 'source-inventory.json'), JSON.stringify(inventory, null, 2));
|
|
const summary = Object.fromEntries(Object.entries(inventory).filter(([,value]) => Array.isArray(value)).map(([key, value]) => [key, value.length]));
|
|
fs.writeFileSync(path.join(output, 'inventory-summary.json'), JSON.stringify(summary, null, 2));
|
|
console.log(JSON.stringify(summary));
|