@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
43 lines • 1.37 kB
JavaScript
import { fetchTheme, themeCreate } from './api.js';
import { DEVELOPMENT_THEME_ROLE } from './utils.js';
import { generateThemeName } from '../../../private/node/themes/generate-theme-name.js';
import { BugError } from '../error.js';
export class ThemeManager {
constructor(adminSession) {
this.adminSession = adminSession;
}
async findOrCreate() {
let theme = await this.fetch();
if (!theme) {
theme = await this.create();
}
return theme;
}
async fetch() {
if (!this.themeId) {
return;
}
const theme = await fetchTheme(parseInt(this.themeId, 10), this.adminSession);
if (!theme) {
this.removeTheme();
}
return theme;
}
generateThemeName(context) {
return generateThemeName(context);
}
async create(themeRole, themeName) {
const name = themeName ?? generateThemeName(this.context);
const role = themeRole ?? DEVELOPMENT_THEME_ROLE;
const theme = await themeCreate({
name,
role,
}, this.adminSession);
if (!theme) {
throw new BugError(`Could not create theme with name "${name}" and role "${role}"`);
}
this.setTheme(theme.id.toString());
return theme;
}
}
//# sourceMappingURL=theme-manager.js.map