import * as fs from "fs" ; import * as path from "path" ; import { promisify } from "util" ; import { src , dest } from "vinyl-fs" ; import * as pump from "pump" ; import * as replace from "gulp-replace" ; import { prepend } from "gulp-insert" ; const promisifiedPump = promisify ( pump ) ; const FILE_HEADER = `\
//////////////////////////////////////////////////////////////
// This file is generated from the Minecraft documentation. //
// DO NOT EDIT THIS FILE! YOUR CHANGES WILL BE OVERWRITTEN! //
//////////////////////////////////////////////////////////////

` ; export default async function ( templateFiles , outputDir , values ) { const regex = /^([ \t]*)\$\$(.*)\$\$/gm ; const replaceFunction = ( text , indent , name ) => { if ( ! values [ name ] ) throw new Error ( `Variable with name "${ name }" doesn't exist` ) ; return values [ name ] . replace ( /^/gm , indent ) ; } ; await promisifiedPump ( src ( templateFiles ) , replace ( regex , replaceFunction ) , prepend ( FILE_HEADER ) , dest ( outputDir ) ) ; }