-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.js
executable file
·58 lines (41 loc) · 1.34 KB
/
setup.js
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
#!/usr/bin/env node
const fs = require('fs-extra');
const download = require('download');
const { resolve } = require('path');
const themes = require('./themes.json');
const activeThemePath = 'public/adminer.css';
const getThemePath = (theme) =>
resolve(__dirname, `public/themes/${theme}.css`);
const activateTheme = async (theme) => {
if (!theme) return;
const themePath = getThemePath(theme);
if (!(await fs.exists(themePath))) {
await downloadTheme(theme);
}
console.log('Using theme:', theme);
await fs.copy(themePath, activeThemePath);
};
const downloadTheme = async (theme) => {
const themeUrl = themes[theme];
const themePath = getThemePath(theme);
// Invalid theme
if (!themeUrl) {
console.log('Invalid theme:', theme);
process.exit(1);
}
if (await fs.exists(themePath)) return;
console.log('Downloading theme:', theme);
await download(themeUrl, 'public/themes', { filename: theme + '.css' });
};
const install = () => {
const adminerSrc =
'https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1-en.php';
fs.mkdirpSync(resolve(__dirname, 'public/themes'));
if (fs.existsSync('public/index.php')) return;
download(adminerSrc).pipe(
fs.createWriteStream(resolve(__dirname, 'public/index.php'))
);
activateTheme('hydra');
};
install();
exports.activateTheme = activateTheme;