Skip to content

Commit 0bb4e52

Browse files
authored
chore: keep generated templates when the starter repo is unreachable (#1447)
1 parent 8d71487 commit 0bb4e52

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

.github/workflows/release.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ jobs:
7171

7272
# The repo's `postinstall` runs `scripts/generate-data.ts` to write
7373
# `packages/nuxt-cli/src/data/*.ts` that the build then bundles. uppt's
74-
# default install path uses `--ignore-scripts`, which would skip it
75-
# and produce a stale or broken nuxi tarball, so we install ourselves
76-
# and pass `install: false` to uppt/pack.
74+
# default install path never runs it, which would produce a stale or
75+
# broken nuxi tarball, so we install and build ourselves and pass
76+
# `install: false` to uppt/pack.
7777
- name: 📦 Install dependencies
78-
run: pnpm install --frozen-lockfile
78+
run: pnpm install --frozen-lockfile --ignore-scripts
79+
80+
- name: 🔨 Generate data and build
81+
run: pnpm run postinstall
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7984

8085
- id: pack
8186
uses: danielroe/uppt/pack@7bcfb5397c37202ef882363f755423130419d28a # v0.5.5

scripts/generate-data.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/** generate completion data from nitropack and Nuxt starter repo */
22

3+
import { existsSync } from 'node:fs'
34
import { mkdir, writeFile } from 'node:fs/promises'
45
import { dirname, join } from 'node:path'
56
import process from 'node:process'
67
import { pathToFileURL } from 'node:url'
78
import { resolveModulePath } from 'exsolve'
9+
import { isCI } from 'std-env'
810

911
import { fetchTemplates } from '../packages/nuxt-cli/src/utils/starter-templates.ts'
1012

@@ -14,21 +16,32 @@ interface PresetMeta {
1416

1517
const dataDir = new URL('../packages/nuxt-cli/src/data/', import.meta.url)
1618

19+
const templatesFile = new URL('templates.ts', dataDir)
20+
1721
export async function generateCompletionData() {
1822
const [nitroPresets, templates] = await Promise.all([
1923
getNitroPresets(),
20-
fetchTemplates(),
24+
fetchTemplates().catch(keepExistingTemplates),
2125
])
2226

2327
await mkdir(dataDir, { recursive: true })
2428
await writeFile(
2529
new URL('nitro-presets.ts', dataDir),
2630
`export const nitroPresets = ${JSON.stringify(nitroPresets, null, 2)} as const`,
2731
)
28-
await writeFile(
29-
new URL('templates.ts', dataDir),
30-
`export const templates = ${JSON.stringify(templates, null, 2)} as const`,
31-
)
32+
if (templates) {
33+
await writeFile(
34+
templatesFile,
35+
`export const templates = ${JSON.stringify(templates, null, 2)} as const`,
36+
)
37+
}
38+
}
39+
40+
function keepExistingTemplates(error: unknown): undefined {
41+
if (isCI || !existsSync(templatesFile)) {
42+
throw error
43+
}
44+
console.warn(`Could not fetch starter templates, keeping the ones already generated: ${error}`)
3245
}
3346

3447
async function getNitroPresets() {

0 commit comments

Comments
 (0)