File tree 3 files changed +54
-10
lines changed
3 files changed +54
-10
lines changed Original file line number Diff line number Diff line change 1
1
const yargs = require ( 'yargs' ) ;
2
+ const validatePresentationMode = require ( './validate/presentation-mode' ) ;
2
3
3
- // Validate and normalize.
4
- const validate = parser => {
4
+ const validate = async parser => {
5
5
const { argv } = parser ;
6
- const { mdx } = argv ;
6
+ const { src } = argv ;
7
7
8
- return Promise . resolve ( { mdx } ) ;
8
+ return await validatePresentationMode ( src ) ;
9
9
} ;
10
10
11
11
const args = ( ) =>
12
12
yargs
13
- . usage ( `Usage: spectacle -m <file>` )
13
+ . usage ( `Usage: spectacle -s <file>` )
14
14
15
15
// MDX File
16
- . option ( 'mdx ' , {
17
- alias : 'm ' ,
18
- describe : 'Path to mdx file from which a presentation will be generated.' ,
16
+ . option ( 'src ' , {
17
+ alias : 's ' ,
18
+ describe : 'Path to a file from which a presentation will be generated.' ,
19
19
default : 'slides.mdx' ,
20
- required : false ,
21
20
type : 'string'
22
21
} )
23
22
Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ const main = () =>
11
11
const mdxFilePath = parsedInput . mdx ;
12
12
if ( mdxFilePath ) {
13
13
actions . launchMDXServer ( mdxFilePath ) ;
14
- } else {
14
+ }
15
+ // add future actions here
16
+ else {
15
17
throw new Error ( 'Unsupported action.' ) ;
16
18
}
17
19
} )
Original file line number Diff line number Diff line change
1
+ const path = require ( 'path' ) ;
2
+ const fs = require ( 'fs' ) ;
3
+
4
+ const isMDXFileType = extension => extension === '.mdx' || extension === '.md' ;
5
+
6
+ const fileExists = srcPath => {
7
+ const absSrcPath = path . resolve ( srcPath ) ;
8
+ return new Promise ( resolve => {
9
+ fs . exists ( absSrcPath , exists => {
10
+ resolve ( exists ) ;
11
+ } ) ;
12
+ } ) ;
13
+ } ;
14
+
15
+ const validatePresentationMode = async src => {
16
+ /* - the default action of the CLI is to boot up a presentation from a file
17
+ * - src defaults to `slides.mdx`
18
+ * - first, check to see if the file type is supported
19
+ * - then check to see if the default or provided file exists
20
+ */
21
+
22
+ const validatedValue = { } ;
23
+ const extension = path . extname ( src ) ;
24
+
25
+ if ( isMDXFileType ( extension ) ) {
26
+ validatedValue [ 'mdx' ] = src ;
27
+ }
28
+ // support other file types here
29
+ else {
30
+ throw new Error ( `The file type ${ extension } is not currently supported.` ) ;
31
+ }
32
+
33
+ const exists = await fileExists ( src ) ;
34
+ if ( ! exists ) {
35
+ throw new Error (
36
+ `A file cannot be found at the path "${ src } ". Remember that the default file is ./slides.mdx`
37
+ ) ;
38
+ }
39
+
40
+ return validatedValue ;
41
+ } ;
42
+
43
+ module . exports = validatePresentationMode ;
You can’t perform that action at this time.
0 commit comments