Skip to content

Commit

Permalink
Merge pull request #3765 from Shopify/jmeng/renderTaskstoStdErr
Browse files Browse the repository at this point in the history
Theme Push: Change progress bar writestream to stderr
  • Loading branch information
jamesmengo authored Apr 30, 2024
2 parents 5bcf616 + ea177a1 commit ab5ebec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-penguins-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Render progress bar for theme uploads to stderr
9 changes: 8 additions & 1 deletion packages/theme/src/cli/utilities/theme-ui.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Theme} from '@shopify/cli-kit/node/themes/types'
import {renderConfirmationPrompt, renderWarning} from '@shopify/cli-kit/node/ui'
import {Task, renderConfirmationPrompt, renderTasks, renderWarning} from '@shopify/cli-kit/node/ui'

export function themeComponent(theme: Theme) {
return [
Expand Down Expand Up @@ -31,3 +31,10 @@ export async function currentDirectoryConfirmed(force: boolean) {
message: 'Do you want to proceed?',
})
}

// This prevents the progress bar from polluting stdout (important for pipe operations)
export async function renderTasksToStdErr(tasks: Task[]) {
if (tasks.length > 0) {
await renderTasks(tasks, {renderOptions: {stdout: process.stderr}})
}
}
13 changes: 4 additions & 9 deletions packages/theme/src/cli/utilities/theme-uploader.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {partitionThemeFiles, readThemeFilesFromDisk} from './theme-fs.js'
import {applyIgnoreFilters} from './asset-ignore.js'
import {renderTasksToStdErr} from './theme-ui.js'
import {AdminSession} from '@shopify/cli-kit/node/session'
import {Result, Checksum, Theme, ThemeFileSystem} from '@shopify/cli-kit/node/themes/types'
import {AssetParams, bulkUploadThemeAssets, deleteThemeAsset} from '@shopify/cli-kit/node/themes/api'
import {fileSize} from '@shopify/cli-kit/node/fs'
import {Task, renderTasks as renderTaskOriginal} from '@shopify/cli-kit/node/ui'
import {Task} from '@shopify/cli-kit/node/ui'
import {outputDebug, outputInfo, outputNewline, outputWarn} from '@shopify/cli-kit/node/output'

interface UploadOptions {
Expand Down Expand Up @@ -33,8 +34,8 @@ export async function uploadTheme(
const uploadTasks = await buildUploadTasks(remoteChecksums, themeFileSystem, options, theme, session, uploadResults)

// The task execution mechanism processes tasks sequentially in the order they are added.
await renderTasks(deleteTasks)
await renderTasks(uploadTasks)
await renderTasksToStdErr(deleteTasks)
await renderTasksToStdErr(uploadTasks)

reportFailedUploads(uploadResults)
return uploadResults
Expand Down Expand Up @@ -321,12 +322,6 @@ async function handleFailedUploads(
return handleBulkUpload(failedUploadParams, themeId, session, count + 1)
}

async function renderTasks(tasks: Task[]) {
if (tasks.length > 0) {
await renderTaskOriginal(tasks)
}
}

function reportFailedUploads(uploadResults: Map<string, Result>) {
for (const [key, result] of uploadResults.entries()) {
if (!result.success) {
Expand Down

0 comments on commit ab5ebec

Please sign in to comment.