# Publish moyun-ultimate to the npm registry (ASCII only) # # One-time setup: create a free account at https://www.npmjs.com/signup, then # either run `npm login` yourself or create an Automation token at # https://www.npmjs.com/settings//tokens and pass it with -Token. # # After the package is on npm, anyone can install it from the DSH plugin market # (Plugin -> Discover -> search "moyun-ultimate") with one click, no scripts. [CmdletBinding()] param( [string]$Token = '', [switch]$DryRun, [switch]$Bump ) $ErrorActionPreference = 'Stop' $Here = Split-Path -Parent $MyInvocation.MyCommand.Path $PkgJson = Join-Path $Here 'package.json' $Registry = 'https://registry.npmjs.org' $NodeExe = 'G:\DeepSeek_Harness\resources\runtime\primary-runtime\dependencies\node\bin\node.exe' $NpmCli = 'E:\Node\node_modules\npm\bin\npm-cli.js' if (-not (Test-Path $NodeExe)) { $NodeExe = 'node' } if (-not (Test-Path $NpmCli)) { $NpmCli = $null } function Npm { param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Args) if ($NpmCli) { & $NodeExe $NpmCli @Args } else { & npm @Args } } Write-Output '' Write-Output 'moyun-ultimate -> npm' Write-Output '=====================' if (-not (Test-Path $PkgJson)) { throw "package.json not found in $Here" } $pkg = Get-Content -LiteralPath $PkgJson -Raw -Encoding UTF8 | ConvertFrom-Json Write-Output (" name : " + $pkg.name) Write-Output (" version : " + $pkg.version) Write-Output (" files : " + $pkg.files.Count + " entries") if ($pkg.name -ne 'moyun-ultimate') { Write-Warning "package name is $($pkg.name); the market index expects moyun-ultimate" } # ---- check name availability ---- Write-Output '' Write-Output ' checking name availability...' $existing = $null try { $existing = (Npm view $pkg.name version --registry=$Registry 2>$null) } catch { $existing = $null } if ($existing) { Write-Output (" already published, latest = " + $existing) if (-not $Bump) { Write-Output (" same version will be rejected by npm; rerun with -Bump to increment to " ) Write-Output (" 0." + (($pkg.version -split '\.')[1]) + "." + ([int](($pkg.version -split '\.')[2]) + 1)) } } else { Write-Output ' name is free' } # ---- auth ---- if ($Token) { Write-Output '' Write-Output ' installing token into a temporary npmrc...' $tmpNpmrc = Join-Path ([IO.Path]::GetTempPath()) ('npmrc-' + [guid]::NewGuid().ToString('N').Substring(0,8)) $line = '//registry.npmjs.org/:_authToken=' + $Token [IO.File]::WriteAllText($tmpNpmrc, $line + "`n", (New-Object Text.UTF8Encoding($false))) $env:NPM_CONFIG_USERCONFIG = $tmpNpmrc Write-Output ' temporary npmrc in place (this shell only)' } else { Write-Output '' Write-Output ' no -Token given, relying on an existing npm login' } $who = $null try { $who = (Npm whoami --registry=$Registry 2>$null) } catch { $who = $null } if (-not $who) { Write-Output '' Write-Output ' NOT LOGGED IN to npm.' Write-Output '' Write-Output ' Do one of these first:' Write-Output ' a) npm login (interactive, opens a browser)' Write-Output ' b) create a token at:' Write-Output ' https://www.npmjs.com/settings//tokens -> Automation' Write-Output ' then rerun: powershell -File .\publish-npm.ps1 -Token npm_xxxxxxxx' Write-Output '' exit 2 } Write-Output (' logged in as: ' + $who) if ($DryRun) { Write-Output '' Write-Output ' -DryRun: would run npm publish now.' Write-Output (' tarball preview: ' + (Npm pack --dry-run 2>&1 | Select-Object -Last 6 | Out-String).Trim()) exit 0 } # ---- publish ---- Write-Output '' Write-Output ' publishing...' & { if ($NpmCli) { & $NodeExe $NpmCli publish --access public --registry=$Registry } else { & npm publish --access public --registry=$Registry } } if ($LASTEXITCODE -ne 0) { Write-Output '' Write-Output ' publish FAILED. common causes:' Write-Output ' - version already exists -> bump version in package.json' Write-Output ' - 403 name taken -> pick another name' Write-Output ' - 401 token invalid / 2FA -> use an Automation token' exit 1 } Write-Output '' Write-Output ' verifying...' Start-Sleep -Seconds 4 $got = $null try { $got = (Npm view $pkg.name version --registry=$Registry 2>$null) } catch { $got = $null } Write-Output (" registry now reports: " + $got) Write-Output '' Write-Output 'DONE.' Write-Output '' Write-Output 'Anyone can now install it from the DSH plugin market:' Write-Output ' 1. DSH -> Plugins -> Market -> Discover' Write-Output ' 2. search: moyun-ultimate (or add the index source URL first)' Write-Output ' 3. click Install' Write-Output '' Write-Output 'No script, no command line, no permission prompt beyond the one click.' if ($env:NPM_CONFIG_USERCONFIG -and $env:NPM_CONFIG_USERCONFIG -like '*npmrc-*') { Remove-Item $env:NPM_CONFIG_USERCONFIG -Force -ErrorAction SilentlyContinue } exit 0