Skip to content

Commit

Permalink
feat(gcp-storage): Use directory option as definition on what to up… (
Browse files Browse the repository at this point in the history
#205)

…load

BREAKING CHANGE: `directory` is now required and needs to be the full
path to the directory
  • Loading branch information
TriPSs authored Dec 29, 2023
2 parents 545d92d + 402d282 commit eaa76a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
12 changes: 6 additions & 6 deletions packages/gcp-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ npm install -D @nx-extend/gcp-storage

#### Available options:

| name | type | default | description |
|----------------|---------|---------|--------------------------------------------------|
| bucket | string | | What bucket to upload to |
| directory | string | `/` | What directory of the apps dist folder to upload |
| gzip | boolean | false | Use gzip when uploading |
| gzipExtensions | string | | For what extensions to use gzip |
| name | type | default | description |
|----------------|---------|---------|---------------------------------|
| bucket | string | | What bucket to upload to |
| directory | string | | Directory to upload |
| gzip | boolean | false | Use gzip when uploading |
| gzipExtensions | string | | For what extensions to use gzip |
2 changes: 1 addition & 1 deletion packages/gcp-storage/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"executors": {
"upload": {
"implementation": "./src/executors/upload/upload.impl",
"schema": "./src/executors/executors/schema.json",
"schema": "./src/executors/upload/schema.json",
"description": "Upload to GCP storage"
}
},
Expand Down
8 changes: 5 additions & 3 deletions packages/gcp-storage/src/executors/upload/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
},
"directory": {
"type": "string",
"description": "Folder from the outputPath to upload",
"default": ""
"description": "Directory to upload"
},
"gzip": {
"type": "boolean",
Expand All @@ -25,5 +24,8 @@
"description": "What extensions to gzip",
"default": "js,css,html"
}
}
},
"directory": [
"name"
]
}
30 changes: 13 additions & 17 deletions packages/gcp-storage/src/executors/upload/upload.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,26 @@ export async function uploadExecutor(
options: UploadExecutorSchema,
context: ExecutorContext
): Promise<{ success: boolean }> {
const { targets } = context.workspace.projects[context.projectName]
const { directory, gzip = false, gzipExtensions, bucket } = options

const directoryToUpload = join(
join(context.root, targets?.build?.options?.outputPath.toString()),
directory
)
if (!directory) {
throw new Error('"directory" is required!')
}

const directoryToUpload = join(context.root, directory)

const uploadTo = `gs://${bucket}`

logger.info(
`Start upload assets from "${directoryToUpload}" to "${uploadTo}"`
)
logger.info(`Start upload assets from "${directoryToUpload}" to "${uploadTo}"`)

return Promise.resolve(
execCommand(
buildCommand([
'gsutil rsync -R',
gzip && `-z "${gzipExtensions}"`,

resolve(process.cwd(), directoryToUpload),
uploadTo
])
)
execCommand(buildCommand([
'gsutil rsync -R',
gzip && `-z "${gzipExtensions}"`,

resolve(process.cwd(), directoryToUpload),
uploadTo
]))
)
}

Expand Down

0 comments on commit eaa76a9

Please sign in to comment.