diff --git a/.gitignore b/.gitignore index 151731c..c9815ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules dist -sample-op -credentials +robot.txt +sitemap.xml .hawk.lrs - +gserv.json +secrets.json diff --git a/CONTRIBUTING b/CONTRIBUTING index 8c97300..28bd84e 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -1,6 +1,6 @@ -# Contributing to HAWK JS +# Contributing to Hawk.js -First off, thank you for considering contributing to HAWK JS! We welcome contributions from the community. +First off, thank you for considering contributing to Hawk.js! We welcome contributions from the community. ## License Agreement diff --git a/README.md b/README.md index 0a7f27b..19cea09 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@
-# Hawk JS - Advanced Sitemap Generator and Deployer for SEO +# Hawk.js - Advanced Sitemap Generator and Deployer for SEO -

Hawk JS is an advanced sitemap generator and deployer designed to enhance your website's search engine optimization (SEO). It automates the creation of comprehensive sitemaps and simplifies submission to major search engines like Google, Bing, Yahoo, Yandex, and more, ensuring your site is indexed accurately and quickly.

+

Hawk.js is an advanced sitemap generator and deployer designed to enhance your website's search engine optimization (SEO). It automates the creation of comprehensive sitemaps and simplifies submission to major search engines like Google, Bing, Yahoo, Yandex, and more, ensuring your site is indexed accurately and quickly.

### Supported Platforms @@ -153,12 +153,12 @@ Thank you for being part of this journey. Your support means the world to us. ## Installation - Step-by-Step Guide đŸĒœ Follow Below link: -[Getting Started with Hawk JS](https://hawkjs.cresteem.com/getting-started-with-hawk-js) +[Getting Started with Hawk.js](https://hawkjs.cresteem.com/getting-started-with-hawk-js) ## Usage -Everything from top to bottom of Hawk JS available here - https://hawkjs.cresteem.com/ +Everything from top to bottom of Hawk.js available here - https://hawkjs.cresteem.com/ ## License Šī¸ @@ -186,7 +186,7 @@ For any questions, please reach out via connect@cresteem.com ## Credits 🙏đŸģ -Hawk JS is developed and maintained by [DARSAN](https://darsan.in/) at [CRESTEEM](https://cresteem.com/). +Hawk.js is developed and maintained by [DARSAN](https://darsan.in/) at [CRESTEEM](https://cresteem.com/). --- @@ -269,5 +269,5 @@ Hawk JS is developed and maintained by [DARSAN](https://darsan.in/) at [CRESTEEM
  • content management
  • digital marketing
  • cresteem
  • -
  • hawk js
  • +
  • Hawk.js
  • diff --git a/bin/CLIDriver.ts b/bin/CLIDriver.ts index 4eb630c..2c7a28c 100644 --- a/bin/CLIDriver.ts +++ b/bin/CLIDriver.ts @@ -3,7 +3,6 @@ import yargs from "yargs"; import { hawk, hawkStrategy } from "../hawk"; import { makeSitemap } from "../lib/utils"; -import { secretLoadWindows } from "./secretsLoader"; async function _genMapHandler(argv: any): Promise { if (argv.commit) { @@ -69,11 +68,8 @@ async function main(): Promise { .help().argv; const isGenMap: boolean = argv._.includes("genmap"); - const isSecret: boolean = argv._.includes("secret"); if (isGenMap) { _genMapHandler(argv); - } else if (isSecret) { - secretLoadWindows(); } else { _mainHandler(argv); } diff --git a/bin/secretsLoader.ts b/bin/secretsLoader.ts deleted file mode 100644 index 6873eb1..0000000 --- a/bin/secretsLoader.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { exec } from "child_process"; -import { randomBytes } from "crypto"; -import { readFileSync, rmSync, writeFileSync } from "fs"; -import { join } from "path"; -import configuration from "../configLoader"; -import { secretObjectStructure } from "../lib/options"; -const { secretFile } = configuration; - -export function secretLoadWindows(): void { - const secretData: secretObjectStructure = JSON.parse( - readFileSync(join(process.cwd(), secretFile), { encoding: "utf8" }), - ); - //make batchFile - const batchScript: string = `setx /M FTPHOST "${secretData.host}"\nsetx /M FTPUSER "${secretData.user}"\nsetx /M FTPPASS "${secretData.pass}"`; - - const batchFile: string = join( - __dirname, - `${randomBytes(8).toString("hex")}.bat`, - ); - - writeFileSync(batchFile, batchScript, { encoding: "utf8" }); - - //runas admin - const command: string = `powershell -Command "Start-Process -Verb RunAs '${batchFile}' -Wait -WindowStyle Hidden"`; - - //Execute batchscript - exec(command, (error, _stdout, stderr) => { - //delete script - rmSync(batchFile); - - if (error || stderr) { - console.log(`Error loading secrets: ${error?.message}`); - } - - console.log("🔐👍đŸģ Secrets loaded successfully"); - }); -} diff --git a/configLoader.ts b/configLoader.ts index b35c42e..596f53f 100644 --- a/configLoader.ts +++ b/configLoader.ts @@ -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; +} diff --git a/hawk.config.json b/hawk.config.json deleted file mode 100644 index aabb91b..0000000 --- a/hawk.config.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "lookupPatterns": [ - "**/*.html", - "**/*.htm" - ], - "ignorePattern": [ - "node_modules/**" - ], - "timeZone": "Asia/Kolkata", - "domainName": "www.example.com", - "sitemapPath": "sitemap.xml", - "robotPath": "robot.txt", - "secretFile": "secrets.json" -} \ No newline at end of file diff --git a/hawk.config.ts b/hawk.config.ts new file mode 100644 index 0000000..e1e0937 --- /dev/null +++ b/hawk.config.ts @@ -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; diff --git a/hawk.ts b/hawk.ts index cce46aa..7a2d5fa 100644 --- a/hawk.ts +++ b/hawk.ts @@ -1,10 +1,10 @@ -import { suppotredStrategies, sitemapMetaOptions } from "./lib/options"; import { googleIndex, lastSubmissionStatusGAPI, submitSitemapGAPI, } from "./lib/gindex"; import { indexNow } from "./lib/indexnow"; +import { SitemapMeta, SuppotredStrategies } from "./lib/types"; import { getLastRunTimeStamp, getUpdatedRoutesPath, @@ -39,14 +39,13 @@ export const hawkStrategy = { await submitSitemapGAPI(); /* check status */ - const statusMeta: sitemapMetaOptions = - await lastSubmissionStatusGAPI(); + const statusMeta: SitemapMeta = await lastSubmissionStatusGAPI(); console.log(statusMeta); }, }; export async function hawk( - strategy: suppotredStrategies, + strategy: SuppotredStrategies, lookupPatterns: string[] = [], ignorePattern: string[] = [], prettify: boolean = true, @@ -89,7 +88,7 @@ async function _makeSitemapRobot( } async function strategyHandler( - strategy: suppotredStrategies, + strategy: SuppotredStrategies, stateChangedRoutes: string[], prettify: boolean = true, lookupPatterns: string[] = [], diff --git a/lib/gindex.ts b/lib/gindex.ts index b7b6233..5ebcdbe 100644 --- a/lib/gindex.ts +++ b/lib/gindex.ts @@ -2,11 +2,10 @@ import { google } from "googleapis"; import { request } from "https"; import { - constants, - googleIndexResponseOptions, - googleIndexStatusCode, - sitemapMetaOptions, -} from "./options"; + GoogleIndexResponseOptions, + GoogleIndexStatusCode, + SitemapMeta, +} from "./types"; import config from "../configLoader"; import { @@ -14,12 +13,12 @@ import { lastStateReader, lastStateWriter, } from "./utils"; -const { domainName, sitemapPath } = config; +const { domainName, sitemapPath, serviceAccountFile } = config(); function _callIndexingAPI( accessToken: string, updatedRoute: string, -): Promise { +): Promise { return new Promise((resolve, reject) => { const postData: string = JSON.stringify({ url: updatedRoute, @@ -42,10 +41,10 @@ function _callIndexingAPI( responseBody += data; }); res.on("end", () => { - const response: googleIndexResponseOptions = { + const response: GoogleIndexResponseOptions = { url: updatedRoute, body: JSON.parse(responseBody), - statusCode: (res.statusCode ?? 0) as googleIndexStatusCode, + statusCode: (res.statusCode ?? 0) as GoogleIndexStatusCode, }; resolve(response); }); @@ -61,10 +60,10 @@ function _callIndexingAPI( } export async function googleIndex(stateChangedRoutes: string[]) { - const callPromises: Promise[] = []; + const callPromises: Promise[] = []; const jwtClient = new google.auth.JWT({ - keyFile: constants.serviceAccountFile, + keyFile: serviceAccountFile, scopes: ["https://www.googleapis.com/auth/indexing"], }); @@ -84,14 +83,14 @@ export async function googleIndex(stateChangedRoutes: string[]) { ); }); - const apiResponses: googleIndexResponseOptions[] = await Promise.all( + const apiResponses: GoogleIndexResponseOptions[] = await Promise.all( callPromises, ); /* Grouping api responses */ const statusGroups: Record< - googleIndexStatusCode, - googleIndexResponseOptions[] + GoogleIndexStatusCode, + GoogleIndexResponseOptions[] > = { 204: [], //dummy 400: [], @@ -166,7 +165,7 @@ export async function googleIndex(stateChangedRoutes: string[]) { } function _sitemapGAPIResponseHandler( - response: googleIndexResponseOptions, + response: GoogleIndexResponseOptions, ) { switch (response.statusCode) { case 200: @@ -194,7 +193,7 @@ export function submitSitemapGAPI(): Promise { const sitemapURL: string = `https://${domainName}/${sitemapPath}`; const jwtClient = new google.auth.JWT({ - keyFile: constants.serviceAccountFile, + keyFile: serviceAccountFile, scopes: ["https://www.googleapis.com/auth/webmasters"], }); @@ -236,10 +235,10 @@ export function submitSitemapGAPI(): Promise { }); res.on("end", () => { - const response: googleIndexResponseOptions = { + const response: GoogleIndexResponseOptions = { url: sitemapURL, body: responseBody ? JSON.parse(responseBody) : "", - statusCode: res.statusCode as googleIndexStatusCode, + statusCode: res.statusCode as GoogleIndexStatusCode, }; _sitemapGAPIResponseHandler(response); @@ -258,7 +257,7 @@ export function submitSitemapGAPI(): Promise { }); } -export function lastSubmissionStatusGAPI(): Promise { +export function lastSubmissionStatusGAPI(): Promise { const lastSubmittedURL: string = lastStateReader( "submittedSitemap", ) as string; @@ -269,7 +268,7 @@ export function lastSubmissionStatusGAPI(): Promise { } const jwtClient = new google.auth.JWT({ - keyFile: constants.serviceAccountFile, + keyFile: serviceAccountFile, scopes: ["https://www.googleapis.com/auth/webmasters"], }); @@ -304,7 +303,7 @@ export function lastSubmissionStatusGAPI(): Promise { reject("😕 Last submittion status not found"); } - const sitemapMeta: sitemapMetaOptions = { + const sitemapMeta: SitemapMeta = { pageCounts: targetedMeta?.contents ? parseInt(targetedMeta?.contents[0].submitted ?? "0") : 0, diff --git a/lib/indexnow.ts b/lib/indexnow.ts index 7aed176..7158724 100644 --- a/lib/indexnow.ts +++ b/lib/indexnow.ts @@ -3,8 +3,8 @@ import { randomBytes } from "crypto"; import { readFileSync, rmSync, writeFileSync } from "fs"; import { request } from "https"; import configurations from "../configLoader"; -import { constants, ranStatusFileStructute } from "./options"; -const { domainName } = configurations; +import { constants, RanStatusFileStructure } from "./types"; +const { domainName, ftpCredential } = configurations(); function _makeSecretKey(): string { /* Make 32 char hex key */ @@ -12,8 +12,8 @@ function _makeSecretKey(): string { } async function _secretKeyManager(): Promise { - let ranStatusObject: ranStatusFileStructute = - {} as ranStatusFileStructute; + let ranStatusObject: RanStatusFileStructure = + {} as RanStatusFileStructure; try { ranStatusObject = JSON.parse( @@ -43,9 +43,9 @@ async function _secretKeyManager(): Promise { const ftp: FTP = new FTP(); try { await ftp.access({ - user: configurations.ftpCredential.username, - password: configurations.ftpCredential.password, - host: configurations.ftpCredential.hostname, + user: ftpCredential.username, + password: ftpCredential.password, + host: ftpCredential.hostname, }); await ftp.uploadFrom(tempkeyfile, keyDestination); console.log("KeyFile Uploaded to server 🔑👍đŸģ"); @@ -55,7 +55,7 @@ async function _secretKeyManager(): Promise { rmSync(tempkeyfile); /* keeping secret key*/ - let newObject: ranStatusFileStructute = { ...ranStatusObject }; + let newObject: RanStatusFileStructure = { ...ranStatusObject }; newObject.secretKey = secretKey; writeFileSync( constants.ranStatusFile, diff --git a/lib/options.ts b/lib/types.ts similarity index 66% rename from lib/options.ts rename to lib/types.ts index a5f83cf..6d61750 100644 --- a/lib/options.ts +++ b/lib/types.ts @@ -13,23 +13,23 @@ export interface ConfigurationOptions { domainName: string; sitemapPath: string; robotPath: string; - secretFile: string; - /* Private property */ ftpCredential: ftpCredentialOptions; + serviceAccountFile: string; } -export interface RouteMetaOptions { +export interface RouteMeta { route: string; modifiedTime: string; } -export type lastStateKeyNames = - | "lastRunTimeStamp" - | "secretKey" - | "submittedSitemap"; +export interface LastStateType { + lastRunTimeStamp: number; + secretKey: string; + submittedSitemap: string; +} -export interface ranStatusFileStructute { +export interface RanStatusFileStructure { lastRunTimeStamp: number; secretKey: string; submittedSitemap: string; @@ -37,30 +37,31 @@ export interface ranStatusFileStructute { interface constantsStructure { ranStatusFile: string; - serviceAccountFile: string; } export const constants: constantsStructure = { ranStatusFile: join(process.cwd(), ".hawk.lrs"), - serviceAccountFile: join(process.cwd(), "gserv.json"), }; -interface responseBodyError { +interface ResponseBodyError { code: string; message: string; status: string; } -interface responseBodyStructure { - error: responseBodyError; + +interface ResponseBodyStructure { + error: ResponseBodyError; } -export type googleIndexStatusCode = 200 | 400 | 403 | 429 | 204; -export interface googleIndexResponseOptions { + +export type GoogleIndexStatusCode = 200 | 400 | 403 | 429 | 204; + +export interface GoogleIndexResponseOptions { url: string; - body: responseBodyStructure; - statusCode: googleIndexStatusCode; + body: ResponseBodyStructure; + statusCode: GoogleIndexStatusCode; } -export interface sitemapMetaOptions { +export interface SitemapMeta { pageCounts: number; lastSubmitted: string; lastDownloaded: string; @@ -69,13 +70,13 @@ export interface sitemapMetaOptions { errors: number; } -export type suppotredStrategies = +export type SuppotredStrategies = | "GIndex" /* Google Indexing API - Only for job posting & live broadcasting video content page*/ | "GWebmaster" /* General web sitemap submission */ | "GWebmaster2" /* General web sitemap submission with status check-back */ | "IndexNow"; /* Index now api only for Bing, Yahoo, Yandex, Yep etc */ -export interface secretObjectStructure { +export interface SecretObjectType { host: string; user: string; pass: string; diff --git a/lib/utils.ts b/lib/utils.ts index e4b4841..3bbe0ce 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -2,9 +2,9 @@ import { Client as FTP } from "basic-ftp"; import { existsSync, readFileSync, + rmSync, statSync, writeFileSync, - rmSync, } from "fs"; import { globSync } from "glob"; import { toXML as XMLBuilder } from "jstoxml"; @@ -12,20 +12,20 @@ import { DateTime } from "luxon"; import { basename, relative } from "path"; import configurations from "../configLoader"; import { - RouteMetaOptions, constants, - lastStateKeyNames, - ranStatusFileStructute, -} from "./options"; -const { timeZone } = configurations; + LastStateType, + RanStatusFileStructure, + RouteMeta, +} from "./types"; +const config = configurations(); /* sitemap oriented function def started */ function _lookupFiles( lookupPatterns: string[] = [], ignorePattern: string[] = [], ): string[] { const webPageFilePaths: string[] = globSync( - [...configurations.lookupPatterns, ...lookupPatterns], - { ignore: [...configurations.ignorePattern, ...ignorePattern] }, + [...config.lookupPatterns, ...lookupPatterns], + { ignore: [...config.ignorePattern, ...ignorePattern] }, ); return webPageFilePaths; @@ -35,7 +35,7 @@ function _lookupFiles( function _getModtime(filePath: string): string | null { const mTime: number = statSync(filePath).mtime.getTime(); //in epoch const ISOTime: string | null = DateTime.fromMillis(mTime) - .setZone(configurations.timeZone) + .setZone(config.timeZone) .toISO(); return ISOTime; } @@ -43,8 +43,8 @@ function _getModtime(filePath: string): string | null { export function getRoutesMeta( lookupPatterns: string[] = [], ignorePattern: string[] = [], -): RouteMetaOptions[] { - const routesMeta: RouteMetaOptions[] = [] as RouteMetaOptions[]; +): RouteMeta[] { + const routesMeta: RouteMeta[] = [] as RouteMeta[]; _lookupFiles(lookupPatterns, ignorePattern).forEach( (filePath: string): void => { @@ -53,7 +53,7 @@ export function getRoutesMeta( /* Make web standard path: */ const pageExtension: string = - "." + basename(relativePath).split(".").at(-1) ?? ""; + "." + basename(relativePath).split(".").at(-1) || ""; let standardPath: string; @@ -79,7 +79,7 @@ export function getRoutesMeta( } } - const route: string = `https://${configurations.domainName}/${standardPath}`; + const route: string = `https://${config.domainName}/${standardPath}`; routesMeta.push({ route: route, @@ -91,9 +91,7 @@ export function getRoutesMeta( return routesMeta; } -function _buildUrlObjects( - routesMeta: RouteMetaOptions[], -): Record[] { +function _buildUrlObjects(routesMeta: RouteMeta[]): Record[] { const urlElements: Record[] = []; for (const routeMeta of routesMeta) { @@ -113,15 +111,15 @@ async function _uploadSitemap(): Promise { try { await ftp.access({ - user: configurations.ftpCredential.username, - password: configurations.ftpCredential.password, - host: configurations.ftpCredential.hostname, + user: config.ftpCredential.username, + password: config.ftpCredential.password, + host: config.ftpCredential.hostname, }); /* Making path relative from root for server */ - const remotePath: string = "/" + configurations.sitemapPath; + const remotePath: string = "/" + config.sitemapPath; - await ftp.uploadFrom(configurations.sitemapPath, remotePath); + await ftp.uploadFrom(config.sitemapPath, remotePath); ftp.close(); return true; @@ -147,7 +145,7 @@ export async function makeSitemap( xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9", }, _content: _buildUrlObjects( - getRoutesMeta(lookupPatterns, ignorePattern), + getRoutesMeta(lookupPatterns, [...ignorePattern, "node_modules/**"]), ), }; @@ -159,7 +157,7 @@ export async function makeSitemap( /* write sitemap.xml */ try { - writeFileSync(configurations.sitemapPath, siteMapXML); + writeFileSync(config.sitemapPath, siteMapXML); if (!dontup) { /* Upload site map to ftp server */ @@ -179,14 +177,14 @@ export async function makeSitemap( /* Robot.txt oriented functions */ export function makeRobot(): string { - const robotContent: string = `sitemap: https://${configurations.domainName}/${configurations.sitemapPath}\n`; + const robotContent: string = `sitemap: https://${config.domainName}/${config.sitemapPath}\n`; - if (existsSync(configurations.robotPath)) { + if (existsSync(config.robotPath)) { let previousContent: string; /* Read and load previous content */ try { - previousContent = readFileSync(configurations.robotPath, "utf8"); + previousContent = readFileSync(config.robotPath, "utf8"); } catch (err) { console.log("Error while reading robot.txt"); process.exit(1); @@ -213,7 +211,7 @@ export function makeRobot(): string { const newRobotContent: string = robotContent + previousContent; try { - writeFileSync(configurations.robotPath, newRobotContent); + writeFileSync(config.robotPath, newRobotContent); return `robot.txt updated`; } catch (err) { console.log("Error updating sitemap in existing robots.txt:", err); @@ -224,7 +222,7 @@ export function makeRobot(): string { /* Adding site map to robot.txt */ try { - writeFileSync(configurations.robotPath, newRobotContent); + writeFileSync(config.robotPath, newRobotContent); return `link added in robot.txt`; } catch (err) { console.log("Error adding sitemap in existing robots.txt:", err); @@ -236,7 +234,7 @@ export function makeRobot(): string { /* Creating robot.txt and adding sitemap link into it */ try { - writeFileSync(configurations.robotPath, robotContent); + writeFileSync(config.robotPath, robotContent); return "robot.txt created"; } catch (err) { console.log("Error while creating robot.txt"); @@ -284,19 +282,19 @@ export function getUpdatedRoutesPath( } function _updateLastRuntimeStamp( - previousDataObject: ranStatusFileStructute | null = null, + previousDataObject: RanStatusFileStructure | null = null, ): void { const currentTimeStamp: number = DateTime.now() - .setZone(timeZone) + .setZone(config.timeZone) .toMillis(); /* Create new object if previous data object is not passed as a parameter */ - const dataObject: ranStatusFileStructute = - ({ ...previousDataObject } as ranStatusFileStructute) ?? + const dataObject: RanStatusFileStructure = + (previousDataObject as RanStatusFileStructure) ?? ({ lastRunTimeStamp: 0, secretKey: "", - } as ranStatusFileStructute); + } as RanStatusFileStructure); /* Updating timestamp */ dataObject.lastRunTimeStamp = currentTimeStamp; @@ -315,7 +313,7 @@ function _updateLastRuntimeStamp( export function getLastRunTimeStamp(): number { if (existsSync(constants.ranStatusFile)) { try { - const ranStatusObject: ranStatusFileStructute = JSON.parse( + const ranStatusObject: RanStatusFileStructure = JSON.parse( readFileSync(constants.ranStatusFile, { encoding: "utf8", }), @@ -340,31 +338,32 @@ export function convertTimeinCTZone(ISOTime: string): string { if (!!!ISOTime) { return ISOTime; } - const timeinCTZone: DateTime = - DateTime.fromISO(ISOTime).setZone(timeZone); + const timeinCTZone: DateTime = DateTime.fromISO( + ISOTime, + ).setZone(config.timeZone); const formatedTime: string = timeinCTZone.toFormat("hh:mm:ss a - DD"); return formatedTime; } export function lastStateWriter( - newObject: Partial, + newObject: Partial, ): void { - let previousDataObject: ranStatusFileStructute; + let previousDataObject: RanStatusFileStructure; try { previousDataObject = JSON.parse( readFileSync(constants.ranStatusFile, { encoding: "utf8" }), ); } catch (err: any) { if (err.code === "ENOENT") { - previousDataObject = {} as ranStatusFileStructute; + previousDataObject = {} as RanStatusFileStructure; } else { console.log("Unexpected error ", err); process.exit(1); } } - const updatedDataObject: ranStatusFileStructute = { + const updatedDataObject: RanStatusFileStructure = { ...previousDataObject, ...newObject, }; @@ -375,9 +374,9 @@ export function lastStateWriter( } export function lastStateReader( - keyName: lastStateKeyNames, + keyName: keyof LastStateType, ): string | number { - let dataObject: ranStatusFileStructute; + let dataObject: RanStatusFileStructure; try { dataObject = JSON.parse( readFileSync(constants.ranStatusFile, { encoding: "utf8" }), diff --git a/package.json b/package.json index e679fa2..4bbe809 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "@cresteem/hawk-js", - "displayName": "Hawk JS", + "displayName": "Hawk.js", "version": "1.0.8", - "description": "Hawk JS is an advanced sitemap generator and deployer designed to enhance your website's search engine optimization (SEO). It automates the creation of comprehensive sitemaps and simplifies submission to major search engines like Google, Bing, Yahoo, Yandex, and more, ensuring your site is indexed accurately and quickly.", + "description": "Hawk.js is an advanced sitemap generator and deployer designed to enhance your website's search engine optimization (SEO). It automates the creation of comprehensive sitemaps and simplifies submission to major search engines like Google, Bing, Yahoo, Yandex, and more, ensuring your site is indexed accurately and quickly.", "main": "./dist/hawk.js", "exports": { + "types": "./dist/types/hawk.d.ts", "import": "./dist/hawk.js", - "require": "./dist/hawk.js", - "types": "./dist/types/hawk.d.ts" + "require": "./dist/hawk.js" }, "files": [ "dist" @@ -36,7 +36,7 @@ "license": "Apache-2.0", "private": false, "scripts": { - "dev": "rimraf dist && tsc -p dev/tscdev.json", + "dev": "rimraf dist && tsc -p tscdev.json", "test": "jest", "build": "cls && eslint && rimraf dist && tsc -p tsconfig.json", "watch": "tsc --watch", @@ -62,7 +62,7 @@ "content management", "digital marketing", "cresteem", - "hawk js" + "Hawk.js" ], "dependencies": { "basic-ftp": "5.0.5", @@ -88,4 +88,4 @@ "ts-node": "10.9.2", "typescript": "5.7.2" } -} +} \ No newline at end of file diff --git a/dev/tscdev.json b/tscdev.json similarity index 80% rename from dev/tscdev.json rename to tscdev.json index 9039be4..b17badf 100644 --- a/dev/tscdev.json +++ b/tscdev.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "ES2022", - "module": "CommonJS", - "moduleResolution": "Node10", + "target": "ESNext", + "module": "NodeNext", + "moduleResolution": "NodeNext", "baseUrl": ".", "rootDir": ".", "outDir": "dist", @@ -23,16 +23,18 @@ "allowSyntheticDefaultImports": true, "resolveJsonModule": true, "pretty": false, - "noUnusedLocals": true, + "noUnusedLocals": false, "noImplicitOverride": false, "noUnusedParameters": true, "noUncheckedIndexedAccess": false, "sourceMap": false, - "removeComments": true + "removeComments": true, + "skipLibCheck": true }, "exclude": [ "node_modules", "test", - "jest.config.ts" + "jest.config.ts", + "dist" ] } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 81208d2..435ff16 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,16 +25,17 @@ "allowSyntheticDefaultImports": true, "resolveJsonModule": true, "pretty": false, - "noUnusedLocals": true, + "noUnusedLocals": false, "noImplicitOverride": false, "noUnusedParameters": true, "noUncheckedIndexedAccess": false, "sourceMap": false, - "removeComments": true + "removeComments": true, + "skipLibCheck": true }, "exclude": [ "node_modules", "test", - "jest.config.ts" + "jest.config.ts", ] } \ No newline at end of file