comment-block-migrator helps migrate markdown files with find-and-replace transformations.
Full documentation, synced from the source README:
Migration utility for markdown-magic - Migrate markdown files with find-and-replace transformations.
npm install comment-block-migratorconst { migrateMarkdownFiles } = require('comment-block-migrator');
await migrateMarkdownFiles({
replacements: [
{ find: /<!--\s*doc-gen/g, replace: '<!-- docs' },
{ find: /<!--\s*end-doc-gen/g, replace: '<!-- /docs' }
]
});Preview what would change without modifying files:
await migrateMarkdownFiles({
pattern: 'docs/**/*.md',
replacements: [
{ find: 'old-word', replace: 'new-word' }
],
dryRun: true
});Convenience function for the common doc-gen → docs migration:
const { migrateDocGenToDocs } = require('comment-block-migrator');
await migrateDocGenToDocs();migrateMarkdownFiles(options)Migrate markdown files by applying find-and-replace transformations.
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 with find and replace propertiesverbose (boolean): Whether to log progress. Default: truedryRun (boolean): If true, don't write files, just report what would change. Default: falsePromise that resolves to:
filesProcessed (number): Total files foundfilesUpdated (number): Number of files that were modifiedupdatedFiles (string[]): Array of file paths that were updatedmigrateDocGenToDocs(options)Convenience function for migrating from doc-gen to docs syntax. Accepts the same options as migrateMarkdownFiles.
await migrateMarkdownFiles({
pattern: 'docs/**/*.md',
replacements: [
{ find: /OLD_SYNTAX/g, replace: 'NEW_SYNTAX' },
{ find: 'foo', replace: 'bar' }
],
verbose: true
});// Migrate specific directories
await migrateMarkdownFiles({
pattern: '{docs,examples}/**/*.md',
replacements: [
{ find: /old-pattern/g, replace: 'new-pattern' }
]
});MIT © David Wells