Skip to main content

file:modify

The file:modify action modifies a file by applying a set of transformations to its content.

Usage

{
type: 'file:modify',
target: 'path/to/file',
transform: (content) => content.toUpperCase()
}

Properties

NameDescriptionDefaultRequired
targetRelative path to the fileYes
transformTransformation function to apply to the file contentYes
patternPattern to match in the file contentNo
replaceReplacement string for the matched patternNo

target

The relative path to the file that needs to be modified.

transform

Type: function

Transformation function to apply to the file content. This function should accept a single argument, content, and return the modified content.

pattern

Type: string or RegExp

Pattern to match in the file content. If provided, the replace option must also be provided.

replace

Type: string

Replacement string for the matched pattern. If provided, the pattern option must also be provided.

Examples

Basic File Modification

import { Scaffold } from '@panda/scaffold'

new Scaffold({
name: 'foo:create',
actions: [
{
type: 'file:modify',
target: 'path/to/file',
transform: (content) => content.toUpperCase()
}
]
})

File Modification with Pattern Matching

import { Scaffold } from '@panda/scaffold'

new Scaffold({
name: 'foo:create',
actions: [
{
type: 'file:modify',
target: 'path/to/file',
pattern: 'foo',
replace: 'bar'
}
]
})

File Modification with Regular Expression

import { Scaffold } from '@panda/scaffold'

new Scaffold({
name: 'foo:create',
actions: [
{
type: 'file:modify',
target: 'path/to/file',
pattern: /foo/g,
replace: 'bar'
}
]
})