Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #44 from felixrieseberg/more-params
Browse files Browse the repository at this point in the history
Add more security, more parameters, more fun!
  • Loading branch information
felixrieseberg authored Dec 22, 2016
2 parents 5fec742 + 9444b80 commit 2ed353c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 30 deletions.
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,47 @@ Both installations are conflict-free, meaning that they do not mess with existin
- ATL and MFC (optional, off by default)
- C++ Build tools specific command prompts

## Proxy
If you're behind a proxy, set a `PROXY` environment variable first. To do that with PowerShell, simply run `$env:PROXY = "Your proxy"`.
## Usage

## Mirror
Microsoft's build tools should be fast across the world, but to use a mirror to download Python, set a `PYTHON_MIRROR` environment variable. To do that with PowerShell, simply run `npm install --global windows-build-tools --python_mirror=https://npm.taobao.org/mirrors/python/`.
```
npm [--python-mirror=''] [--proxy=''] [--verbose] [--strict-ssl] [--resume] [--sockets=5] [--vcc-build-tools-parameters=''] install --global windows-build-tools
```

Optional arguments:
- `--python-mirror`: Use a given mirror to download Python (like `--python_mirror=https://npm.taobao.org/mirrors/python/`). You can alternatively set a `PYTHON_MIRROR` environment variable.
- `--proxy`: Use a given proxy. You can alternatively set a `PROXY` environment variable.
- `--debug`: Be extra verbose in the logger output. Equal to setting the environment variable `DEBUG` to `*`.
- `--strict-ssl`: Enables "Strict SSL" mode. Defaults to false.
- `--resume`: By default, `windows-build-tools` will resume aborted downloads. Set to `false` to disable.
- `--sockets`: Specifies the number of http sockets to use at once (this controls concurrency). Defaults to infinity.
- `--vcc-build-tools-parameters`: Specifies additional parameters for the Visual C++ Build Tools 2015. See below for more detailed usage instructions.

## Supplying Parameters to the VCC Build Tools
You can pass additional parameters directly to the VCC Build Tools installer. This tool does not check if the parameters make sense - passing incorrect parameters might break the whole installation. As of January 2017, the following parameters are available:

- `/AdminFile`: <filename> Specifies the installation control file.
- `/CreateAdminFile`: <filename> Specifies the location to create a control file that can then be used
- `/CustomInstallPath`: <path> Set Custom install location.
- `/ForceRestart`: Always restart the system after installation.
- `/Full`: Install all product features.
- `/InstallSelectableItems`: <item1;item2;...;itemN> Choose which selectable item(s) to be installed.
selectable item to be installed, just pass in this switch without any value.
- `/Layout`: Create a copy of the media in specified folder.
- `/NoRefresh`: Prevent setup checking for updates from the internet.
- `/NoRestart`: Do not restart during or after installation.
- `/NoWeb`: Prevent setup downloading from the internet.
- `/Passive`: Display progress but do not wait for user input.
- `/ProductKey`: <25-character product key> Set custom product key (no dashes).
- `/PromptRestart`: Prompt the user before restarting the system.
- `/Repair`: Repair the product.
- `/Uninstall`: Uninstall the product.
- `/Uninstall /Force`: Uninstall the product and features shared with other products.

Supply parameters to `windows-build-tools` as a JSON array. Here's quick example (note the double quotes):

```
npm --vcc-build-tools-parameters='[""/InstallSelectableItems"", ""item1;item2;item3""]' install --global windows-build-tools
```

## Support & Help

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "windows-build-tools",
"version": "0.7.0",
"version": "0.8.0",
"description": "Install C++ Build Tools for Windows using npm",
"main": "lib/index.js",
"scripts": {
Expand Down
32 changes: 22 additions & 10 deletions ps1/launch-installer.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$path
[string]$path,
[string]$extraBuildToolsParameters
)

# Returns whether or not the current user has administrative privileges
Expand All @@ -24,8 +25,19 @@ function runInstaller
if (Test-Path $path)
{
$params = "/NoRestart", "/S", "/L", "`"$path\build-tools-log.txt`""
$extraParams = $extraBuildToolsParameters -split "%_; "

if ($extraParams.count -gt 0)
{
foreach ($element in $extraParams)
{
$params += $element
}
}

cd $path
./BuildTools_Full.exe $params

}
}

Expand Down Expand Up @@ -53,8 +65,8 @@ runPythonInstaller;
# SIG # Begin signature block
# MIINQAYJKoZIhvcNAQcCoIINM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yDX
# wPDDUL8bk7CSw/qyx+wOWLW3Xk82I6oKKRQDao7u6T3TxKZUL+9kdfMsob7kbCYK
# pku4U2IJ96uf1pmqL/dFcE6fIQwC3gZ7cczakDUWGtSSXUgi9PgAFG3pT2DFnoa4
# Z8ogaNp2fKuRgESraJjlGFR5GSXHdaHc8RgewX+0RgiNoDg1
# BgorBgEEAYI3AgEVMCMGCSqGSIb3DQEJBDEWBBQiLPk3N6rpLHc+zJpSXqV7NkDH
# rDANBgkqhkiG9w0BAQEFAASCAQCId+ESBkhigxShLezY4Yx7mL4pF9+lk+0C7UND
# 0okepr7gR1nqH9HY4TgNHSa6ThQ3LNp9ghtoSZSedlp9WdpWMVw090EDuglBKvyt
# f/WC/NnBE4BIx7H3YrutT4dfHWMYCcCcIgpLkgQfal6flNMvF4omgJJaMAmR3xtV
# KnT0y78B3VJ7448Jxbenn+rJ4z049k6MTcLK54hA7v/U3e2sm/l00/YUiTncMTwn
# bXC8okSr2rZdW90T5pdA6SE6/BmvZVsyhC/NHvItpAifV2yJnTdZoXwv5y0ImBcH
# aMO/SUJlEPnNcm6DvtNrpxtOQ8J4Un1JO9srNhhHyRWp7t9t
# SIG # End signature block
19 changes: 10 additions & 9 deletions ps1/set-environment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ npm config set msvs_version 2015

# Setting python path
npm config set python $pythonPath

# SIG # Begin signature block
# MIINQAYJKoZIhvcNAQcCoIINMTCCDS0CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUlYl+bcot6F6Gd1FbRn2f6FI/
# Plagggp+MIIFJzCCBA+gAwIBAgIQBicsjH4LxacitIAMXdcrMDANBgkqhkiG9w0B
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUo5BckTGwFih1l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UJqEYNANdzYViFus3BwE0RmLu0RcBu
# Mvf9ZX0G/UVyRJdCQKGMDSXcjCj5uoaWrw2wPeiC7/mynFZVDTTEaaOm2OQtiSBx
# pzO/Yw4CMqvSK0DpWW8Y+rBuFD8EXfo5g4O5K9opZmPXAahAFV7GtlR0Nm3VWFGl
# qP04bumv1ZN9H35ILD6OxWYVRWswqlbD/mmZhoRAOjWfI22B4HTWjx677nHCju25
# JoERNGHDIKzVlxgYbydgpd1rmmtzpDv2kOm41Oo6n20O7vagZr9Lc/LA1KnxVsDL
# cH4OwY+VTlN8fa/doQYEf6Y4DKZj5NEGIm8lQ0yAEdSGA3sa
# SIG # End signature block
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var pythonMirror = process.env.npm_config_python_mirror || process.env.PYTHON_MIRROR || 'https://www.python.org/ftp/python/'
var pythonMirror = process.env['npm_config_python_mirror'] || process.env.PYTHON_MIRROR || 'https://www.python.org/ftp/python/'

var buildTools = {
installerName: 'BuildTools_Full.exe',
installerUrl: 'http://download.microsoft.com/download/5/f/7/5f7acaeb-8363-451f-9425-68a90f98b238/visualcppbuildtools_full.exe',
installerUrl: 'https://download.microsoft.com/download/5/f/7/5f7acaeb-8363-451f-9425-68a90f98b238/visualcppbuildtools_full.exe',
logName: 'build-tools-log.txt'
}

Expand Down
7 changes: 4 additions & 3 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ function downloadTools (installer) {
const nuggetOptions = {
target: installer.fileName,
dir: installer.directory,
resume: true,
resume: process.env.npm_config_resume || true,
verbose: true,
strictSSL: false,
proxy: process.env.PROXY || undefined
strictSSL: process.env.npm_config_strict_ssl || false,
proxy: process.env.npm_config_proxy || process.env.PROXY || undefined,
sockets: process.env.npm_config_sockets || undefined
}

nugget(installer.url, nuggetOptions, (errors) => {
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict'

// Set verbose mode
if (process.env.npm_config_debug) {
process.env.DEBUG = '*'
}

require('./compatible')

const download = require('./download')
Expand Down
19 changes: 18 additions & 1 deletion src/install/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ const installer = utils.getBuildToolsInstallerPath()
*/
function launchInstaller () {
return new Promise((resolve, reject) => {
let extraArgs = ''
let parsedArgs = {}

if (process.env.npm_config_vcc_build_tools_parameters) {
try {
parsedArgs = JSON.parse(process.env.npm_config_vcc_build_tools_parameters)

if (parsedArgs && parsedArgs.length > 0) {
extraArgs = parsedArgs.join('%_; ')
}
} catch (e) {
debug(`Installer: Parsing additional arguments for VCC build tools failed: ${JSON.stringify(e)}`)
debug(`Input received: ${process.env.npm_config_vcc_build_tools_parameters}`)
}
}


const scriptPath = path.join(__dirname, '..', '..', 'ps1', 'launch-installer.ps1')
const psArgs = `& {& '${scriptPath}' -path '${installer.directory}' }`
const psArgs = `& {& '${scriptPath}' -path '${installer.directory}' -extraBuildToolsParameters '${extraArgs}' }`
const args = ['-ExecutionPolicy', 'Bypass', '-NoProfile', '-NoLogo', psArgs]

debug(`Installer: Launching installer in ${installer.directory} with file ${installer.fileName}`)
Expand Down

0 comments on commit 2ed353c

Please sign in to comment.