-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.js
More file actions
104 lines (89 loc) · 2.85 KB
/
Copy pathbuild.js
File metadata and controls
104 lines (89 loc) · 2.85 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const fs = require('fs');
const path = require('path');
const KITS = require('./js/data/kits.js').default;
const root = __dirname;
const outDir = path.join(root, 'docs');
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src)) {
if (entry === 'url.txt') continue; // skip helper metadata files
copyRecursive(path.join(src, entry), path.join(dest, entry));
}
} else {
fs.copyFileSync(src, dest);
}
}
// clean output directory
if (fs.existsSync(outDir)) {
fs.rmSync(outDir, { recursive: true, force: true });
}
fs.mkdirSync(outDir, { recursive: true });
// files/directories to copy
const items = [
{ src: 'template.html', dest: 'index.html' },
{ src: 'console.html', dest: 'console.html' },
{ src: 'privacy.txt', dest: 'privacy.txt' },
{ src: 'css', dest: 'css' },
{ src: 'js', dest: 'js' },
{ src: 'CNAME', dest: 'CNAME' },
{ src: 'apk', dest: 'apk' }
];
for (const item of items) {
const srcPath = path.join(root, item.src);
const destPath = path.join(outDir, item.dest);
copyRecursive(srcPath, destPath);
}
// generate APK metadata for static builds
function generateApkMetadata() {
const apkDir = path.join(root, 'apk');
const entries = fs.readdirSync(apkDir, { withFileTypes: true });
const apps = entries
.filter((e) => e.isDirectory() && e.name !== 'blog')
.map((dir) => {
const dirPath = path.join(apkDir, dir.name);
let postInstallCommands = null;
const commandPath = path.join(dirPath, 'command.txt');
if (fs.existsSync(commandPath)) {
const content = fs.readFileSync(commandPath, 'utf8');
postInstallCommands = content
.trim()
.split('\n')
.filter((c) => c.trim());
}
let imageUrl = null;
for (const file of fs.readdirSync(dirPath)) {
if (/\.(png|jpe?g|svg)$/i.test(file)) {
imageUrl = `apk/${dir.name}/${file}`;
break;
}
}
// Allow per-app override of APK URL via optional url.txt
let apkUrl = `https://pub-587c8a0ce03148689a821b1655d304f5.r2.dev/${dir.name}.apk`;
const urlPath = path.join(dirPath, 'url.txt');
if (fs.existsSync(urlPath)) {
apkUrl = fs.readFileSync(urlPath, 'utf8').trim();
}
return {
name: dir.name,
image: imageUrl,
url: apkUrl,
postInstallCommands
};
});
const enrichedApps = apps.map((app) => {
const kit = KITS.find((k) => k.key === app.name);
if (kit) {
if (kit.pricing) app.pricing = kit.pricing;
if (kit.badge) app.badge = kit.badge;
}
return app;
});
fs.writeFileSync(
path.join(outDir, 'apks.json'),
JSON.stringify(enrichedApps, null, 2)
);
}
generateApkMetadata();
console.log(`Built static site in ${outDir}`);