n8n-workflow-manager
Version:
Command-line tools for managing n8n workflows with version control and TypeScript support
352 lines (269 loc) ⢠10.3 kB
Markdown
# n8n-workflow-manager
> Command-line tools for managing n8n workflows with version control and TypeScript support
[](https://www.npmjs.com/package/n8n-workflow-manager)
[](https://www.npmjs.com/package/n8n-workflow-manager)
[](https://github.com/northfacejmb/n8n-workflow-manager)
[](https://opensource.org/licenses/MIT)
[](https://github.com/northfacejmb/n8n-workflow-manager/issues)
[](https://github.com/northfacejmb/n8n-workflow-manager/stargazers)
## š Quick Start
### Installation
```bash
npm install --save-dev n8n-workflow-manager
```
### Initialize your project
```bash
npx n8n-workflow-manager init
```
### Basic Usage
```bash
# Split n8n workflows into individual files
npx n8n-workflow-manager split
# Package files back into n8n workflow JSON
npx n8n-workflow-manager package
# Generate TypeScript types
npx n8n-workflow-manager types
```
## š What is n8n-workflow-manager?
n8n-workflow-manager is a powerful CLI tool that helps you manage n8n workflows with proper version control, TypeScript support, and team collaboration features. It solves the common problems of:
- **Version Control**: n8n workflows are large JSON files that are difficult to version control and review
- **Team Collaboration**: Multiple developers can't easily work on the same workflow
- **Code Organization**: Complex workflows become hard to maintain and understand
- **Type Safety**: No TypeScript support for workflow development
## šÆ Features
### ⨠Core Features
- š **Bidirectional Conversion**: JSON ā Individual Files
- š **Smart File Organization**: Automatic directory structure creation
- šÆ **Interactive Workflow Selection**: Choose which workflows to process
- š§ **Configurable**: Customize behavior via `n8n-config.json`
- š¦ **Local Installation**: No global dependencies required
### š§ Advanced Features
- š·ļø **TypeScript Support**: Generate type definitions for workflows
- š¾ **Backup Creation**: Automatic backups before packaging
- ā
**Workflow Validation**: Validate workflow structure and integrity
- š **Progress Reporting**: Detailed operation statistics
- š **Code Node Extraction**: Split JavaScript/TypeScript code into separate files
## š Commands
### `npx n8n-workflow-manager init`
Initialize n8n workflow management in your project.
```bash
npx n8n-workflow-manager init
```
**Options:**
- `--force` - Overwrite existing configuration
### `npx n8n-workflow-manager split`
Extract n8n workflows into individual files for version control.
```bash
# Interactive selection
npx n8n-workflow-manager split
# Split all workflows
npx n8n-workflow-manager split --all
# Split specific workflow
npx n8n-workflow-manager split --workflow bug-tracker
```
**Options:**
- `--workflow <name>` - Split specific workflow
- `--all` - Split all workflows
- `--dry-run` - Preview changes without making them
### `npx n8n-workflow-manager package`
Package individual files back into n8n workflow JSON.
```bash
# Interactive selection
npx n8n-workflow-manager package
# Package all workflows
npx n8n-workflow-manager package --all
# Package specific workflow
npx n8n-workflow-manager package --workflow bug-tracker
```
**Options:**
- `--workflow <name>` - Package specific workflow
- `--all` - Package all workflows
- `--dry-run` - Preview changes without making them
### `npx n8n-workflow-manager types`
Generate TypeScript type definitions for workflows.
```bash
# Generate types for all workflows
npx n8n-workflow-manager types
# Generate types for specific workflow
npx n8n-workflow-manager types --workflow bug-tracker
```
**Options:**
- `--workflow <name>` - Generate types for specific workflow
- `--all` - Generate types for all workflows
- `--base` - Generate base type definitions only
## āļø Configuration
Create `n8n-config.json` in your project root to customize behavior:
```json
{
"workflowsDir": "workflows",
"n8nDir": "n8n",
"generateTypes": true,
"typeScript": {
"enabled": true,
"outputDir": "types"
},
"ignore": [
"node_modules",
".git",
".env",
".env.*"
],
"extraction": {
"preserveIds": true,
"generateIndex": true,
"splitCodeNodes": true
},
"packaging": {
"validateWorkflows": true,
"minifyOutput": false,
"backupOriginal": true
}
}
```
### Configuration Options
| Option | Description | Default |
|--------|-------------|---------|
| `workflowsDir` | Directory for extracted workflows | `workflows` |
| `n8nDir` | Directory for n8n JSON files | `n8n` |
| `generateTypes` | Generate TypeScript types | `true` |
| `typeScript.enabled` | Enable TypeScript support | `true` |
| `typeScript.outputDir` | TypeScript output directory | `types` |
| `extraction.preserveIds` | Keep original node IDs | `true` |
| `extraction.generateIndex` | Generate node index files | `true` |
| `extraction.splitCodeNodes` | Split code nodes into separate files | `true` |
| `packaging.validateWorkflows` | Validate workflow structure | `true` |
| `packaging.backupOriginal` | Backup before packaging | `true` |
## š Directory Structure
After initialization, your project will have:
```
your-project/
āāā n8n/ # n8n workflow JSON files
ā āāā bug-tracker.json # Original workflow exports
ā āāā github-pr.json
āāā workflows/ # Extracted workflow files
ā āāā bug-tracker/
ā ā āāā workflow.json # Base workflow structure
ā ā āāā metadata.json # Workflow metadata
ā ā āāā connections.json # Node connections
ā ā āāā nodes/ # Individual node files
ā ā ā āāā webhook.json
ā ā ā āāā code-node.js
ā ā ā āāā linear-create.json
ā ā āāā types/ # TypeScript definitions
ā ā āāā nodes.d.ts
ā āāā github-pr/
ā āāā ...
āāā types/ # Global TypeScript types
ā āāā n8n-workflows.d.ts
āāā n8n-config.json # Configuration file
```
## š§ Global Options
Available on all commands:
- `--config <path>` - Path to config file (default: `n8n-config.json`)
- `--verbose` - Enable verbose logging
- `--dry-run` - Show what would be done without making changes
- `--help` - Show help information
## š” Use Cases
### Team Collaboration
1. **Split workflows** into individual files for easier code review
2. **Version control** each node and connection separately
3. **Merge conflicts** become manageable with individual files
4. **Parallel development** on different parts of the same workflow
### Code Organization
1. **Extract code nodes** into separate `.js`/`.ts` files
2. **Organize complex workflows** into logical file structures
3. **Reuse common nodes** across multiple workflows
4. **Generate TypeScript types** for better development experience
### CI/CD Integration
1. **Validate workflows** before deployment
2. **Automatic packaging** in build pipelines
3. **Type checking** for workflow code
4. **Backup creation** before updates
## š Examples
### Basic Workflow Management
```bash
# Initialize project
npx n8n-workflow-manager init
# Place your n8n workflow JSON files in the n8n/ directory
cp my-workflow.json n8n/
# Split into individual files
npx n8n-workflow-manager split
# Edit files in workflows/ directory
# ...make changes...
# Package back to JSON
npx n8n-workflow-manager package
```
### TypeScript Development
```bash
# Generate TypeScript types
npx n8n-workflow-manager types
# Your code nodes can now use proper types
// workflows/my-workflow/nodes/process-data.ts
import { N8nNode, WorkflowContext } from '../types/nodes';
export function processData(context: WorkflowContext): N8nNode {
// Type-safe workflow development
return {
json: {
processed: true,
data: context.inputData
}
};
}
```
### CI/CD Pipeline
```yaml
# .github/workflows/n8n-workflows.yml
name: n8n Workflows
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Validate workflows
run: npx n8n-workflow-manager package --dry-run
- name: Generate types
run: npx n8n-workflow-manager types
- name: Type check
run: npx tsc --noEmit
```
## š Development
To contribute to this project:
1. **Clone the repository:**
```bash
git clone https://github.com/northfacejmb/n8n-workflow-manager.git
cd n8n-workflow-manager
```
2. **Install dependencies:**
```bash
npm install
```
3. **Run linting:**
```bash
npm run lint
```
4. **Test your changes:**
```bash
npm test
```
## š¤ Contributing
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
**Quick ways to contribute:**
- š [Report bugs](https://github.com/northfacejmb/n8n-workflow-manager/issues/new?labels=bug)
- š” [Request features](https://github.com/northfacejmb/n8n-workflow-manager/issues/new?labels=enhancement)
- š Improve documentation
- š§ Submit pull requests
## š License
MIT Ā© [Jeremy Press](https://github.com/jeremypress)
## š Links
- š¦ **[npm Package](https://www.npmjs.com/package/n8n-workflow-manager)** - Install and use the CLI tool
- š **[GitHub Repository](https://github.com/northfacejmb/n8n-workflow-manager)** - Source code and development
- š **[Issue Tracker](https://github.com/northfacejmb/n8n-workflow-manager/issues)** - Report bugs and request features
- š **[n8n Documentation](https://docs.n8n.io/)** - Learn about n8n workflows
---
Made with ā¤ļø for the n8n community