@@ -9,7 +9,7 @@ import { LogLevel, ViteDevServer } from 'vite'
9
9
import * as parser from '@slidev/parser/fs'
10
10
import { version } from '../package.json'
11
11
import { createServer } from './server'
12
- import { ResolvedSlidevOptions , resolveOptions } from './options'
12
+ import { getThemeRoots , isRelative , ResolvedSlidevOptions , resolveOptions } from './options'
13
13
import { resolveThemeName } from './themes'
14
14
15
15
const cli = yargs
@@ -155,6 +155,56 @@ cli.command(
155
155
} ,
156
156
)
157
157
158
+ cli . command (
159
+ 'theme [subcommand]' ,
160
+ 'Theme related operations' ,
161
+ ( command ) => {
162
+ return command
163
+ . command (
164
+ 'eject' ,
165
+ 'Eject current theme into local file system' ,
166
+ args => commonOptions ( args )
167
+ . option ( 'dir' , {
168
+ type : 'string' ,
169
+ default : 'theme' ,
170
+ } ) ,
171
+ async ( { entry, dir, theme : themeInput } ) => {
172
+ const data = await parser . load ( entry )
173
+ const theme = resolveThemeName ( themeInput || data . config . theme )
174
+ if ( theme === 'none' ) {
175
+ console . error ( 'Can not eject theme "none"' )
176
+ process . exit ( 1 )
177
+ }
178
+ if ( isRelative ( theme ) ) {
179
+ console . error ( 'Theme is already ejected' )
180
+ process . exit ( 1 )
181
+ }
182
+ const roots = getThemeRoots ( theme , entry )
183
+ if ( ! roots . length ) {
184
+ console . error ( `Does not found theme "${ theme } "` )
185
+ process . exit ( 1 )
186
+ }
187
+ const root = roots [ 0 ]
188
+
189
+ await fs . copy ( root , path . resolve ( dir ) , {
190
+ filter : i => ! / n o d e _ m o d u l e s | .g i t / . test ( path . relative ( root , i ) ) ,
191
+ } )
192
+
193
+ const dirPath = `./${ dir } `
194
+ data . slides [ 0 ] . frontmatter . theme = dirPath
195
+ data . slides [ 0 ] . raw = ''
196
+ await parser . save ( data )
197
+
198
+ console . log ( `Theme "${ theme } " ejected successfully to "${ dirPath } "` )
199
+ } ,
200
+ )
201
+ } ,
202
+ ( ) => {
203
+ cli . showHelp ( )
204
+ process . exit ( 1 )
205
+ } ,
206
+ )
207
+
158
208
cli . command (
159
209
'export [entry]' ,
160
210
'Export slides to PDF' ,
0 commit comments