Skip to content

Commit

Permalink
feat: add a themes:import command
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-almeida committed Jun 5, 2023
1 parent 32afe39 commit c9b8fe8
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/zcli-themes/src/commands/themes/import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Command, Flags } from '@oclif/core'
import * as path from 'path'
import * as chalk from 'chalk'
import createThemeImportJob from '../../lib/createThemeImportJob'
import getBrandId from '../../lib/getBrandId'
import createThemePackage from '../../lib/createThemePackage'
import uploadThemePackage from '../../lib/uploadThemePackage'
import pollJobStatus from '../../lib/pollJobStatus'

export default class Import extends Command {
static description = 'import a theme'

static flags = {
brandId: Flags.string({ description: 'The id of the brand where the theme should be imported to' })
}

static args = [
{ name: 'themeDirectory', required: true, default: '.' }
]

static examples = [
'$ zcli themes:import ./copenhagen_theme'
]

static strict = false

async run () {
let { flags: { brandId }, argv: [themeDirectory] } = await this.parse(Import)
const themePath = path.resolve(themeDirectory)

brandId = brandId || await getBrandId()

const job = await createThemeImportJob(brandId)
const { readStream, removePackage } = await createThemePackage(themePath)

try {
await uploadThemePackage(job, readStream)
} finally {
removePackage()
}

await pollJobStatus(themePath, job.id)

this.log(chalk.green('Theme imported successfully'), `theme ID: ${job.data.theme_id}`)
}
}

0 comments on commit c9b8fe8

Please sign in to comment.