@@ -5,33 +5,33 @@ var CODE_SAMPLE = /```[\S]+\s*[\s\S]*?```/g;
55var PARTS = / ` ` ` [ \S ] + \s * \/ \/ \s + ( .+ ?) \n ( [ \s \S ] * ?) ` ` ` / ;
66
77function truncate ( s , n ) {
8- n = n || 256
9- if ( s . length < n ) {
10- return s ;
11- }
12- return s . substring ( 0 , n ) + '...' ;
8+ n = n || 256
9+ if ( s . length < n ) {
10+ return s ;
11+ }
12+ return s . substring ( 0 , n ) + '...' ;
1313}
1414
1515function main ( dest , filenames ) {
16- if ( ! dest ) {
17- throw new Error ( 'no dest provided' ) ;
18- }
19- filenames . map ( function ( filename ) {
20- var content = fs . readFileSync ( filename ) . toString ( 'utf8' ) ;
21- var codeSamples = content . match ( CODE_SAMPLE ) ;
16+ if ( ! dest ) {
17+ throw new Error ( 'no dest provided' ) ;
18+ }
19+ filenames . map ( function ( filename ) {
20+ var content = fs . readFileSync ( filename ) . toString ( 'utf8' ) ;
21+ var codeSamples = content . match ( CODE_SAMPLE ) ;
2222
23- codeSamples . map ( function ( codeSample ) {
24- // Do a little jank preprocessing
25- codeSample = codeSample . replace ( '<!--' , '//' ) . replace ( ' -->' , '' ) ;
26- var extracted = codeSample . match ( PARTS ) ;
27- if ( ! extracted ) {
28- throw new Error ( 'Code sample did not match correct format in ' + filename + ': ' + truncate ( codeSample ) ) ;
29- }
30- var filename = extracted [ 1 ] ;
31- var content = extracted [ 2 ] . replace ( / \* \* / g, '' ) ;
32- fs . writeFileSync ( argv . dest + '/' + filename , content ) ;
33- } ) ;
23+ codeSamples . map ( function ( codeSample ) {
24+ // Do a little jank preprocessing
25+ codeSample = codeSample . replace ( '<!--' , '//' ) . replace ( ' -->' , '' ) ;
26+ var extracted = codeSample . match ( PARTS ) ;
27+ if ( ! extracted ) {
28+ throw new Error ( 'Code sample did not match correct format in ' + filename + ': ' + truncate ( codeSample ) ) ;
29+ }
30+ var filename = extracted [ 1 ] ;
31+ var content = extracted [ 2 ] . replace ( / \* \* / g, '' ) ;
32+ fs . writeFileSync ( argv . dest + '/' + filename , content ) ;
3433 } ) ;
34+ } ) ;
3535}
3636
37- main ( argv . dest , argv . _ ) ;
37+ main ( argv . dest , argv . _ ) ;
0 commit comments