UNPKG

@template-tools/template-sync

Version:
36 lines (32 loc) 817 B
import { StringContentEntry } from "content-entry"; import { Merger } from "../merger.mjs"; /** * Overwrites none existing entries from template. */ export class ReplaceIfEmpty extends Merger { static get priority() { return 0.1; } static async *commits( context, destinationEntry, sourceEntry, options = this.options ) { if (await destinationEntry.isEmpty) { const source = await sourceEntry.string; if (source.length > 0) { yield { message: `${options.messagePrefix}add missing ${destinationEntry.name} from template`, entries: [ new StringContentEntry( destinationEntry.name, undefined, context.expand(source, options.expand) ) ] }; } } } }