Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support command line usage #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

dist/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ cp .env.example .env.local
PROJECT_DIRECTORY=/path/to/your/project # Ex: /Users/you/your-project
```

4. run on commad line
```bash
npm install
npm link

o1-xml-parser <xml-code-changes-file> <project-directory>
```

## The XML Prompt

You are an expert software engineer.
Expand Down
2 changes: 1 addition & 1 deletion app/_components/apply-changes-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function ApplyChangesForm() {
type="text"
value={projectDirectory}
onChange={(e) => setProjectDirectory(e.target.value)}
placeholder="e.g. /Users/myusername/projects/o1-xml-parser"
placeholder={projectDirectory.trim() !== "" ? projectDirectory.trim() : process.env.PROJECT_DIRECTORY}
/>
</div>
<div className="flex flex-col">
Expand Down
42 changes: 42 additions & 0 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

import { promises as fs } from "fs";
import { parseXmlString } from "./lib/xml-parser";
import { applyFileChanges } from "./lib/apply-changes";
import { join } from "path";

async function main() {
try {
// Get arguments
const xmlPath = process.argv[2];
const projectDir = process.argv[3];

if (!xmlPath || !projectDir) {
console.error("Usage: o1-xml-parser <xml-file-path> <project-directory>");
process.exit(1);
}

// Read XML file
const xmlContent = await fs.readFile(xmlPath, "utf-8");

// Parse XML
const changes = await parseXmlString(xmlContent);
if (!changes) {
console.error("Failed to parse XML or no changes found");
process.exit(1);
}

// Apply changes
for (const change of changes) {
console.log(`Applying ${change.file_operation} to ${change.file_path}...`);
await applyFileChanges(change, projectDir);
}

console.log("All changes applied successfully!");
} catch (error) {
console.error("Error:", error);
process.exit(1);
}
}

main();
17 changes: 14 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"name": "o1-xml-parser",
"version": "0.1.0",
"private": true,
"bin": {
"o1-xml-parser": "./dist/cli.js"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"build": "next build && tsc cli.ts --outDir dist --esModuleInterop --module commonjs",
"postbuild": "chmod +x ./dist/cli.js",
"start": "next start",
"lint": "next lint"
},
Expand All @@ -23,10 +27,11 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/xmldom": "^0.1.34",
"eslint": "^8",
"eslint-config-next": "14.2.16",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
}