From d2f580413074e28d6cdd28682186ecf38529c1ed Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Wed, 19 Jul 2023 04:16:12 +0300 Subject: [PATCH] Update file.js --- scripts/core/file.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/core/file.js b/scripts/core/file.js index 55300e7e..8a2f7eab 100644 --- a/scripts/core/file.js +++ b/scripts/core/file.js @@ -4,6 +4,23 @@ const fs = require('fs-extra') const file = {} +file.templateVariables = function (template) { + const match = template.match(/{[^}]+}/g) + + return Array.isArray(match) ? match.map(s => s.substring(1, s.length - 1)) : [] +} + +file.templateFormat = function (template, obj) { + let output = template + for (let key in obj) { + const regex = new RegExp(`{${key}}`, 'g') + const value = obj[key] || undefined + output = output.replace(regex, value) + } + + return output +} + file.list = function (pattern) { return new Promise(resolve => { glob(pattern, function (err, files) {