UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

44 lines (43 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const path = require("path"); const chalk = require("chalk"); const createThemeImportJob_1 = require("../../lib/createThemeImportJob"); const getBrandId_1 = require("../../lib/getBrandId"); const createThemePackage_1 = require("../../lib/createThemePackage"); const uploadThemePackage_1 = require("../../lib/uploadThemePackage"); const pollJobStatus_1 = require("../../lib/pollJobStatus"); class Import extends core_1.Command { async run() { let { flags: { brandId }, argv: [themeDirectory] } = await this.parse(Import); const themePath = path.resolve(themeDirectory); brandId = brandId || await (0, getBrandId_1.default)(); const job = await (0, createThemeImportJob_1.default)(brandId); const { file, removePackage } = await (0, createThemePackage_1.default)(themePath); try { await (0, uploadThemePackage_1.default)(job, file, path.basename(themePath)); } finally { removePackage(); } await (0, pollJobStatus_1.default)(themePath, job.id); const themeId = job.data.theme_id; this.log(chalk.green('Theme imported successfully'), `theme ID: ${themeId}`); return { themeId }; } } exports.default = Import; Import.description = 'import a theme'; Import.enableJsonFlag = true; Import.flags = { brandId: core_1.Flags.string({ description: 'The id of the brand where the theme should be imported to' }) }; Import.args = [ { name: 'themeDirectory', required: true, default: '.' } ]; Import.examples = [ '$ zcli themes:import ./copenhagen_theme', '$ zcli themes:import ./copenhagen_theme --brandId=123456' ]; Import.strict = false;