yeoman-adapter-clack
v0.2.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 🚀
To make use of this adapter, you need to overwrite the default one.
[!TIP]
For easy migration, you can import
ClackCompatAdapterinstead. Unlike the default adapter, it's API-compatible with Inquirer.
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";
if (!isTestAdapter && !(adapter instanceof ClackAdapter)) {
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.
API ⚙️
ClackAdapter
Usage: new ClackAdapter()
The default adapter implements its own API for prompts. It's basically follows 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,
multiselect, password, select 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.
