Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Gardusi committed Aug 29, 2024
1 parent 862f663 commit 00ac815
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
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

Check failure on line 18 in src/main.ts

View workflow job for this annotation

GitHub Actions / test

Insert `,`
);
}

0 comments on commit 00ac815

Please sign in to comment.