fix index function to handle options passed

This commit is contained in:
Antoine Kingue 2024-03-18 13:28:58 +01:00
parent 9478b8a7b5
commit 9467e82496
2 changed files with 15 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
"google-indexing-script": patch
---
Fix index function to handle options passed

View File

@ -21,10 +21,7 @@ export type IndexOptions = {
path?: string;
};
export const index = async (
input: string = process.argv[2],
options: IndexOptions = {},
) => {
export const index = async (input: string = process.argv[2], options: IndexOptions = {}) => {
if (!input) {
console.error("❌ Please provide a domain or site URL as the first argument.");
console.error("");
@ -32,9 +29,15 @@ export const index = async (
}
const args = parseCommandLineArgs(process.argv.slice(2));
options.client_email = args['client-email'] || process.env.GIS_CLIENT_EMAIL;
options.private_key = args['private-key'] || process.env.GIS_PRIVATE_KEY;
options.path = args['path'] || process.env.GIS_PATH;
if (!options.client_email) {
options.client_email = args["client-email"] || process.env.GIS_CLIENT_EMAIL;
}
if (!options.private_key) {
options.private_key = args["private-key"] || process.env.GIS_PRIVATE_KEY;
}
if (!options.path) {
options.path = args["path"] || process.env.GIS_PATH;
}
const accessToken = await getAccessToken(options.client_email, options.private_key, options.path);
const siteUrl = convertToSiteUrl(input);