File tree 3 files changed +68
-0
lines changed
3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ const yargs = require ( 'yargs' ) ;
2
+ const fs = require ( 'fs' ) ;
3
+
4
+ // Validate and normalize.
5
+ const validate = parser => {
6
+ const { argv } = parser ;
7
+ const { mdx } = argv ;
8
+
9
+ return Promise . resolve ( ) . then ( ( ) =>
10
+ new Promise ( ( resolve , reject ) => {
11
+ fs . readFile ( mdx , ( err , data ) => {
12
+ if ( err ) {
13
+ reject ( err ) ;
14
+ } else {
15
+ resolve ( data ) ;
16
+ }
17
+ } ) ;
18
+ } ) . then ( buf => buf . toString ( 'utf8' ) )
19
+ ) ;
20
+ } ;
21
+
22
+ const args = ( ) =>
23
+ yargs
24
+ . usage ( `Usage: spectacle -m <file>` )
25
+
26
+ // MDX File
27
+ . option ( 'mdx' , {
28
+ alias : 'm' ,
29
+ describe : 'Path to mdx file from which a presentation will be generated.' ,
30
+ default : 'slides.mdx' ,
31
+ required : false ,
32
+ type : 'string'
33
+ } )
34
+
35
+ // Logistical
36
+ . help ( )
37
+ . alias ( 'help' , 'h' )
38
+ . version ( )
39
+ . alias ( 'version' , 'v' )
40
+ . strict ( ) ;
41
+
42
+ module . exports = {
43
+ parse : ( ) => validate ( args ( ) )
44
+ } ;
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ const parse = require ( './args' ) . parse ;
4
+
5
+ const main = ( ) =>
6
+ Promise . resolve ( )
7
+ // Parse arguments.
8
+ . then ( parse )
9
+ . then ( out => {
10
+ console . log ( out ) ;
11
+ } )
12
+ . catch ( err => {
13
+ // Try to get full stack, then full string if not.
14
+ console . error ( err . stack || err . toString ( ) ) ;
15
+
16
+ process . exit ( 1 ) ;
17
+ } ) ;
18
+
19
+ if ( require . main === module ) {
20
+ main ( ) ;
21
+ }
Original file line number Diff line number Diff line change 17
17
"test" : " jest --verbose" ,
18
18
"check" : " "
19
19
},
20
+ "bin" : {
21
+ "spectacle" : " ./bin/cli.js"
22
+ },
20
23
"author" : " " ,
21
24
"license" : " MIT" ,
22
25
"repository" : {
You can’t perform that action at this time.
0 commit comments