File tree Expand file tree Collapse file tree 7 files changed +42
-7
lines changed Expand file tree Collapse file tree 7 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,14 @@ var fs_1 = require('fs');
33var path_1 = require ( 'path' ) ;
44var file_1 = require ( '../../tools/file' ) ;
55var cleanup_1 = require ( './cleanup' ) ;
6+ var settings_1 = require ( './settings' ) ;
67function loadImport ( lines , pathToMd ) {
78 pathToMd = cleanup_1 . trimQuotes ( pathToMd ) ;
89 if ( ! pathToMd . match ( / \. m d $ / ) ) {
910 pathToMd = pathToMd . concat ( '.md' ) ;
1011 }
11- var realPath = path_1 . join ( process . cwd ( ) , pathToMd ) ;
12- if ( ! file_1 . fileExists ( pathToMd ) ) {
12+ var realPath = path_1 . join ( process . cwd ( ) , settings_1 . tutorialDir , pathToMd ) ;
13+ if ( ! file_1 . fileExists ( realPath ) ) {
1314 console . log ( 'Invalid path to markdown file' , realPath ) ;
1415 return ;
1516 }
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ var fs_1 = require ( 'fs' ) ;
3+ var path_1 = require ( 'path' ) ;
4+ var chalk_1 = require ( 'chalk' ) ;
5+ var settings = null ;
6+ try {
7+ settings = JSON . parse ( fs_1 . readFileSync ( path_1 . join ( process . cwd ( ) , 'package.json' ) , 'utf8' ) ) ;
8+ }
9+ catch ( e ) {
10+ console . log ( chalk_1 . red ( 'No package.json config found in directory ' , process . cwd ( ) , e ) ) ;
11+ }
12+ exports . tutorialDir = settings . dir || 'tutorial' ;
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ exports . tutorialDir = 'tutorial' ;
Original file line number Diff line number Diff line change @@ -2,14 +2,17 @@ import {readFileSync} from 'fs';
22import { join } from 'path' ;
33import { fileExists } from '../../tools/file' ;
44import { trimQuotes } from './cleanup' ;
5+ import { tutorialDir } from './settings' ;
56
67export function loadImport ( lines : string [ ] , pathToMd : string ) : string [ ] {
8+ // add .md suffix
79 pathToMd = trimQuotes ( pathToMd ) ;
810 if ( ! pathToMd . match ( / \. m d $ / ) ) {
911 pathToMd = pathToMd . concat ( '.md' ) ;
1012 }
11- let realPath : string = join ( process . cwd ( ) , pathToMd ) ;
12- if ( ! fileExists ( pathToMd ) ) {
13+ // get path to imports
14+ let realPath : string = join ( process . cwd ( ) , tutorialDir , pathToMd ) ;
15+ if ( ! fileExists ( realPath ) ) {
1316 console . log ( 'Invalid path to markdown file' , realPath ) ;
1417 return ;
1518 }
Original file line number Diff line number Diff line change 1+ import { readFileSync } from 'fs' ;
2+ import { join } from 'path' ;
3+ import { red } from 'chalk' ;
4+
5+ let settings = null ;
6+ try {
7+ settings = JSON . parse (
8+ readFileSync (
9+ join ( process . cwd ( ) , 'package.json' ) , 'utf8'
10+ )
11+ ) ;
12+ } catch ( e ) {
13+ console . log ( red ( 'No package.json config found in directory ' , process . cwd ( ) , e ) ) ;
14+ }
15+
16+ export const tutorialDir = settings . dir || 'tutorial' ;
Original file line number Diff line number Diff line change @@ -13,10 +13,10 @@ program
1313 . version ( '0.3.27' )
1414 . usage ( '[options] <keywords>' )
1515 . option ( '-b, --build [path/to/tutorial.md]' ,
16- 'tutorial markdown file' , / ^ .+ \. m d $ / i)
16+ 'tutorial markdown file' , / ^ .+ \. m d $ / i)
1717 . option ( '-c, --create [name]' , 'tutorial name' )
1818 . option ( '-p, --publish [version]' ,
19- 'publish tutorial to npm with new version number' )
19+ 'publish tutorial to npm with new version number' )
2020 . option ( '-t, --tutorials' , 'list of tutorial packages' )
2121 . option ( '-s, --search [query]' , 'search for tutorial package' )
2222 . option ( '-r, --run' , 'run tutorial' )
@@ -55,6 +55,6 @@ switch (true) {
5555 program . help ( ) ;
5656}
5757
58- // exit
58+ // success! exit
5959process . stdout . write ( green ( ' ✓\n' ) ) ;
6060process . exit ( 0 ) ;
Original file line number Diff line number Diff line change 2323 " src/build/parser/info.ts" ,
2424 " src/build/parser/match.ts" ,
2525 " src/build/parser/page.ts" ,
26+ " src/build/parser/settings.ts" ,
2627 " src/build/parser/task.ts" ,
2728 " src/build/readme.ts" ,
2829 " src/build/validators.ts" ,
You can’t perform that action at this time.
0 commit comments