yeoman-adapter-clack
v0.5.1
Published
A Yeoman adapter that replaces Inquirer with Clack as the default prompt library
Maintainers
Readme
yeoman-adapter-clack
A Yeoman adapter that replaces
inquirerwith@clack/promptsas the default prompt library.
Installation 💿
npm install yeoman-adapter-clackUsage 🚀
This package exposes two adapters to choose from, implementing either is as easy as the following example. Make sure to read the full documentation for details on each adapter.
import { ClackAdapter } from "yeoman-adapter-clack";
import { createEnv } from "yeoman-environment";
import Generator from "yeoman-generator";
export default class extends Generator {
constructor(args, options) {
if (options.env) {
const adapter = options.env.adapter;
const isTestAdapter = adapter.constructor.name === "TestAdapter";
const isClackInstance = adapter instanceof ClackAdapter;
if (!isTestAdapter && !isClackInstance) {
options.env.adapter = new ClackAdapter();
}
} else {
options.env = createEnv({ adapter: new ClackAdapter() });
}
super(args, options);
}
}[!TIP]
Alternatively, you can use replace the default generator with @idleberg/yeoman-generator. This also exposes access to the full Clack prompts API and a modern templating engine.
API ⚙️
ClackAdapter
Usage: new ClackAdapter()
The default adapter implements its own API for prompts. It basically follows the Clack prompt API with additional properties based on the default Yeoman prompt API.
Example
const answers = await this.prompt([
{
// Required adapter-specific properties
type: "text",
name: "userName",
// Standard Clack API
message: "What is your name?",
placeholder: "John Appleseed",
validate: (value) => {
if (value.length < 2) return "Name must be at least 2 characters";
return undefined;
},
// Optional adapter-specific properties
store: true,
when: () => true,
},
]);Supported types are autocomplete, autocompleteMultiselect, confirm,
date, groupMultiselect, multiline, multiselect, password, path,
select, selectKey and text. For backwards-compatibility,
there is also an expand type matching the behavior of
Inquirer.
For further details, please check the type signatures.
ClackCompatAdapter
Usage: new ClackCompatAdapter()
This adapter provides an Inquirer-compatible prompt API, see the official Yeoman documentation.
Limitations ⛑️
Sadly, not all features can be realized in Clack prompts. The following limitations apply:
- separators are not supported in the compatibility adapter and need to be removed
- ~~the
expandtype does not support keyboard shortcuts~~
License ©️
This work is licensed under The MIT License.
