-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f13b25a
commit 37aaebe
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import "dotenv/config"; | ||
import fs from "node:fs"; | ||
import readline from "node:readline"; | ||
|
||
function readConfigIfExists(filePath) { | ||
if (fs.existsSync(filePath)) { | ||
return JSON.parse(fs.readFileSync(filePath)); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
function runMigration(cron) { | ||
const configObject = { | ||
twitchLogin: process.env.BROADCASTER_LOGIN, | ||
cron: cron, | ||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
discordWebhook: process.env.DISCORD_WEBHOOK_URL, | ||
pollingInterval: process.env.POLLING_INTERVAL, | ||
suppressUntitled: process.env.SUPPRESS_UNTITLED.toLowerCase() == "true", | ||
showCreatedDate: process.env.SHOW_CREATED_DATE.toLowerCase() == "true", | ||
}; | ||
|
||
const config = readConfigIfExists(".config.json"); | ||
|
||
config.push(configObject); | ||
|
||
fs.writeFileSync(".config.json", JSON.stringify(config, null, 2)); | ||
console.log(JSON.stringify(config, null, 2)); | ||
|
||
const newEnv = `TWITCH_CLIENT_ID=${process.env.TWITCH_CLIENT_ID ?? "[0-9a-z]"}\nTWITCH_CLIENT_SECRET=${process.env.TWITCH_CLIENT_SECRET ?? "[0-9a-z]"}`; | ||
|
||
fs.writeFileSync(".env", newEnv); | ||
console.log(newEnv); | ||
} | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
rl.question( | ||
"Please enter the cron expression you want to have it run as:\n", | ||
(cron) => { | ||
rl.close(); | ||
runMigration(cron); | ||
}, | ||
); |