@swell/cli
Version:
Swell's command line interface/utility
103 lines (99 loc) • 4.09 kB
JavaScript
import { Args, Flags } from '@oclif/core';
import { ThemeConfigPaths, filePathExists, isPathDirectory, } from '../../lib/apps/index.js';
import { default as localConfig } from '../../lib/config.js';
import style from '../../lib/style.js';
import AppPush from '../app/push.js';
export default class AppThemePush extends AppPush {
static args = {
file: Args.string({
char: 'f',
description: 'relative path to a configuration file or directory to push',
}),
};
static description = `Push all theme files, a specific file, or a specific configuration
type to an theme in your store's test environment.
If the theme does not exist, it will be created and its global ID saved to a .swellrc file.
- If no file is specified, all configuration files will be pushed to the store.
This includes the theme icon (assets/icon.png) and swell.json.
- If a file is specified, only that file will be pushed to the store.
- If a directory is specified, only files in that directory will be pushed.
Theme file directories:
${Object.values(ThemeConfigPaths)
.map((dir) => style.path(`${dir}/`))
.join('\n')}`;
static examples = [
'swell theme push',
'swell theme push assets',
'swell theme push theme/sections',
'swell theme push --sync-app',
'swell theme push --force',
'swell theme push --storefront-select',
'swell theme push --storefront-id <id>',
];
static flags = {
force: Flags.boolean({
default: false,
description: 'force push all files',
}),
'storefront-id': Flags.string({
description: 'identify a storefront to push theme files to',
}),
'storefront-select': Flags.boolean({
default: false,
description: 'prompt to select a storefront to push theme files to',
}),
env: Flags.string({
char: 'e',
description: 'target environment to push to, defaults to live',
}),
'sync-app': Flags.boolean({
default: false,
description: 'push app files in addition to theme files',
}),
};
static summary = 'Push local files to your Swell theme.';
appType = 'theme';
async run() {
const { args, flags } = await this.parse(AppThemePush);
const { file } = args;
const { force } = flags;
this.themeSyncApp = flags['sync-app'];
// Set default storefront env only if not syncing app, then it must be test env only
if (this.themeSyncApp) {
const currentStore = localConfig.getDefaultStore();
await this.api.setStoreEnv(currentStore, 'test');
}
else {
const defaultStorefront = localConfig.getDefaultStorefront(this.appPath);
await this.setStorefrontEnv(flags, defaultStorefront);
}
if (!(await this.ensureAppExists(file, this.themeSyncApp))) {
return;
}
if (!this.themeSyncApp && this.appCreated) {
this.themeSyncApp = true;
}
await this.getStorefrontToPush(flags);
await this.logOrientation();
if (file) {
const { filePath, relativePath } = this.resolvePushPaths(file);
// Push individual files if not referring to the whole app path
if (filePath !== this.appPath) {
if (!filePathExists(filePath)) {
this.error(`Path ${style.path(file)} does not exist.`);
}
// Targeting a directory
const pushPromise = isPathDirectory(filePath)
? this.pushFilePath(relativePath, force)
: this.pushFile(relativePath);
await pushPromise;
this.log();
this.logStorefrontFrontendUrl(this.storefront);
return;
}
}
await this.pushAppConfigs(force);
this.logStorefrontFrontendUrl(this.storefront);
this.saveCurrentStorefront();
}
}