@swell/cli
Version:
Swell's command line interface/utility
53 lines (52 loc) • 2.07 kB
JavaScript
import { Args } from '@oclif/core';
import path from 'node:path';
import CreateApp, { appHelpMetaBase } from '../create/app.js';
export default class InitApp extends CreateApp {
// Override command example for error messages
commandExample = 'swell app init';
static args = {
id: Args.string({
default: '',
description: 'App identifier (defaults to current directory name)',
}),
};
static description = 'Initialize app swell.json in the current directory.';
static examples = [
'$ swell app init',
'$ swell app init my-app',
'$ swell app init -t admin -y',
'$ swell app init my-app -t admin -y',
'$ swell app init my-app -t admin --frontend astro -y',
'$ swell app init my_theme -t theme --storefront-app proxima -y',
];
static helpMeta = {
...appHelpMetaBase,
usageDirect: '[id] -t <type> [...] -y',
};
// Inherit all flags from CreateApp (includes -p, -t, -n, -v, -d)
// baseFlags from CreateAppCommand (-y, --frontend, etc.) are merged automatically by oclif
static flags = {
...CreateApp.flags,
};
async run() {
const { args, flags } = await this.parse(InitApp);
const { id: argId } = args;
const { yes: confirmYes, type, name, version, description, frontend, } = flags;
// Use provided id argument, or fall back to current directory name
const id = argId || process.cwd().split(path.sep).pop() || 'Swell App';
await this.createSwellConfig({
allowOverwrite: false,
inputId: id,
inputType: type || this.appType,
inputName: name,
inputVersion: version,
inputDescription: description,
inputFrontend: frontend,
inputStorefrontApp: flags['storefront-app'],
inputIntegrationType: flags['integration-type'],
inputIntegrationId: flags['integration-id'],
inputYes: confirmYes,
nestedPath: false,
});
}
}