-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Content] Add
astro sync
type gen command (#5647)
* feat: add `astro sync` command * chore: move fixture types.generated to gitignore * test: types generate with astro:content * chore: changeset * docs: Astro error for CLI errors
- Loading branch information
1 parent
68c20be
commit d72da52
Showing
11 changed files
with
118 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Add `astro sync` CLI command for type generation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type fsMod from 'node:fs'; | ||
import { performance } from 'node:perf_hooks'; | ||
import { dim } from 'kleur/colors'; | ||
import type { AstroSettings } from '../../@types/astro'; | ||
import { info, LogOptions } from '../../core/logger/core.js'; | ||
import { contentObservable, createContentTypesGenerator } from '../../content/index.js'; | ||
import { getTimeStat } from '../../core/build/util.js'; | ||
import { AstroError, AstroErrorData } from '../../core/errors/index.js'; | ||
|
||
export async function sync( | ||
settings: AstroSettings, | ||
{ logging, fs }: { logging: LogOptions; fs: typeof fsMod } | ||
): Promise<0 | 1> { | ||
const timerStart = performance.now(); | ||
|
||
try { | ||
const contentTypesGenerator = await createContentTypesGenerator({ | ||
contentConfigObserver: contentObservable({ status: 'loading' }), | ||
logging, | ||
fs, | ||
settings, | ||
}); | ||
await contentTypesGenerator.init(); | ||
} catch (e) { | ||
throw new AstroError(AstroErrorData.GenerateContentTypesError); | ||
} | ||
|
||
info(logging, 'content', `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
types.generated.d.ts |
125 changes: 0 additions & 125 deletions
125
packages/astro/test/fixtures/content-collections/src/content/types.generated.d.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters