-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: theme shorthand and auto installations
- Loading branch information
Showing
10 changed files
with
550 additions
and
62 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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
layout: cover | ||
theme: '@slidev/theme-default' | ||
--- | ||
|
||
# Composable Vue | ||
|
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 |
---|---|---|
@@ -1,38 +1,24 @@ | ||
import { bold, cyan, dim, green, yellow } from 'kolorist' | ||
import { createServer as createViteServer, InlineConfig, mergeConfig } from 'vite' | ||
import { version } from '../package.json' | ||
import { resolveOptions, SlidevEntryOptions, SlidevPluginOptions } from './plugins/options' | ||
import { ResolvedSlidevOptions, SlidevPluginOptions } from './plugins/options' | ||
import { ViteSlidevPlugin } from './plugins/preset' | ||
|
||
export async function createServer( | ||
entry: SlidevEntryOptions, | ||
pluginConfig: Omit<SlidevPluginOptions, 'slidev'> = {}, | ||
options: ResolvedSlidevOptions, | ||
pluginConfig: SlidevPluginOptions = {}, | ||
viteConfig: InlineConfig = {}, | ||
) { | ||
const resolved = await resolveOptions(entry) | ||
const server = await createViteServer( | ||
mergeConfig( | ||
viteConfig, | ||
{ | ||
plugins: [ | ||
ViteSlidevPlugin({ | ||
...pluginConfig, | ||
slidev: resolved, | ||
}), | ||
ViteSlidevPlugin(options, pluginConfig), | ||
], | ||
}, | ||
), | ||
) | ||
|
||
console.log() | ||
console.log(cyan(bold(' Slidev ')) + yellow(`v${version}`)) | ||
console.log() | ||
console.log(` theme ${green(resolved.theme)}`) | ||
console.log(` entry ${dim(resolved.entry)}`) | ||
console.log() | ||
|
||
return { | ||
server, | ||
resolved, | ||
} | ||
return server | ||
} |
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,51 @@ | ||
import { prompt } from 'enquirer' | ||
import { parseNi, run } from '@antfu/ni' | ||
|
||
const officialThemes: Record<string, string> = { | ||
none: '', | ||
default: '@slidev/theme-default', | ||
seriph: '@slidev/theme-seriph', | ||
} | ||
|
||
export function packageExists(name: string) { | ||
try { | ||
if (require.resolve(`${name}/package.json`)) | ||
return true | ||
} | ||
catch {} | ||
return false | ||
} | ||
|
||
export function resolveThemeName(name: string) { | ||
if (!name) | ||
return '' | ||
if (name.startsWith('@slidev/theme-') || name.startsWith('slidev-theme-')) | ||
return name | ||
if (officialThemes[name]) | ||
return officialThemes[name] | ||
|
||
return `slidev-theme-${name}` | ||
} | ||
|
||
export async function promptForThemeInstallation(name: string) { | ||
name = resolveThemeName(name) | ||
if (!name) | ||
return name | ||
|
||
if (packageExists(name)) | ||
return name | ||
|
||
const { confirm } = await prompt<{ confirm: boolean }>({ | ||
name: 'confirm', | ||
initial: 'Y', | ||
type: 'confirm', | ||
message: `Does not found theme "${name}" in your project, do you want to install it now?`, | ||
}) | ||
|
||
if (!confirm) | ||
return false | ||
|
||
await run(parseNi, [name]) | ||
|
||
return name | ||
} |
Oops, something went wrong.