From e51f10023a20eb79cd3560e92758ce6050b6b00b Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 8 Sep 2021 20:46:19 +0300 Subject: [PATCH] Update file.js --- scripts/helpers/file.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/helpers/file.js b/scripts/helpers/file.js index 578c76a73c..71889707b2 100644 --- a/scripts/helpers/file.js +++ b/scripts/helpers/file.js @@ -1,10 +1,30 @@ const markdownInclude = require('markdown-include') const path = require('path') +const glob = require('glob') const fs = require('fs') const rootPath = path.resolve(__dirname) + '/../../' const file = {} +file.list = function (include = [], exclude = []) { + return new Promise(resolve => { + glob('channels/*.m3u', function (err, files) { + console.log(include, exclude) + if (include.length) { + include = include.map(filename => `channels/${filename}.m3u`) + files = files.filter(filename => include.includes(filename)) + } + + if (exclude.length) { + exclude = exclude.map(filename => `channels/${filename}.m3u`) + files = files.filter(filename => !exclude.includes(filename)) + } + + resolve(files) + }) + }) +} + file.getFilename = function (filename) { return path.parse(filename).name }