From c9b8fe837b54d0ae754393fe477d5358cf574e6d Mon Sep 17 00:00:00 2001 From: Luis Almeida Date: Fri, 19 May 2023 11:09:31 +0200 Subject: [PATCH] feat: add a themes:import command --- .../zcli-themes/src/commands/themes/import.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/zcli-themes/src/commands/themes/import.ts diff --git a/packages/zcli-themes/src/commands/themes/import.ts b/packages/zcli-themes/src/commands/themes/import.ts new file mode 100644 index 00000000..9fbe5553 --- /dev/null +++ b/packages/zcli-themes/src/commands/themes/import.ts @@ -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}`) + } +}