-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
60 lines (53 loc) · 1.91 KB
/
Copy pathbuild.js
File metadata and controls
60 lines (53 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import fs from 'fs';
import path from 'path';
// Mock some deps
global.window = {};
window.RssFinder = {};
window.RssFinder.settings = {};
window.Handlebars = {
registerHelper: () => {},
compile: () => {}
}
const statusFile = path.join('www', 'data', 'status.json');
const outputFile = path.join('www', 'js', 'SubscriberList.js');
const subscriberPath = path.join('www', 'js', 'subscribers');
const subscriberFiles = fs.readdirSync(subscriberPath).filter(file => file.endsWith('.js')).sort();
let subscribers = [];
await Promise.all(subscriberFiles.map(async file => {
console.log('Processing ./' + path.join(subscriberPath, file));
const m = await import('./' + path.join(subscriberPath, file));
const s = m.SubscriberImpl;
subscribers.push({
name: s.name,
module: file,
favicon: s.favicon
});
}));
console.log(`Writing ${outputFile} ...`);
fs.writeFileSync(outputFile, `
export class SubscriberList {
static #subscribers = ${JSON.stringify(subscribers.sort((a, b) => a.module.localeCompare(b.module)), null, 2)};
static getByName = (name) => SubscriberList.#subscribers.find(s => s.name === name);
static getAll = () => SubscriberList.#subscribers;
}`);
console.log(`Writing ${statusFile} ...`);
const now = Math.ceil(new Date() / 1000);
// FIXME: hard-coded interval (pipeline runs at least weekly)
const refreshInterval = 7 * 24 * 60 * 60;
fs.writeFileSync(statusFile, JSON.stringify({
meta: {
name: "RSS Finder Build",
links: {
"Website": "https://lwindolf.github.io/rss-finder/",
"GitHub": "https://github.com/lwindolf/rss-finder"
},
favicon: "https://lwindolf.github.io/rss-finder/icons/default.svg"
},
schedule: {
lastUpdate : now,
refresh : refreshInterval,
nextRun : refreshInterval + now,
maxAge : refreshInterval * 2
}
}, null, 2));
console.log('Done.');