Creating Your Own Extension
This section will help you develop custom extensions for Scaffold-Stark 2, from simple additions to more complex modifications.
Extension Structureโ
Before diving into the development process, let's understand the structure an extension should follow:
your-extension/
โโโ extension/
โ โโโ packages/
โ โ โโโ snfoundry/ # (optional) For Foundry-specific additions
โ โ โโโ nextjs/
โ โ โโโ app/ # Any new pages/files
โ โ โ โโโ my-page
โ โ โ โโโ page.tsx
โ โ โ
โ โ โโโ ... # Any extra files/directories
โ โ โโโ package.json # Only include additional dependencies/scripts
โ โโโ package.json # Monorepo root package.json file
โ โโโ README.md # Instance README
โโโ README.md # Documentation for your extension
Developing a Simple Extensionโ
For simple extensions, such as adding a new page or component, you can directly create the extension structure without going through the full development workflow. Here's how:
- Create the directory structure as shown above.
- Add your new page or component in the appropriate directory.
- If needed, create a
package.jsonwith any additional dependencies. - Push your extension to our create-stark-extension github.
- Create a PR to create-stark and add your extensions to
src/extensions.json. - That's it! Your simple extension is ready to be reviewed and merge by us.
Developing an Advanced Extensionโ
Template Files and Argsโ
create-stark uses a templating system for advanced extensions that need to modify existing files. This system allows you to inject content into specific files in the base project using the *.args.mjs files.
Key points:
- They allow you to add specific content to files in the base project.
- Not all files can be modified this way, files with
*.template.mjsare supported template files. - To use a template file, create an
*.args.mjsfile in your extension having the same path structure as*.template.mjs. For example, to modify .gitignore, you'd createextension/packages/nextjs/.gitignore.args.mjs.
Advanced Development Workflowโ
When creating complex extensions, Scaffold-Stark 2 provides a set of tools to make the process easier. This workflow allows you to test your extension locally.
Extension Development Utilityโ
-
Clone the
create-starkRepository:git clone https://github.com/Scaffold-Stark/create-stark.git
cd create-stark
yarn install -
Add your extension:
In src/extensions.json, add path to your extensions:
...,
{
"extensionFlagValue": "your-extension",
"description": "Your extension",
"repository": "https://github.com/{github-username}/{extension-repo-name}",
"branch": "{branch-name}"
}
-
Run the Build Script:
yarn build:devThis creates
cli.jsin thedistdirectory. -
Run the CLI to Create a New Instance:
yarn cliThis command will create a new base instance, similar to running
npx create-stark@latest. Note: It's recommended to create a new base instance outside of thecreate-starkfolder, so use../<your-instance-name>.The name mentioned for the "Your project name" question will be used as the extension name. For example, if you provide
../eipas the value to the question, then the final extension name will beeip. -
Test the Extension:
- cd into the instance directory.
- Install dependencies and test your extension.