import assert = require ( "assert" ) ; import { TypeScriptVersion } from "definitelytyped-header-parser" ; import { Logger } from "../util/logging" ; import { joinPaths } from "../util/util" ; import { readFileAndWarn , Registry } from "./common" ; import { NpmPublishClient } from "./npm-client" ; import { AnyPackage , NotNeededPackage } from "./packages" ; import { ChangedTyping } from "./versions" ; export async function publishTypingsPackage ( client , changedTyping , dry , log , registry ) { const { pkg , version , latestVersion } = changedTyping ; await common ( client , pkg , log , dry , registry ) ; if ( pkg . isLatest ) { await updateTypeScriptVersionTags ( pkg , version , client , log , dry ) ; } assert ( ( latestVersion === undefined ) === pkg . isLatest ) ; if ( latestVersion !== undefined ) { await updateLatestTag ( pkg . fullNpmName , latestVersion , client , log , dry ) ; } } export async function publishNotNeededPackage ( client , pkg , dry , log , registry ) { log ( `Deprecating ${ pkg . name }` ) ; await common ( client , pkg , log , dry , registry ) ; await deprecateNotNeededPackage ( client , pkg , dry , log ) ; } async function common ( client , pkg , log , dry , registry ) { const packageDir = pkg . outputDirectory ; const packageJson = await readFileAndWarn ( "generate" , joinPaths ( packageDir + ( registry === Registry . Github ? "-github" : "" ) , "package.json" ) ) ; await client . publish ( packageDir , packageJson , dry , log ) ; } export async function deprecateNotNeededPackage ( client , pkg , dry = false , log ) { const name = pkg . fullNpmName ; if ( dry ) { log ( "(dry) Skip deprecate not needed package " + name + " at " + pkg . version . versionString ) ; } else { log ( `Deprecating ${ name } at ${ pkg . version . versionString } with message: ${ pkg . deprecatedMessage ( ) }.` ) ; await client . deprecate ( name , pkg . version . versionString , pkg . deprecatedMessage ( ) ) ; } } export async function updateTypeScriptVersionTags ( pkg , version , client , log , dry ) { const tags = TypeScriptVersion . tagsToUpdate ( pkg . minTypeScriptVersion ) ; const name = pkg . fullNpmName ; log ( `Tag ${ name }@${ version } as ${ JSON . stringify ( tags ) }` ) ; if ( dry ) { log ( "(dry) Skip tag" ) ; } else { for ( const tagName of tags ) { await client . tag ( name , version , tagName , dry , log ) ; } } } export async function updateLatestTag ( fullName , version , client , log , dry ) { log ( `   but tag ${ fullName }@${ version } as "latest"` ) ; if ( dry ) { log ( "   (dry) Skip move \"latest\" back to newest version" ) ; } else { await client . tag ( fullName , version , "latest" , dry , log ) ; } }