import-code-xml
v1.0.0
Published
CLI tool to import code files from an XML manifest with diff support, auto-skip identical files, and force-overwrite option
Downloads
108
Maintainers
Readme
Import Code XML
A CLI tool to import code files from an XML manifest with diff support, auto-skip identical files, and force-overwrite option. Perfect for importing generated code from AI assistants while preserving exact formatting.
Features
- Smart diff detection: Automatically skips identical files
- Visual diff display: Shows differences before overwriting
- Interactive prompts: Choose to overwrite, skip, or view diff again
- Force overwrite mode: Bypass prompts for batch operations
- Format preservation: Maintains exact line breaks, tabs, and whitespace
Installation
Option 1: Install from local package
# Navigate to package directory
cd /path/to/import-code-xml
# Install globally
npm install -g .Option 2: Install from npm (if published)
npm install -g import-code-xmlAfter installation, the import-code command will be available globally.
Usage
Basic usage with prompts:
import-code -f import_code.xmlForce overwrite all files:
import-code -f import_code.xml --force-overwrite
# or
import-code -f import_code.xml --foXML File Format
The XML file should follow this structure:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<path>relative/or/absolute/path/to/file.extension</path>
<content><![CDATA[
Your file content here
with exact formatting
including:
- Line breaks
- Tabs
- Indentation
- Special characters
]]></content>
</item>
<item>
<path>another/file/path.js</path>
<content><![CDATA[
function example() {
return "Hello World";
}
]]></content>
</item>
</root>Important Notes:
- Use
<![CDATA[ ... ]]>to preserve all formatting exactly - Each file is defined in an
<item>block <path>should be the destination file path<content>contains the exact file content
AI Assistant Prompt Template
When asking an AI chatbot (like Claude, ChatGPT, etc.) to generate code for import, use this prompt:
Please generate an XML file for code import with the following files.
Use the exact format below with CDATA sections to preserve formatting:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<path>[FILE_PATH_1]</path>
<content><![CDATA[
[EXACT_FILE_CONTENT_1]
]]></content>
</item>
<item>
<path>[FILE_PATH_2]</path>
<content><![CDATA[
[EXACT_FILE_CONTENT_2]
]]></content>
</item>
</root>
Replace the bracketed placeholders with:
- [FILE_PATH_X]: The path where the file should be saved
- [EXACT_FILE_CONTENT_X]: The exact code with all formatting preserved
Files to include:
1. [Describe first file and its purpose]
2. [Describe second file and its purpose]
[Add more as needed]Example AI Prompt:
Please generate an XML file for code import with the following files.
Use the exact format below with CDATA sections to preserve formatting:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<path>utils/helpers.js</path>
<content><![CDATA[
[EXACT_FILE_CONTENT_1]
]]></content>
</item>
<item>
<path>config/settings.json</path>
<content><![CDATA[
[EXACT_FILE_CONTENT_2]
]]></content>
</item>
</root>
Files to include:
1. utils/helpers.js: A JavaScript utility module with helper functions
2. config/settings.json: Configuration file with default settingsWorkflow Example
- Prepare XML: Ask AI to generate code in the XML format
- Save XML: Save the AI's response as
import_code.xml - Run import:
import-code -f import_code.xml - Review diffs: The tool will show differences and prompt for actions
- Manage conflicts: Choose to overwrite (o), skip (s), or view diff again (d)
Behavior
- New files: Automatically created
- Identical files: Automatically skipped with notification
- Changed files: Shows diff and prompts for action
- Force overwrite: All files overwritten without prompts
- Missing directories: Automatically created
Dependencies
xml2js: XML parsing library
Troubleshooting
Permission denied: Ensure you have write permissions for target directories
XML parsing errors: Verify XML format and CDATA sections are properly closed
diff command not found: On Windows, install diffutils or use Git Bash/Cygwin
Global command not found: Try npm link in the package directory
License
MIT
