├── docs ├── connectionError ├── fileNotSupported └── usage ├── templates ├── AppxManifest │ ├── img │ │ ├── logo.png │ │ ├── smalllogo.png │ │ ├── storelogo.png │ │ └── splashscreen.png │ └── AppxManifest.xml ├── rdConfig.rdp └── w3c-AppxManifest-template.xml ├── .gitignore ├── projects ├── typings │ ├── adapter.d.ts │ └── node.d.ts └── vs2015 │ ├── vs2015.sln │ └── hwa-cli.csproj ├── tsconfig.json ├── .gitattributes ├── LICENSE ├── package.json ├── src ├── phantom-image.ts ├── cloudAppx.ts ├── cli.ts ├── adapter.ts ├── crxConverter.ts └── webConverter.ts ├── main.js ├── README.md └── tests └── adapterTests.ts /docs/connectionError: -------------------------------------------------------------------------------- 1 | Cannot connect to server -------------------------------------------------------------------------------- /docs/fileNotSupported: -------------------------------------------------------------------------------- 1 | The specified file must be called AppxManifest.xml -------------------------------------------------------------------------------- /templates/AppxManifest/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MicrosoftEdge/hwa-cli/HEAD/templates/AppxManifest/img/logo.png -------------------------------------------------------------------------------- /templates/AppxManifest/img/smalllogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MicrosoftEdge/hwa-cli/HEAD/templates/AppxManifest/img/smalllogo.png -------------------------------------------------------------------------------- /templates/AppxManifest/img/storelogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MicrosoftEdge/hwa-cli/HEAD/templates/AppxManifest/img/storelogo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /node_modules 3 | /projects/vs2015/bin 4 | /projects/vs2015/obj 5 | /projects/vs2015/.vs 6 | /publish 7 | 8 | *.csproj.user -------------------------------------------------------------------------------- /templates/AppxManifest/img/splashscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MicrosoftEdge/hwa-cli/HEAD/templates/AppxManifest/img/splashscreen.png -------------------------------------------------------------------------------- /projects/typings/adapter.d.ts: -------------------------------------------------------------------------------- 1 | interface HWAAdapter { 2 | launchAppx(): void; 3 | registerAndLaunchAppxManifest(path: string): void; 4 | } 5 | 6 | interface HWAProxyAdapter extends HWAAdapter { 7 | clearSession(): void; 8 | exit(): void; 9 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "umd", 4 | "target": "ES5", 5 | "outDir": "bin/", 6 | "newLine": "LF" 7 | }, 8 | "files": [ 9 | "src/adapter.ts", 10 | "src/cli.ts", 11 | "src/cloudAppx.ts", 12 | "src/crxConverter.ts", 13 | "src/phantom-image.ts", 14 | "src/webConverter.ts", 15 | "tests/adapterTests.ts" 16 | ] 17 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.ts text 7 | *.js text 8 | 9 | # Declare files that will always have CRLF line endings on checkout. 10 | *.sln text eol=crlf 11 | 12 | # Denote all files that are truly binary and should not be modified. 13 | *.png binary 14 | *.jpg binary -------------------------------------------------------------------------------- /docs/usage: -------------------------------------------------------------------------------- 1 | hwa (command) [args] 2 | 3 | convert: 4 | Converts a supported package to a Windows Appx package. I.e.: 5 | hwa convert path/to/myapp.crx 6 | 7 | deploy: 8 | Registers and launches an AppxManifest or URL. I.e.: 9 | hwa deploy http://dev.windows.com 10 | hwa deploy path-to-AppxManifest.xml 11 | 12 | restart: 13 | Starts or restarts the previous Appx deployed using this tool. 14 | 15 | 16 | Remote Commands 17 | The following commands are only usable when using this tool to connect to an HWA-Server. 18 | 19 | clearsession: 20 | Clears the session file, causing the next deploy to re-provision a server. 21 | 22 | exit: 23 | Disconnects the provisioned HWA-Server. -------------------------------------------------------------------------------- /projects/vs2015/vs2015.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hwa-cli", "hwa-cli.csproj", "{963D9A06-99CC-4A38-9245-0EC766EF53B7}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {963D9A06-99CC-4A38-9245-0EC766EF53B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {963D9A06-99CC-4A38-9245-0EC766EF53B7}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {963D9A06-99CC-4A38-9245-0EC766EF53B7}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {963D9A06-99CC-4A38-9245-0EC766EF53B7}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.22", 3 | "name": "hwa-cli", 4 | "title": "HWA Deployment Command-Line interface", 5 | "description": "Command-Line interface for deploying HWAs locally and remotely via HWA-Server.", 6 | "preferGlobal": true, 7 | "bin": { 8 | "hwa": "main.js" 9 | }, 10 | "author": { 11 | "name": "Zack Hall", 12 | "url": "https://github.com/zackhall" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/MicrosoftEdge/hwa-cli" 17 | }, 18 | "bugs": "https://github.com/MicrosoftEdge/hwa-cli/issues", 19 | "licenses": [ 20 | { 21 | "type": "MIT", 22 | "url": "https://github.com/MicrosoftEdge/hwa-cli/blob/master/LICENSE" 23 | } 24 | ], 25 | "dependencies": { 26 | "adm-zip": "^0.4.7", 27 | "archiver": "^0.16.0", 28 | "guid": "^0.0.12", 29 | "inquirer": "^0.11.0", 30 | "ncp": "^2.0.0", 31 | "phantomjs": "^1.9.18", 32 | "request": "^2.65.0", 33 | "rimraf": "^2.4.3", 34 | "tldjs": "^1.6.1", 35 | "validator": "^4.0.5", 36 | "yargs": "^3.30.0" 37 | }, 38 | "optionalDependencies": { 39 | "appx-tools": "^0.0.3" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /templates/rdConfig.rdp: -------------------------------------------------------------------------------- 1 | screen mode id:i:2 2 | use multimon:i:0 3 | desktopwidth:i:1920 4 | desktopheight:i:1080 5 | session bpp:i:32 6 | winposstr:s:0,3,0,0,800,600 7 | compression:i:1 8 | keyboardhook:i:2 9 | audiocapturemode:i:0 10 | videoplaybackmode:i:1 11 | connection type:i:7 12 | networkautodetect:i:1 13 | bandwidthautodetect:i:1 14 | displayconnectionbar:i:1 15 | enableworkspacereconnect:i:0 16 | disable wallpaper:i:0 17 | allow font smoothing:i:0 18 | allow desktop composition:i:0 19 | disable full window drag:i:1 20 | disable menu anims:i:1 21 | disable themes:i:0 22 | disable cursor setting:i:0 23 | bitmapcachepersistenable:i:1 24 | full address:s:{address} 25 | audiomode:i:0 26 | redirectprinters:i:1 27 | redirectcomports:i:0 28 | redirectsmartcards:i:1 29 | redirectclipboard:i:1 30 | redirectposdevices:i:0 31 | autoreconnection enabled:i:1 32 | authentication level:i:2 33 | prompt for credentials:i:1 34 | negotiate security layer:i:1 35 | remoteapplicationmode:i:0 36 | alternate shell:s: 37 | shell working directory:s: 38 | gatewayhostname:s: 39 | gatewayusagemethod:i:4 40 | gatewaycredentialssource:i:4 41 | gatewayprofileusagemethod:i:0 42 | promptcredentialonce:i:0 43 | gatewaybrokeringtype:i:0 44 | use redirection server name:i:0 45 | rdgiskdcproxy:i:0 46 | kdcproxyname:s: 47 | username:s: -------------------------------------------------------------------------------- /src/phantom-image.ts: -------------------------------------------------------------------------------- 1 | declare var phantom: any; 2 | 3 | var system = require("system"); 4 | var inputPath = system.args[1]; 5 | var targetWidth = +system.args[2]; 6 | var targetHeight = +system.args[3]; 7 | var outputPath = system.args[4]; 8 | 9 | var page = require('webpage').create(); 10 | page.open('about:blank', function () { 11 | page.onCallback = function () { 12 | page.clipRect = { 13 | top: 0, 14 | left: 0, 15 | width: targetWidth, 16 | height: targetHeight 17 | }; 18 | page.render(outputPath); 19 | phantom.exit(); 20 | }; 21 | page.evaluate(function (src: string, w: number, h: number) { 22 | src = 'file:///' + src; 23 | 24 | var img = new Image(); 25 | img.onload = () => { 26 | var div = document.createElement("div"); 27 | div.style.width = w + "px"; 28 | div.style.height = h + "px"; 29 | div.style.backgroundImage = `url("${src.replace(/\\/g, "\\\\")}")`; 30 | div.style.backgroundRepeat = "no-repeat"; 31 | 32 | if (img.width > w || img.height > h) { 33 | // Scale down 34 | div.style.backgroundSize = "contain"; 35 | } else { 36 | // Center 37 | div.style.backgroundPosition = "50%"; 38 | } 39 | document.body.style.margin = "0"; 40 | document.body.appendChild(div); 41 | setTimeout((window).callPhantom, 1); 42 | }; 43 | img.src = src; 44 | }, inputPath, targetWidth, targetHeight); 45 | }); -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | var argv = require('yargs') 4 | .usage('Usage: $0 [options]') 5 | .command('convert', 'Converts a supported package to a Windows Appx package.', function(yargs) { 6 | argv = yargs 7 | .usage('Usage: $0 convert [options]') 8 | .demand(2, 'You must specify the path of a package to convert.') 9 | .option('m', { 10 | alias: 'more', 11 | demand: false, 12 | describe: 'Optional flag to customize converted' 13 | }) 14 | .help('help') 15 | .argv; 16 | }) 17 | .command('deploy', '[EXPERIMENTAL] Registers and launches an AppxManifest or URL.', function(yargs) { 18 | argv = yargs 19 | .usage('Usage: $0 deploy ') 20 | .demand(2, 'You must supply a path to an AppxManifest or url to deploy.') 21 | .help('help') 22 | .argv; 23 | }) 24 | .command('restart', '[EXPERIMENTAL] Starts or restarts the previous Appx deployed using this tool.', function(yargs) { 25 | argv = yargs 26 | .usage('Usage: $0 restart') 27 | .help('help') 28 | .argv; 29 | }) 30 | .command('clearsession', '[EXPERIMENTAL] Clears the session file, causing the next deploy to re-provision a server.', function(yargs) { 31 | argv = yargs 32 | .usage('Usage: $0 clearsession') 33 | .help('help') 34 | .argv; 35 | }) 36 | .command('exit', '[EXPERIMENTAL] Disconnects the provisioned HWA-Server.', function(yargs) { 37 | argv = yargs 38 | .usage('Usage: $0 exit') 39 | .help('help') 40 | .argv; 41 | }) 42 | .demand(1) 43 | .help('help', "Use 'hwa help' to get help on a specific command.") 44 | .argv; 45 | 46 | if (module.parent) { 47 | module.exports = {}; 48 | } else { 49 | var hwaCli = require("./bin/src/cli.js"); 50 | hwaCli.main(argv); 51 | ;} 52 | -------------------------------------------------------------------------------- /src/cloudAppx.ts: -------------------------------------------------------------------------------- 1 | import fs = require("fs"); 2 | import os = require("os"); 3 | import p = require("path"); 4 | import url = require("url"); 5 | 6 | var archiver = require("archiver"); 7 | var request = require("request"); 8 | 9 | var serviceEndpoint = 'http://cloudappx.azurewebsites.net'; 10 | 11 | export function invoke(appName: string, appFolder: string, outputPath: string, callback: Function) { 12 | var archive = archiver('zip'); 13 | var zipFile = p.join(os.tmpdir(), appName + '.zip'); 14 | var output = fs.createWriteStream(zipFile); 15 | archive.on('error', function (err: any) { 16 | return callback && callback(err); 17 | }); 18 | 19 | archive.pipe(output); 20 | 21 | archive.directory(appFolder, appName); 22 | archive.finalize(); 23 | output.on('close', function () { 24 | var options = { 25 | method: 'POST', 26 | url: url.resolve(serviceEndpoint, '/v2/build'), 27 | encoding: 'binary' 28 | }; 29 | console.log('Invoking the CloudAppX service...'); 30 | 31 | var req = request.post(options, function (err: any, resp: any, body: string) { 32 | if (err) { 33 | return callback && callback(err); 34 | } 35 | 36 | if (resp.statusCode !== 200) { 37 | return callback && callback(new Error('Failed to create the package. The CloudAppX service returned an error - ' + resp.statusMessage + ' (' + resp.statusCode + '): ' + body)); 38 | } 39 | 40 | fs.writeFile(outputPath, body, { 'encoding': 'binary' }, function (err) { 41 | if (err) { 42 | return callback && callback(err); 43 | } 44 | 45 | fs.unlink(zipFile, function (err) { 46 | return callback && callback(err); 47 | }); 48 | }); 49 | }); 50 | 51 | req.form().append('xml', fs.createReadStream(zipFile)); 52 | }); 53 | } -------------------------------------------------------------------------------- /templates/AppxManifest/AppxManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | TestApp 7 | Test User 8 | img\storelogo.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /templates/w3c-AppxManifest-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {MetadataItems} 7 | 8 | 9 | {AppDisplayName} 10 | {PublisherDisplayName} 11 | {LogoStore} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | {ApplicationContentUriRules} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/cli.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import cp = require("child_process"); 5 | import fs = require("fs"); 6 | import net = require("net"); 7 | import os = require("os"); 8 | import p = require("path"); 9 | import readline = require("readline"); 10 | 11 | import cloudAppx = require("./cloudAppx"); 12 | import crxConverter = require("./crxConverter"); 13 | import webConverter = require("./webConverter"); 14 | 15 | var ncp = require("ncp"); 16 | var rimraf = require("rimraf"); 17 | var validator = require("validator"); 18 | 19 | var templateAppxManifestPath = "templates/AppxManifest"; 20 | var rootTempPath = p.join(os.tmpdir(), "hwa-client"); 21 | var appxManifestTempPath = p.join(rootTempPath, "AppxManifest"); 22 | var appxManifestFilePath = p.join(appxManifestTempPath, "AppxManifest.xml"); 23 | 24 | var hwaAdapter: HWAAdapter; 25 | try { 26 | hwaAdapter = require("appx-tools"); 27 | } catch (e) { 28 | hwaAdapter = require("./adapter.js"); 29 | } 30 | 31 | function cleanTemp() { 32 | rimraf.sync(rootTempPath); 33 | fs.mkdirSync(rootTempPath); 34 | } 35 | cleanTemp(); 36 | 37 | export function main(argv: any) { 38 | var cmd = (argv._[0] || "").toLowerCase(); 39 | var args = argv._.slice(1); 40 | var handled = true; 41 | 42 | switch (cmd) { 43 | case "convert": 44 | if (fs.existsSync(args[0])) { 45 | var filenameWithoutExt = p.parse(args[0]).name; 46 | var outputPath = p.join(rootTempPath, "convert"); 47 | crxConverter.convert(argv, args[0], outputPath).then(() => { 48 | cloudAppx.invoke(filenameWithoutExt, outputPath, p.join(p.dirname(args[0]), filenameWithoutExt + ".appx"), (e: Error) => { 49 | e && console.log(e); 50 | }); 51 | }, (e: any) => { 52 | e && console.log(e); 53 | }); 54 | } else { 55 | handled = false; 56 | } 57 | break; 58 | 59 | case "deploy": 60 | if (fs.existsSync(args[0])) { 61 | if (p.basename(args[0]).toLocaleLowerCase() === "appxmanifest.xml") { 62 | // Argument is the path to an AppxManifest.xml 63 | hwaAdapter.registerAndLaunchAppxManifest(args[0]); 64 | } else { 65 | printDocs("fileNotSupported"); 66 | } 67 | } else if (validator.isURL(args[0], { require_protocol: true })) { 68 | // Argument is an URL 69 | // Copy AppxManifest template to temp 70 | cleanTemp(); 71 | ncp.ncp(p.resolve(p.join(__dirname, "..", templateAppxManifestPath)), appxManifestTempPath, {}, () => { 72 | // Edit the template AppxManifest file 73 | var file = fs.readFileSync(appxManifestFilePath, "utf8"); 74 | file = file.replace("{startpage}", args[0]); 75 | fs.writeFileSync(appxManifestFilePath, file, "utf8"); 76 | hwaAdapter.registerAndLaunchAppxManifest(appxManifestFilePath); 77 | }); 78 | } else { 79 | handled = false; 80 | } 81 | break; 82 | 83 | case "restart": 84 | hwaAdapter.launchAppx(); 85 | break; 86 | 87 | // Proxy Adapter commands 88 | case "clearsession": 89 | var proxyAdapter = hwaAdapter; 90 | proxyAdapter.clearSession && proxyAdapter.clearSession(); 91 | break; 92 | 93 | case "exit": 94 | var proxyAdapter = hwaAdapter; 95 | proxyAdapter.exit && proxyAdapter.exit(); 96 | break; 97 | 98 | default: 99 | handled = false; 100 | break; 101 | } 102 | 103 | if (!handled) { 104 | argv.help(); 105 | } 106 | } 107 | 108 | export function printDocs(filename: string) { 109 | var filePath = p.join(p.dirname(fs.realpathSync(__filename)), "../../docs", filename); 110 | console.log(fs.readFileSync(filePath, "utf8")); 111 | } 112 | -------------------------------------------------------------------------------- /src/adapter.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import cp = require("child_process"); 4 | import fs = require("fs"); 5 | import net = require("net"); 6 | import os = require("os"); 7 | import p = require("path"); 8 | 9 | var admzip = require("adm-zip"); 10 | 11 | var debugHost = "localhost"; 12 | //var debugHost = "10.137.229.56"; 13 | 14 | var PORT = 6767; 15 | var PROTOCOL_VERSION = 1; 16 | 17 | module ProxyAdapter { 18 | export var _sessionFilePath = p.join(os.tmpdir(), "hwa.session"); 19 | export var _numRetries = 5; 20 | 21 | export function clearSession() { 22 | if (fs.existsSync(_sessionFilePath)) { 23 | fs.unlinkSync(_sessionFilePath); 24 | } 25 | } 26 | 27 | export function exit() { 28 | rpc("exit", null, true); 29 | ProxyAdapter.clearSession(); 30 | } 31 | 32 | export function launchAppx() { 33 | rpc("launchAppx", null, true); 34 | } 35 | 36 | export function registerAndLaunchAppxManifest(path: string) { 37 | // Compress the entire folder where the AppxManifest file is and send it to the VM. 38 | rpc("deployAppxManifest", ProxyAdapter._compressPath(p.dirname(p.resolve(path)))); 39 | } 40 | 41 | export function _launchRdp(address: string) { 42 | var rdConfig = fs.readFileSync("./templates/rdConfig.rdp", "utf-8"); 43 | rdConfig = rdConfig.replace("{address}", address); 44 | fs.writeFileSync("./bin/rdConfig.rdp", rdConfig, "utf-8"); 45 | cp.execSync("start " + "./bin/rdConfig.rdp"); 46 | } 47 | 48 | export function _compressPath(path: string) { 49 | var zip = new admzip(); 50 | zip.addLocalFolder(path); 51 | return zip.toBuffer(); 52 | } 53 | } 54 | var typeCheck: HWAProxyAdapter = ProxyAdapter; 55 | export = ProxyAdapter; 56 | 57 | 58 | function establishConnection(sessionOnly: boolean, callback: (socket: net.Socket) => any) { 59 | function doConnect(address: string, success: (socket: net.Socket) => any, error: (e: string) => any) { 60 | var socket = new net.Socket(); 61 | socket.once("error", (e: string) => { 62 | // Connection timed out or server forcefully disconnected 63 | socket.destroy(); 64 | error(e); 65 | }); 66 | socket.connect(6767, address, () => { 67 | // Successfully connected, waiting on first ACK from server 68 | socket.once("data", () => { 69 | socket.removeAllListeners("error"); 70 | success(socket); 71 | }); 72 | }); 73 | } 74 | 75 | if (fs.existsSync(ProxyAdapter._sessionFilePath)) { 76 | // Found session file, try reconnecting 77 | var sessionFile = fs.readFileSync(ProxyAdapter._sessionFilePath, "utf-8"); 78 | var address = sessionFile; 79 | 80 | doConnect(address, 81 | socket => { 82 | // Reconnect successful 83 | callback(socket); 84 | }, 85 | error => { 86 | // Reconnect failed, retry from scratch 87 | ProxyAdapter.clearSession(); 88 | if (!sessionOnly) { 89 | establishConnection(false, callback); 90 | } 91 | }); 92 | } else if (!sessionOnly) { 93 | // Todo: Provision VM with RD 94 | var address = debugHost; 95 | 96 | // Establish Remote Desktop 97 | ProxyAdapter._launchRdp(address); 98 | 99 | // Connect to remote socket 100 | var retriesLeft = ProxyAdapter._numRetries; 101 | var successHandler = function successHandler(socket: net.Socket) { 102 | // Connection successful, save to session file 103 | fs.writeFileSync(ProxyAdapter._sessionFilePath, address, "utf-8"); 104 | callback(socket); 105 | }; 106 | var errorHandler = function errorHandler(e: string) { 107 | // Failed to connect, retry 108 | retriesLeft--; 109 | if (retriesLeft > 0) { 110 | setTimeout(() => { 111 | doConnect(address, successHandler, errorHandler); 112 | }, 10000); 113 | } 114 | }; 115 | doConnect(address, successHandler, errorHandler); 116 | } else { 117 | callback(null); 118 | } 119 | } 120 | 121 | function rpc(command: string, data?: Buffer, sessionOnly = false) { 122 | data = data || new Buffer(0); 123 | 124 | var payloadBuffer = Buffer.concat( 125 | [ 126 | new Buffer(PROTOCOL_VERSION + ";"), 127 | new Buffer(command + ";"), 128 | new Buffer(data.length + ";"), 129 | data 130 | ]); 131 | 132 | establishConnection(sessionOnly, socket => { 133 | if (!socket) { 134 | module.parent.exports.printDocs("connectionError"); 135 | return; 136 | } 137 | socket.once("data", () => { 138 | // Block the CLI tool until the server finishes processing the request 139 | socket.destroy(); 140 | }); 141 | socket.once("error", (e: any) => { 142 | socket.destroy(); 143 | }); 144 | socket.write(payloadBuffer); 145 | }); 146 | } -------------------------------------------------------------------------------- /projects/vs2015/hwa-cli.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | {963D9A06-99CC-4A38-9245-0EC766EF53B7} 7 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 8 | Library 9 | bin 10 | v4.5 11 | full 12 | true 13 | 1.5 14 | true 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | src\adapter.ts 27 | 28 | 29 | src\cli.ts 30 | 31 | 32 | src\cloudAppx.ts 33 | 34 | 35 | src\crxConverter.ts 36 | 37 | 38 | src\phantom-image.ts 39 | 40 | 41 | src\webConverter.ts 42 | 43 | 44 | tests\adapterTests.ts 45 | 46 | 47 | typings\adapter.d.ts 48 | 49 | 50 | typings\node.d.ts 51 | 52 | 53 | 54 | 55 | main.js 56 | 57 | 58 | templates\AppxManifest\AppxManifest.xml 59 | 60 | 61 | templates\w3c-AppxManifest-template.xml 62 | 63 | 64 | 65 | 66 | templates\rdConfig.rdp 67 | 68 | 69 | 70 | 71 | docs\connectionError 72 | 73 | 74 | docs\fileNotSupported 75 | 76 | 77 | docs\usage 78 | 79 | 80 | 81 | 82 | package.json 83 | 84 | 85 | 86 | 12.0 87 | 88 | 89 | vs2015 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | True 98 | True 99 | 13307 100 | / 101 | http://localhost:13307/ 102 | False 103 | False 104 | 105 | 106 | False 107 | 108 | 109 | 110 | 111 | 112 | false 113 | False 114 | ES5 115 | True 116 | True 117 | UMD 118 | 119 | ..\..\bin 120 | False 121 | True 122 | 123 | 124 | 125 | 126 | true 127 | false 128 | 129 | 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hwa-cli 2 | 3 | ## Convert your Chrome app to a Windows hosted app 4 | 1. Install [NodeJS and npm](https://nodejs.org/en/) 5 | 1. Open a command prompt window to the directory of your choice 6 | 1. Install hwa cli: `npm i -g hwa-cli` 7 | 1. Convert your [Chrome package](#supported-chrome-package-formats): `hwa convert path/to/chrome/app.crx` or `hwa convert path/to/chrome/app.zip` 8 | 1. Fill out the [Windows Store prompts](#how-to-fill-out-the-windows-store-prompts) 9 | 1. The generated `.appx` will appear in the same folder as your Chrome package. 10 | 11 | You are now ready to [upload](https://dev.windows.com) your Hosted Web App to the Windows Store. Upload your AppX package by navigating to the "Packages" page in the Submissions section. 12 | 13 | Be sure to [check out the guide below](#guide-for-migrating-your-hosted-web-app) for more information on migrating your Hosted Web App. 14 | 15 | ### Supported Chrome package formats 16 | The following package formats are supported: `.crx`, `.zip`. 17 | 18 | ### How to fill out the Windows Store prompts 19 | During the conversion process, you will be prompted for an Identity Name, Publisher Identity, and Publisher Display Name. To retrieve these values, visit the Dashboard in the [Windows Dev Center](https://dev.windows.com/). 20 | 21 | 1. Click on "Create a new app" and reserve your [app name](https://cloud.githubusercontent.com/assets/3271834/11040454/3780d02a-86c1-11e5-90b1-4775a66f7247.png). 22 | 23 | 2. Next, click on "[App identity](https://cloud.githubusercontent.com/assets/3271834/11040490/640fd870-86c1-11e5-9821-85e411fd747e.png)" in the menu on the left under the "App management" section. 24 | 25 | 3. You should see the [three values](https://cloud.githubusercontent.com/assets/3271834/11041022/3050589a-86c4-11e5-9ce5-5985b81c97a3.png) for which you are prompted listed on the page. 26 | * Identity Name: `Package/Identity/Name` 27 | * Publisher Identity: `Package/Identity/Publisher` 28 | * Publisher Display Name: `Package/Properties/PublisherDisplayName` 29 | 30 | ## Guide for migrating your Hosted Web App 31 | ### Things you should know 32 | * [Application Content URI Rules](#application-content-uri-rules) 33 | * [Flash](#flash) 34 | * [Image assets](#image-assets) 35 | * [Capabilities](#capabilities) 36 | * [File downloads](#file-downloads) 37 | * [Chrome platform APIs](#chrome-platform-apis) 38 | 39 | ### Application Content URI Rules 40 | [Application Content URI Rules](http://microsoftedge.github.io/WebAppsDocs/en-US/win10/HWAfeatures.htm#keep-your-app-secure----setting-application-content-uri-rules-acurs) (ACURs) or Content URIs define the scope of your Hosted Web App through a URL allow list in your app package manifest. In order to control the communication to and from remote content, you must define which URLs are included in, and/or excluded from, this list. If a user clicks a URL that is not explicitly included, Windows will open the target path in the default browser. With ACURs, you are also able to grant a URL access to [Universal Windows APIs](https://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx). 41 | 42 | At the very minimum, your rules should include your app’s start page. The conversion tool will automatically create a set of ACURs for you, based on your start page and its domain. However, if there are any programmatic redirects, whether on the server or on the client, those destinations will need to be added to the allow list. 43 | 44 | Note: ACURs only apply to page navigation. Images, JavaScript libraries, and other similar assets are not affected by these restrictions. 45 | 46 | Many apps use third-party sites for their login flows, e.g. Facebook and Google. The conversion tool will automatically create a set of ACURs for you, based on the most popular sites. If your method of authentication is not included in that list, and it’s a redirect flow, you will need to add its path(s) as an ACUR. You can also consider using a [web authentication broker](http://microsoftedge.github.io/WebAppsDocs/en-US/win10/HWAfeatures.htm#web-authentication-broker). 47 | 48 | ### Flash 49 | Flash is not allowed in Windows 10 apps. You will need to make sure your app experience is not affected by its absence. 50 | 51 | For ads, you will need to make sure your ad provider has an HTML5 option. You can check out [Bing Ads](https://bingads.microsoft.com/) and [Ads in Apps](http://adsinapps.microsoft.com/). 52 | 53 | YouTube videos should still work, as they now [default to HTML5 <video>](http://youtube-eng.blogspot.com/2015/01/youtube-now-defaults-to-html5_27.html), so long as you are using the [<iframe> embed method](https://developers.google.com/youtube/iframe_api_reference). If your app still uses the Flash API, you will need to switch to the aforementioned style of embed. 54 | 55 | ### Image assets 56 | The Chrome web store already [requires](https://developer.chrome.com/webstore/images) a 128x128 app icon image in your app package. For Windows 10 apps, you must supply 44x44, 50x50, 150x150, and 600x350 app icon images, at the very minimum. The conversion tool will automatically create these images for you, based on the 128x128 image. For a richer, more polished app experience, we highly recommend creating your own image files. Here are some [guidelines](https://msdn.microsoft.com/en-us/library/windows/apps/mt412102.aspx) for tile and icon assets. 57 | 58 | ### Capabilities 59 | App capabilities must be [declared](https://msdn.microsoft.com/en-us/library/windows/apps/Mt270968.aspx) in your package manifest in order to access certain APIs and resources. The conversion tool will automatically enable three popular device capabilities for you: location, microphone, and webcam. With the former, the system will still prompt the user for permission before granting access. 60 | 61 | Note: Users are notified of all the capabilities that an app declares. We would recommend removing any capabilities that your app does not need. 62 | 63 | ### File downloads 64 | Traditional file downloads, like you see in the browser, are not currently supported. 65 | 66 | ### Chrome platform APIs 67 | Chrome provides apps with [special-purpose APIs](https://developer.chrome.com/apps/api_index) that can be run as background script. These are not supported. You can find equivalent functionality, and much more, with the [Windows Runtime APIs](https://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx). 68 | 69 | ## Accessing Windows features 70 | For more information, [visit this page](http://microsoftedge.github.io/WebAppsDocs/en-US/win10/HWAfeatures.htm). 71 | 72 | ## Code of Conduct 73 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 74 | -------------------------------------------------------------------------------- /tests/adapterTests.ts: -------------------------------------------------------------------------------- 1 | declare function afterEach(teardownFunc: Function): void; 2 | declare function beforeEach(setupFunc: Function): void; 3 | declare function describe(what: string, body: Function): void; 4 | declare function it(should: string, testFunction: (done?: Function) => void): void; 5 | declare var mocha: any; 6 | 7 | import assert = require("assert"); 8 | import cp = require("child_process"); 9 | import fs = require("fs"); 10 | import net = require("net"); 11 | 12 | import adapter = require("../src/adapter"); 13 | 14 | class MockObject { 15 | onceHandlers: { eventName: string; callback: Function; }[] = []; 16 | onHandlers: { eventName: string; callback: Function; }[] = []; 17 | 18 | on(eventName: string, callback: Function) { 19 | this.onHandlers.push({ eventName: eventName, callback: callback }); 20 | } 21 | 22 | once(eventName: string, callback: Function) { 23 | this.onceHandlers.push({ eventName: eventName, callback: callback }); 24 | } 25 | 26 | removeAllListeners(eventName: string) { 27 | for (var i = this.onceHandlers.length - 1; i >= 0; i--) { 28 | var handler = this.onceHandlers[i]; 29 | if (handler.eventName === eventName) { 30 | this.onceHandlers.splice(i, 1); 31 | } 32 | } 33 | for (var i = this.onHandlers.length - 1; i >= 0; i--) { 34 | var handler = this.onHandlers[i]; 35 | if (handler.eventName === eventName) { 36 | this.onHandlers.splice(i, 1); 37 | } 38 | } 39 | } 40 | 41 | _dispatch(eventName: string, eventObj: any) { 42 | this.onHandlers.forEach(handler => { 43 | if (handler.eventName !== eventName) { 44 | return; 45 | } 46 | handler.callback(eventObj); 47 | }); 48 | 49 | for (var i = this.onceHandlers.length - 1; i >= 0; i--) { 50 | var handler = this.onceHandlers[i]; 51 | if (handler.eventName !== eventName) { 52 | continue; 53 | } 54 | handler.callback(eventObj); 55 | this.onceHandlers.splice(i, 1); 56 | } 57 | } 58 | } 59 | 60 | class MockSocket extends MockObject { 61 | private static _kidnapper: (socket: MockSocket) => void = null; 62 | 63 | destroyed = false; 64 | 65 | constructor() { 66 | super(); 67 | if (MockSocket._kidnapper) { 68 | var kidnapper = MockSocket._kidnapper; 69 | MockSocket._kidnapper = null; 70 | kidnapper(this); 71 | } 72 | } 73 | 74 | connect(port: number, host: string, callback: Function) { 75 | } 76 | 77 | destroy() { 78 | this.destroyed = true; 79 | } 80 | 81 | write(buffer: Buffer) { 82 | return true; 83 | } 84 | 85 | static kidnapNextInstance(kidnapper: (socket: MockSocket) => void) { 86 | MockSocket._kidnapper = kidnapper; 87 | } 88 | } 89 | 90 | class SuccessMockSocket extends MockSocket { 91 | connect(port: number, host: string, callback: Function) { 92 | callback(); 93 | } 94 | } 95 | 96 | class FailMockSocket extends MockSocket { 97 | connect(port: number, host: string, callback: Function) { 98 | this._dispatch("error", {}); 99 | } 100 | } 101 | 102 | function makeCache(hostname = "1.2.3.4") { 103 | fs.writeFileSync(adapter._sessionFilePath, hostname, "utf-8"); 104 | } 105 | 106 | function monkeyPatch(obj: any, funcName: string, callback: Function, dontRestoreAfterFirstCall: boolean) { 107 | var orig = obj[funcName]; 108 | 109 | var patch = function () { 110 | var result = callback.apply(obj, arguments); 111 | if (!dontRestoreAfterFirstCall) { 112 | (patch).restore(); 113 | } 114 | return result; 115 | }; 116 | (patch).restore = function () { 117 | obj[funcName] = orig; 118 | }; 119 | (patch).orig = orig; 120 | obj[funcName] = patch; 121 | } 122 | 123 | var _socket = net.Socket; 124 | 125 | function setup() { 126 | // Zipping sums up to a significant amount of time over several 127 | // tests, we will mock it by default and have tests opt-out by 128 | // calling .restore() on _compressPath if necessary 129 | monkeyPatch(adapter, "_compressPath", function () { 130 | return new Buffer("testdata"); 131 | }, true); 132 | 133 | // execSync is used to launch remote desktop which we don't want 134 | // to happen during tests. We will no-op it by default and have 135 | // tests opt-out if necessary 136 | monkeyPatch(cp, "execSync", function () { }, true); 137 | 138 | // Disable retries, tests that are interested in testing the retry 139 | // logic will opt-out 140 | adapter._numRetries = 0; 141 | 142 | // Delete cache file 143 | if (fs.existsSync(adapter._sessionFilePath)) { 144 | fs.unlinkSync(adapter._sessionFilePath); 145 | } 146 | } 147 | 148 | function teardown() { 149 | // Restore socket class in case it was mocked 150 | net.Socket = _socket; 151 | 152 | // Restore execSync 153 | (cp).execSync.restore(); 154 | 155 | // Restore any direct APIs on the Adapter 156 | Object.keys(adapter).forEach(key => { 157 | var member = (adapter)[key]; 158 | member.restore && member.restore(); 159 | }); 160 | 161 | // Delete cache file 162 | if (fs.existsSync(adapter._sessionFilePath)) { 163 | fs.unlinkSync(adapter._sessionFilePath); 164 | } 165 | } 166 | 167 | describe("Adapter", function () { 168 | beforeEach(setup); 169 | afterEach(teardown); 170 | 171 | describe("registerAndLaunchAppxManifest", function () { 172 | 173 | describe("RDP scenarios", function () { 174 | it("should launch rdp when no cache file is found", function (done) { 175 | net.Socket = SuccessMockSocket; 176 | monkeyPatch(cp, "execSync", function (cmd: string) { 177 | if (cmd.indexOf(".rdp") === -1) { 178 | assert.fail(); 179 | } 180 | done(); 181 | }, false); 182 | adapter.registerAndLaunchAppxManifest("test"); 183 | }); 184 | 185 | it("should launch rdp when connecting to cached hostname fails", function (done) { 186 | makeCache(); 187 | net.Socket = FailMockSocket; 188 | monkeyPatch(cp, "execSync", function (cmd: string) { 189 | if (cmd.indexOf(".rdp") === -1) { 190 | assert.fail(); 191 | } 192 | done(); 193 | }, false); 194 | adapter.registerAndLaunchAppxManifest("test"); 195 | }); 196 | 197 | it("should not launch rdp when connecting to cached hostname succeeds", function (done) { 198 | makeCache(); 199 | net.Socket = SuccessMockSocket; 200 | monkeyPatch(cp, "execSync", function (cmd: string) { 201 | assert.fail(); 202 | }, false); 203 | 204 | MockSocket.kidnapNextInstance(socket => { 205 | socket.write = function (buffer: Buffer) { 206 | done(); 207 | return true; 208 | }; 209 | }); 210 | adapter.registerAndLaunchAppxManifest("test"); 211 | 212 | (cp.execSync).restore(); 213 | }); 214 | }); 215 | 216 | describe("Caching scenarios", function () { 217 | it("should connect to cached hostname if cache file exists", function (done) { 218 | var testHostname = "testHostname"; 219 | makeCache(testHostname); 220 | net.Socket = SuccessMockSocket; 221 | 222 | MockSocket.kidnapNextInstance(socket => { 223 | socket.connect = function (port: number, host: string, callback: Function) { 224 | assert.equal(testHostname, host); 225 | done(); 226 | }; 227 | }); 228 | adapter.registerAndLaunchAppxManifest("test"); 229 | }); 230 | 231 | it("should create cache file if connection was successful", function (done) { 232 | net.Socket = SuccessMockSocket; 233 | 234 | MockSocket.kidnapNextInstance(socket => { 235 | socket.write = function (buffer: Buffer) { 236 | assert.ok(fs.existsSync(adapter._sessionFilePath)); 237 | done(); 238 | return true; 239 | }; 240 | }); 241 | adapter.registerAndLaunchAppxManifest("test"); 242 | }); 243 | 244 | it("should delete cache file if connection failed", function (done) { 245 | net.Socket = FailMockSocket; 246 | makeCache(); 247 | 248 | MockSocket.kidnapNextInstance(socket => { 249 | // This is the fail socket, after which we expect the adapter 250 | // to start over and create another socket 251 | assert.ok(fs.existsSync(adapter._sessionFilePath)); 252 | MockSocket.kidnapNextInstance(socket => { 253 | // This is the retry attempt, at this point the cache file 254 | // should've been deleted 255 | assert.ok(!fs.existsSync(adapter._sessionFilePath)); 256 | done(); 257 | }); 258 | }); 259 | adapter.registerAndLaunchAppxManifest("test"); 260 | }); 261 | }); 262 | }); 263 | }); -------------------------------------------------------------------------------- /src/crxConverter.ts: -------------------------------------------------------------------------------- 1 | declare var Promise: PromiseConstructorLike; 2 | 3 | import cp = require("child_process"); 4 | import fs = require("fs"); 5 | import readline = require("readline"); 6 | import os = require("os"); 7 | import p = require("path"); 8 | 9 | import webConverter = require("./webConverter"); 10 | 11 | var admzip = require("adm-zip"); 12 | var guid = require("guid"); 13 | var inquirer = require("inquirer"); 14 | var phantomjs = require("phantomjs"); 15 | var rimraf = require("rimraf"); 16 | var yargs = require("yargs"); 17 | 18 | /* 19 | .crx file format (Little Endian) 20 | 43 72 32 34 - "Cr24" 21 | xx xx xx xx - crx format version number 22 | xx xx xx xx - length of the public key in bytes 23 | xx xx xx xx - length of the signature in bytes 24 | ........... - the contents of the public key 25 | ........... - the contents of the signature 26 | ........... - the contents of the zip file 27 | */ 28 | 29 | var assetSizes = { 30 | logoStore: { w: 50, h: 50 }, 31 | logoSmall: { w: 44, h: 44 }, 32 | logoLarge: { w: 150, h: 150 }, 33 | splashScreen: { w: 620, h: 300 } 34 | }; 35 | var offsetPublicKeyLength = 8; 36 | var offsetSignatureLength = 12; 37 | 38 | interface IAssetInfo { 39 | requiredSize: { w: number; h: number; }; 40 | nativeSize: { w: number; h: number; }; 41 | src: string; 42 | } 43 | 44 | export function convert(argv: any, src: string, dest: string) { 45 | return new Promise(c => { 46 | // Setup tmp 47 | rimraf.sync(dest); 48 | fs.mkdirSync(dest); 49 | 50 | 51 | // Extract crx 52 | extractCrx(src, dest); 53 | 54 | 55 | // Convert manifest 56 | var chromeOSManifest = JSON.parse(sanitizeJSONString(fs.readFileSync(p.join(dest, "manifest.json"), "utf8"))); 57 | 58 | var w3cManifest = webConverter.chromeToW3CManifest(chromeOSManifest, (locale, varName) => { 59 | // Note: variable name is not case sensitive 60 | varName = varName.toLowerCase(); 61 | var locResPath = p.join(dest, "_locales", locale, "messages.json"); 62 | if (fs.existsSync(locResPath)) { 63 | // We've encountered a bunch of malformed JSON so we need to trim them, then replace all newline characters with a space 64 | var msgs = JSON.parse(sanitizeJSONString(fs.readFileSync(locResPath, "utf8"))); 65 | for (var key in msgs) { 66 | if (key.toLowerCase() === varName) { 67 | return msgs[key].message; 68 | } 69 | } 70 | } 71 | return null; 72 | }); 73 | 74 | 75 | // Establish assets 76 | function matchBest(matchRecord: IAssetInfo, asset: { sizes: string; src: string; }) { 77 | if (matchRecord.nativeSize === matchRecord.requiredSize) { 78 | return; 79 | } 80 | var prevDeltaW = matchRecord.nativeSize.w - matchRecord.requiredSize.w; 81 | var prevDeltaH = matchRecord.nativeSize.h - matchRecord.requiredSize.h; 82 | var prevDelta = Math.abs(prevDeltaW) < Math.abs(prevDeltaW) ? prevDeltaW : prevDeltaH; 83 | var w = +asset.sizes.split("x")[0] 84 | var h = +asset.sizes.split("x")[1]; 85 | var deltaW = w - matchRecord.requiredSize.w; 86 | var deltaH = h - matchRecord.requiredSize.h; 87 | var delta = Math.abs(deltaW) < Math.abs(deltaH) ? deltaW : deltaH; 88 | if ((prevDelta < 0 && delta > prevDelta) || (prevDelta > 0 && delta < prevDelta)) { 89 | // Update rules 90 | // If the recorded delta is negative, then no image has been set yet, or a smaller-than-ideal image is currently recorded 91 | // Use the new image if the delta is greater (closer to 0) than before 92 | // If the recorded delta is positive, then a larger-than-ideal is currently recorded 93 | // Use the new image if the delta is smaller (closer to 0) than before 94 | matchRecord.nativeSize = { w: w, h: h }; 95 | matchRecord.src = asset.src; 96 | } 97 | } 98 | function resizeAndAddToManifest(assetInfo: IAssetInfo) { 99 | var newSize = `${assetInfo.requiredSize.w}x${assetInfo.requiredSize.h}`; 100 | var newSrc = p.parse(assetInfo.src).name + `_scaled_${newSize}.png`; 101 | resizeImage(p.join(dest, assetInfo.src), assetInfo.requiredSize.w, assetInfo.requiredSize.h, newSrc); 102 | w3cManifest.icons = w3cManifest.icons.filter(icon => icon.sizes !== newSize); 103 | w3cManifest.icons.push({ 104 | sizes: newSize, 105 | src: newSrc 106 | }); 107 | console.log(`Resized ${assetInfo.src} (${assetInfo.nativeSize.w}x${assetInfo.nativeSize.h}) to ${newSrc}`); 108 | } 109 | var logoStore = { nativeSize: { w: Number.NEGATIVE_INFINITY, h: Number.NEGATIVE_INFINITY }, src: "", requiredSize: assetSizes.logoStore }; 110 | var logoSmall = { nativeSize: { w: Number.NEGATIVE_INFINITY, h: Number.NEGATIVE_INFINITY }, src: "", requiredSize: assetSizes.logoSmall }; 111 | var logoLarge = { nativeSize: { w: Number.NEGATIVE_INFINITY, h: Number.NEGATIVE_INFINITY }, src: "", requiredSize: assetSizes.logoLarge }; 112 | var splashScreen = { nativeSize: { w: Number.NEGATIVE_INFINITY, h: Number.NEGATIVE_INFINITY }, src: "", requiredSize: assetSizes.splashScreen }; 113 | var iconAsSplashScreen = !w3cManifest.splash_screens.length; 114 | for (var i = 0; i < w3cManifest.icons.length; i++) { 115 | var iconData = w3cManifest.icons[i]; 116 | matchBest(logoStore, iconData); 117 | matchBest(logoSmall, iconData); 118 | matchBest(logoLarge, iconData); 119 | iconAsSplashScreen && matchBest(splashScreen, iconData); 120 | } 121 | if (!iconAsSplashScreen) { 122 | for (var i = 0; i < w3cManifest.splash_screens.length; i++) { 123 | matchBest(splashScreen, w3cManifest.splash_screens[i]); 124 | } 125 | } 126 | 127 | (logoStore.nativeSize.w !== logoStore.requiredSize.w || logoStore.nativeSize.h !== logoStore.requiredSize.h) && resizeAndAddToManifest(logoStore); 128 | (logoSmall.nativeSize.w !== logoSmall.requiredSize.w || logoSmall.nativeSize.h !== logoSmall.requiredSize.h) && resizeAndAddToManifest(logoSmall); 129 | (logoLarge.nativeSize.w !== logoLarge.requiredSize.w || logoLarge.nativeSize.h !== logoLarge.requiredSize.h) && resizeAndAddToManifest(logoLarge); 130 | (splashScreen.nativeSize.w !== splashScreen.requiredSize.w || splashScreen.nativeSize.h !== splashScreen.requiredSize.h) && resizeAndAddToManifest(splashScreen); 131 | 132 | var questions:any[] = [{ 133 | type: "input", 134 | name: "identityName", 135 | message: "Identity Name:" 136 | }, { 137 | type: "input", 138 | name: "appVersion", 139 | message: "App Version (default: \"1.0.0.0\" req'd format: \"...0\"):" 140 | }, { 141 | type: "input", 142 | name: "publisherIdentity", 143 | message: "Publisher Identity:" 144 | }, { 145 | type: "input", 146 | name: "publisherDisplayName", 147 | message: "Publisher Display Name:" 148 | }]; 149 | 150 | if ((argv).more) { 151 | questions.push({ 152 | type: "confirm", 153 | name: "useCurrentName", 154 | message: "'" + w3cManifest.short_name + "' is current the App Display Name. Is this okay?" 155 | }); 156 | questions.push({ 157 | type: "input", 158 | name: "appDisplayName", 159 | message: "App Display Name:", 160 | when: (function(answers) { 161 | return !answers.useCurrentName 162 | }) 163 | }); 164 | } 165 | 166 | 167 | 168 | inquirer.prompt(questions, function(answers: any) { 169 | console.log("Converting manifest to AppxManifest"); 170 | var xmlManifest = 171 | webConverter.w3CToAppxManifest( 172 | w3cManifest, 173 | fs.readFileSync(p.join(__dirname, "../../templates/w3c-AppxManifest-template.xml"), "utf8"), 174 | { 175 | appDisplayName: answers.useCurrentName ? w3cManifest.short_name : answers.appDisplayName, 176 | appVersion: answers.appVersion || "1.0.0.0", 177 | identityName: answers.identityName, 178 | // identityName: answers.identityName || "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 179 | publisherDisplayName: answers.publisherDisplayName, 180 | // publisherDisplayName: answers.publisherDisplayName || "AUTHOR_NAME", 181 | publisherIdentity: answers.publisherIdentity 182 | // publisherIdentity: answers.publisherIdentity || "CN=AUTHOR_NAME" 183 | }, [ 184 | { name: "GeneratedFrom", value: "HWA-CLI" }, 185 | { name: "GenerationDate", value: new Date().toUTCString() }, 186 | { name: "ToolVersion", value: "0.1.0" } 187 | ]); 188 | console.log(); 189 | // Write the AppxManifest 190 | var appxManifestOutputPath = p.join(dest, "AppxManifest.xml"); 191 | console.log("Writing AppxManifest: " + appxManifestOutputPath); 192 | if (fs.existsSync(appxManifestOutputPath)) { 193 | fs.unlinkSync(appxManifestOutputPath); 194 | } 195 | fs.writeFileSync(appxManifestOutputPath, xmlManifest); 196 | console.log(); 197 | c(); 198 | }); 199 | }); 200 | } 201 | 202 | export function extractCrx(src: string, dest: string) { 203 | if (!fs.existsSync(dest)) { 204 | fs.mkdirSync(dest); 205 | } 206 | var zipPath = p.join(dest, guid.raw() + ".zip"); 207 | 208 | // Read crx file 209 | var crxFile = fs.readFileSync(src); 210 | 211 | // Make sure that it is a crx archive by searching for the signature "67 114 50 52" 212 | if (crxFile[0] !== 67 || crxFile[1] !== 114 || crxFile[2] !== 50 || crxFile[3] !== 52) { 213 | // src is not a crx archive, just unzip it directly 214 | new admzip(src).extractAllTo(dest); 215 | return; 216 | } 217 | 218 | // Write zip contents 219 | var lengthPK = crxFile.readUIntLE(offsetPublicKeyLength, 4); 220 | var lengthSig = crxFile.readUIntLE(offsetSignatureLength, 4); 221 | var zipContentsOffset = offsetSignatureLength + 4 + lengthPK + lengthSig; 222 | var zipContents = crxFile.slice(zipContentsOffset) 223 | fs.writeFileSync(zipPath, zipContents); 224 | 225 | // Extract zip and cleanup 226 | new admzip(zipPath).extractAllTo(dest); 227 | fs.unlinkSync(zipPath); 228 | } 229 | 230 | function resizeImage(absSrcPath: string, targetWidth: number, targetHeight: number, newFilename: string) { 231 | var outputPath = p.join(p.dirname(absSrcPath), newFilename); 232 | cp.execFileSync(phantomjs.path, [p.join(__dirname, "phantom-image.js"), absSrcPath, "" + targetWidth, "" + targetHeight, outputPath], { stdio: [process.stdin, process.stdout, process.stderr] }); 233 | } 234 | 235 | function sanitizeJSONString(str: string) { 236 | return str.trim().replace(/\r/g, "").replace(/\n/g, ""); 237 | } -------------------------------------------------------------------------------- /src/webConverter.ts: -------------------------------------------------------------------------------- 1 | import Url = require("url"); 2 | var tld = require("tldjs"); 3 | 4 | // Constants 5 | var assetSizes = { 6 | logoStore: { w: 50, h: 50 }, 7 | logoSmall: { w: 44, h: 44 }, 8 | logoLarge: { w: 150, h: 150 }, 9 | splashScreen: { w: 620, h: 300 } 10 | }; 11 | var validIconFormats = [ 12 | 'png', 13 | 'image/png' 14 | ]; 15 | 16 | export interface IAppIdentity { 17 | appDisplayName?: string; 18 | identityName: string; 19 | appVersion: string; 20 | publisherIdentity: string; 21 | publisherDisplayName: string; 22 | } 23 | 24 | export interface IW3CManifest { 25 | // All defined propterties in the W3C manifest spec 26 | lang: string; 27 | name: string; 28 | short_name: string; 29 | icons: { sizes: string; src: string }[]; 30 | splash_screens: { sizes: string; src: string }[]; 31 | scope: string; 32 | start_url: string; 33 | display: string; 34 | orientation: string; 35 | theme_color: string; 36 | background_color: string; 37 | 38 | // ManifoldJS metadata 39 | mjs_access_whitelist?: { apiAccess: string; url: string; }[]; 40 | } 41 | 42 | export interface IChromeOSManifest { 43 | // Required properties 44 | app: { 45 | launch: { 46 | local_path: string; 47 | web_url: string; 48 | }; 49 | urls?: string[]; 50 | }; 51 | 52 | manifest_version: number; 53 | version: string; 54 | 55 | // Optional (non-exhaustive) 56 | default_locale?: string; 57 | icons?: { [size: string]: string; }; 58 | 59 | // Since the ChromeOSManifest is mostly compatible with the W3CManifest, 60 | // all W3CManifest properties are optionally defined as well, except 'icons' 61 | lang?: string; 62 | name?: string; 63 | short_name?: string; 64 | splash_screens?: { sizes: string; src: string }[]; 65 | scope?: string; 66 | start_url?: string; 67 | display?: string; 68 | orientation?: string; 69 | theme_color?: string; 70 | background_color?: string; 71 | } 72 | 73 | export function chromeToW3CManifest(chromeManifest: IChromeOSManifest, resolveVariable?: (locale: string, varName: string) => string) { 74 | // Create manifest object 75 | if (!chromeManifest.app || !chromeManifest.app.launch || (!chromeManifest.app.launch.web_url && !chromeManifest.app.launch.local_path)) { 76 | throw "Manifest error: No start page found"; 77 | } 78 | var startUrl = chromeManifest.app.launch.web_url || ("ms-appx-web:///" + chromeManifest.app.launch.local_path); 79 | 80 | var w3cManifest: IW3CManifest = { 81 | lang: chromeManifest.lang || "en-us", 82 | name: chromeManifest.name, 83 | short_name: chromeManifest.short_name || chromeManifest.name, 84 | icons: [], 85 | splash_screens: chromeManifest.splash_screens || [], 86 | scope: chromeManifest.scope || "", 87 | start_url: startUrl, 88 | display: chromeManifest.display || "", 89 | orientation: chromeManifest.orientation || "portrait", 90 | theme_color: chromeManifest.theme_color || "aliceBlue", 91 | background_color: chromeManifest.background_color || "gray" 92 | }; 93 | 94 | // Resolve variables 95 | if (resolveVariable && chromeManifest.default_locale) { 96 | for (var key in w3cManifest) { 97 | var value = (w3cManifest)[key]; 98 | if (typeof value === "string" && value.toLowerCase().indexOf("__msg_") === 0) { 99 | (w3cManifest)[key] = resolveVariable(chromeManifest.default_locale, value.substring(6, value.lastIndexOf("__"))) || value; 100 | } 101 | } 102 | } 103 | 104 | // Extract icons 105 | for (var size in chromeManifest.icons) { 106 | w3cManifest.icons.push({ 107 | sizes: size + 'x' + size, 108 | src: chromeManifest.icons[size] 109 | }); 110 | } 111 | 112 | // Extract app urls 113 | var extractedUrls: { apiAccess: string; url: string; }[] = []; 114 | var urls = [startUrl]; 115 | if (chromeManifest.app.urls && chromeManifest.app.urls.length) { 116 | urls = urls.concat(chromeManifest.app.urls); 117 | } 118 | for (var i = 0; i < urls.length; i++) { 119 | var url = urls[i]; 120 | 121 | // Url doesn't parse domain correctly when protocol is '*://', 122 | // replace with x instead to resolve 123 | var parsedUrl = 124 | url.indexOf("*://") === 0 125 | ? Url.parse("x" + url.substr(1)) 126 | : Url.parse(url); 127 | 128 | // if input url has * in domain (e.g. "http://*.domain.com"), Url parse returns: 129 | // host => '' 130 | // path => '/*.something.com' 131 | // To get the right host, path we test for this condition and adjust accordingly 132 | var host = 133 | parsedUrl.path.indexOf("/*.") !== 0 134 | ? parsedUrl.hostname 135 | : parsedUrl.pathname.split('/')[1].substr(2); 136 | 137 | var domain = tld.getDomain(host); 138 | 139 | // When protocol is http or the case tested for above where protocol is '*://' 140 | if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "x:") { 141 | ["http://", "http://*.", "https://", "https://*."].forEach(function(protocol) { 142 | extractedUrls.push({ 143 | url: protocol + domain + "/", 144 | apiAccess: "none" 145 | }); 146 | }); 147 | } else if (parsedUrl.protocol === "https:") { 148 | ["https://", "https://*."].forEach(function(protocol) { 149 | extractedUrls.push({ 150 | url: protocol + domain + "/", 151 | apiAccess: "none" 152 | }); 153 | }); 154 | } 155 | } 156 | removeDupesInPlace(extractedUrls, function (a, b) { 157 | return a.url === b.url; 158 | }); 159 | w3cManifest.mjs_access_whitelist = (w3cManifest.mjs_access_whitelist || []).concat(extractedUrls); 160 | 161 | // Copy any remaining string properties from the Chrome manifest 162 | for (var prop in chromeManifest) { 163 | var val = (w3cManifest)[prop]; 164 | if (!val && (typeof val === "string")) { 165 | console.log("Additional property ingested: '" + prop + "'='" + val + "'"); 166 | (w3cManifest)[prop] = val; 167 | } 168 | } 169 | 170 | return w3cManifest; 171 | } 172 | 173 | export function w3CToAppxManifest(w3cManifest: IW3CManifest, appxManifestTemplate: string, appIdentity: IAppIdentity, metadataItems: { name: string; value: string }[] = []) { 174 | if (!w3cManifest.start_url) { 175 | return; 176 | } 177 | 178 | var guid = newGuid(); 179 | 180 | var logoStore: string, 181 | logoSmall: string, 182 | logoLarge: string, 183 | splashScreen: string; 184 | 185 | for (var i = 0; i < w3cManifest.icons.length; i++) { 186 | var icon = w3cManifest.icons[i]; 187 | var updated = false; 188 | if (!logoStore && icon.sizes === `${assetSizes.logoStore.w}x${assetSizes.logoStore.h}`) { 189 | logoStore = icon.src; 190 | } 191 | if (!logoSmall && icon.sizes === `${assetSizes.logoSmall.w}x${assetSizes.logoSmall.h}`) { 192 | logoSmall = icon.src; 193 | } 194 | if (!logoLarge && icon.sizes === `${assetSizes.logoLarge.w}x${assetSizes.logoLarge.h}`) { 195 | logoLarge = icon.src; 196 | } 197 | if (!splashScreen && icon.sizes === `${assetSizes.splashScreen.w}x${assetSizes.splashScreen.h}`) { 198 | splashScreen = icon.src; 199 | } 200 | if (logoStore && logoSmall && logoLarge && splashScreen) { 201 | break; 202 | } 203 | } 204 | 205 | console.log("Established Assets:"); 206 | console.log(` Store logo: ${logoStore}`); 207 | console.log(` Small logo: ${logoSmall}`); 208 | console.log(` Large logo: ${logoLarge}`); 209 | console.log(` Splashscreen: ${splashScreen}`); 210 | 211 | // Update properties 212 | var appxManifest = appxManifestTemplate 213 | .replace(/{IdentityName}/g, appIdentity.identityName) 214 | .replace(/{Version}/g, appIdentity.appVersion) 215 | .replace(/{PublisherIdentity}/g, appIdentity.publisherIdentity) 216 | .replace(/{PhoneProductId}/g, guid) 217 | .replace(/{AppDisplayName}/g, encodeXML(appIdentity.appDisplayName || w3cManifest.short_name)) 218 | .replace(/{PublisherDisplayName}/g, appIdentity.publisherDisplayName) 219 | .replace(/{LogoStore}/g, logoStore) 220 | .replace(/{Locale}/g, w3cManifest.lang) 221 | .replace(/{ApplicationId}/g, sanitizeName(w3cManifest.short_name)) 222 | .replace(/{StartPage}/g, encodeXML(w3cManifest.start_url)) 223 | .replace(/{AppDescription}/g, encodeXML((w3cManifest)["description"] || w3cManifest.name)) 224 | .replace(/{ThemeColor}/g, w3cManifest.theme_color) 225 | .replace(/{LogoLarge}/g, logoLarge) 226 | .replace(/{LogoSmall}/g, logoSmall) 227 | .replace(/{SplashScreen}/g, splashScreen) 228 | .replace(/{RotationPreference}/g, w3cManifest.orientation); 229 | 230 | console.log("Start Page: " + w3cManifest.start_url); 231 | 232 | // Add additional metadata items 233 | var indentationChars = '\r\n\t\t'; 234 | var metadataTags = metadataItems.map(entry => { 235 | console.log("Writing metadata: " + entry.name + "=" + entry.value); 236 | return ''; 237 | }); 238 | appxManifest = appxManifest.replace(/{MetadataItems}/g, metadataTags.join(indentationChars)); 239 | 240 | // Update access rules 241 | // Set the base access rule using the start_url's base url 242 | var baseUrlPattern = Url.resolve(w3cManifest.start_url, '/'); 243 | var baseApiAccess = 'none'; 244 | if (w3cManifest.scope && w3cManifest.scope.length) { 245 | // If the scope is defined, the base access rule is defined by the scope 246 | var parsedScopeUrl = Url.parse(w3cManifest.scope); 247 | 248 | if (parsedScopeUrl.host && parsedScopeUrl.protocol) { 249 | baseUrlPattern = w3cManifest.scope; 250 | } else { 251 | baseUrlPattern = Url.resolve(baseUrlPattern, w3cManifest.scope); 252 | } 253 | } 254 | 255 | // If the base access rule ends with '/*', remove the '*'. 256 | if (baseUrlPattern.indexOf('/*', baseUrlPattern.length - 2) !== -1) { 257 | baseUrlPattern = baseUrlPattern.substring(0, baseUrlPattern.length - 1); 258 | } 259 | 260 | var applicationContentUriRules = ''; 261 | 262 | // Add additional access rules 263 | console.log("Access Rule added: [" + baseApiAccess + "] - " + baseUrlPattern); 264 | if (w3cManifest.mjs_access_whitelist && w3cManifest.mjs_access_whitelist instanceof Array) { 265 | for (var j = 0; j < w3cManifest.mjs_access_whitelist.length; j++) { 266 | var accessUrl = encodeXML(w3cManifest.mjs_access_whitelist[j].url); 267 | // Ignore the '*' rule 268 | if (accessUrl !== '*') { 269 | // If the access url ends with '/*', remove the '*'. 270 | if (accessUrl.indexOf('/*', accessUrl.length - 2) !== -1) { 271 | accessUrl = accessUrl.substring(0, accessUrl.length - 1); 272 | } 273 | 274 | var apiAccess = w3cManifest.mjs_access_whitelist[j].apiAccess || 'none'; 275 | 276 | if (accessUrl === baseUrlPattern) { 277 | baseApiAccess = apiAccess; 278 | } else { 279 | indentationChars = '\r\n '; 280 | applicationContentUriRules += indentationChars + ''; 281 | console.log("Access Rule added: [" + apiAccess + "] - " + accessUrl); 282 | } 283 | } 284 | } 285 | } 286 | 287 | // Added base rule 288 | applicationContentUriRules = '' + applicationContentUriRules; 289 | appxManifest = appxManifest.replace(/{ApplicationContentUriRules}/g, applicationContentUriRules); 290 | 291 | return appxManifest; 292 | } 293 | 294 | // Helpers 295 | function encodeXML(str: string) { 296 | return str.replace(/&/g, '&') 297 | .replace(//g, '>') 299 | .replace(/"/g, '"') 300 | .replace(/'/g, '''); 301 | } 302 | 303 | function getFormatFromIcon(icon: { src: string; type?: string }) { 304 | return icon.type || (icon.src && icon.src.split('.').pop()); 305 | } 306 | 307 | function isValidIconFormat(icon: { src: string; type?: string }, validFormats: string[]) { 308 | if (!validFormats || validFormats.length === 0) { 309 | return true; 310 | } 311 | 312 | var iconFormat = getFormatFromIcon(icon); 313 | for (var i = 0; i < validFormats.length; i++) { 314 | if (validFormats[i].toLowerCase() === iconFormat) { 315 | return true; 316 | } 317 | } 318 | return false; 319 | } 320 | 321 | function newGuid() { 322 | function s4() { 323 | return Math.floor((1 + Math.random()) * 0x10000) 324 | .toString(16) 325 | .substring(1); 326 | } 327 | return s4() + s4() + '-' + s4() + '-' + s4() + '-' + 328 | s4() + '-' + s4() + s4() + s4(); 329 | } 330 | 331 | function removeDupesInPlace(arr: T[], comparator: (left: T, right: T) => boolean) { 332 | for (var i = 0; i < arr.length; i++) { 333 | for (var j = arr.length - 1; j > i; j--) { 334 | if (comparator(arr[j], arr[i])) { 335 | arr.splice(j, 1); 336 | } 337 | } 338 | } 339 | return arr; 340 | } 341 | 342 | function sanitizeName(name: string) { 343 | var sanitizedName = name || ""; 344 | 345 | // Remove all invalid characters 346 | sanitizedName = sanitizedName.replace(/[^A-Za-z0-9\.]/g, ''); 347 | 348 | var currentLength: number; 349 | do { 350 | currentLength = sanitizedName.length; 351 | 352 | // If the name starts with a number, remove the number 353 | sanitizedName = sanitizedName.replace(/^[0-9]/, ''); 354 | 355 | // If the name starts with a dot, remove the dot 356 | sanitizedName = sanitizedName.replace(/^\./, ''); 357 | 358 | // If there is a number right after a dot, remove the number 359 | sanitizedName = sanitizedName.replace(/\.[0-9]/g, '.'); 360 | 361 | // If there are two consecutive dots, remove one dot 362 | sanitizedName = sanitizedName.replace(/\.\./g, '.'); 363 | 364 | // if the name ends with a dot, remove the dot 365 | sanitizedName = sanitizedName.replace(/\.$/, ''); 366 | } 367 | while (currentLength > sanitizedName.length); 368 | 369 | if (sanitizedName.length === 0) { 370 | sanitizedName = 'MyManifoldJSApp'; 371 | } 372 | return sanitizedName; 373 | } 374 | -------------------------------------------------------------------------------- /projects/typings/node.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Node.js v0.12.0 2 | // Project: http://nodejs.org/ 3 | // Definitions by: Microsoft TypeScript , DefinitelyTyped 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /************************************************ 7 | * * 8 | * Node.js v0.12.0 API * 9 | * * 10 | ************************************************/ 11 | 12 | // compat for TypeScript 1.5.3 13 | // if you use with --target es3 or --target es5 and use below definitions, 14 | // use the lib.es6.d.ts that is bundled with TypeScript 1.5.3. 15 | interface MapConstructor { } 16 | interface WeakMapConstructor { } 17 | interface SetConstructor { } 18 | interface WeakSetConstructor { } 19 | 20 | /************************************************ 21 | * * 22 | * GLOBAL * 23 | * * 24 | ************************************************/ 25 | declare var process: NodeJS.Process; 26 | declare var global: NodeJS.Global; 27 | 28 | declare var __filename: string; 29 | declare var __dirname: string; 30 | 31 | declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 32 | declare function clearTimeout(timeoutId: NodeJS.Timer): void; 33 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 34 | declare function clearInterval(intervalId: NodeJS.Timer): void; 35 | declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; 36 | declare function clearImmediate(immediateId: any): void; 37 | 38 | interface NodeRequireFunction { 39 | (id: string): any; 40 | } 41 | 42 | interface NodeRequire extends NodeRequireFunction { 43 | resolve(id: string): string; 44 | cache: any; 45 | extensions: any; 46 | main: any; 47 | } 48 | 49 | declare var require: NodeRequire; 50 | 51 | interface NodeModule { 52 | exports: any; 53 | require: NodeRequireFunction; 54 | id: string; 55 | filename: string; 56 | loaded: boolean; 57 | parent: any; 58 | children: any[]; 59 | } 60 | 61 | declare var module: NodeModule; 62 | 63 | // Same as module.exports 64 | declare var exports: any; 65 | declare var SlowBuffer: { 66 | new (str: string, encoding?: string): Buffer; 67 | new (size: number): Buffer; 68 | new (size: Uint8Array): Buffer; 69 | new (array: any[]): Buffer; 70 | prototype: Buffer; 71 | isBuffer(obj: any): boolean; 72 | byteLength(string: string, encoding?: string): number; 73 | concat(list: Buffer[], totalLength?: number): Buffer; 74 | }; 75 | 76 | 77 | // Buffer class 78 | interface Buffer extends NodeBuffer { } 79 | 80 | /** 81 | * Raw data is stored in instances of the Buffer class. 82 | * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. 83 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 84 | */ 85 | declare var Buffer: { 86 | /** 87 | * Allocates a new buffer containing the given {str}. 88 | * 89 | * @param str String to store in buffer. 90 | * @param encoding encoding to use, optional. Default is 'utf8' 91 | */ 92 | new (str: string, encoding?: string): Buffer; 93 | /** 94 | * Allocates a new buffer of {size} octets. 95 | * 96 | * @param size count of octets to allocate. 97 | */ 98 | new (size: number): Buffer; 99 | /** 100 | * Allocates a new buffer containing the given {array} of octets. 101 | * 102 | * @param array The octets to store. 103 | */ 104 | new (array: Uint8Array): Buffer; 105 | /** 106 | * Allocates a new buffer containing the given {array} of octets. 107 | * 108 | * @param array The octets to store. 109 | */ 110 | new (array: any[]): Buffer; 111 | prototype: Buffer; 112 | /** 113 | * Returns true if {obj} is a Buffer 114 | * 115 | * @param obj object to test. 116 | */ 117 | isBuffer(obj: any): boolean; 118 | /** 119 | * Returns true if {encoding} is a valid encoding argument. 120 | * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 121 | * 122 | * @param encoding string to test. 123 | */ 124 | isEncoding(encoding: string): boolean; 125 | /** 126 | * Gives the actual byte length of a string. encoding defaults to 'utf8'. 127 | * This is not the same as String.prototype.length since that returns the number of characters in a string. 128 | * 129 | * @param string string to test. 130 | * @param encoding encoding used to evaluate (defaults to 'utf8') 131 | */ 132 | byteLength(string: string, encoding?: string): number; 133 | /** 134 | * Returns a buffer which is the result of concatenating all the buffers in the list together. 135 | * 136 | * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. 137 | * If the list has exactly one item, then the first item of the list is returned. 138 | * If the list has more than one item, then a new Buffer is created. 139 | * 140 | * @param list An array of Buffer objects to concatenate 141 | * @param totalLength Total length of the buffers when concatenated. 142 | * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. 143 | */ 144 | concat(list: Buffer[], totalLength?: number): Buffer; 145 | /** 146 | * The same as buf1.compare(buf2). 147 | */ 148 | compare(buf1: Buffer, buf2: Buffer): number; 149 | }; 150 | 151 | /************************************************ 152 | * * 153 | * GLOBAL INTERFACES * 154 | * * 155 | ************************************************/ 156 | declare module NodeJS { 157 | export interface ErrnoException extends Error { 158 | errno?: number; 159 | code?: string; 160 | path?: string; 161 | syscall?: string; 162 | stack?: string; 163 | } 164 | 165 | export interface EventEmitter { 166 | addListener(event: string, listener: Function): EventEmitter; 167 | on(event: string, listener: Function): EventEmitter; 168 | once(event: string, listener: Function): EventEmitter; 169 | removeListener(event: string, listener: Function): EventEmitter; 170 | removeAllListeners(event?: string): EventEmitter; 171 | setMaxListeners(n: number): void; 172 | listeners(event: string): Function[]; 173 | emit(event: string, ...args: any[]): boolean; 174 | } 175 | 176 | export interface ReadableStream extends EventEmitter { 177 | readable: boolean; 178 | read(size?: number): string|Buffer; 179 | setEncoding(encoding: string): void; 180 | pause(): void; 181 | resume(): void; 182 | pipe(destination: T, options?: { end?: boolean; }): T; 183 | unpipe(destination?: T): void; 184 | unshift(chunk: string): void; 185 | unshift(chunk: Buffer): void; 186 | wrap(oldStream: ReadableStream): ReadableStream; 187 | } 188 | 189 | export interface WritableStream extends EventEmitter { 190 | writable: boolean; 191 | write(buffer: Buffer, cb?: Function): boolean; 192 | write(str: string, cb?: Function): boolean; 193 | write(str: string, encoding?: string, cb?: Function): boolean; 194 | end(): void; 195 | end(buffer: Buffer, cb?: Function): void; 196 | end(str: string, cb?: Function): void; 197 | end(str: string, encoding?: string, cb?: Function): void; 198 | } 199 | 200 | export interface ReadWriteStream extends ReadableStream, WritableStream { } 201 | 202 | export interface Process extends EventEmitter { 203 | stdout: WritableStream; 204 | stderr: WritableStream; 205 | stdin: ReadableStream; 206 | argv: string[]; 207 | execPath: string; 208 | abort(): void; 209 | chdir(directory: string): void; 210 | cwd(): string; 211 | env: any; 212 | exit(code?: number): void; 213 | getgid(): number; 214 | setgid(id: number): void; 215 | setgid(id: string): void; 216 | getuid(): number; 217 | setuid(id: number): void; 218 | setuid(id: string): void; 219 | version: string; 220 | versions: { 221 | http_parser: string; 222 | node: string; 223 | v8: string; 224 | ares: string; 225 | uv: string; 226 | zlib: string; 227 | openssl: string; 228 | }; 229 | config: { 230 | target_defaults: { 231 | cflags: any[]; 232 | default_configuration: string; 233 | defines: string[]; 234 | include_dirs: string[]; 235 | libraries: string[]; 236 | }; 237 | variables: { 238 | clang: number; 239 | host_arch: string; 240 | node_install_npm: boolean; 241 | node_install_waf: boolean; 242 | node_prefix: string; 243 | node_shared_openssl: boolean; 244 | node_shared_v8: boolean; 245 | node_shared_zlib: boolean; 246 | node_use_dtrace: boolean; 247 | node_use_etw: boolean; 248 | node_use_openssl: boolean; 249 | target_arch: string; 250 | v8_no_strict_aliasing: number; 251 | v8_use_snapshot: boolean; 252 | visibility: string; 253 | }; 254 | }; 255 | kill(pid: number, signal?: string): void; 256 | pid: number; 257 | title: string; 258 | arch: string; 259 | platform: string; 260 | memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; 261 | nextTick(callback: Function): void; 262 | umask(mask?: number): number; 263 | uptime(): number; 264 | hrtime(time?: number[]): number[]; 265 | 266 | // Worker 267 | send?(message: any, sendHandle?: any): void; 268 | } 269 | 270 | export interface Global { 271 | Array: typeof Array; 272 | ArrayBuffer: typeof ArrayBuffer; 273 | Boolean: typeof Boolean; 274 | Buffer: typeof Buffer; 275 | DataView: typeof DataView; 276 | Date: typeof Date; 277 | Error: typeof Error; 278 | EvalError: typeof EvalError; 279 | Float32Array: typeof Float32Array; 280 | Float64Array: typeof Float64Array; 281 | Function: typeof Function; 282 | GLOBAL: Global; 283 | Infinity: typeof Infinity; 284 | Int16Array: typeof Int16Array; 285 | Int32Array: typeof Int32Array; 286 | Int8Array: typeof Int8Array; 287 | Intl: typeof Intl; 288 | JSON: typeof JSON; 289 | Map: MapConstructor; 290 | Math: typeof Math; 291 | NaN: typeof NaN; 292 | Number: typeof Number; 293 | Object: typeof Object; 294 | Promise: Function; 295 | RangeError: typeof RangeError; 296 | ReferenceError: typeof ReferenceError; 297 | RegExp: typeof RegExp; 298 | Set: SetConstructor; 299 | String: typeof String; 300 | Symbol: Function; 301 | SyntaxError: typeof SyntaxError; 302 | TypeError: typeof TypeError; 303 | URIError: typeof URIError; 304 | Uint16Array: typeof Uint16Array; 305 | Uint32Array: typeof Uint32Array; 306 | Uint8Array: typeof Uint8Array; 307 | Uint8ClampedArray: Function; 308 | WeakMap: WeakMapConstructor; 309 | WeakSet: WeakSetConstructor; 310 | clearImmediate: (immediateId: any) => void; 311 | clearInterval: (intervalId: NodeJS.Timer) => void; 312 | clearTimeout: (timeoutId: NodeJS.Timer) => void; 313 | console: typeof console; 314 | decodeURI: typeof decodeURI; 315 | decodeURIComponent: typeof decodeURIComponent; 316 | encodeURI: typeof encodeURI; 317 | encodeURIComponent: typeof encodeURIComponent; 318 | escape: (str: string) => string; 319 | eval: typeof eval; 320 | global: Global; 321 | isFinite: typeof isFinite; 322 | isNaN: typeof isNaN; 323 | parseFloat: typeof parseFloat; 324 | parseInt: typeof parseInt; 325 | process: Process; 326 | root: Global; 327 | setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; 328 | setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 329 | setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 330 | undefined: typeof undefined; 331 | unescape: (str: string) => string; 332 | gc: () => void; 333 | } 334 | 335 | export interface Timer { 336 | ref(): void; 337 | unref(): void; 338 | } 339 | } 340 | 341 | /** 342 | * @deprecated 343 | */ 344 | interface NodeBuffer { 345 | [index: number]: number; 346 | write(string: string, offset?: number, length?: number, encoding?: string): number; 347 | toString(encoding?: string, start?: number, end?: number): string; 348 | toJSON(): any; 349 | length: number; 350 | equals(otherBuffer: Buffer): boolean; 351 | compare(otherBuffer: Buffer): number; 352 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 353 | slice(start?: number, end?: number): Buffer; 354 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 355 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 356 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 357 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 358 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 359 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 360 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 361 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 362 | readUInt8(offset: number, noAsset?: boolean): number; 363 | readUInt16LE(offset: number, noAssert?: boolean): number; 364 | readUInt16BE(offset: number, noAssert?: boolean): number; 365 | readUInt32LE(offset: number, noAssert?: boolean): number; 366 | readUInt32BE(offset: number, noAssert?: boolean): number; 367 | readInt8(offset: number, noAssert?: boolean): number; 368 | readInt16LE(offset: number, noAssert?: boolean): number; 369 | readInt16BE(offset: number, noAssert?: boolean): number; 370 | readInt32LE(offset: number, noAssert?: boolean): number; 371 | readInt32BE(offset: number, noAssert?: boolean): number; 372 | readFloatLE(offset: number, noAssert?: boolean): number; 373 | readFloatBE(offset: number, noAssert?: boolean): number; 374 | readDoubleLE(offset: number, noAssert?: boolean): number; 375 | readDoubleBE(offset: number, noAssert?: boolean): number; 376 | writeUInt8(value: number, offset: number, noAssert?: boolean): void; 377 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; 378 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; 379 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; 380 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; 381 | writeInt8(value: number, offset: number, noAssert?: boolean): void; 382 | writeInt16LE(value: number, offset: number, noAssert?: boolean): void; 383 | writeInt16BE(value: number, offset: number, noAssert?: boolean): void; 384 | writeInt32LE(value: number, offset: number, noAssert?: boolean): void; 385 | writeInt32BE(value: number, offset: number, noAssert?: boolean): void; 386 | writeFloatLE(value: number, offset: number, noAssert?: boolean): void; 387 | writeFloatBE(value: number, offset: number, noAssert?: boolean): void; 388 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; 389 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; 390 | fill(value: any, offset?: number, end?: number): void; 391 | } 392 | 393 | /************************************************ 394 | * * 395 | * MODULES * 396 | * * 397 | ************************************************/ 398 | declare module "buffer" { 399 | export var INSPECT_MAX_BYTES: number; 400 | } 401 | 402 | declare module "querystring" { 403 | export function stringify(obj: any, sep?: string, eq?: string): string; 404 | export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; 405 | export function escape(str: string): string; 406 | export function unescape(str: string): string; 407 | } 408 | 409 | declare module "events" { 410 | export class EventEmitter implements NodeJS.EventEmitter { 411 | static listenerCount(emitter: EventEmitter, event: string): number; 412 | 413 | addListener(event: string, listener: Function): EventEmitter; 414 | on(event: string, listener: Function): EventEmitter; 415 | once(event: string, listener: Function): EventEmitter; 416 | removeListener(event: string, listener: Function): EventEmitter; 417 | removeAllListeners(event?: string): EventEmitter; 418 | setMaxListeners(n: number): void; 419 | listeners(event: string): Function[]; 420 | emit(event: string, ...args: any[]): boolean; 421 | } 422 | } 423 | 424 | declare module "http" { 425 | import * as events from "events"; 426 | import * as net from "net"; 427 | import * as stream from "stream"; 428 | 429 | export interface Server extends events.EventEmitter { 430 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; 431 | listen(port: number, hostname?: string, callback?: Function): Server; 432 | listen(path: string, callback?: Function): Server; 433 | listen(handle: any, listeningListener?: Function): Server; 434 | close(cb?: any): Server; 435 | address(): { port: number; family: string; address: string; }; 436 | maxHeadersCount: number; 437 | } 438 | /** 439 | * @deprecated Use IncomingMessage 440 | */ 441 | export interface ServerRequest extends IncomingMessage { 442 | connection: net.Socket; 443 | } 444 | export interface ServerResponse extends events.EventEmitter, stream.Writable { 445 | // Extended base methods 446 | write(buffer: Buffer): boolean; 447 | write(buffer: Buffer, cb?: Function): boolean; 448 | write(str: string, cb?: Function): boolean; 449 | write(str: string, encoding?: string, cb?: Function): boolean; 450 | write(str: string, encoding?: string, fd?: string): boolean; 451 | 452 | writeContinue(): void; 453 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 454 | writeHead(statusCode: number, headers?: any): void; 455 | statusCode: number; 456 | statusMessage: string; 457 | setHeader(name: string, value: string): void; 458 | sendDate: boolean; 459 | getHeader(name: string): string; 460 | removeHeader(name: string): void; 461 | write(chunk: any, encoding?: string): any; 462 | addTrailers(headers: any): void; 463 | 464 | // Extended base methods 465 | end(): void; 466 | end(buffer: Buffer, cb?: Function): void; 467 | end(str: string, cb?: Function): void; 468 | end(str: string, encoding?: string, cb?: Function): void; 469 | end(data?: any, encoding?: string): void; 470 | } 471 | export interface ClientRequest extends events.EventEmitter, stream.Writable { 472 | // Extended base methods 473 | write(buffer: Buffer): boolean; 474 | write(buffer: Buffer, cb?: Function): boolean; 475 | write(str: string, cb?: Function): boolean; 476 | write(str: string, encoding?: string, cb?: Function): boolean; 477 | write(str: string, encoding?: string, fd?: string): boolean; 478 | 479 | write(chunk: any, encoding?: string): void; 480 | abort(): void; 481 | setTimeout(timeout: number, callback?: Function): void; 482 | setNoDelay(noDelay?: boolean): void; 483 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 484 | 485 | // Extended base methods 486 | end(): void; 487 | end(buffer: Buffer, cb?: Function): void; 488 | end(str: string, cb?: Function): void; 489 | end(str: string, encoding?: string, cb?: Function): void; 490 | end(data?: any, encoding?: string): void; 491 | } 492 | export interface IncomingMessage extends events.EventEmitter, stream.Readable { 493 | httpVersion: string; 494 | headers: any; 495 | rawHeaders: string[]; 496 | trailers: any; 497 | rawTrailers: any; 498 | setTimeout(msecs: number, callback: Function): NodeJS.Timer; 499 | /** 500 | * Only valid for request obtained from http.Server. 501 | */ 502 | method?: string; 503 | /** 504 | * Only valid for request obtained from http.Server. 505 | */ 506 | url?: string; 507 | /** 508 | * Only valid for response obtained from http.ClientRequest. 509 | */ 510 | statusCode?: number; 511 | /** 512 | * Only valid for response obtained from http.ClientRequest. 513 | */ 514 | statusMessage?: string; 515 | socket: net.Socket; 516 | } 517 | /** 518 | * @deprecated Use IncomingMessage 519 | */ 520 | export interface ClientResponse extends IncomingMessage { } 521 | 522 | export interface AgentOptions { 523 | /** 524 | * Keep sockets around in a pool to be used by other requests in the future. Default = false 525 | */ 526 | keepAlive?: boolean; 527 | /** 528 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. 529 | * Only relevant if keepAlive is set to true. 530 | */ 531 | keepAliveMsecs?: number; 532 | /** 533 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity 534 | */ 535 | maxSockets?: number; 536 | /** 537 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. 538 | */ 539 | maxFreeSockets?: number; 540 | } 541 | 542 | export class Agent { 543 | maxSockets: number; 544 | sockets: any; 545 | requests: any; 546 | 547 | constructor(opts?: AgentOptions); 548 | 549 | /** 550 | * Destroy any sockets that are currently in use by the agent. 551 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, 552 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, 553 | * sockets may hang open for quite a long time before the server terminates them. 554 | */ 555 | destroy(): void; 556 | } 557 | 558 | export var METHODS: string[]; 559 | 560 | export var STATUS_CODES: { 561 | [errorCode: number]: string; 562 | [errorCode: string]: string; 563 | }; 564 | export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) => void): Server; 565 | export function createClient(port?: number, host?: string): any; 566 | export function request(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 567 | export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 568 | export var globalAgent: Agent; 569 | } 570 | 571 | declare module "cluster" { 572 | import * as child from "child_process"; 573 | import * as events from "events"; 574 | 575 | export interface ClusterSettings { 576 | exec?: string; 577 | args?: string[]; 578 | silent?: boolean; 579 | } 580 | 581 | export class Worker extends events.EventEmitter { 582 | id: string; 583 | process: child.ChildProcess; 584 | suicide: boolean; 585 | send(message: any, sendHandle?: any): void; 586 | kill(signal?: string): void; 587 | destroy(signal?: string): void; 588 | disconnect(): void; 589 | } 590 | 591 | export var settings: ClusterSettings; 592 | export var isMaster: boolean; 593 | export var isWorker: boolean; 594 | export function setupMaster(settings?: ClusterSettings): void; 595 | export function fork(env?: any): Worker; 596 | export function disconnect(callback?: Function): void; 597 | export var worker: Worker; 598 | export var workers: Worker[]; 599 | 600 | // Event emitter 601 | export function addListener(event: string, listener: Function): void; 602 | export function on(event: string, listener: Function): any; 603 | export function once(event: string, listener: Function): void; 604 | export function removeListener(event: string, listener: Function): void; 605 | export function removeAllListeners(event?: string): void; 606 | export function setMaxListeners(n: number): void; 607 | export function listeners(event: string): Function[]; 608 | export function emit(event: string, ...args: any[]): boolean; 609 | } 610 | 611 | declare module "zlib" { 612 | import * as stream from "stream"; 613 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 614 | 615 | export interface Gzip extends stream.Transform { } 616 | export interface Gunzip extends stream.Transform { } 617 | export interface Deflate extends stream.Transform { } 618 | export interface Inflate extends stream.Transform { } 619 | export interface DeflateRaw extends stream.Transform { } 620 | export interface InflateRaw extends stream.Transform { } 621 | export interface Unzip extends stream.Transform { } 622 | 623 | export function createGzip(options?: ZlibOptions): Gzip; 624 | export function createGunzip(options?: ZlibOptions): Gunzip; 625 | export function createDeflate(options?: ZlibOptions): Deflate; 626 | export function createInflate(options?: ZlibOptions): Inflate; 627 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 628 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 629 | export function createUnzip(options?: ZlibOptions): Unzip; 630 | 631 | export function deflate(buf: Buffer, callback: (error: Error, result: any) => void): void; 632 | export function deflateSync(buf: Buffer, options?: ZlibOptions): any; 633 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void; 634 | export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; 635 | export function gzip(buf: Buffer, callback: (error: Error, result: any) => void): void; 636 | export function gzipSync(buf: Buffer, options?: ZlibOptions): any; 637 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) => void): void; 638 | export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; 639 | export function inflate(buf: Buffer, callback: (error: Error, result: any) => void): void; 640 | export function inflateSync(buf: Buffer, options?: ZlibOptions): any; 641 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void; 642 | export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; 643 | export function unzip(buf: Buffer, callback: (error: Error, result: any) => void): void; 644 | export function unzipSync(buf: Buffer, options?: ZlibOptions): any; 645 | 646 | // Constants 647 | export var Z_NO_FLUSH: number; 648 | export var Z_PARTIAL_FLUSH: number; 649 | export var Z_SYNC_FLUSH: number; 650 | export var Z_FULL_FLUSH: number; 651 | export var Z_FINISH: number; 652 | export var Z_BLOCK: number; 653 | export var Z_TREES: number; 654 | export var Z_OK: number; 655 | export var Z_STREAM_END: number; 656 | export var Z_NEED_DICT: number; 657 | export var Z_ERRNO: number; 658 | export var Z_STREAM_ERROR: number; 659 | export var Z_DATA_ERROR: number; 660 | export var Z_MEM_ERROR: number; 661 | export var Z_BUF_ERROR: number; 662 | export var Z_VERSION_ERROR: number; 663 | export var Z_NO_COMPRESSION: number; 664 | export var Z_BEST_SPEED: number; 665 | export var Z_BEST_COMPRESSION: number; 666 | export var Z_DEFAULT_COMPRESSION: number; 667 | export var Z_FILTERED: number; 668 | export var Z_HUFFMAN_ONLY: number; 669 | export var Z_RLE: number; 670 | export var Z_FIXED: number; 671 | export var Z_DEFAULT_STRATEGY: number; 672 | export var Z_BINARY: number; 673 | export var Z_TEXT: number; 674 | export var Z_ASCII: number; 675 | export var Z_UNKNOWN: number; 676 | export var Z_DEFLATED: number; 677 | export var Z_NULL: number; 678 | } 679 | 680 | declare module "os" { 681 | export function tmpdir(): string; 682 | export function hostname(): string; 683 | export function type(): string; 684 | export function platform(): string; 685 | export function arch(): string; 686 | export function release(): string; 687 | export function uptime(): number; 688 | export function loadavg(): number[]; 689 | export function totalmem(): number; 690 | export function freemem(): number; 691 | export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; 692 | export function networkInterfaces(): any; 693 | export var EOL: string; 694 | } 695 | 696 | declare module "https" { 697 | import * as tls from "tls"; 698 | import * as events from "events"; 699 | import * as http from "http"; 700 | 701 | export interface ServerOptions { 702 | pfx?: any; 703 | key?: any; 704 | passphrase?: string; 705 | cert?: any; 706 | ca?: any; 707 | crl?: any; 708 | ciphers?: string; 709 | honorCipherOrder?: boolean; 710 | requestCert?: boolean; 711 | rejectUnauthorized?: boolean; 712 | NPNProtocols?: any; 713 | SNICallback?: (servername: string) => any; 714 | } 715 | 716 | export interface RequestOptions { 717 | host?: string; 718 | hostname?: string; 719 | port?: number; 720 | path?: string; 721 | method?: string; 722 | headers?: any; 723 | auth?: string; 724 | agent?: any; 725 | pfx?: any; 726 | key?: any; 727 | passphrase?: string; 728 | cert?: any; 729 | ca?: any; 730 | ciphers?: string; 731 | rejectUnauthorized?: boolean; 732 | } 733 | 734 | export interface Agent { 735 | maxSockets: number; 736 | sockets: any; 737 | requests: any; 738 | } 739 | export var Agent: { 740 | new (options?: RequestOptions): Agent; 741 | }; 742 | export interface Server extends tls.Server { } 743 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 744 | export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; 745 | export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; 746 | export var globalAgent: Agent; 747 | } 748 | 749 | declare module "punycode" { 750 | export function decode(string: string): string; 751 | export function encode(string: string): string; 752 | export function toUnicode(domain: string): string; 753 | export function toASCII(domain: string): string; 754 | export var ucs2: ucs2; 755 | interface ucs2 { 756 | decode(string: string): string; 757 | encode(codePoints: number[]): string; 758 | } 759 | export var version: any; 760 | } 761 | 762 | declare module "repl" { 763 | import * as stream from "stream"; 764 | import * as events from "events"; 765 | 766 | export interface ReplOptions { 767 | prompt?: string; 768 | input?: NodeJS.ReadableStream; 769 | output?: NodeJS.WritableStream; 770 | terminal?: boolean; 771 | eval?: Function; 772 | useColors?: boolean; 773 | useGlobal?: boolean; 774 | ignoreUndefined?: boolean; 775 | writer?: Function; 776 | } 777 | export function start(options: ReplOptions): events.EventEmitter; 778 | } 779 | 780 | declare module "readline" { 781 | import * as events from "events"; 782 | import * as stream from "stream"; 783 | 784 | export interface ReadLine extends events.EventEmitter { 785 | setPrompt(prompt: string): void; 786 | prompt(preserveCursor?: boolean): void; 787 | question(query: string, callback: Function): void; 788 | pause(): void; 789 | resume(): void; 790 | close(): void; 791 | write(data: any, key?: any): void; 792 | } 793 | export interface ReadLineOptions { 794 | input: NodeJS.ReadableStream; 795 | output: NodeJS.WritableStream; 796 | completer?: Function; 797 | terminal?: boolean; 798 | } 799 | export function createInterface(options: ReadLineOptions): ReadLine; 800 | } 801 | 802 | declare module "vm" { 803 | export interface Context { } 804 | export interface Script { 805 | runInThisContext(): void; 806 | runInNewContext(sandbox?: Context): void; 807 | } 808 | export function runInThisContext(code: string, filename?: string): void; 809 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; 810 | export function runInContext(code: string, context: Context, filename?: string): void; 811 | export function createContext(initSandbox?: Context): Context; 812 | export function createScript(code: string, filename?: string): Script; 813 | } 814 | 815 | declare module "child_process" { 816 | import * as events from "events"; 817 | import * as stream from "stream"; 818 | 819 | export interface ChildProcess extends events.EventEmitter { 820 | stdin: stream.Writable; 821 | stdout: stream.Readable; 822 | stderr: stream.Readable; 823 | pid: number; 824 | kill(signal?: string): void; 825 | send(message: any, sendHandle?: any): void; 826 | disconnect(): void; 827 | unref(): void; 828 | } 829 | 830 | export function spawn(command: string, args?: string[], options?: { 831 | cwd?: string; 832 | stdio?: any; 833 | custom?: any; 834 | env?: any; 835 | detached?: boolean; 836 | }): ChildProcess; 837 | export function exec(command: string, options: { 838 | cwd?: string; 839 | stdio?: any; 840 | customFds?: any; 841 | env?: any; 842 | encoding?: string; 843 | timeout?: number; 844 | maxBuffer?: number; 845 | killSignal?: string; 846 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; 847 | export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; 848 | export function execFile(file: string, 849 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; 850 | export function execFile(file: string, args?: string[], 851 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; 852 | export function execFile(file: string, args?: string[], options?: { 853 | cwd?: string; 854 | stdio?: any; 855 | customFds?: any; 856 | env?: any; 857 | encoding?: string; 858 | timeout?: number; 859 | maxBuffer?: string; 860 | killSignal?: string; 861 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; 862 | export function fork(modulePath: string, args?: string[], options?: { 863 | cwd?: string; 864 | env?: any; 865 | encoding?: string; 866 | }): ChildProcess; 867 | export function execSync(command: string, options?: { 868 | cwd?: string; 869 | input?: string|Buffer; 870 | stdio?: any; 871 | env?: any; 872 | uid?: number; 873 | gid?: number; 874 | timeout?: number; 875 | maxBuffer?: number; 876 | killSignal?: string; 877 | encoding?: string; 878 | }): ChildProcess; 879 | export function execFileSync(command: string, args?: string[], options?: { 880 | cwd?: string; 881 | input?: string|Buffer; 882 | stdio?: any; 883 | env?: any; 884 | uid?: number; 885 | gid?: number; 886 | timeout?: number; 887 | maxBuffer?: number; 888 | killSignal?: string; 889 | encoding?: string; 890 | }): ChildProcess; 891 | } 892 | 893 | declare module "url" { 894 | export interface Url { 895 | href: string; 896 | protocol: string; 897 | auth: string; 898 | hostname: string; 899 | port: string; 900 | host: string; 901 | pathname: string; 902 | search: string; 903 | query: any; // string | Object 904 | slashes: boolean; 905 | hash?: string; 906 | path?: string; 907 | } 908 | 909 | export interface UrlOptions { 910 | protocol?: string; 911 | auth?: string; 912 | hostname?: string; 913 | port?: string; 914 | host?: string; 915 | pathname?: string; 916 | search?: string; 917 | query?: any; 918 | hash?: string; 919 | path?: string; 920 | } 921 | 922 | export function parse(urlStr: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url; 923 | export function format(url: UrlOptions): string; 924 | export function resolve(from: string, to: string): string; 925 | } 926 | 927 | declare module "dns" { 928 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) => void): string; 929 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) => void): string; 930 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) => void): string[]; 931 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 932 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 933 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 934 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 935 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 936 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 937 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 938 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; 939 | export function reverse(ip: string, callback: (err: Error, domains: string[]) => void): string[]; 940 | } 941 | 942 | declare module "net" { 943 | import * as stream from "stream"; 944 | 945 | export interface Socket extends stream.Duplex { 946 | // Extended base methods 947 | write(buffer: Buffer): boolean; 948 | write(buffer: Buffer, cb?: Function): boolean; 949 | write(str: string, cb?: Function): boolean; 950 | write(str: string, encoding?: string, cb?: Function): boolean; 951 | write(str: string, encoding?: string, fd?: string): boolean; 952 | 953 | connect(port: number, host?: string, connectionListener?: Function): void; 954 | connect(path: string, connectionListener?: Function): void; 955 | bufferSize: number; 956 | setEncoding(encoding?: string): void; 957 | write(data: any, encoding?: string, callback?: Function): void; 958 | destroy(): void; 959 | pause(): void; 960 | resume(): void; 961 | setTimeout(timeout: number, callback?: Function): void; 962 | setNoDelay(noDelay?: boolean): void; 963 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 964 | address(): { port: number; family: string; address: string; }; 965 | unref(): void; 966 | ref(): void; 967 | 968 | remoteAddress: string; 969 | remoteFamily: string; 970 | remotePort: number; 971 | localAddress: string; 972 | localPort: number; 973 | bytesRead: number; 974 | bytesWritten: number; 975 | 976 | // Extended base methods 977 | end(): void; 978 | end(buffer: Buffer, cb?: Function): void; 979 | end(str: string, cb?: Function): void; 980 | end(str: string, encoding?: string, cb?: Function): void; 981 | end(data?: any, encoding?: string): void; 982 | } 983 | 984 | export var Socket: { 985 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; 986 | }; 987 | 988 | export interface Server extends Socket { 989 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 990 | listen(path: string, listeningListener?: Function): Server; 991 | listen(handle: any, listeningListener?: Function): Server; 992 | close(callback?: Function): Server; 993 | address(): { port: number; family: string; address: string; }; 994 | maxConnections: number; 995 | connections: number; 996 | } 997 | export function createServer(connectionListener?: (socket: Socket) => void): Server; 998 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) => void): Server; 999 | export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1000 | export function connect(port: number, host?: string, connectionListener?: Function): Socket; 1001 | export function connect(path: string, connectionListener?: Function): Socket; 1002 | export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1003 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; 1004 | export function createConnection(path: string, connectionListener?: Function): Socket; 1005 | export function isIP(input: string): number; 1006 | export function isIPv4(input: string): boolean; 1007 | export function isIPv6(input: string): boolean; 1008 | } 1009 | 1010 | declare module "dgram" { 1011 | import * as events from "events"; 1012 | 1013 | interface RemoteInfo { 1014 | address: string; 1015 | port: number; 1016 | size: number; 1017 | } 1018 | 1019 | interface AddressInfo { 1020 | address: string; 1021 | family: string; 1022 | port: number; 1023 | } 1024 | 1025 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; 1026 | 1027 | interface Socket extends events.EventEmitter { 1028 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; 1029 | bind(port: number, address?: string, callback?: () => void): void; 1030 | close(): void; 1031 | address(): AddressInfo; 1032 | setBroadcast(flag: boolean): void; 1033 | setMulticastTTL(ttl: number): void; 1034 | setMulticastLoopback(flag: boolean): void; 1035 | addMembership(multicastAddress: string, multicastInterface?: string): void; 1036 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 1037 | } 1038 | } 1039 | 1040 | declare module "fs" { 1041 | import * as stream from "stream"; 1042 | import * as events from "events"; 1043 | 1044 | interface Stats { 1045 | isFile(): boolean; 1046 | isDirectory(): boolean; 1047 | isBlockDevice(): boolean; 1048 | isCharacterDevice(): boolean; 1049 | isSymbolicLink(): boolean; 1050 | isFIFO(): boolean; 1051 | isSocket(): boolean; 1052 | dev: number; 1053 | ino: number; 1054 | mode: number; 1055 | nlink: number; 1056 | uid: number; 1057 | gid: number; 1058 | rdev: number; 1059 | size: number; 1060 | blksize: number; 1061 | blocks: number; 1062 | atime: Date; 1063 | mtime: Date; 1064 | ctime: Date; 1065 | } 1066 | 1067 | interface FSWatcher extends events.EventEmitter { 1068 | close(): void; 1069 | } 1070 | 1071 | export interface ReadStream extends stream.Readable { 1072 | close(): void; 1073 | } 1074 | export interface WriteStream extends stream.Writable { 1075 | close(): void; 1076 | bytesWritten: number; 1077 | } 1078 | 1079 | /** 1080 | * Asynchronous rename. 1081 | * @param oldPath 1082 | * @param newPath 1083 | * @param callback No arguments other than a possible exception are given to the completion callback. 1084 | */ 1085 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1086 | /** 1087 | * Synchronous rename 1088 | * @param oldPath 1089 | * @param newPath 1090 | */ 1091 | export function renameSync(oldPath: string, newPath: string): void; 1092 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1093 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1094 | export function truncateSync(path: string, len?: number): void; 1095 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1096 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1097 | export function ftruncateSync(fd: number, len?: number): void; 1098 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1099 | export function chownSync(path: string, uid: number, gid: number): void; 1100 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1101 | export function fchownSync(fd: number, uid: number, gid: number): void; 1102 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1103 | export function lchownSync(path: string, uid: number, gid: number): void; 1104 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1105 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1106 | export function chmodSync(path: string, mode: number): void; 1107 | export function chmodSync(path: string, mode: string): void; 1108 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1109 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1110 | export function fchmodSync(fd: number, mode: number): void; 1111 | export function fchmodSync(fd: number, mode: string): void; 1112 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1113 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1114 | export function lchmodSync(path: string, mode: number): void; 1115 | export function lchmodSync(path: string, mode: string): void; 1116 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1117 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1118 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1119 | export function statSync(path: string): Stats; 1120 | export function lstatSync(path: string): Stats; 1121 | export function fstatSync(fd: number): Stats; 1122 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1123 | export function linkSync(srcpath: string, dstpath: string): void; 1124 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1125 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 1126 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; 1127 | export function readlinkSync(path: string): string; 1128 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 1129 | export function realpath(path: string, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 1130 | export function realpathSync(path: string, cache?: { [path: string]: string }): string; 1131 | /* 1132 | * Asynchronous unlink - deletes the file specified in {path} 1133 | * 1134 | * @param path 1135 | * @param callback No arguments other than a possible exception are given to the completion callback. 1136 | */ 1137 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1138 | /* 1139 | * Synchronous unlink - deletes the file specified in {path} 1140 | * 1141 | * @param path 1142 | */ 1143 | export function unlinkSync(path: string): void; 1144 | /* 1145 | * Asynchronous rmdir - removes the directory specified in {path} 1146 | * 1147 | * @param path 1148 | * @param callback No arguments other than a possible exception are given to the completion callback. 1149 | */ 1150 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1151 | /* 1152 | * Synchronous rmdir - removes the directory specified in {path} 1153 | * 1154 | * @param path 1155 | */ 1156 | export function rmdirSync(path: string): void; 1157 | /* 1158 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1159 | * 1160 | * @param path 1161 | * @param callback No arguments other than a possible exception are given to the completion callback. 1162 | */ 1163 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1164 | /* 1165 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1166 | * 1167 | * @param path 1168 | * @param mode 1169 | * @param callback No arguments other than a possible exception are given to the completion callback. 1170 | */ 1171 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1172 | /* 1173 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1174 | * 1175 | * @param path 1176 | * @param mode 1177 | * @param callback No arguments other than a possible exception are given to the completion callback. 1178 | */ 1179 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1180 | /* 1181 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1182 | * 1183 | * @param path 1184 | * @param mode 1185 | * @param callback No arguments other than a possible exception are given to the completion callback. 1186 | */ 1187 | export function mkdirSync(path: string, mode?: number): void; 1188 | /* 1189 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1190 | * 1191 | * @param path 1192 | * @param mode 1193 | * @param callback No arguments other than a possible exception are given to the completion callback. 1194 | */ 1195 | export function mkdirSync(path: string, mode?: string): void; 1196 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; 1197 | export function readdirSync(path: string): string[]; 1198 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1199 | export function closeSync(fd: number): void; 1200 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1201 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1202 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1203 | export function openSync(path: string, flags: string, mode?: number): number; 1204 | export function openSync(path: string, flags: string, mode?: string): number; 1205 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1206 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1207 | export function utimesSync(path: string, atime: number, mtime: number): void; 1208 | export function utimesSync(path: string, atime: Date, mtime: Date): void; 1209 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1210 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1211 | export function futimesSync(fd: number, atime: number, mtime: number): void; 1212 | export function futimesSync(fd: number, atime: Date, mtime: Date): void; 1213 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1214 | export function fsyncSync(fd: number): void; 1215 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1216 | export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1217 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1218 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; 1219 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1220 | /* 1221 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1222 | * 1223 | * @param fileName 1224 | * @param encoding 1225 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1226 | */ 1227 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1228 | /* 1229 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1230 | * 1231 | * @param fileName 1232 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1233 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1234 | */ 1235 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1236 | /* 1237 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1238 | * 1239 | * @param fileName 1240 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1241 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1242 | */ 1243 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1244 | /* 1245 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1246 | * 1247 | * @param fileName 1248 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1249 | */ 1250 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1251 | /* 1252 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1253 | * 1254 | * @param fileName 1255 | * @param encoding 1256 | */ 1257 | export function readFileSync(filename: string, encoding: string): string; 1258 | /* 1259 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1260 | * 1261 | * @param fileName 1262 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1263 | */ 1264 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; 1265 | /* 1266 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1267 | * 1268 | * @param fileName 1269 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1270 | */ 1271 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; 1272 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1273 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1274 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1275 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1276 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1277 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1278 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1279 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1280 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1281 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1282 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; 1283 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; 1284 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 1285 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; 1286 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; 1287 | export function exists(path: string, callback?: (exists: boolean) => void): void; 1288 | export function existsSync(path: string): boolean; 1289 | /** Constant for fs.access(). File is visible to the calling process. */ 1290 | export var F_OK: number; 1291 | /** Constant for fs.access(). File can be read by the calling process. */ 1292 | export var R_OK: number; 1293 | /** Constant for fs.access(). File can be written by the calling process. */ 1294 | export var W_OK: number; 1295 | /** Constant for fs.access(). File can be executed by the calling process. */ 1296 | export var X_OK: number; 1297 | /** Tests a user's permissions for the file specified by path. */ 1298 | export function access(path: string, callback: (err: NodeJS.ErrnoException) => void): void; 1299 | export function access(path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; 1300 | /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ 1301 | export function accessSync(path: string, mode?: number): void; 1302 | export function createReadStream(path: string, options?: { 1303 | flags?: string; 1304 | encoding?: string; 1305 | fd?: string; 1306 | mode?: number; 1307 | bufferSize?: number; 1308 | }): ReadStream; 1309 | export function createReadStream(path: string, options?: { 1310 | flags?: string; 1311 | encoding?: string; 1312 | fd?: string; 1313 | mode?: string; 1314 | bufferSize?: number; 1315 | }): ReadStream; 1316 | export function createWriteStream(path: string, options?: { 1317 | flags?: string; 1318 | encoding?: string; 1319 | string?: string; 1320 | }): WriteStream; 1321 | } 1322 | 1323 | declare module "path" { 1324 | 1325 | /** 1326 | * A parsed path object generated by path.parse() or consumed by path.format(). 1327 | */ 1328 | export interface ParsedPath { 1329 | /** 1330 | * The root of the path such as '/' or 'c:\' 1331 | */ 1332 | root: string; 1333 | /** 1334 | * The full directory path such as '/home/user/dir' or 'c:\path\dir' 1335 | */ 1336 | dir: string; 1337 | /** 1338 | * The file name including extension (if any) such as 'index.html' 1339 | */ 1340 | base: string; 1341 | /** 1342 | * The file extension (if any) such as '.html' 1343 | */ 1344 | ext: string; 1345 | /** 1346 | * The file name without extension (if any) such as 'index' 1347 | */ 1348 | name: string; 1349 | } 1350 | 1351 | /** 1352 | * Normalize a string path, reducing '..' and '.' parts. 1353 | * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. 1354 | * 1355 | * @param p string path to normalize. 1356 | */ 1357 | export function normalize(p: string): string; 1358 | /** 1359 | * Join all arguments together and normalize the resulting path. 1360 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1361 | * 1362 | * @param paths string paths to join. 1363 | */ 1364 | export function join(...paths: any[]): string; 1365 | /** 1366 | * Join all arguments together and normalize the resulting path. 1367 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1368 | * 1369 | * @param paths string paths to join. 1370 | */ 1371 | export function join(...paths: string[]): string; 1372 | /** 1373 | * The right-most parameter is considered {to}. Other parameters are considered an array of {from}. 1374 | * 1375 | * Starting from leftmost {from} paramter, resolves {to} to an absolute path. 1376 | * 1377 | * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. 1378 | * 1379 | * @param pathSegments string paths to join. Non-string arguments are ignored. 1380 | */ 1381 | export function resolve(...pathSegments: any[]): string; 1382 | /** 1383 | * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. 1384 | * 1385 | * @param path path to test. 1386 | */ 1387 | export function isAbsolute(path: string): boolean; 1388 | /** 1389 | * Solve the relative path from {from} to {to}. 1390 | * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve. 1391 | * 1392 | * @param from 1393 | * @param to 1394 | */ 1395 | export function relative(from: string, to: string): string; 1396 | /** 1397 | * Return the directory name of a path. Similar to the Unix dirname command. 1398 | * 1399 | * @param p the path to evaluate. 1400 | */ 1401 | export function dirname(p: string): string; 1402 | /** 1403 | * Return the last portion of a path. Similar to the Unix basename command. 1404 | * Often used to extract the file name from a fully qualified path. 1405 | * 1406 | * @param p the path to evaluate. 1407 | * @param ext optionally, an extension to remove from the result. 1408 | */ 1409 | export function basename(p: string, ext?: string): string; 1410 | /** 1411 | * Return the extension of the path, from the last '.' to end of string in the last portion of the path. 1412 | * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string 1413 | * 1414 | * @param p the path to evaluate. 1415 | */ 1416 | export function extname(p: string): string; 1417 | /** 1418 | * The platform-specific file separator. '\\' or '/'. 1419 | */ 1420 | export var sep: string; 1421 | /** 1422 | * The platform-specific file delimiter. ';' or ':'. 1423 | */ 1424 | export var delimiter: string; 1425 | /** 1426 | * Returns an object from a path string - the opposite of format(). 1427 | * 1428 | * @param pathString path to evaluate. 1429 | */ 1430 | export function parse(pathString: string): ParsedPath; 1431 | /** 1432 | * Returns a path string from an object - the opposite of parse(). 1433 | * 1434 | * @param pathString path to evaluate. 1435 | */ 1436 | export function format(pathObject: ParsedPath): string; 1437 | 1438 | export module posix { 1439 | export function normalize(p: string): string; 1440 | export function join(...paths: any[]): string; 1441 | export function resolve(...pathSegments: any[]): string; 1442 | export function isAbsolute(p: string): boolean; 1443 | export function relative(from: string, to: string): string; 1444 | export function dirname(p: string): string; 1445 | export function basename(p: string, ext?: string): string; 1446 | export function extname(p: string): string; 1447 | export var sep: string; 1448 | export var delimiter: string; 1449 | export function parse(p: string): ParsedPath; 1450 | export function format(pP: ParsedPath): string; 1451 | } 1452 | 1453 | export module win32 { 1454 | export function normalize(p: string): string; 1455 | export function join(...paths: any[]): string; 1456 | export function resolve(...pathSegments: any[]): string; 1457 | export function isAbsolute(p: string): boolean; 1458 | export function relative(from: string, to: string): string; 1459 | export function dirname(p: string): string; 1460 | export function basename(p: string, ext?: string): string; 1461 | export function extname(p: string): string; 1462 | export var sep: string; 1463 | export var delimiter: string; 1464 | export function parse(p: string): ParsedPath; 1465 | export function format(pP: ParsedPath): string; 1466 | } 1467 | } 1468 | 1469 | declare module "string_decoder" { 1470 | export interface NodeStringDecoder { 1471 | write(buffer: Buffer): string; 1472 | detectIncompleteChar(buffer: Buffer): number; 1473 | } 1474 | export var StringDecoder: { 1475 | new (encoding: string): NodeStringDecoder; 1476 | }; 1477 | } 1478 | 1479 | declare module "tls" { 1480 | import * as crypto from "crypto"; 1481 | import * as net from "net"; 1482 | import * as stream from "stream"; 1483 | 1484 | var CLIENT_RENEG_LIMIT: number; 1485 | var CLIENT_RENEG_WINDOW: number; 1486 | 1487 | export interface TlsOptions { 1488 | pfx?: any; //string or buffer 1489 | key?: any; //string or buffer 1490 | passphrase?: string; 1491 | cert?: any; 1492 | ca?: any; //string or buffer 1493 | crl?: any; //string or string array 1494 | ciphers?: string; 1495 | honorCipherOrder?: any; 1496 | requestCert?: boolean; 1497 | rejectUnauthorized?: boolean; 1498 | NPNProtocols?: any; //array or Buffer; 1499 | SNICallback?: (servername: string) => any; 1500 | } 1501 | 1502 | export interface ConnectionOptions { 1503 | host?: string; 1504 | port?: number; 1505 | socket?: net.Socket; 1506 | pfx?: any; //string | Buffer 1507 | key?: any; //string | Buffer 1508 | passphrase?: string; 1509 | cert?: any; //string | Buffer 1510 | ca?: any; //Array of string | Buffer 1511 | rejectUnauthorized?: boolean; 1512 | NPNProtocols?: any; //Array of string | Buffer 1513 | servername?: string; 1514 | } 1515 | 1516 | export interface Server extends net.Server { 1517 | // Extended base methods 1518 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 1519 | listen(path: string, listeningListener?: Function): Server; 1520 | listen(handle: any, listeningListener?: Function): Server; 1521 | 1522 | listen(port: number, host?: string, callback?: Function): Server; 1523 | close(): Server; 1524 | address(): { port: number; family: string; address: string; }; 1525 | addContext(hostName: string, credentials: { 1526 | key: string; 1527 | cert: string; 1528 | ca: string; 1529 | }): void; 1530 | maxConnections: number; 1531 | connections: number; 1532 | } 1533 | 1534 | export interface ClearTextStream extends stream.Duplex { 1535 | authorized: boolean; 1536 | authorizationError: Error; 1537 | getPeerCertificate(): any; 1538 | getCipher: { 1539 | name: string; 1540 | version: string; 1541 | }; 1542 | address: { 1543 | port: number; 1544 | family: string; 1545 | address: string; 1546 | }; 1547 | remoteAddress: string; 1548 | remotePort: number; 1549 | } 1550 | 1551 | export interface SecurePair { 1552 | encrypted: any; 1553 | cleartext: any; 1554 | } 1555 | 1556 | export interface SecureContextOptions { 1557 | pfx?: any; //string | buffer 1558 | key?: any; //string | buffer 1559 | passphrase?: string; 1560 | cert?: any; // string | buffer 1561 | ca?: any; // string | buffer 1562 | crl?: any; // string | string[] 1563 | ciphers?: string; 1564 | honorCipherOrder?: boolean; 1565 | } 1566 | 1567 | export interface SecureContext { 1568 | context: any; 1569 | } 1570 | 1571 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) => void): Server; 1572 | export function connect(options: TlsOptions, secureConnectionListener?: () => void): ClearTextStream; 1573 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () => void): ClearTextStream; 1574 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () => void): ClearTextStream; 1575 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 1576 | export function createSecureContext(details: SecureContextOptions): SecureContext; 1577 | } 1578 | 1579 | declare module "crypto" { 1580 | export interface CredentialDetails { 1581 | pfx: string; 1582 | key: string; 1583 | passphrase: string; 1584 | cert: string; 1585 | ca: any; //string | string array 1586 | crl: any; //string | string array 1587 | ciphers: string; 1588 | } 1589 | export interface Credentials { context?: any; } 1590 | export function createCredentials(details: CredentialDetails): Credentials; 1591 | export function createHash(algorithm: string): Hash; 1592 | export function createHmac(algorithm: string, key: string): Hmac; 1593 | export function createHmac(algorithm: string, key: Buffer): Hmac; 1594 | interface Hash { 1595 | update(data: any, input_encoding?: string): Hash; 1596 | digest(encoding: 'buffer'): Buffer; 1597 | digest(encoding: string): any; 1598 | digest(): Buffer; 1599 | } 1600 | interface Hmac { 1601 | update(data: any, input_encoding?: string): Hmac; 1602 | digest(encoding: 'buffer'): Buffer; 1603 | digest(encoding: string): any; 1604 | digest(): Buffer; 1605 | } 1606 | export function createCipher(algorithm: string, password: any): Cipher; 1607 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 1608 | interface Cipher { 1609 | update(data: Buffer): Buffer; 1610 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1611 | final(): Buffer; 1612 | final(output_encoding: string): string; 1613 | setAutoPadding(auto_padding: boolean): void; 1614 | } 1615 | export function createDecipher(algorithm: string, password: any): Decipher; 1616 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 1617 | interface Decipher { 1618 | update(data: Buffer): Buffer; 1619 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1620 | final(): Buffer; 1621 | final(output_encoding: string): string; 1622 | setAutoPadding(auto_padding: boolean): void; 1623 | } 1624 | export function createSign(algorithm: string): Signer; 1625 | interface Signer extends NodeJS.WritableStream { 1626 | update(data: any): void; 1627 | sign(private_key: string, output_format: string): string; 1628 | } 1629 | export function createVerify(algorith: string): Verify; 1630 | interface Verify extends NodeJS.WritableStream { 1631 | update(data: any): void; 1632 | verify(object: string, signature: string, signature_format?: string): boolean; 1633 | } 1634 | export function createDiffieHellman(prime_length: number): DiffieHellman; 1635 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 1636 | interface DiffieHellman { 1637 | generateKeys(encoding?: string): string; 1638 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 1639 | getPrime(encoding?: string): string; 1640 | getGenerator(encoding: string): string; 1641 | getPublicKey(encoding?: string): string; 1642 | getPrivateKey(encoding?: string): string; 1643 | setPublicKey(public_key: string, encoding?: string): void; 1644 | setPrivateKey(public_key: string, encoding?: string): void; 1645 | } 1646 | export function getDiffieHellman(group_name: string): DiffieHellman; 1647 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; 1648 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; 1649 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number): Buffer; 1650 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number, digest: string): Buffer; 1651 | export function randomBytes(size: number): Buffer; 1652 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; 1653 | export function pseudoRandomBytes(size: number): Buffer; 1654 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; 1655 | } 1656 | 1657 | declare module "stream" { 1658 | import * as events from "events"; 1659 | 1660 | export interface Stream extends events.EventEmitter { 1661 | pipe(destination: T, options?: { end?: boolean; }): T; 1662 | } 1663 | 1664 | export interface ReadableOptions { 1665 | highWaterMark?: number; 1666 | encoding?: string; 1667 | objectMode?: boolean; 1668 | } 1669 | 1670 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { 1671 | readable: boolean; 1672 | constructor(opts?: ReadableOptions); 1673 | _read(size: number): void; 1674 | read(size?: number): string|Buffer; 1675 | setEncoding(encoding: string): void; 1676 | pause(): void; 1677 | resume(): void; 1678 | pipe(destination: T, options?: { end?: boolean; }): T; 1679 | unpipe(destination?: T): void; 1680 | unshift(chunk: string): void; 1681 | unshift(chunk: Buffer): void; 1682 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1683 | push(chunk: any, encoding?: string): boolean; 1684 | } 1685 | 1686 | export interface WritableOptions { 1687 | highWaterMark?: number; 1688 | decodeStrings?: boolean; 1689 | } 1690 | 1691 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream { 1692 | writable: boolean; 1693 | constructor(opts?: WritableOptions); 1694 | _write(data: Buffer, encoding: string, callback: Function): void; 1695 | _write(data: string, encoding: string, callback: Function): void; 1696 | write(buffer: Buffer, cb?: Function): boolean; 1697 | write(str: string, cb?: Function): boolean; 1698 | write(str: string, encoding?: string, cb?: Function): boolean; 1699 | end(): void; 1700 | end(buffer: Buffer, cb?: Function): void; 1701 | end(str: string, cb?: Function): void; 1702 | end(str: string, encoding?: string, cb?: Function): void; 1703 | } 1704 | 1705 | export interface DuplexOptions extends ReadableOptions, WritableOptions { 1706 | allowHalfOpen?: boolean; 1707 | } 1708 | 1709 | // Note: Duplex extends both Readable and Writable. 1710 | export class Duplex extends Readable implements NodeJS.ReadWriteStream { 1711 | writable: boolean; 1712 | constructor(opts?: DuplexOptions); 1713 | _write(data: Buffer, encoding: string, callback: Function): void; 1714 | _write(data: string, encoding: string, callback: Function): void; 1715 | write(buffer: Buffer, cb?: Function): boolean; 1716 | write(str: string, cb?: Function): boolean; 1717 | write(str: string, encoding?: string, cb?: Function): boolean; 1718 | end(): void; 1719 | end(buffer: Buffer, cb?: Function): void; 1720 | end(str: string, cb?: Function): void; 1721 | end(str: string, encoding?: string, cb?: Function): void; 1722 | } 1723 | 1724 | export interface TransformOptions extends ReadableOptions, WritableOptions { } 1725 | 1726 | // Note: Transform lacks the _read and _write methods of Readable/Writable. 1727 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { 1728 | readable: boolean; 1729 | writable: boolean; 1730 | constructor(opts?: TransformOptions); 1731 | _transform(chunk: Buffer, encoding: string, callback: Function): void; 1732 | _transform(chunk: string, encoding: string, callback: Function): void; 1733 | _flush(callback: Function): void; 1734 | read(size?: number): any; 1735 | setEncoding(encoding: string): void; 1736 | pause(): void; 1737 | resume(): void; 1738 | pipe(destination: T, options?: { end?: boolean; }): T; 1739 | unpipe(destination?: T): void; 1740 | unshift(chunk: string): void; 1741 | unshift(chunk: Buffer): void; 1742 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1743 | push(chunk: any, encoding?: string): boolean; 1744 | write(buffer: Buffer, cb?: Function): boolean; 1745 | write(str: string, cb?: Function): boolean; 1746 | write(str: string, encoding?: string, cb?: Function): boolean; 1747 | end(): void; 1748 | end(buffer: Buffer, cb?: Function): void; 1749 | end(str: string, cb?: Function): void; 1750 | end(str: string, encoding?: string, cb?: Function): void; 1751 | } 1752 | 1753 | export class PassThrough extends Transform { } 1754 | } 1755 | 1756 | declare module "util" { 1757 | export interface InspectOptions { 1758 | showHidden?: boolean; 1759 | depth?: number; 1760 | colors?: boolean; 1761 | customInspect?: boolean; 1762 | } 1763 | 1764 | export function format(format: any, ...param: any[]): string; 1765 | export function debug(string: string): void; 1766 | export function error(...param: any[]): void; 1767 | export function puts(...param: any[]): void; 1768 | export function print(...param: any[]): void; 1769 | export function log(string: string): void; 1770 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 1771 | export function inspect(object: any, options: InspectOptions): string; 1772 | export function isArray(object: any): boolean; 1773 | export function isRegExp(object: any): boolean; 1774 | export function isDate(object: any): boolean; 1775 | export function isError(object: any): boolean; 1776 | export function inherits(constructor: any, superConstructor: any): void; 1777 | } 1778 | 1779 | declare module "assert" { 1780 | function internal(value: any, message?: string): void; 1781 | module internal { 1782 | export class AssertionError implements Error { 1783 | name: string; 1784 | message: string; 1785 | actual: any; 1786 | expected: any; 1787 | operator: string; 1788 | generatedMessage: boolean; 1789 | 1790 | constructor(options?: { 1791 | message?: string; actual?: any; expected?: any; 1792 | operator?: string; stackStartFunction?: Function 1793 | }); 1794 | } 1795 | 1796 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; 1797 | export function ok(value: any, message?: string): void; 1798 | export function equal(actual: any, expected: any, message?: string): void; 1799 | export function notEqual(actual: any, expected: any, message?: string): void; 1800 | export function deepEqual(actual: any, expected: any, message?: string): void; 1801 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 1802 | export function strictEqual(actual: any, expected: any, message?: string): void; 1803 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 1804 | export var throws: { 1805 | (block: Function, message?: string): void; 1806 | (block: Function, error: Function, message?: string): void; 1807 | (block: Function, error: RegExp, message?: string): void; 1808 | (block: Function, error: (err: any) => boolean, message?: string): void; 1809 | }; 1810 | 1811 | export var doesNotThrow: { 1812 | (block: Function, message?: string): void; 1813 | (block: Function, error: Function, message?: string): void; 1814 | (block: Function, error: RegExp, message?: string): void; 1815 | (block: Function, error: (err: any) => boolean, message?: string): void; 1816 | }; 1817 | 1818 | export function ifError(value: any): void; 1819 | } 1820 | 1821 | export = internal; 1822 | } 1823 | 1824 | declare module "tty" { 1825 | import * as net from "net"; 1826 | 1827 | export function isatty(fd: number): boolean; 1828 | export interface ReadStream extends net.Socket { 1829 | isRaw: boolean; 1830 | setRawMode(mode: boolean): void; 1831 | } 1832 | export interface WriteStream extends net.Socket { 1833 | columns: number; 1834 | rows: number; 1835 | } 1836 | } 1837 | 1838 | declare module "domain" { 1839 | import * as events from "events"; 1840 | 1841 | export class Domain extends events.EventEmitter { 1842 | run(fn: Function): void; 1843 | add(emitter: events.EventEmitter): void; 1844 | remove(emitter: events.EventEmitter): void; 1845 | bind(cb: (err: Error, data: any) => any): any; 1846 | intercept(cb: (data: any) => any): any; 1847 | dispose(): void; 1848 | 1849 | addListener(event: string, listener: Function): Domain; 1850 | on(event: string, listener: Function): Domain; 1851 | once(event: string, listener: Function): Domain; 1852 | removeListener(event: string, listener: Function): Domain; 1853 | removeAllListeners(event?: string): Domain; 1854 | } 1855 | 1856 | export function create(): Domain; 1857 | } 1858 | 1859 | declare module "constants" { 1860 | export var E2BIG: number; 1861 | export var EACCES: number; 1862 | export var EADDRINUSE: number; 1863 | export var EADDRNOTAVAIL: number; 1864 | export var EAFNOSUPPORT: number; 1865 | export var EAGAIN: number; 1866 | export var EALREADY: number; 1867 | export var EBADF: number; 1868 | export var EBADMSG: number; 1869 | export var EBUSY: number; 1870 | export var ECANCELED: number; 1871 | export var ECHILD: number; 1872 | export var ECONNABORTED: number; 1873 | export var ECONNREFUSED: number; 1874 | export var ECONNRESET: number; 1875 | export var EDEADLK: number; 1876 | export var EDESTADDRREQ: number; 1877 | export var EDOM: number; 1878 | export var EEXIST: number; 1879 | export var EFAULT: number; 1880 | export var EFBIG: number; 1881 | export var EHOSTUNREACH: number; 1882 | export var EIDRM: number; 1883 | export var EILSEQ: number; 1884 | export var EINPROGRESS: number; 1885 | export var EINTR: number; 1886 | export var EINVAL: number; 1887 | export var EIO: number; 1888 | export var EISCONN: number; 1889 | export var EISDIR: number; 1890 | export var ELOOP: number; 1891 | export var EMFILE: number; 1892 | export var EMLINK: number; 1893 | export var EMSGSIZE: number; 1894 | export var ENAMETOOLONG: number; 1895 | export var ENETDOWN: number; 1896 | export var ENETRESET: number; 1897 | export var ENETUNREACH: number; 1898 | export var ENFILE: number; 1899 | export var ENOBUFS: number; 1900 | export var ENODATA: number; 1901 | export var ENODEV: number; 1902 | export var ENOENT: number; 1903 | export var ENOEXEC: number; 1904 | export var ENOLCK: number; 1905 | export var ENOLINK: number; 1906 | export var ENOMEM: number; 1907 | export var ENOMSG: number; 1908 | export var ENOPROTOOPT: number; 1909 | export var ENOSPC: number; 1910 | export var ENOSR: number; 1911 | export var ENOSTR: number; 1912 | export var ENOSYS: number; 1913 | export var ENOTCONN: number; 1914 | export var ENOTDIR: number; 1915 | export var ENOTEMPTY: number; 1916 | export var ENOTSOCK: number; 1917 | export var ENOTSUP: number; 1918 | export var ENOTTY: number; 1919 | export var ENXIO: number; 1920 | export var EOPNOTSUPP: number; 1921 | export var EOVERFLOW: number; 1922 | export var EPERM: number; 1923 | export var EPIPE: number; 1924 | export var EPROTO: number; 1925 | export var EPROTONOSUPPORT: number; 1926 | export var EPROTOTYPE: number; 1927 | export var ERANGE: number; 1928 | export var EROFS: number; 1929 | export var ESPIPE: number; 1930 | export var ESRCH: number; 1931 | export var ETIME: number; 1932 | export var ETIMEDOUT: number; 1933 | export var ETXTBSY: number; 1934 | export var EWOULDBLOCK: number; 1935 | export var EXDEV: number; 1936 | export var WSAEINTR: number; 1937 | export var WSAEBADF: number; 1938 | export var WSAEACCES: number; 1939 | export var WSAEFAULT: number; 1940 | export var WSAEINVAL: number; 1941 | export var WSAEMFILE: number; 1942 | export var WSAEWOULDBLOCK: number; 1943 | export var WSAEINPROGRESS: number; 1944 | export var WSAEALREADY: number; 1945 | export var WSAENOTSOCK: number; 1946 | export var WSAEDESTADDRREQ: number; 1947 | export var WSAEMSGSIZE: number; 1948 | export var WSAEPROTOTYPE: number; 1949 | export var WSAENOPROTOOPT: number; 1950 | export var WSAEPROTONOSUPPORT: number; 1951 | export var WSAESOCKTNOSUPPORT: number; 1952 | export var WSAEOPNOTSUPP: number; 1953 | export var WSAEPFNOSUPPORT: number; 1954 | export var WSAEAFNOSUPPORT: number; 1955 | export var WSAEADDRINUSE: number; 1956 | export var WSAEADDRNOTAVAIL: number; 1957 | export var WSAENETDOWN: number; 1958 | export var WSAENETUNREACH: number; 1959 | export var WSAENETRESET: number; 1960 | export var WSAECONNABORTED: number; 1961 | export var WSAECONNRESET: number; 1962 | export var WSAENOBUFS: number; 1963 | export var WSAEISCONN: number; 1964 | export var WSAENOTCONN: number; 1965 | export var WSAESHUTDOWN: number; 1966 | export var WSAETOOMANYREFS: number; 1967 | export var WSAETIMEDOUT: number; 1968 | export var WSAECONNREFUSED: number; 1969 | export var WSAELOOP: number; 1970 | export var WSAENAMETOOLONG: number; 1971 | export var WSAEHOSTDOWN: number; 1972 | export var WSAEHOSTUNREACH: number; 1973 | export var WSAENOTEMPTY: number; 1974 | export var WSAEPROCLIM: number; 1975 | export var WSAEUSERS: number; 1976 | export var WSAEDQUOT: number; 1977 | export var WSAESTALE: number; 1978 | export var WSAEREMOTE: number; 1979 | export var WSASYSNOTREADY: number; 1980 | export var WSAVERNOTSUPPORTED: number; 1981 | export var WSANOTINITIALISED: number; 1982 | export var WSAEDISCON: number; 1983 | export var WSAENOMORE: number; 1984 | export var WSAECANCELLED: number; 1985 | export var WSAEINVALIDPROCTABLE: number; 1986 | export var WSAEINVALIDPROVIDER: number; 1987 | export var WSAEPROVIDERFAILEDINIT: number; 1988 | export var WSASYSCALLFAILURE: number; 1989 | export var WSASERVICE_NOT_FOUND: number; 1990 | export var WSATYPE_NOT_FOUND: number; 1991 | export var WSA_E_NO_MORE: number; 1992 | export var WSA_E_CANCELLED: number; 1993 | export var WSAEREFUSED: number; 1994 | export var SIGHUP: number; 1995 | export var SIGINT: number; 1996 | export var SIGILL: number; 1997 | export var SIGABRT: number; 1998 | export var SIGFPE: number; 1999 | export var SIGKILL: number; 2000 | export var SIGSEGV: number; 2001 | export var SIGTERM: number; 2002 | export var SIGBREAK: number; 2003 | export var SIGWINCH: number; 2004 | export var SSL_OP_ALL: number; 2005 | export var SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number; 2006 | export var SSL_OP_CIPHER_SERVER_PREFERENCE: number; 2007 | export var SSL_OP_CISCO_ANYCONNECT: number; 2008 | export var SSL_OP_COOKIE_EXCHANGE: number; 2009 | export var SSL_OP_CRYPTOPRO_TLSEXT_BUG: number; 2010 | export var SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number; 2011 | export var SSL_OP_EPHEMERAL_RSA: number; 2012 | export var SSL_OP_LEGACY_SERVER_CONNECT: number; 2013 | export var SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number; 2014 | export var SSL_OP_MICROSOFT_SESS_ID_BUG: number; 2015 | export var SSL_OP_MSIE_SSLV2_RSA_PADDING: number; 2016 | export var SSL_OP_NETSCAPE_CA_DN_BUG: number; 2017 | export var SSL_OP_NETSCAPE_CHALLENGE_BUG: number; 2018 | export var SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number; 2019 | export var SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number; 2020 | export var SSL_OP_NO_COMPRESSION: number; 2021 | export var SSL_OP_NO_QUERY_MTU: number; 2022 | export var SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number; 2023 | export var SSL_OP_NO_SSLv2: number; 2024 | export var SSL_OP_NO_SSLv3: number; 2025 | export var SSL_OP_NO_TICKET: number; 2026 | export var SSL_OP_NO_TLSv1: number; 2027 | export var SSL_OP_NO_TLSv1_1: number; 2028 | export var SSL_OP_NO_TLSv1_2: number; 2029 | export var SSL_OP_PKCS1_CHECK_1: number; 2030 | export var SSL_OP_PKCS1_CHECK_2: number; 2031 | export var SSL_OP_SINGLE_DH_USE: number; 2032 | export var SSL_OP_SINGLE_ECDH_USE: number; 2033 | export var SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number; 2034 | export var SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number; 2035 | export var SSL_OP_TLS_BLOCK_PADDING_BUG: number; 2036 | export var SSL_OP_TLS_D5_BUG: number; 2037 | export var SSL_OP_TLS_ROLLBACK_BUG: number; 2038 | export var ENGINE_METHOD_DSA: number; 2039 | export var ENGINE_METHOD_DH: number; 2040 | export var ENGINE_METHOD_RAND: number; 2041 | export var ENGINE_METHOD_ECDH: number; 2042 | export var ENGINE_METHOD_ECDSA: number; 2043 | export var ENGINE_METHOD_CIPHERS: number; 2044 | export var ENGINE_METHOD_DIGESTS: number; 2045 | export var ENGINE_METHOD_STORE: number; 2046 | export var ENGINE_METHOD_PKEY_METHS: number; 2047 | export var ENGINE_METHOD_PKEY_ASN1_METHS: number; 2048 | export var ENGINE_METHOD_ALL: number; 2049 | export var ENGINE_METHOD_NONE: number; 2050 | export var DH_CHECK_P_NOT_SAFE_PRIME: number; 2051 | export var DH_CHECK_P_NOT_PRIME: number; 2052 | export var DH_UNABLE_TO_CHECK_GENERATOR: number; 2053 | export var DH_NOT_SUITABLE_GENERATOR: number; 2054 | export var NPN_ENABLED: number; 2055 | export var RSA_PKCS1_PADDING: number; 2056 | export var RSA_SSLV23_PADDING: number; 2057 | export var RSA_NO_PADDING: number; 2058 | export var RSA_PKCS1_OAEP_PADDING: number; 2059 | export var RSA_X931_PADDING: number; 2060 | export var RSA_PKCS1_PSS_PADDING: number; 2061 | export var POINT_CONVERSION_COMPRESSED: number; 2062 | export var POINT_CONVERSION_UNCOMPRESSED: number; 2063 | export var POINT_CONVERSION_HYBRID: number; 2064 | export var O_RDONLY: number; 2065 | export var O_WRONLY: number; 2066 | export var O_RDWR: number; 2067 | export var S_IFMT: number; 2068 | export var S_IFREG: number; 2069 | export var S_IFDIR: number; 2070 | export var S_IFCHR: number; 2071 | export var S_IFLNK: number; 2072 | export var O_CREAT: number; 2073 | export var O_EXCL: number; 2074 | export var O_TRUNC: number; 2075 | export var O_APPEND: number; 2076 | export var F_OK: number; 2077 | export var R_OK: number; 2078 | export var W_OK: number; 2079 | export var X_OK: number; 2080 | export var UV_UDP_REUSEADDR: number; 2081 | } 2082 | 2083 | --------------------------------------------------------------------------------