CLI tool to import code files from an XML manifest with diff support, auto-skip identical files, and force-overwrite option
npm install import-code-xmlA 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.
- 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
``bashNavigate to package directory
cd /path/to/import-code-xml
$3
`bash
npm install -g import-code-xml
`After installation, the
import-code command will be available globally.Usage
$3
`bash
import-code -f import_code.xml
`$3
`bash
import-code -f import_code.xml --force-overwrite
or
import-code -f import_code.xml --fo
`XML File Format
The XML file should follow this structure:
`xml
relative/or/absolute/path/to/file.extension
Your file content here
with exact formatting
including:
- Line breaks
- Tabs
- Indentation
- Special characters
]]>
another/file/path.js
function example() {
return "Hello World";
}
]]>
`$3
1. Use to preserve all formatting exactly
2. Each file is defined in an block
3. should be the destination file path
4. contains the exact file contentAI 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:
[FILE_PATH_1]
[EXACT_FILE_CONTENT_1]
]]>
[FILE_PATH_2]
[EXACT_FILE_CONTENT_2]
]]>
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]
`$3
`
Please generate an XML file for code import with the following files.
Use the exact format below with CDATA sections to preserve formatting:
utils/helpers.js
[EXACT_FILE_CONTENT_1]
]]>
config/settings.json
[EXACT_FILE_CONTENT_2]
]]>
Files to include:
1. utils/helpers.js: A JavaScript utility module with helper functions
2. config/settings.json: Configuration file with default settings
`Workflow Example
1. Prepare XML: Ask AI to generate code in the XML format
2. Save XML: Save the AI's response as
import_code.xml
3. Run import: import-code -f import_code.xml
4. Review diffs: The tool will show differences and prompt for actions
5. 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 libraryTroubleshooting
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 directoryMIT