module ts { export interface System { args : string [ ] ; newLine : string ; useCaseSensitiveFileNames : boolean ; write ( s ) : void ; readFile ( fileName , encoding ? ) : string ; writeFile ( fileName , data , writeByteOrderMark ? ) : void ; watchFile ? ( fileName , callback ) : FileWatcher ; resolvePath ( path ) : string ; fileExists ( path ) : boolean ; directoryExists ( path ) : boolean ; createDirectory ( directoryName ) : void ; getExecutingFilePath ( ) : string ; getCurrentDirectory ( ) : string ; getMemoryUsage ? ( ) : number ; exit ( exitCode ? ) : number ; } export interface FileWatcher { close ( ) : void ; } declare var require ; declare var module ; declare var process ; declare var global ; declare var __filename ; export var sys = ( function ( ) { function getWScriptSystem ( ) { var fso = new ActiveXObject ( "Scripting.FileSystemObject" ) ; var fileStream = new ActiveXObject ( "ADODB.Stream" ) ; fileStream . Type = 2 ; var binaryStream = new ActiveXObject ( "ADODB.Stream" ) ; binaryStream . Type = 1 ; var args = [ ] ; for ( var i = 0 ; i < WScript . Arguments . length ; i ++ ) { args [ i ] = WScript . Arguments . Item ( i ) ; } function readFile ( fileName , encoding ? ) { if ( ! fso . FileExists ( fileName ) ) { return undefined ; } fileStream . Open ( ) ; try { if ( encoding ) { fileStream . Charset = encoding ; fileStream . LoadFromFile ( fileName ) ; } else { fileStream . Charset = "x-ansi" ; fileStream . LoadFromFile ( fileName ) ; var bom = fileStream . ReadText ( 2 ) || "" ; fileStream . Position = 0 ; fileStream . Charset = bom . length >= 2 && ( bom . charCodeAt ( 0 ) === 0xFF && bom . charCodeAt ( 1 ) === 0xFE || bom . charCodeAt ( 0 ) === 0xFE && bom . charCodeAt ( 1 ) === 0xFF ) ? "unicode" : "utf-8" ; } return fileStream . ReadText ( ) ; } catch ( e ) { throw e ; } finally { fileStream . Close ( ) ; } } function writeFile ( fileName , data , writeByteOrderMark ? ) { fileStream . Open ( ) ; binaryStream . Open ( ) ; try { fileStream . Charset = "utf-8" ; fileStream . WriteText ( data ) ; if ( writeByteOrderMark ) { fileStream . Position = 0 ; } else { fileStream . Position = 3 ; } fileStream . CopyTo ( binaryStream ) ; binaryStream . SaveToFile ( fileName , 2 ) ; } finally { binaryStream . Close ( ) ; fileStream . Close ( ) ; } } return { args , newLine : "\r\n" , useCaseSensitiveFileNames : false , write ( s ) { WScript . StdOut . Write ( s ) ; } , readFile , writeFile , resolvePath ( path ) { return fso . GetAbsolutePathName ( path ) ; } , fileExists ( path ) { return fso . FileExists ( path ) ; } , directoryExists ( path ) { return fso . FolderExists ( path ) ; } , createDirectory ( directoryName ) { if ( ! this . directoryExists ( directoryName ) ) { fso . CreateFolder ( directoryName ) ; } } , getExecutingFilePath ( ) { return WScript . ScriptFullName ; } , getCurrentDirectory ( ) { return new ActiveXObject ( "WScript.Shell" ) . CurrentDirectory ; } , exit ( exitCode ? ) { try { WScript . Quit ( exitCode ) ; return exitCode ; } catch ( e ) { } } } ; } function getNodeSystem ( ) { var _fs = require ( "fs" ) ; var _path = require ( "path" ) ; var _os = require ( 'os' ) ; var platform = _os . platform ( ) ; var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin" ; function readFile ( fileName , encoding ? ) { if ( ! _fs . existsSync ( fileName ) ) { return undefined ; } var buffer = _fs . readFileSync ( fileName ) ; var len = buffer . length ; if ( len >= 2 && buffer [ 0 ] === 0xFE && buffer [ 1 ] === 0xFF ) { len &= ~ 1 ; for ( var i = 0 ; i < len ; i += 2 ) { var temp = buffer [ i ] ; buffer [ i ] = buffer [ i + 1 ] ; buffer [ i + 1 ] = temp ; } return buffer . toString ( "utf16le" , 2 ) ; } if ( len >= 2 && buffer [ 0 ] === 0xFF && buffer [ 1 ] === 0xFE ) { return buffer . toString ( "utf16le" , 2 ) ; } if ( len >= 3 && buffer [ 0 ] === 0xEF && buffer [ 1 ] === 0xBB && buffer [ 2 ] === 0xBF ) { return buffer . toString ( "utf8" , 3 ) ; } return buffer . toString ( "utf8" ) ; } function writeFile ( fileName , data , writeByteOrderMark ? ) { if ( writeByteOrderMark ) { data = '\uFEFF' + data ; } _fs . writeFileSync ( fileName , data , "utf8" ) ; } return { args : process . argv . slice ( 2 ) , newLine : _os . EOL , useCaseSensitiveFileNames : useCaseSensitiveFileNames , write ( s ) { _fs . writeSync ( 1 , s ) ; } , readFile , writeFile , watchFile : ( fileName , callback ) => { _fs . watchFile ( fileName , { persistent : true , interval : 250 } , fileChanged ) ; return { close ( ) { _fs . unwatchFile ( fileName , fileChanged ) ; } } ; function fileChanged ( curr , prev ) { if ( + curr . mtime <= + prev . mtime ) { return ; } callback ( fileName ) ; } ; } , resolvePath : function ( path ) : string { return _path . resolve ( path ) ; } , fileExists ( path ) { return _fs . existsSync ( path ) ; } , directoryExists ( path ) { return _fs . existsSync ( path ) && _fs . statSync ( path ) . isDirectory ( ) ; } , createDirectory ( directoryName ) { if ( ! this . directoryExists ( directoryName ) ) { _fs . mkdirSync ( directoryName ) ; } } , getExecutingFilePath ( ) { return __filename ; } , getCurrentDirectory ( ) { return process . cwd ( ) ; } , getMemoryUsage ( ) { if ( global . gc ) { global . gc ( ) ; } return process . memoryUsage ( ) . heapUsed ; } , exit ( exitCode ? ) { process . exit ( exitCode ) ; return exitCode ; } } ; } if ( typeof WScript !== "undefined" && typeof ActiveXObject === "function" ) { return getWScriptSystem ( ) ; } else if ( typeof module !== "undefined" && module . exports ) { return getNodeSystem ( ) ; } else { return undefined ; } } ) ( ) ; }