-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
91 lines (84 loc) · 3.17 KB
/
gulpfile.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
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
const gulp = require('gulp');
const fs = require('fs');
gulp.task('generate-config', () => {
return new Promise((resolve, reject) => {
// Get current environment
let env = 'dev'; // default environment
if ('SHOWTUNES_ENV' in process.env) {
env = process.env.SHOWTUNES_ENV;
}
let configJson = {};
// Get values from current config file if exists
const configFilepath = `./src/assets/config/config.${env}.json`;
if (fs.existsSync(configFilepath)) {
configJson = JSON.parse(fs.readFileSync(configFilepath));
console.log('In gulp :: Read from file: ' + JSON.stringify(configJson));
}
// Check config objects exist
if (!configJson.env) {
configJson.env = {};
}
if (!configJson.auth) {
configJson.auth = {};
}
// Overwrite config with environment variables
if ('SHOWTUNES_DOMAIN' in process.env) {
configJson.env.domain = process.env.SHOWTUNES_DOMAIN;
}
if ('SHOWTUNES_SPOTIFY_API_URL' in process.env) {
configJson.env.spotifyApiUrl = process.env.SHOWTUNES_SPOTIFY_API_URL;
}
if ('SHOWTUNES_SPOTIFY_ACCOUNTS_URL' in process.env) {
configJson.env.spotifyAccountsUrl = process.env.SHOWTUNES_SPOTIFY_ACCOUNTS_URL;
}
if ('SHOWTUNES_PLAYBACK_POLLING' in process.env) {
const playbackPolling = parseInt(process.env.SHOWTUNES_PLAYBACK_POLLING);
if (!isNaN(playbackPolling)) {
configJson.env.playbackPolling = playbackPolling;
}
}
if ('SHOWTUNES_IDLE_POLLING' in process.env) {
const idlePolling = parseInt(process.env.SHOWTUNES_IDLE_POLLING);
if (!isNaN(idlePolling)) {
configJson.env.idlePolling = idlePolling;
}
}
if ('SHOWTUNES_THROTTLE_DELAY' in process.env) {
const throttleDelay = parseInt(process.env.SHOWTUNES_THROTTLE_DELAY);
if (!isNaN(throttleDelay)) {
configJson.env.throttleDelay = throttleDelay;
}
}
if ('SHOWTUNES_CLIENT_ID' in process.env) {
configJson.auth.clientId = process.env.SHOWTUNES_CLIENT_ID;
}
if ('SHOWTUNES_SCOPES' in process.env) {
configJson.auth.scopes = process.env.SHOWTUNES_SCOPES;
}
if ('SHOWTUNES_FORCE_PKCE' in process.env) {
configJson.auth.forcePkce = process.env.SHOWTUNES_FORCE_PKCE;
}
if ('SHOWTUNES_CLIENT_SECRET' in process.env) {
configJson.auth.clientSecret = process.env.SHOWTUNES_CLIENT_SECRET;
}
if ('SHOWTUNES_TOKEN_URL' in process.env) {
configJson.auth.tokenUrl = process.env.SHOWTUNES_TOKEN_URL;
}
if ('SHOWTUNES_AUTH_SHOW_DIALOG' in process.env) {
configJson.auth.showDialog = process.env.SHOWTUNES_AUTH_SHOW_DIALOG;
}
if ('SHOWTUNES_AUTH_EXPIRY_THRESHOLD' in process.env) {
const expiryThreshold = parseInt(process.env.SHOWTUNES_AUTH_EXPIRY_THRESHOLD);
if (!isNaN(expiryThreshold)) {
configJson.auth.expiryThreshold = expiryThreshold;
}
}
console.log('In gulp :: After OS Env: ' + JSON.stringify(configJson));
if (!configJson.env.name) {
configJson.env.name = env;
}
// Rewrite json config to dist
fs.writeFileSync(`./dist/showtunes/assets/config/config.${env}.json`, JSON.stringify(configJson));
resolve();
});
});