()
| 67 | } |
| 68 | |
| 69 | function main() { |
| 70 | const args = parseArgs(process.argv); |
| 71 | if (args.help) { |
| 72 | process.stdout.write(`${usage()}\n`); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | if (args.mode === 'compile') { |
| 77 | const result = compileMemoryBlocks(args.projectRoot); |
| 78 | const lint = lintMemoryBlocks(args.projectRoot); |
| 79 | if (args.json) process.stdout.write(`${JSON.stringify({ ...result, lint }, null, 2)}\n`); |
| 80 | else process.stdout.write(renderCompile(args.projectRoot, result, lint)); |
| 81 | process.exitCode = lint.pass ? 0 : 1; |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | if (args.mode === 'lint') { |
| 86 | const lint = lintMemoryBlocks(args.projectRoot); |
| 87 | if (args.json) process.stdout.write(`${JSON.stringify(lint, null, 2)}\n`); |
| 88 | else process.stdout.write(renderCompile(args.projectRoot, { blocks: lint.blocks, indexPath: path.join(args.projectRoot, '.planning', 'memory', 'index.json') }, lint)); |
| 89 | process.exitCode = lint.pass ? 0 : 1; |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | if (args.mode === 'list') { |
| 94 | const blocks = loadMemoryBlocks(args.projectRoot, args); |
| 95 | if (args.json) process.stdout.write(`${JSON.stringify(blocks, null, 2)}\n`); |
| 96 | else process.stdout.write(renderList(args.projectRoot, blocks)); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | process.stderr.write(`${usage()}\n`); |
| 101 | process.exitCode = 2; |
| 102 | } |
| 103 | |
| 104 | if (require.main === module) { |
| 105 | main(); |
no test coverage detected