add windows npm usage example
This commit is contained in:
parent
40a0bfcf78
commit
58b63b6ef0
|
|
@ -53,6 +53,7 @@ Vagrant.configure(2) do |config|
|
|||
config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['provision-base.ps1', nexus_domain]
|
||||
config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-chocolatey-repository.ps1', nexus_domain]
|
||||
config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-powershell-repository.ps1', nexus_domain]
|
||||
config.vm.provision :shell, path: 'provision/windows/ps.ps1', args: ['use-npm-repository.ps1', nexus_domain]
|
||||
end
|
||||
|
||||
config.trigger.before :up, :vm => ['nexus'] do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
# dump all the windows trusted roots into a ca file.
|
||||
$pems = New-Object System.Text.StringBuilder
|
||||
Get-ChildItem Cert:\LocalMachine\Root | ForEach-Object {
|
||||
# $_ is-a System.Security.Cryptography.X509Certificates.X509Certificate2
|
||||
Write-Host "Exporting the $($_.Issuer) certificate..."
|
||||
[void]$pems.AppendLine('-----BEGIN CERTIFICATE-----')
|
||||
[void]$pems.AppendLine(
|
||||
[Convert]::ToBase64String(
|
||||
$_.Export('Cert'),
|
||||
'InsertLineBreaks'));
|
||||
[void]$pems.AppendLine("-----END CERTIFICATE-----");
|
||||
}
|
||||
Set-Content `
|
||||
-Encoding Ascii `
|
||||
C:\ProgramData\ca-certificates.crt `
|
||||
$pems.ToString()
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
param(
|
||||
[string]$nexusDomain = 'nexus.example.com'
|
||||
)
|
||||
|
||||
function external([string]$cmd, [string[]]$arguments) {
|
||||
$eap = $ErrorActionPreference
|
||||
$ErrorActionPreference = 'Continue'
|
||||
try {
|
||||
&$cmd @arguments
|
||||
if ($LASTEXITCODE) {
|
||||
throw "$cmd failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
} finally {
|
||||
$ErrorActionPreference = $eap
|
||||
}
|
||||
}
|
||||
function node { external node.exe $Args }
|
||||
function npm { external npm.cmd $Args }
|
||||
|
||||
cd $env:USERPROFILE
|
||||
mkdir tmp | Out-Null
|
||||
mkdir tmp/use-npm-repository | Out-Null
|
||||
cd tmp/use-npm-repository
|
||||
|
||||
#
|
||||
# test the npm repositories.
|
||||
# see https://help.sonatype.com/display/NXRM3/Node+Packaged+Modules+and+npm+Registries
|
||||
# see https://docs.npmjs.com/private-modules/ci-server-config
|
||||
# see https://docs.npmjs.com/cli/adduser
|
||||
|
||||
# install node LTS.
|
||||
choco install -y nodejs-lts
|
||||
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
|
||||
Update-SessionEnvironment
|
||||
node --version
|
||||
npm --version
|
||||
|
||||
# configure npm to trust our system trusted CAs.
|
||||
# NB never turn off ssl verification with npm config set strict-ssl false
|
||||
c:\vagrant\provision\windows\export-windows-ca-certificates.ps1
|
||||
npm config set cafile c:/ProgramData/ca-certificates.crt
|
||||
|
||||
#
|
||||
# configure npm to use the npm-group repository.
|
||||
|
||||
npm config set registry https://$nexusDomain/repository/npm-group/
|
||||
|
||||
# install a package that indirectly uses the npmjs.org-proxy repository.
|
||||
mkdir hello-world-win-npm | Out-Null
|
||||
pushd hello-world-win-npm
|
||||
Set-Content `
|
||||
-Encoding Ascii `
|
||||
package.json `
|
||||
@'
|
||||
{
|
||||
"name": "hello-world-win",
|
||||
"description": "the classic hello world",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"main": "hello-world-win.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.example.com/hello-world-win.git"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
'@
|
||||
Set-Content `
|
||||
-Encoding Ascii `
|
||||
hello-world-win.js `
|
||||
@'
|
||||
const leftPad = require('left-pad')
|
||||
console.log(leftPad('hello world', 40))
|
||||
'@
|
||||
npm install --save left-pad
|
||||
node hello-world-win.js
|
||||
|
||||
#
|
||||
# publish a package to the npm-hosted repository.
|
||||
|
||||
# login.
|
||||
$env:NPM_USER='alice.doe'
|
||||
$env:NPM_PASS='password'
|
||||
$env:NPM_EMAIL='alice.doe@example.com'
|
||||
$env:NPM_REGISTRY="https://$nexusDomain/repository/npm-hosted/"
|
||||
npm install npm-registry-client@8.5.0
|
||||
$env:NODE_PATH="$PWD/node_modules"
|
||||
$env:NODE_EXTRA_CA_CERTS='C:\ProgramData\ca-certificates.crt'
|
||||
$npmAuthToken = node --use-openssl-ca /vagrant/provision/npm-login.js 2>$null
|
||||
npm set "//$nexusDomain/repository/npm-hosted/:_authToken" $npmAuthToken
|
||||
|
||||
# publish.
|
||||
npm publish --registry=$env:NPM_REGISTRY
|
||||
popd
|
||||
|
||||
# use the published package.
|
||||
mkdir use-hello-world-win-npm | Out-Null
|
||||
pushd use-hello-world-win-npm
|
||||
Set-Content `
|
||||
-Encoding Ascii `
|
||||
hello-world-win.js `
|
||||
@'
|
||||
{
|
||||
"name": "use-hello-world-win",
|
||||
"description": "use the classic hello world",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.example.com/use-hello-world-win.git"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
'@
|
||||
npm install hello-world-win
|
||||
node node_modules/hello-world-win/hello-world-win.js
|
||||
popd
|
||||
Loading…
Reference in New Issue