Skip to content

Commit

Permalink
user project config bug fixed
Browse files Browse the repository at this point in the history
Signed-off-by: iamspdarsan <iamspdarsan@gmail.com>
  • Loading branch information
darsan-in committed May 18, 2024
1 parent 2d526b6 commit b5cad3d
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 34 deletions.
41 changes: 41 additions & 0 deletions configLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { existsSync, readFileSync } from "fs";
import { join } from "path";
import { configurationOptions } from "./lib/options";

const CONFIG_FILE_NAME = "rjsconfig.json";

const projectConfigFile = join(process.cwd(), CONFIG_FILE_NAME);
const projectHasConfig = existsSync(projectConfigFile);

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");
}
process.exit(1);
}
} else {
//load default configuration
defaultConfig = JSON.parse(
readFileSync(join(__dirname, CONFIG_FILE_NAME), { encoding: "utf8" }),
);
}

const configurations: configurationOptions = {
...defaultConfig,
...projectConfig,
};

export default configurations;
4 changes: 3 additions & 1 deletion lib/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ import {
import { basename, dirname, join, relative, resolve } from "node:path";
import { cwd } from "node:process";

import { reservedNames, timeFormat } from "../rjsconfig.json";
import configurations from "../configLoader";

const { reservedNames, timeFormat } = configurations;

import { getCode } from "country-list";
import { stat } from "node:fs/promises";
Expand Down
210 changes: 210 additions & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,213 @@ export interface testProps {
testfile: string;
destFile: string;
}

export interface configurationOptions {
domainAddress: string;
timeFormat: string;
siteSearchBoxFieldName: string;
reservedNames: {
aggregateRating: {
wrapper: string;
aggregatedRatingValue: string;
maxRangeOfRating: string;
numberOfRatings: string;
};
reviews: {
parentWrapper: string;
childWrapper: string;
raterName: string;
ratedValue: string;
maxRateRange: string;
reviewPublishedOn: string;
};
common: {
fallbackCurrency: string;
publishedDate: string;
modifiedDate: string;
heroImage: string;
author: {
name: string;
url: string;
jobTitle: string;
};
publisher: {
name: string;
url: string;
};
authorAndPubPrefix: {
person: string;
organisation: string;
};
heroName: string;
entityDescription: string;
keywords: string;
MO: string;
currencyDataVar: string;
heroCost: string;
cuisineType: string;
heroLinkRef: string;
videoFrame: string;
};
article: {
baseID: string;
articleType: string;
authorNameStartwith: string;
publisherNameStartwith: string;
};
movie: {
baseID: string;
director: string;
};
recipe: {
baseID: string;
preptime: {
hours: string;
minutes: string;
hoursAndMinutes: string;
};
cooktime: {
hours: string;
minutes: string;
hoursAndMinutes: string;
};
durationID: {
hours: string;
minutes: string;
};
serveCount: string;
recipeCategory: string;
nutritionInformations: {
wrapper: string;
calories: string;
};
ingredients: string;
instructions: {
wrapper: string;
childwrapper: string;
shortInstruction: string;
longInstruction: string;
image: string;
};
};
course: {
baseID: string;
language: string;
instructor: string;
duration: string;
courseFrequency: string;
courseRepeatation: string;
};
restaurant: {
baseID: string;
};
events: {
baseID: string;
startFrom: string;
endAt: string;
status: string;
};
faqPage: {
baseID: string;
question: string;
answer: string;
};
video: {
baseID: string;
segmentsWrapper: string;
startOffsetDataVar: string;
};
localBusiness: {
baseID: string;
areaAvailablity: string;
};
organisation: {
baseID: string;
logo: string;
email: string;
foundingYear: string;
taxid: string;
};
product: {
baseID: string;
productPriceValidUntilNext: number;
productGroupIDHashLength: string;
producrVariableDelimiter: string;
skuID: string;
mpnCode: string;
brand: string;
variesByDataVar: string;
offer: {
shippingDetails: {
deliveryCost: string;
deliveryOver: string;
processingTime: string;
transitTime: string;
rangeDataVar: string;
};
returnPolicy: {
returnWithin: string;
returnFees: string;
};
availability: string;
itemCondition: string;
};
varientParameterName: string;
fallbacks: {
deliveryOver: string;
};
};
profilePage: {
baseID: string;
altName: string;
uniquePlatformID: string;
authorWorks: {
wrapper: string;
headline: string;
thumbnail: string;
publishedOn: string;
url: string;
};
authorActionCounts: {
written: string;
liked: string;
follows: string;
shared: string;
};
audienceActionCounts: {
followers: string;
likes: string;
mutualConnections: string;
};
};
softwareApp: {
baseID: string;
operatingSystem: string;
OSSeperator: string;
category: string;
};
businessEntity: {
location: {
wrapper: string;
physicalLocationName: string;
virtualLocation: string;
street: string;
city: string;
state: string;
country: string;
pincode: string;
};
telephone: string;
reservationDataVar: string;
workHours: {
wrapper: string;
dayRange: string;
dayAlone: string;
timein24: string;
timein12: string;
};
menuLink: string;
mapFrame: string;
};
};
}
25 changes: 12 additions & 13 deletions lib/schemaWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { existsSync } from "fs";
import { copyFile, readFile, writeFile } from "fs/promises";
import { mkdirpSync } from "mkdirp";
import { dirname, join, basename } from "path";
import { basename, dirname, join } from "path";

const defaultConfigPaths: Record<string, string> = {
win32: `${process.env.APPDATA}/Code/User/settings.json`,
Expand Down Expand Up @@ -130,20 +130,19 @@ function writeSettings(
basename(sourceSchema),
).replaceAll("\\", "/");

let schemaDestPath = mode === "ws" ?
"./.vscode/richiejs-config-schema.json"
: userSchemaPath;


let schemaPath: string = mode === 'user' && process.platform === 'win32'
? schemaDestPath.slice(3) //remove drive letter
: schemaDestPath;

let schemaDestPath =
mode === "ws" ?
"./.vscode/richiejs-config-schema.json"
: userSchemaPath;

let schemaPath: string =
mode === "user" && process.platform === "win32" ?
schemaDestPath.slice(3) //remove drive letter
: schemaDestPath;

const schemaConfigSnippet: Record<string, any> = {
fileMatch: ["rjsconfig.json"],
/* schema file url */ url: schemaPath
/* schema file url */ url: schemaPath,
};

if (existsSync(configPath) && !forceCreate) {
Expand Down Expand Up @@ -202,8 +201,8 @@ function main(): Promise<void> {

const validParam: boolean | string =
mode === "user" ? userSettings
: mode === "ws" ? workspaceSettings
: false;
: mode === "ws" ? workspaceSettings
: false;

return new Promise((resolve, reject) => {
if (validParam) {
Expand Down
5 changes: 3 additions & 2 deletions lib/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import {
httpsDomainBase,
} from "./utilities";

import { siteSearchBoxFieldName } from "../rjsconfig.json";
import configurations from "../configLoader";
const { siteSearchBoxFieldName } = configurations;

import { relative, basename, join, dirname } from "path";
import { basename, dirname, join, relative } from "path";

function aggregateRatingSerializer(
aggregateRating: aggregateRatingOptions,
Expand Down
Loading

0 comments on commit b5cad3d

Please sign in to comment.