Post-clone manipulation system allowing repositories to define automated actions via degit.json configuration files for customizing the cloned output.
Actions are defined in a degit.json file placed at the root of the source repository.
// degit.json format
interface DegitAction[] {
action: "clone" | "remove";
// Action-specific properties
}Usage Examples:
[
{
"action": "clone",
"src": "user/another-repo"
},
{
"action": "remove",
"files": ["LICENSE", "README.md"]
}
]Clones additional repositories into the current working directory, preserving existing content.
/**
* Clone action configuration for adding additional repositories
*/
interface CloneAction {
action: "clone";
src: string;
cache?: boolean;
verbose?: boolean;
}Usage Examples:
// degit.json
[
{
"action": "clone",
"src": "user/additional-files"
},
{
"action": "clone",
"src": "org/shared-config",
"cache": true,
"verbose": true
}
]Behavior:
Removes specified files or directories from the cloned repository.
/**
* Remove action configuration for deleting files/directories
*/
interface RemoveAction {
action: "remove";
files: string | string[];
}Usage Examples:
// degit.json - Remove single file
[
{
"action": "remove",
"files": "LICENSE"
}
]
// Remove multiple files
[
{
"action": "remove",
"files": ["LICENSE", "README.md", "docs/"]
}
]Behavior:
Actions are processed automatically after the main repository clone completes.
/**
* Internal action processing system
*/
interface DirectiveActions {
clone: (dir: string, dest: string, action: CloneAction) => Promise<void>;
remove: (dir: string, dest: string, action: RemoveAction) => void;
}Processing Order:
degit.json is read from the destination directorydegit.json is automatically removed after processingEvent Handling:
The actions system includes a file stashing mechanism to preserve existing content during clone actions.
/**
* File stashing utilities for preserving content during clone actions
*/
function stashFiles(dir: string, dest: string): void;
function unstashFiles(dir: string, dest: string): void;Stashing Behavior:
degit.json from being restored (it's consumed during processing)// Main template degit.json
[
{
"action": "clone",
"src": "shared/base-config"
},
{
"action": "clone",
"src": "shared/eslint-config"
},
{
"action": "remove",
"files": ["shared/base-config/.gitignore"]
}
]// Remove development files for production template
[
{
"action": "remove",
"files": [
"test/",
"src/__tests__/",
".travis.yml",
"jest.config.js"
]
}
]// Repository A degit.json
[
{
"action": "clone",
"src": "org/repo-b" // repo-b can have its own degit.json
}
]The actions system automatically detects and processes degit.json files.
/**
* Configuration file detection and processing
*/
const degitConfigName = "degit.json";
function _getDirectives(dest: string): DegitAction[] | false;Detection Process:
degit.json in the root of the cloned directoryError Handling:
degit.json will cause the clone to fail