1+ import * as child_process from 'child_process'
12import * as fs from 'fs'
23import * as path from 'path'
34
@@ -53,19 +54,6 @@ class InternalFileSystem implements FileSystem {
5354 } )
5455 }
5556
56- public readfile ( filepath : string ) : Promise < Buffer > {
57- return new Promise < Buffer > ( ( resolve , reject ) => {
58- fs . readFile ( filepath , ( error : NodeJS . ErrnoException , data : Buffer ) => {
59- if ( error ) {
60- reject ( error )
61- } else {
62- this . log . debug ( 'read-file' , filepath )
63- resolve ( data )
64- }
65- } )
66- } )
67- }
68-
6957 public listdirs ( filepath : string ) : Promise < string [ ] > {
7058 return this . statfiles ( filepath ) . then ( stats => stats . filter ( stat => stat . dir ) . map ( stat => stat . filename ) )
7159 }
@@ -86,6 +74,37 @@ class InternalFileSystem implements FileSystem {
8674 } )
8775 }
8876
77+ public mkdirp ( filepath : string ) : Promise < void > {
78+ return new Promise < void > ( ( resolve , reject ) =>
79+ child_process . exec ( `mkdir -p "${ filepath } "` )
80+ . on ( 'close' , code => code === 0 ? resolve ( ) : reject ( ) )
81+ . on ( 'error' , error => reject ( error ) )
82+ )
83+ }
84+
85+ public readfile ( filepath : string ) : Promise < Buffer > {
86+ return new Promise < Buffer > ( ( resolve , reject ) => {
87+ fs . readFile ( filepath , ( error : NodeJS . ErrnoException , data : Buffer ) => {
88+ if ( error ) {
89+ reject ( error )
90+ } else {
91+ this . log . debug ( 'read-file' , filepath )
92+ resolve ( data )
93+ }
94+ } )
95+ } )
96+ }
97+
98+ public rename ( original : string , filepath : string ) : Promise < void > {
99+ return new Promise < void > ( ( resolve , reject ) => fs . rename ( original , filepath , ( error : NodeJS . ErrnoException ) => {
100+ if ( error ) {
101+ reject ( error )
102+ } else {
103+ resolve ( )
104+ }
105+ } ) )
106+ }
107+
89108 public save < T > ( filepath : string , data : T ) : Promise < void > {
90109 return this . writefile ( filepath , JSON . stringify ( data , null , 2 ) )
91110 }
0 commit comments