@@ -3,25 +3,35 @@ var fs_1 = require('fs');
33var path_1 = require ( 'path' ) ;
44var sort_package_json_1 = require ( 'sort-package-json' ) ;
55var node_file_exists_1 = require ( 'node-file-exists' ) ;
6- function createFile ( pathToFile ) {
7- if ( ! node_file_exists_1 . default ( pathToFile ) ) {
8- var inputPath = path_1 . join ( __dirname , '..' , '..' , 'setup' , pathToFile ) ;
9- var test = fs_1 . readFileSync ( inputPath , 'utf8' ) ;
10- fs_1 . writeFileSync ( pathToFile , test , 'utf8' ) ;
6+ function createFile ( dir , pathToFile ) {
7+ try {
8+ if ( ! node_file_exists_1 . default ( pathToFile ) ) {
9+ var inputPath = path_1 . join ( __dirname , '..' , '..' , 'setup' , pathToFile ) ;
10+ var test = fs_1 . readFileSync ( inputPath , 'utf8' ) ;
11+ fs_1 . writeFileSync ( path_1 . join ( dir , pathToFile ) , test , 'utf8' ) ;
12+ }
13+ }
14+ catch ( e ) {
15+ console . log ( e ) ;
1116 }
1217}
1318function createFolder ( pathToFolder ) {
14- if ( ! node_file_exists_1 . default ( pathToFolder ) ) {
15- fs_1 . mkdirSync ( pathToFolder ) ;
19+ try {
20+ if ( ! node_file_exists_1 . default ( pathToFolder ) ) {
21+ fs_1 . mkdirSync ( pathToFolder ) ;
22+ }
23+ }
24+ catch ( e ) {
25+ console . log ( e ) ;
1626 }
1727}
18- var folders = [
19- 'tutorial' ,
20- path_1 . join ( 'tutorial' , '01' ) ,
21- path_1 . join ( 'tutorial' , '02' )
22- ] ;
28+ var folders = function ( dir ) { return [
29+ path_1 . join ( dir , 'tutorial' ) ,
30+ path_1 . join ( dir , 'tutorial' , '01' ) ,
31+ path_1 . join ( dir , 'tutorial' , '02' )
32+ ] ; } ;
2333var files = [
24- '.gitignore' ,
34+ path_1 . join ( '.gitignore' ) ,
2535 path_1 . join ( 'tutorial' , 'tutorial.md' ) ,
2636 path_1 . join ( 'tutorial' , '01' , 'page-one.md' ) ,
2737 path_1 . join ( 'tutorial' , '01' , '01.spec.js' ) ,
@@ -30,22 +40,23 @@ var files = [
3040 path_1 . join ( 'tutorial' , '02' , '01.spec.js' ) ,
3141 path_1 . join ( 'tutorial' , '02' , '02.spec.js' )
3242] ;
33- function createTutorialMd ( ) {
43+ function createTutorialMd ( dir ) {
44+ console . log ( 'dir' , dir ) ;
3445 return new Promise ( function ( resolve , reject ) {
35- folders . forEach ( function ( folder ) { return createFolder ( folder ) ; } ) ;
36- files . forEach ( function ( file ) { return createFile ( file ) ; } ) ;
46+ folders ( dir ) . forEach ( function ( folder ) { return createFolder ( folder ) ; } ) ;
47+ files . forEach ( function ( file ) { return createFile ( dir , file ) ; } ) ;
3748 resolve ( true ) ;
3849 } ) ;
3950}
4051exports . createTutorialMd = createTutorialMd ;
41- function createPackageJson ( name ) {
52+ function createPackageJson ( dir , name ) {
4253 return new Promise ( function ( resolve , reject ) {
43- if ( ! node_file_exists_1 . default ( 'package.json' ) ) {
54+ if ( ! node_file_exists_1 . default ( path_1 . join ( dir , 'package.json' ) ) ) {
4455 var inputPath = path_1 . join ( __dirname , '..' , '..' , 'setup' , 'package.json' ) ;
4556 var packageJson = JSON . parse ( fs_1 . readFileSync ( inputPath , 'utf8' ) ) ;
4657 packageJson . name = 'coderoad-' + name ;
4758 var packageJsonString = sort_package_json_1 . sortPackageJson ( JSON . stringify ( packageJson , null , 2 ) ) ;
48- fs_1 . writeFileSync ( 'package.json' , packageJsonString , 'utf8' ) ;
59+ fs_1 . writeFileSync ( path_1 . join ( dir , 'package.json' ) , packageJsonString , 'utf8' ) ;
4960 resolve ( true ) ;
5061 }
5162 else {
0 commit comments