'use strict' ; import cp = require ( 'child_process' ) ; import fs = require ( 'fs' ) ; import moment = require ( 'moment' ) ; import path = require ( 'path' ) ; import semver = require ( 'semver' ) ; import util = require ( 'util' ) ; import { getBinPath , getGoPlusConfig , GoVersion } from './util' ; export interface Tool { name : string ; importPath : string ; isImportant : boolean ; description : string ; latestVersion ? : semver . SemVer ; latestVersionTimestamp ? : moment . Moment ; latestPrereleaseVersion ? : semver . SemVer ; latestPrereleaseVersionTimestamp ? : moment . Moment ; minimumGoVersion ? : semver . SemVer ; maximumGoVersion ? : semver . SemVer ; close ? : ( ) => Promise < string > ; } param tool param goVersion export function getImportPath ( tool ) { return tool . importPath ; } export function getImportPathWithVersion ( tool , version ) { const importPath = getImportPath ( tool ) ; if ( version ) { return importPath + '@v' + version ; } return importPath ; } param tool param goVersion export function disableModulesForWildcard ( tool , goVersion ) { const importPath = getImportPath ( tool ) ; const isWildcard = importPath . endsWith ( '...' ) ; return isWildcard && goVersion . lt ( '1.13' ) ; } export function containsTool ( tools , tool ) { return tools . indexOf ( tool ) > - 1 ; } export function containsString ( tools , toolName ) { return tools . some ( ( tool ) => tool . name === toolName ) ; } export function getTool ( name ) { return allToolsInformation [ name ] ; } export function hasModSuffix ( tool ) { return tool . name . endsWith ( '-gomod' ) ; } export function isGocode ( tool ) { return tool . name === 'gocode' || tool . name === 'gocode-gomod' ; } export function getConfiguredTools ( ) { const tools = [ ] ; function maybeAddTool ( name ) { const tool = allToolsInformation [ name ] ; if ( tool ) { tools . push ( tool ) ; } } const goPlusConfig = getGoPlusConfig ( ) ; maybeAddTool ( goPlusConfig [ 'formatTool' ] ) ; return tools ; } export const allToolsInformation = { 'gopfmt' : { name : 'gopfmt' , importPath : 'github.com/goplus/gop/cmd/gopfmt' , isImportant : true , description : 'Formatter' } } ; /**
 * ToolAtVersion is a Tool at a specific version.
 * Lack of version implies the latest version.
 */ export interface ToolAtVersion extends Tool { version ? : semver . SemVer ; } export function getToolAtVersion ( name , version ? ) { return { ... allToolsInformation [ name ] , version } ; }