UNPKG

@swell/cli

Version:

Swell's command line interface/utility

46 lines (45 loc) 1.65 kB
import { Flags } from '@oclif/core'; import * as path from 'node:path'; import { default as swellConfig } from './lib/app-config.js'; import { SwellCommand } from './swell-command.js'; /** * A base class for Swell CLI commands that do not require an app to be saved * to the API. If your command requires an app to be saved to the API, extend * the `RemoteAppCommand` class instead. * * This class extends the `SwellCommand` class and adds: * * - a config instance * - a shorthand attribute for the app directory */ export class AppCommand extends SwellCommand { // base flags for all AppCommands // needs to be in a ES2021 format: https://github.com/oclif/oclif/issues/1100 static baseFlags = { 'app-path': Flags.string({ description: 'Path to your app directory', }), }; // the local path to the app directory appPath = ''; // local app configuration, what developers define swellConfig; constructor(argv, config) { super(argv, config); this.swellConfig = swellConfig(); this.appPath = path.resolve(this.swellConfig.swDirPath); } async init() { await super.init(); await this.initBaseFlags(); } async initBaseFlags() { const klass = super.ctor; // ensure the base flags are available klass.flags = { ...klass.flags, ...AppCommand.baseFlags }; const { flags } = await this.parse(klass); // if the user passed an app path, use it: reload the app config this.swellConfig = swellConfig(flags['app-path']); this.appPath = path.resolve(this.swellConfig.swDirPath); } }