@swell/cli
Version:
Swell's command line interface/utility
54 lines (51 loc) • 2.11 kB
JavaScript
import { Args, Flags } from '@oclif/core';
import * as path from 'node:path';
import { AllConfigPaths } from '../../lib/apps/index.js';
import style from '../../lib/style.js';
import { PushAppCommand } from '../../push-app-command.js';
export default class AppPull extends PushAppCommand {
static args = {
appId: Args.string({ default: '', description: 'app id to pull' }),
targetPath: Args.string({
default: '',
description: 'path to download app files into',
}),
};
static description = `Pull all app files, a specific file, or a specific configuration
type from an app in your store's test environment to your local machine.
If APPID is not specified, you will be prompted with a list of apps to choose from.
App file directories:
${Object.values(AllConfigPaths)
.map((dir) => style.path(`${dir}/`))
.join('\n')}\n${style.path(`frontend/`)}`;
static examples = [
'swell app pull',
'swell app pull example_app',
'swell app pull example_app example-folder',
'swell app pull --force',
];
static flags = {
force: Flags.boolean({
default: false,
description: 'force pull all files',
}),
};
static orientation = {
env: 'test',
};
static summary = 'Pull app files from Swell to your local machine.';
logPulledChanges(pulled, removed) {
const typeLabel = this.appType === 'theme' ? 'theme' : 'app';
const changeCount = pulled.length + removed.length;
const pluralFiles = changeCount === 1 ? 'file' : 'files';
this.log(`Pulled ${changeCount} ${pluralFiles} from ${style.appConfigValue(this.app.name)} ${typeLabel} in ${style.path(path.resolve(this.appPath))}.`);
}
async run() {
const { args, flags } = await this.parse(AppPull);
const { force } = flags;
await this.ensureLoggedIn();
this.app = (await this.getAppToPull(args));
const { pulled, removed } = await this.pullAppConfigs(force);
this.logPulledChanges(pulled, removed);
}
}