comment-block-migrator
v1.0.2
Published
Migration utility for markdown-magic - Migrate markdown files with find-and-replace transformations
Maintainers
Readme
comment-block-migrator
Migration utility for markdown-magic - Migrate markdown files with find-and-replace transformations.
Installation
npm install comment-block-migratorUsage
Basic Migration
const { migrateMarkdownFiles } = require('comment-block-migrator');
await migrateMarkdownFiles({
replacements: [
{ find: /<!--\s*doc-gen/g, replace: '<!-- docs' },
{ find: /<!--\s*end-doc-gen/g, replace: '<!-- /docs' }
]
});Dry Run Mode
Preview what would change without modifying files:
await migrateMarkdownFiles({
pattern: 'docs/**/*.md',
replacements: [
{ find: 'old-word', replace: 'new-word' }
],
dryRun: true
});Migrate from doc-gen to docs
Convenience function for the common doc-gen → docs migration:
const { migrateDocGenToDocs } = require('comment-block-migrator');
await migrateDocGenToDocs();API
migrateMarkdownFiles(options)
Migrate markdown files by applying find-and-replace transformations.
Options
pattern(string): Glob pattern for files to migrate. Default:**/*.mdcwd(string): Current working directory. Default:process.cwd()ignore(string[]): Patterns to ignore. Default:['**/node_modules/**']replacements(Array): Array of replacement rules withfindandreplacepropertiesverbose(boolean): Whether to log progress. Default:truedryRun(boolean): If true, don't write files, just report what would change. Default:false
Returns
Promise that resolves to:
filesProcessed(number): Total files foundfilesUpdated(number): Number of files that were modifiedupdatedFiles(string[]): Array of file paths that were updated
migrateDocGenToDocs(options)
Convenience function for migrating from doc-gen to docs syntax. Accepts the same options as migrateMarkdownFiles.
Examples
Custom Replacements
await migrateMarkdownFiles({
pattern: 'docs/**/*.md',
replacements: [
{ find: /OLD_SYNTAX/g, replace: 'NEW_SYNTAX' },
{ find: 'foo', replace: 'bar' }
],
verbose: true
});Multiple Patterns
// Migrate specific directories
await migrateMarkdownFiles({
pattern: '{docs,examples}/**/*.md',
replacements: [
{ find: /old-pattern/g, replace: 'new-pattern' }
]
});License
MIT © David Wells
