1. Creating your first powerup
The first step is to create the powerup package. This is done using the pup author create command:
pup author create hello-world --description="Creates a hello world script" \
--variables=name \
--type=single-use
This creates ~/.powerups/installed/_internal/hello-world/ with the following files:
├── .gitignore
├── package.json
├── tsconfig.json
├── index.ts
└── scripts
└── create-github-repo.sh
A. Setup the package.json
Your package.json is setup automatically.By default, the main instructions file is mapped to index.ts, you can change it to another file if you prefer.
{
"name": "hello-world",
// ...
"powerup": {
"instructions": "index.ts" // <-- Here
}
}
B. Add a step to the instructions file
1import { defineInstructions, type Instructions } from "@liolocs/powerups-sdk";23const instructions: Instructions = {4 name: "hello-world",5 type: "single-use",6 description: "Creates a hello world script",7 variables: {8 required: ["name"],9 optional: [],10 },11 intent: [12 "create a hello world script",13 ],14 steps: [15 {16 type: "dynamic-create",17 name: "hello-world.ts",18 template: "src/dynamic-create/hello-world.ts",19 outputPath: "hello-world.ts",20 },21 ],22};2324export default defineInstructions(instructions, import.meta.url); // <-- RequiredC. Create the template
Create the template your create step is referring to at src/dynamic-create/hello-world.ts.
export default function(variables: Record<string, string>): string {
const { name } = variables;
return `console.log("Hello ${name}!");`;
}
2. Preview the powerup
You can test your powerup before publishing or building it with the preview command:
pup author previewYou can pass preview flags to the command to control the output:
pup author preview --variables=name --exec="npm run dev"You can also use a preview.json file instead of passing flags:
{
"variables": {
"name": "world"
},
"exec": "npm run dev"
}3. Build the powerup
You must build the powerup before it can be used with the command:
pup author buildThis will run a verification on the instructions file and create a dist folder containing the necessary files for the powerup to be used.
Your output should look like this:
✓ Built powerup: hello-world
output: /Users/<user>/.powerups/installed/_internal/hello-world/dist4. Use powerup
Once the powerup is built you can use it locally anywhere by running the following command:
pup use hello-world --name=world --target-dir=./test-hello-worldThis will result in the following output:
Created: hello-world.ts
✓ Powerup hello-world was successfully used in /Users/<user>/<path>/test-hello-world5. Share the powerup
Once the powerup is built you can share by publishing it to npm or git.
Publishing to npm
To publish the powerup to npm run:
npm publishYou may use the conventional commits script to generate a changelog with npm run release.
Users will then be able to install the powerup by running:
pup install npm:<your-user-scope>/hello-worldPublishing to git
To publish the powerup to git simply push the package to a git repo.
You may run the following script to create a github repo using the gh cli and push the package to it.
./scripts/create-github-repo.shUsers will then be able to install the powerup by running:
pup install git:github.com/<owner>/hello-world