diff --git a/scripts/templates/_config.js b/scripts/templates/_config.js index b4eb9b46..2e40921d 100644 --- a/scripts/templates/_config.js +++ b/scripts/templates/_config.js @@ -1,16 +1,16 @@ -module.exports = { - site: '', - url({ channel, date }) { - return `https://example.com/api/${channel.site_id}/${date.format('YYYY-MM-DD')}` - }, - parser({ content }) { - try { - return JSON.parse(content) - } catch { - return [] - } - }, - channels() { - return [] - } -} +module.exports = { + site: '', + url({ channel, date }) { + return `https://example.com/api/${channel.site_id}/${date.format('YYYY-MM-DD')}` + }, + parser({ content }) { + try { + return JSON.parse(content) + } catch { + return [] + } + }, + channels() { + return [] + } +} diff --git a/scripts/templates/_readme.md b/scripts/templates/_readme.md index 0b807f7f..4aa94527 100644 --- a/scripts/templates/_readme.md +++ b/scripts/templates/_readme.md @@ -1,21 +1,21 @@ -# - -https:// - -### Download the guide - -```sh -npm run grab --- --site= -``` - -### Update channel list - -```sh -npm run channels:parse --- --config=./sites//.config.js --output=./sites//.channels.xml -``` - -### Test - -```sh -npm test --- -``` +# + +https:// + +### Download the guide + +```sh +npm run grab --- --site= +``` + +### Update channel list + +```sh +npm run channels:parse --- --config=./sites//.config.js --output=./sites//.channels.xml +``` + +### Test + +```sh +npm test --- +``` diff --git a/scripts/templates/_sites.md b/scripts/templates/_sites.md index d0633a4c..46191a4e 100644 --- a/scripts/templates/_sites.md +++ b/scripts/templates/_sites.md @@ -1,3 +1,3 @@ -# Sites - -_TABLE_ +# Sites + +_TABLE_ diff --git a/scripts/templates/_test.js b/scripts/templates/_test.js index b02a2648..6375d7e7 100644 --- a/scripts/templates/_test.js +++ b/scripts/templates/_test.js @@ -1,38 +1,38 @@ -const { parser, url } = require('./.config.js') -const dayjs = require('dayjs') -const utc = require('dayjs/plugin/utc') -const customParseFormat = require('dayjs/plugin/customParseFormat') -dayjs.extend(customParseFormat) -dayjs.extend(utc) - -const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d') -const channel = { site_id: 'bbc1' } - -it('can generate valid url', () => { - expect(url({ channel, date })).toBe('https://example.com/api/bbc1/2025-01-12') -}) - -it('can parse response', () => { - const content = - '[{"title":"Program 1","start":"2025-01-12T00:00:00.000Z","stop":"2025-01-12T00:30:00.000Z"},{"title":"Program 2","start":"2025-01-12T00:30:00.000Z","stop":"2025-01-12T01:00:00.000Z"}]' - - const results = parser({ content }) - - expect(results.length).toBe(2) - expect(results[0]).toMatchObject({ - title: 'Program 1', - start: '2025-01-12T00:00:00.000Z', - stop: '2025-01-12T00:30:00.000Z' - }) - expect(results[1]).toMatchObject({ - title: 'Program 2', - start: '2025-01-12T00:30:00.000Z', - stop: '2025-01-12T01:00:00.000Z' - }) -}) - -it('can handle empty guide', () => { - const results = parser({ content: '' }) - - expect(results).toMatchObject([]) -}) +const { parser, url } = require('./.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +const date = dayjs.utc('2025-01-12', 'YYYY-MM-DD').startOf('d') +const channel = { site_id: 'bbc1' } + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://example.com/api/bbc1/2025-01-12') +}) + +it('can parse response', () => { + const content = + '[{"title":"Program 1","start":"2025-01-12T00:00:00.000Z","stop":"2025-01-12T00:30:00.000Z"},{"title":"Program 2","start":"2025-01-12T00:30:00.000Z","stop":"2025-01-12T01:00:00.000Z"}]' + + const results = parser({ content }) + + expect(results.length).toBe(2) + expect(results[0]).toMatchObject({ + title: 'Program 1', + start: '2025-01-12T00:00:00.000Z', + stop: '2025-01-12T00:30:00.000Z' + }) + expect(results[1]).toMatchObject({ + title: 'Program 2', + start: '2025-01-12T00:30:00.000Z', + stop: '2025-01-12T01:00:00.000Z' + }) +}) + +it('can handle empty guide', () => { + const results = parser({ content: '' }) + + expect(results).toMatchObject([]) +}) diff --git a/scripts/types/langs.d.ts b/scripts/types/langs.d.ts index 60fb498a..74921c68 100644 --- a/scripts/types/langs.d.ts +++ b/scripts/types/langs.d.ts @@ -1 +1 @@ -declare module 'langs' +declare module 'langs'