Skip to content

Commit

Permalink
docs: document the create-solana-dapp init script
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Oct 11, 2024
1 parent eacc580 commit fad243c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ The `--template` (or `-t`) flag supports anything that [giget](https://github.co
pnpx create-solana-dapp --template <github-org>/<github-repo>
```

## Init script

Template authors can add an init script to the `package.json` file to help set up the project.

Use this script to return instructions to the user, check the `anchor` and `solana` versions, and replace text and files
in the project.

```json
{
"name": "your-template",
"create-solana-dapp": {
// These instructions will be returned to the user after installation
"instructions": [
"Run Anchor commands:",
// Adding a '+' will make the line bold and '{pm}' is replaced with the package manager
"+{pm} run anchor build | test | localnet | deploy"
],
// Rename is a map of terms to rename
"rename": {
// Rename every instance of counter
"counter": {
// With the name of the project
"to": "{{name}}",
// In the following paths
"paths": ["anchor", "src"]
}
},
// Check versions and give a warning if it's not installed or the version is lower
"versions": {
"anchor": "0.30.1",
"solana": "1.18.0"
}
}
}
```

### Planned frameworks to support

The following UI frameworks are planned and expected to be supported in the future:
Expand Down
2 changes: 1 addition & 1 deletion src/templates/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Framework {
templates: Template[]
}

export const defaultRepository = `github:solana-developers/template-{{name}}`
export const defaultRepository = `gh:solana-developers/template-{{name}}`

export const frameworks: Framework[] = [
{
Expand Down
15 changes: 6 additions & 9 deletions src/templates/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ export interface Template {
path?: string
}

export function createExternalTemplate(name: string): Template {
return {
name,
description: `${name} (external)`,
repository: name.includes(':') ? name : `github:${name}`,
}
}

export function findTemplate(name: string): Template {
// A template name with a `/` is considered external
if (name.includes('/')) {
return createExternalTemplate(name)
return {
name,
description: `${name} (external)`,
repository: name.includes(':') ? name : `gh:${name}`,
}
}

const template: Template | undefined = templates.find((template) => template.name === name)
Expand Down

0 comments on commit fad243c

Please sign in to comment.