Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ToiletPaper version and remove code complexity #5

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"libraries": [
{
"userSymbol": "ToiletPaper",
"version": "5",
"version": "6",
"libraryId": "1dOeIbk9S0Jx1W8CpNtjmSSLIRml6PMu2MKj4ryfr_Jhb_T992I7TnicG",
"developmentMode": false
}
Expand Down
33 changes: 0 additions & 33 deletions src/journal/journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,4 @@ export namespace Journal {
const weekNumber = Cupid.DateService.getCurrentWeekNumber();
return `week-${weekNumber}`;
}

export function appendToCurrentFile(date: string): void {
const file = getCurrentFile();
const doc = DocumentApp.openById(file.getId());
const body = doc.getBody();
body
.appendParagraph(date)
.setHeading(DocumentApp.ParagraphHeading.HEADING3);
doc.saveAndClose();
}

function getCurrentFile(): GoogleAppsScript.Drive.File {
let currentFolder = DriveApp.getRootFolder();
const folders = getCurrentFolder().split("/");
for (const nextFolder of folders) {
const subFoldersWithName = currentFolder.getFoldersByName(nextFolder);
if (!subFoldersWithName.hasNext()) {
throw new Error(
`Failed to find the next folder: ${nextFolder} within ${currentFolder.getName()}`,
);
}
Logger.log(`Moving from ${currentFolder} to ${nextFolder}`);
currentFolder = subFoldersWithName.next();
}
const fileName = getCurrentFileName();
const filesWithName = currentFolder.getFilesByName(fileName);
if (!filesWithName.hasNext()) {
throw new Error(
`Document ${fileName} not found at folder: ${currentFolder.getName()}`,
);
}
return filesWithName.next();
}
}
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export function createWeeklyJournal(): void {
}

export function appendCurrentDateToFile(): void {
const folder = Journal.getCurrentFolder();
const fileName = Journal.getCurrentFileName();
const currentDate = Cupid.DateService.getCurrentDateFormatted();
Journal.appendToCurrentFile(currentDate);
ToiletPaper.Tissuer.appendToFile(
folder,
fileName,
currentDate,
DocumentApp.ParagraphHeading.HEADING3,
);
}
Loading