@@ -8,9 +8,10 @@ const readdir = promisify(fs.readdir);
88const copyFile = promisify ( fs . copyFile ) ;
99const { COPYFILE_EXCL } = fs . constants ;
1010const stat = promisify ( fs . stat ) ;
11+ const path = require ( 'path' ) ;
1112
12- function createDirectory ( path , dirName ) {
13- return mkdir ( path + '/' + dirName ) ;
13+ function createDirectory ( pathName , dirName ) {
14+ return mkdir ( path . join ( pathName , dirName ) ) ;
1415}
1516
1617function createFile ( fullPath , content ) {
@@ -19,8 +20,8 @@ function createFile(fullPath, content) {
1920 } ) ;
2021}
2122
22- function createPackageJSON ( path , name ) {
23- const fullPath = ` ${ path } / package.json` ;
23+ function createPackageJSON ( pathName , name ) {
24+ const fullPath = path . join ( pathName , ' package.json' ) ;
2425 const packageJSON = JSON . stringify (
2526 {
2627 name : name ,
@@ -45,37 +46,40 @@ function copyRecursively(src, dest) {
4546 return readdir ( src ) . then ( children => {
4647 return Promise . all (
4748 children . map ( child =>
48- stat ( ` ${ src } / ${ child } ` ) . then ( stat => {
49+ stat ( path . join ( src , child ) ) . then ( stat => {
4950 if ( stat . isDirectory ( ) ) {
50- return mkdir ( ` ${ dest } / ${ child } ` ) . then ( ( ) =>
51- copyRecursively ( ` ${ src } / ${ child } ` , ` ${ dest } / ${ child } ` )
51+ return mkdir ( path . join ( dest , child ) ) . then ( ( ) =>
52+ copyRecursively ( path . join ( src , child ) , path . join ( dest , child ) )
5253 ) ;
5354 } else {
5455 return copyFile (
55- `./ ${ src } / ${ child } ` ,
56- ` ${ dest } / ${ child } ` ,
56+ path . join ( src , child ) ,
57+ path . join ( dest , child ) ,
5758 COPYFILE_EXCL
58- ) ;
59+ ) . catch ( console . error ) ;
5960 }
6061 } )
6162 )
6263 ) ;
6364 } ) ;
6465}
6566
66- function createExampleFromTemplates ( path ) {
67- return copyRecursively ( './templates' , path ) ;
67+ function createExampleFromTemplates ( pathName ) {
68+ return copyRecursively (
69+ path . join ( __dirname , '..' , '..' , 'templates' ) ,
70+ pathName
71+ ) ;
6872}
6973
70- function createEnvFile ( path , { accountSid, authToken } ) {
71- const fullPath = ` ${ path } /. env` ;
74+ function createEnvFile ( pathName , { accountSid, authToken } ) {
75+ const fullPath = path . join ( pathName , '. env' ) ;
7276 const content = `ACCOUNT_SID=${ accountSid }
7377AUTH_TOKEN=${ authToken } ` ;
7478 return createFile ( fullPath , content ) ;
7579}
7680
77- function createNvmrcFile ( path ) {
78- const fullPath = ` ${ path } /. nvmrc` ;
81+ function createNvmrcFile ( pathName ) {
82+ const fullPath = path . join ( pathName , '. nvmrc' ) ;
7983 const content = versions . node ;
8084 return createFile ( fullPath , content ) ;
8185}
0 commit comments