Skip to content

Commit

Permalink
✨ feature: add gas properties types
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvtiradentes committed Jan 19, 2024
1 parent a51eb70 commit b6db95a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 12 deletions.
5 changes: 5 additions & 0 deletions dist/classes/GAS.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import { TGasPropertiesSchema, TGasPropertiesSchemaKeys } from '../consts/configs';
export declare function checkIfisGASEnvironment(): boolean;
export declare function listAllGASProperties(): TGasPropertiesSchemaKeys[];
export declare function deleteGASProperty(property: TGasPropertiesSchemaKeys): void;
export declare function getGASProperty<TProperty extends TGasPropertiesSchemaKeys>(property: TProperty): TGasPropertiesSchema[TProperty];
export declare function updateGASProperty<TProperty extends TGasPropertiesSchemaKeys>(property: TProperty, value: TGasPropertiesSchema[TProperty]): void;
13 changes: 13 additions & 0 deletions dist/consts/configs.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
export declare const CONFIGS: {
readonly DEBUG_MODE: true;
};
export type TGasPropertiesSchema = {
todayGithubAddedCommits: string;
todayTicktickAddedTasks: string;
todayTicktickUpdateTasks: string;
lastReleasedVersionAlerted: string;
githubLastAddedCommits: string;
lastDailyEmailSentDate: string;
todayTicktickCompletedTasks: string;
githubLastDeletedCommits: string;
githubCommitChangesCount: string;
todayGithubDeletedCommits: string;
};
export type TGasPropertiesSchemaKeys = keyof TGasPropertiesSchema;
1 change: 0 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ declare class GcalSync {
today_date: string;
isGASEnvironment: boolean;
constructor(configs: TConfigs);
showConfigs(): void;
sync(): Promise<void>;
}
export default GcalSync;
Expand Down
10 changes: 6 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};

// GENERAL =====================================================================
function checkIfisGASEnvironment() {
return typeof Calendar !== 'undefined';
}
Expand Down Expand Up @@ -65,6 +66,7 @@
else {
response = yield fetch(url);
}
console.log(response);
const data = (_a = JSON.parse(yield response.text())) !== null && _a !== void 0 ? _a : {};
if (response.status !== 200) {
if (data.message === 'Validation Failed') {
Expand Down Expand Up @@ -319,17 +321,15 @@
this.today_date = getDateFixedByTimezone(this.configs.settings.timezone_correction).toISOString().split('T')[0];
logger.info(`${APP_INFO.name} is running at version ${APP_INFO.version}!`);
}
showConfigs() {
console.log(this.configs);
}
sync() {
return __awaiter(this, void 0, void 0, function* () {
const shouldSyncGithub = this.configs[githubConfigsKey];
const shouldSyncTicktick = this.configs[ticktickConfigsKey];
// prettier-ignore
const allGoogleCalendars = [...new Set([]
.concat(shouldSyncGithub ? [this.configs[githubConfigsKey].commits_configs.commits_calendar, this.configs[githubConfigsKey].issues_configs.issues_calendar] : [])
.concat(shouldSyncTicktick ? [...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.gcal), ...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.dcal_done)] : []))];
.concat(shouldSyncTicktick ? [...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.gcal), ...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.dcal_done)] : []))
];
console.log(allGoogleCalendars);
// createMissingCalendars(allGoogleCalendars);
const allIcsLinks = this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.link);
Expand All @@ -338,7 +338,9 @@
return tasks;
}))));
console.log(ticktickTasks);
console.log(1);
const githubCommits = yield getAllGithubCommits(this.configs[githubConfigsKey].username, this.configs[githubConfigsKey].personal_token);
console.log(3);
console.log(githubCommits);
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions src/classes/GAS.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
import { TGasPropertiesSchema, TGasPropertiesSchemaKeys } from '../consts/configs';

// GENERAL =====================================================================

export function checkIfisGASEnvironment() {
return typeof Calendar !== 'undefined';
}

// PROPERTIES ==================================================================

export function listAllGASProperties(): TGasPropertiesSchemaKeys[] {
const allProperties = PropertiesService.getScriptProperties().getProperties() as unknown as TGasPropertiesSchemaKeys[];
return allProperties;
}

export function deleteGASProperty(property: TGasPropertiesSchemaKeys) {
PropertiesService.getScriptProperties().deleteProperty(property);
}

export function getGASProperty<TProperty extends TGasPropertiesSchemaKeys>(property: TProperty): TGasPropertiesSchema[TProperty] {
const value = PropertiesService.getScriptProperties().getProperty(property);
let parsedValue;

try {
parsedValue = JSON.parse(value);
} catch {
parsedValue = value;
}

return parsedValue;
}

export function updateGASProperty<TProperty extends TGasPropertiesSchemaKeys>(property: TProperty, value: TGasPropertiesSchema[TProperty]) {
const parsedValue = typeof value === 'string' ? value : JSON.stringify(value);
PropertiesService.getScriptProperties().setProperty(property, parsedValue);
}
2 changes: 2 additions & 0 deletions src/classes/Github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export async function getAllGithubCommits(username: string, personalToken: strin
response = await fetch(url);
}

console.log(response);

const data = JSON.parse(await response.text()) ?? {};

if (response.status !== 200) {
Expand Down
15 changes: 15 additions & 0 deletions src/consts/configs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
export const CONFIGS = {
DEBUG_MODE: true
} as const;

export type TGasPropertiesSchema = {
todayGithubAddedCommits: string;
todayTicktickAddedTasks: string;
todayTicktickUpdateTasks: string;
lastReleasedVersionAlerted: string;
githubLastAddedCommits: string;
lastDailyEmailSentDate: string;
todayTicktickCompletedTasks: string;
githubLastDeletedCommits: string;
githubCommitChangesCount: string;
todayGithubDeletedCommits: string;
};

export type TGasPropertiesSchemaKeys = keyof TGasPropertiesSchema;
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ class GcalSync {
logger.info(`${APP_INFO.name} is running at version ${APP_INFO.version}!`);
}

showConfigs() {
console.log(this.configs);
}

async sync() {
const shouldSyncGithub = this.configs[githubConfigsKey];
const shouldSyncTicktick = this.configs[ticktickConfigsKey];

// prettier-ignore
const allGoogleCalendars: string[] = [... new Set([]
.concat(shouldSyncGithub ? [this.configs[githubConfigsKey].commits_configs.commits_calendar, this.configs[githubConfigsKey].issues_configs.issues_calendar] : [])
.concat(shouldSyncTicktick ? [...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.gcal), ...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.dcal_done)] : []))]
.concat(shouldSyncTicktick ? [...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.gcal), ...this.configs[ticktickConfigsKey].ics_calendars.map((item) => item.dcal_done)] : []))
]

console.log(allGoogleCalendars);
// createMissingCalendars(allGoogleCalendars);
Expand All @@ -47,8 +44,9 @@ class GcalSync {
)
);
console.log(ticktickTasks);

console.log(1);
const githubCommits = await getAllGithubCommits(this.configs[githubConfigsKey].username, this.configs[githubConfigsKey].personal_token);
console.log(3);
console.log(githubCommits);
}
}
Expand Down

0 comments on commit b6db95a

Please sign in to comment.