-
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.
config style json to js, secret loader removed
- Loading branch information
Showing
16 changed files
with
164 additions
and
217 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
dist | ||
sample-op | ||
credentials | ||
robot.txt | ||
sitemap.xml | ||
.hawk.lrs | ||
|
||
gserv.json | ||
secrets.json |
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
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 was deleted.
Oops, something went wrong.
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,47 +1,33 @@ | ||
import { existsSync, readFileSync } from "fs"; | ||
import { join } from "path"; | ||
import { ConfigurationOptions, ftpCredentialOptions } from "./lib/options"; | ||
import { existsSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
import { ConfigurationOptions } from "./lib/types"; | ||
|
||
const CONFIG_FILE_NAME = "hawk.config.json"; | ||
export default function loadConfig(): ConfigurationOptions { | ||
const CONFIG_FILE_NAME = "hawk.config"; | ||
|
||
const projectConfigFile = join(process.cwd(), CONFIG_FILE_NAME); | ||
const projectHasConfig = existsSync(projectConfigFile); | ||
const projectConfigFile = join(process.cwd(), `${CONFIG_FILE_NAME}.js`); | ||
const projectHasConfig = existsSync(projectConfigFile); | ||
|
||
let projectConfig: ConfigurationOptions = {} as ConfigurationOptions; | ||
let defaultConfig: ConfigurationOptions = {} as ConfigurationOptions; | ||
let projectConfig: ConfigurationOptions = {} as ConfigurationOptions; | ||
let defaultConfig: ConfigurationOptions = {} as ConfigurationOptions; | ||
|
||
if (projectHasConfig) { | ||
//load project config | ||
try { | ||
projectConfig = JSON.parse( | ||
readFileSync(projectConfigFile, { encoding: "utf8" }), | ||
); | ||
} catch (err) { | ||
if (err instanceof SyntaxError) { | ||
console.log( | ||
"Error: Check configuration file if there any syntax mistake", | ||
); | ||
} else { | ||
console.log("Unexpected Error while loading settings"); | ||
if (projectHasConfig) { | ||
//load project config | ||
try { | ||
projectConfig = require(projectConfigFile).default; | ||
} catch (err) { | ||
console.log("Error while loading settings\n", err); | ||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
} | ||
//load default configuration | ||
defaultConfig = JSON.parse( | ||
readFileSync(join(__dirname, CONFIG_FILE_NAME), { encoding: "utf8" }), | ||
); | ||
|
||
const ftpCredential: ftpCredentialOptions = { | ||
hostname: process.env.FTPHOST ?? "", | ||
username: process.env.FTPUSER ?? "", | ||
password: process.env.FTPPASS ?? "", | ||
}; | ||
//load default configuration | ||
defaultConfig = require(join(__dirname, CONFIG_FILE_NAME)).default; | ||
|
||
const configurations: ConfigurationOptions = { | ||
...defaultConfig, | ||
...projectConfig, | ||
...{ ftpCredential: ftpCredential }, | ||
}; | ||
const configurations: ConfigurationOptions = { | ||
...defaultConfig, | ||
...projectConfig, | ||
}; | ||
|
||
export default configurations; | ||
return configurations; | ||
} |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import { ConfigurationOptions } from "./lib/types"; | ||
|
||
const config: ConfigurationOptions = { | ||
lookupPatterns: ["**/*.html", "**/*.htm"], | ||
ignorePattern: ["node_modules/**"], | ||
timeZone: "Asia/Kolkata", | ||
domainName: "www.cresteem.com", | ||
sitemapPath: "sitemap.xml", | ||
robotPath: "robot.txt", | ||
serviceAccountFile: "gserv.json", | ||
ftpCredential: {} as any, | ||
}; | ||
|
||
export default config; |
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
Oops, something went wrong.