Skip to content

Commit

Permalink
chore: cleanup and optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ahochsteger committed Dec 26, 2024
1 parent b4715ff commit f75a1af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
13 changes: 8 additions & 5 deletions scripts/clasp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,17 @@ case "${cmd}" in
checkGuardedAction "${cmd}"
checkRunAuthFile
# Create named pipes
mkfifo stdout_pipe full_pipe
rm -f "${CLASP_BASEDIR}/stdout_pipe" "${CLASP_BASEDIR}/full_pipe"
mkfifo "${CLASP_BASEDIR}/stdout_pipe" "${CLASP_BASEDIR}/full_pipe"
# Run the command with redirections in the background
runClaspWithRunAuth run "${functionName}" > >(tee build/full.log | tee full_pipe) 2>&1 > >(tee build/stdout.log | tee stdout_pipe >&2)
runClaspWithRunAuth run "${functionName}" \
> >(tee build/full.log | tee "${CLASP_BASEDIR}/full_pipe") 2>&1 \
> >(tee build/stdout.log | tee "${CLASP_BASEDIR}/stdout_pipe" >&2)
# Read from the pipes
out=$(cat stdout_pipe)
full=$(cat full_pipe)
out=$(cat "${CLASP_BASEDIR}/stdout_pipe")
full=$(cat "${CLASP_BASEDIR}/full_pipe")
# Remove the named pipes
rm stdout_pipe full_pipe
rm "${CLASP_BASEDIR}/stdout_pipe" "${CLASP_BASEDIR}/full_pipe"
# Evaluate test output:
status=$(
echo "${out}" \
Expand Down
1 change: 1 addition & 0 deletions scripts/update-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function extractAllPlaceholder() {
--testPathPattern 'docs/update-docs\.spec\.ts' \
2>/dev/null \
| gojq -s .
# TODO: The redirection to /dev/null hides execution errors - find a better solution!
}

function generateActionDocs() {
Expand Down
17 changes: 4 additions & 13 deletions src/lib/adapter/GDriveAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ export class DriveUtils {
const { filename } = locationInfo
const parentFolder = this.getParentFolder(ctx.env.gdriveApp, locationInfo)

if (!parentFolder) {
const errorMessage = `Invalid parent folder: ${location}`
ctx.log.error(errorMessage)
throw new Error(errorMessage)
}

const existingFiles = parentFolder.getFilesByName(filename)
return {
locationInfo,
Expand Down Expand Up @@ -193,9 +187,6 @@ export class DriveUtils {
const { folderId, pathSegments } = locationInfo
if (folderId) {
parentFolder = gdriveApp.getFolderById(folderId)
if (!parentFolder) {
throw new Error(`Invalid parent folder ID: ${folderId}`)
}
} else {
parentFolder = gdriveApp.getRootFolder()
}
Expand Down Expand Up @@ -257,7 +248,7 @@ export class DriveUtils {
fileMetadata,
fileData.blob,
)
if (!createdFile?.id) {
if (!createdFile.id) {
throw new Error(
`Failed creating file '${filename}' ${fileData.toMimeType ? " (using MimeType '" + fileData.toMimeType + "')" : ""}!`,
)
Expand All @@ -280,7 +271,7 @@ export class DriveUtils {
fileData: FileContent,
): GoogleAppsScript.Drive.File {
ctx.log.info(`Updating existing file '${file.getName()}' ...`)
ctx.env.driveApi.Files!.update(
ctx.env.driveApi.Files.update(
{
mimeType: fileData.toMimeType ?? file.getMimeType(),
description: fileData.description,
Expand Down Expand Up @@ -390,7 +381,7 @@ export class GDriveAdapter extends BaseAdapter {
this.ctx.log.debug(
`GDriveAdapter.extractAttachmentText(): -> ${JSON.stringify(docsFile)}`,
)
const id = docsFile?.id
const id = docsFile.id
if (!id) return { text: null }
const file = this.ctx.env.gdriveApp.getFileById(id)

Expand Down Expand Up @@ -426,7 +417,7 @@ export class GDriveAdapter extends BaseAdapter {

return {
text: textContent,
file: file,
file: args.docsFileLocation ? file : undefined,
}
}

Expand Down

0 comments on commit f75a1af

Please sign in to comment.