Skip to Content
🎉 Hyperse Wizard has been published.
DocumentationGetting Started

Getting Started

📦 Installation

npm install @hyperse/wizard

🚀 Quick Start

Create CLI Instance

import { createWizard } from '@hyperse/wizard'; const hpsCli = createWizard({ name: 'hps', // i18n message key description: 'hpsCli.description', // i18n message key version: 'hpsCli.version', // i18n messages // cliMessages only provide the messages for the cli, not the commands and plugins localeMessages: cliMessages, });

Define Commands and Subcommands

import { defineCommand } from '@hyperse/wizard'; type MiniContext = { projectCwd: string; }; const buildCommand = defineCommand('build', { // i18n message key description: 'buildPlugin.command.build.description', }) .use( defineCommand<'mini', MiniContext>('mini', { // i18n message key description: 'buildPlugin.command.build.mini.description', }) .flags({ compiler: { type: String, // i18n message key description: 'buildPlugin.command.build.mini.flags.compiler', default: 'webpack', }, }) .handler(async (ctx) => { ctx.log.info('build mini', ctx.flags); }) ) .flags({ projectCwd: { type: Boolean, // i18n message key description: 'buildPlugin.command.build.flags.projectCwd', default: process.cwd(), required: true, }, }) .resolve((ctx) => { // just provide the projectCwd for subcommand to work ctx.log.info('build resolve', ctx.flags); return { projectCwd: ctx.flags.projectCwd, }; });

Define Plugin

import { definePlugin } from '@hyperse/wizard'; hpsCli .use( definePlugin({ name: 'buildPlugin.plugin.name', setup: (cli) => { return cli.register(buildCommand); }, }) ) .on('build.mini', (ctx) => { // when the build.mini command is executed, the ctx will be the context of the command ctx.log.info('build mini', ctx.flags); }); // parse the command hpsCli.parse(['build', 'mini', '--compiler=webpack']);
Last updated on