Skip to content

Commit 7755780

Browse files
committed
feat(create): ensure add-on metadata always includes version
1 parent 5205c20 commit 7755780

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

docs/creating-add-ons.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Required fields:
5656
```json
5757
{
5858
"name": "My Feature",
59+
"version": "0.0.1",
5960
"description": "What it does",
6061
"type": "add-on",
6162
"phase": "add-on",
@@ -66,6 +67,7 @@ Required fields:
6667

6768
| Field | Values |
6869
|-------|--------|
70+
| `version` | Semantic version for your add-on metadata (e.g. `0.0.1`) |
6971
| `type` | `add-on`, `toolchain`, `deployment`, `example` |
7072
| `phase` | `setup`, `add-on`, `example` |
7173
| `category` | `tanstack`, `auth`, `database`, `orm`, `deploy`, `tooling`, `monitoring`, `api`, `i18n`, `cms`, `other` |

packages/create/src/custom-add-ons/add-on.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ export async function readOrGenerateAddOnInfo(
122122
},
123123
dependsOn: options.chosenAddOns,
124124
} as AddOnInfo)
125+
126+
if (!info.version) {
127+
info.version = '0.0.1'
128+
}
129+
125130
return info
126131
}
127132

packages/create/src/custom-add-ons/starter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const COMPILED_FILE = 'starter.json'
2727
export async function readOrGenerateStarterInfo(
2828
options: PersistedOptions,
2929
): Promise<StarterInfo> {
30-
return existsSync(INFO_FILE)
30+
const info = existsSync(INFO_FILE)
3131
? JSON.parse((await readFile(INFO_FILE)).toString())
3232
: {
3333
id: `${options.projectName}-starter`,
@@ -51,6 +51,12 @@ export async function readOrGenerateStarterInfo(
5151
dependsOn: options.chosenAddOns,
5252
typescript: true,
5353
}
54+
55+
if (!info.version) {
56+
info.version = '0.0.1'
57+
}
58+
59+
return info
5460
}
5561

5662
async function loadCurrentStarterInfo(environment: Environment) {

packages/create/src/frameworks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function scanAddOnDirectories(addOnsDirectories: Array<string>) {
111111
addOns.push({
112112
...info,
113113
id: dir,
114+
version: info.version ?? '0.0.0',
114115
packageAdditions,
115116
packageTemplate,
116117
readme,

packages/create/tests/custom-add-ons/starter.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,33 @@ describe('readOrGenerateStarterInfo', () => {
5555
})
5656
expect(starterInfo.name).toEqual('test-starter')
5757
})
58+
59+
it('should backfill version when missing', async () => {
60+
fs.mkdirSync(process.cwd(), { recursive: true })
61+
fs.writeFileSync(
62+
'starter-info.json',
63+
JSON.stringify({
64+
framework: 'test',
65+
chosenAddOns: [],
66+
starter: undefined,
67+
name: 'test-starter',
68+
mode: 'code-router',
69+
typescript: true,
70+
tailwind: true,
71+
git: true,
72+
}),
73+
)
74+
const starterInfo = await readOrGenerateStarterInfo({
75+
framework: 'test',
76+
version: 1,
77+
chosenAddOns: [],
78+
starter: undefined,
79+
projectName: 'test',
80+
mode: 'code-router',
81+
typescript: true,
82+
tailwind: true,
83+
git: true,
84+
})
85+
expect(starterInfo.version).toEqual('0.0.1')
86+
})
5887
})

0 commit comments

Comments
 (0)