diff --git a/.gitignore b/.gitignore index fd3dbb5..04e4071 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +dist/ \ No newline at end of file diff --git a/README.md b/README.md index aa113ba..a091bd6 100644 --- a/README.md +++ b/README.md @@ -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 +``` + ## The XML Prompt You are an expert software engineer. diff --git a/app/_components/apply-changes-form.tsx b/app/_components/apply-changes-form.tsx index f583622..db6a914 100644 --- a/app/_components/apply-changes-form.tsx +++ b/app/_components/apply-changes-form.tsx @@ -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} />
diff --git a/cli.ts b/cli.ts new file mode 100644 index 0000000..911c23d --- /dev/null +++ b/cli.ts @@ -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 "); + 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(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f575b10..b212cb4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,10 +18,14 @@ "tailwind-merge": "^2.5.5", "tailwindcss-animate": "^1.0.7" }, + "bin": { + "o1-xml-parser": "dist/cli.js" + }, "devDependencies": { "@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", @@ -524,6 +528,13 @@ "@types/react": "^18" } }, + "node_modules/@types/xmldom": { + "version": "0.1.34", + "resolved": "https://registry.npmjs.org/@types/xmldom/-/xmldom-0.1.34.tgz", + "integrity": "sha512-7eZFfxI9XHYjJJuugddV6N5YNeXgQE1lArWOcd1eCOKWb/FGs5SIjacSYuEJuwhsGS3gy4RuZ5EUIcqYscuPDA==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.17.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.17.0.tgz", @@ -1189,9 +1200,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001687", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001687.tgz", - "integrity": "sha512-0S/FDhf4ZiqrTUiQ39dKeUjYRjkv7lOZU1Dgif2rIqrTzX/1wV2hfKu9TOm1IHkdSijfLswxTFzl/cvir+SLSQ==", + "version": "1.0.30001688", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001688.tgz", + "integrity": "sha512-Nmqpru91cuABu/DTCXbM2NSRHzM2uVHfPnhJ/1zEAJx/ILBRVmz3pzH4N7DZqbdG0gWClsCC05Oj0mJ/1AWMbA==", "funding": [ { "type": "opencollective", diff --git a/package.json b/package.json index bc156d3..c98b77c 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } -} +} \ No newline at end of file