-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for manually updating js file
- Loading branch information
Showing
3 changed files
with
59 additions
and
28 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
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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import { existsSync } from "fs"; | ||
import { config } from "dotenv"; | ||
|
||
export default class Config { | ||
public readonly personaId: string; | ||
public readonly githubToken: string; | ||
public readonly giteeToken: string; | ||
public readonly paratranzToken: string; | ||
public readonly manualMode: boolean; | ||
|
||
constructor(debug: boolean = false) { | ||
if (debug) { | ||
constructor() { | ||
if (existsSync(".env.debug")) { | ||
config({ path: ".env.debug" }); | ||
} | ||
|
||
this.personaId = process.env.PERSONA_ID || ""; | ||
this.githubToken = process.env.GH_TOKEN || ""; | ||
this.giteeToken = process.env.GITEE_TOKEN || ""; | ||
this.paratranzToken = process.env.PARATRANZ_TOKEN || ""; | ||
const rawConfig = { | ||
personaId: process.env.PERSONA_ID, | ||
githubToken: process.env.GH_TOKEN, | ||
giteeToken: process.env.GITEE_TOKEN, | ||
paratranzToken: process.env.PARATRANZ_TOKEN, | ||
manualMode: process.env.MANUAL_MODE, | ||
}; | ||
|
||
if (Object.values(this).some((value) => value === "")) { | ||
if (Object.values(this).some((value) => value === undefined)) { | ||
throw new Error("Missing environment variables."); | ||
} | ||
|
||
this.personaId = rawConfig.personaId as string; | ||
this.githubToken = rawConfig.githubToken as string; | ||
this.giteeToken = rawConfig.giteeToken as string; | ||
this.paratranzToken = rawConfig.paratranzToken as string; | ||
this.manualMode = Boolean(rawConfig.manualMode as string); | ||
} | ||
} |
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