mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update file.js
This commit is contained in:
parent
b50351137d
commit
356b63bc63
1 changed files with 19 additions and 3 deletions
|
@ -1,16 +1,15 @@
|
||||||
const glob = require('glob')
|
const glob = require('glob')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
function list(pattern, include = [], exclude = []) {
|
function list(pattern, include = [], exclude = []) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
glob(pattern, function (err, files) {
|
glob(pattern, function (err, files) {
|
||||||
if (include.length) {
|
if (include.length) {
|
||||||
include = include.map(filename => `channels/${filename}.xml`)
|
|
||||||
files = files.filter(filename => include.includes(filename))
|
files = files.filter(filename => include.includes(filename))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exclude.length) {
|
if (exclude.length) {
|
||||||
exclude = exclude.map(filename => `channels/${filename}.xml`)
|
|
||||||
files = files.filter(filename => !exclude.includes(filename))
|
files = files.filter(filename => !exclude.includes(filename))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +18,28 @@ function list(pattern, include = [], exclude = []) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load(filename) {
|
||||||
|
const filePath = path.resolve(filename)
|
||||||
|
|
||||||
|
return require(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
function read(filename) {
|
function read(filename) {
|
||||||
return fs.readFileSync(filename, { encoding: 'utf8' })
|
return fs.readFileSync(filename, { encoding: 'utf8' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function write(filename, data) {
|
||||||
|
const dir = path.resolve(path.dirname(filename))
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
fs.mkdirSync(dir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(path.resolve(filename), data)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
list,
|
list,
|
||||||
read
|
read,
|
||||||
|
write,
|
||||||
|
load
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue