About Building Templates
So youβd like to build a repository template with Bingo. Wonderful!
Bingo is still early stage. It runs well but its APIs are still in flux. Please try it out and report any issues on GitHub! π
Getting Started
Bingo templates can be defined in as little as two files:
- Template File: defining the logic for the template
- Runner File: script file to run on the CLI
1. Template File
In a new empty directory, create a package.json
, install bingo
as a dependency, then create a template.js
file:
{ "name": "my-template", "version": "0.0.0", "type": "module"}
npm i bingo
import { createTemplate } from "bingo";
export default createTemplate({ produce() { return { files: { "README.md": "# Hello, world!", }, }; },});
You can then provide the path to that file to the bingo
CLI to create a README.md
file:
npx bingo template.js
# Hello, world!
π₯³ Congratulations! You just built and ran your first template with Bingo.
2. Runner File
Bingo templates provide their own CLI to use instead of bingo
.
Create one in an index.js
file with the following content:
#!/usr/bin/env nodeimport { runTemplateCLI } from "bingo";
import template from "./template.js";
process.exitCode = await runTemplateCLI(template);
Then, add a bin
entry for the index.js
file to your package.json
:
{ "name": "my-template", "version": "0.0.0", "type": "module", "bin": "index.js", "dependencies": { ... },}
You and your templateβs users will now be able to run your template with npx
.
Try it out locally with:
npx .
β β¨ my-template@0.0.0 β¨ββ Running with mode --transition using the template:β my-templateββ Ran my-templateββ Done. Enjoy your updated repository! π
π₯³ Congratulations! You just built and ran your first Bingo template CLI.
Learning More
Here are the main concepts youβll want to understand:
- Templates: describing how to setup or transition a repository given a set of options
- Creations: how the pieces of a repository are described by templates in-memory
- Inputs: the recommended way for inferring default option values from system resources
See also API documentation for the functions referenced on this page: