-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpreact.config.js
47 lines (45 loc) · 1.39 KB
/
preact.config.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
export default (config, env, helpers) => {
saveFile();
let uglify = helpers.getPluginsByName(config, 'UglifyJsPlugin')[0];
if (uglify) {
uglify.plugin.options.sourceMap = false;
}
};
// FIXME... this is a pretty bad place to do this :|
async function saveFile() {
require('dotenv').config();
if (!process.env.FIREBASE_LOGIN_URL || process.env.FIREBASE_LOGIN_URL === 'https://example.com') {
return;
}
const firebaseAuth = await fetch(process.env.FIREBASE_LOGIN_URL, {
body: JSON.stringify({
email: process.env.FIREBASE_USER_EMAIL,
password: process.env.FIREBASE_USER_PASSWORD,
returnSecureToken: true,
}),
method: 'POST',
});
const firebaseAuthResult = await firebaseAuth.json();
var firebaseAuthToken = firebaseAuthResult.idToken;
const fs = require('fs');
await fetch(`${process.env.FIREBASE_URL}/podcasts.json?auth=${firebaseAuthToken}`, {
method: 'get',
})
.then((resp) => resp.json())
.then(function (data) {
let keyArray = Object.keys(data);
let newDataArray = [];
for (let i = 0; i < keyArray.length; i++) {
let pc = data[keyArray[i]];
pc.name = pc.title;
newDataArray.push(pc);
}
fs.writeFileSync(
'./assets/data/podcasts.json',
JSON.stringify({
podcasts: newDataArray,
})
);
console.log('--- new podcasts.json saved --');
});
}