@template-tools/template-sync
Version:
Keep repository in sync with its template
36 lines (32 loc) • 817 B
JavaScript
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)
)
]
};
}
}
}
}