Exec Plugin
The exec plugin runs a shell command or an arbitrary function during code generation. Use it for build steps that have to happen alongside Baeta's own generation — formatting hooks, asset bundling, anything you'd otherwise wire as a separate npm script.
Installation
- yarn
- npm
- pnpm
- bun
yarn add @baeta/plugin-exec -D
npm install @baeta/plugin-exec -D
pnpm add @baeta/plugin-exec -D
bun add @baeta/plugin-exec -D
Usage
import { defineConfig } from "@baeta/cli";
import { createExecPlugin } from "@baeta/plugin-exec";
export default defineConfig({
// ... other config
plugins: [
createExecPlugin({
// Optional: Identifier for the plugin instance
name: 'build-assets',
// Optional: Description of what's being generated/executed
actionName: 'assets',
// Required: Command to execute or function to run
exec: 'yarn build:assets',
// OR
exec: async (ctx) => {
// Custom logic here
await buildAssets();
},
// Optional: Watch configuration for development mode
watch: (generatorOptions, watcher, reload) => {
const assetsPath = resolve(generatorOptions.cwd, 'src/assets');
const handleChange = (file: WatcherFile) => {
if (file.path.startsWith(assetsPath)) {
reload(file);
}
};
watcher.on('create', handleChange);
watcher.on('update', handleChange);
watcher.on('delete', handleChange);
}
// Optional: Skip execution based on condition
skip: async (ctx) => process.env.NODE_ENV === 'test',
}),
],
});
For the full configuration interface, see the ExecPluginOptions API reference.