-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32afe39
commit c9b8fe8
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
} | ||
} |