Skip to content

Commit

Permalink
Merge a4210dc into 9dfbcf5
Browse files Browse the repository at this point in the history
  • Loading branch information
SkReD authored May 27, 2022
2 parents 9dfbcf5 + a4210dc commit 7bd8a19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
37 changes: 26 additions & 11 deletions packages/pvm-vcs/lib/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,17 @@ import { logger } from '@pvm/core/lib/logger'
import { wdShell } from '@pvm/core/lib/shell'
import type { HostApi } from '@pvm/core/lib/plugins'
import { getHostApi } from '@pvm/core/lib/plugins'
import { GitlabPlatform } from '@pvm/gitlab/lib/platform'
import { cachedRealPath } from '@pvm/core/lib/fs'
import { initFsVcs } from '@pvm/vcs-fs'
import { initGitVcs } from '@pvm/vcs-git/lib/git-vcs'

import type { SyncAttachmentOpts } from '@pvm/gitlab/lib/hal/mark-pr'
import type { GitCommitContext } from '@pvm/vcs-git/lib/git-vcs'
import type {
ReleasePayload, CreateReleasePayload, VcsRelease, VcsOnly, UnknownCommitContext,
AbstractVcs, AddTagOptions, CommitResult, GetReleaseResult, PushOptions, PlatformReleaseTag,
} from '../types'
import { env } from '@pvm/core/lib/env'
import { GithubPlatform } from '@pvm/github'

const Platforms = {
gitlab: GitlabPlatform,
github: GithubPlatform,
}
import { mema } from '@pvm/core/lib/memoize'

const VcsMap = {
git: initGitVcs,
Expand Down Expand Up @@ -73,18 +66,40 @@ async function loadBuiltinVcs(cwd: string, customVcsType?: string): Promise<void
hostApi.provideRecord('vcs', VcsMap[vcsType](cwd))
}

const getPlatforms = mema(async function getPlatformsRaw() {
const gitlabPlatform = (await (import('@pvm/gitlab/lib/platform').catch(() => {
logger.info('@pvm/gitlab not installed. Gitlab platform support is disabled')
return {
GitlabPlatform: undefined,
}
}))).GitlabPlatform

const githubPlatform = (await (import('@pvm/github').catch(() => {
logger.info('@pvm/github not installed. Github platform support is disabled')
return {
GithubPlatform: undefined,
}
}))).GithubPlatform

return {
gitlab: gitlabPlatform,
github: githubPlatform,
}
})

async function loadBuiltinPlatform(cwd: string): Promise<void> {
const platforms = await getPlatforms()
const platformType = detectPlatformType(cwd)

if (!Platforms[platformType]) {
if (!platforms[platformType]) {
// если нет платформы ничего страшного, возможно она и не понадобится вообще
return
}

const hostApi = await getHostApi(cwd)
const config = await getConfig(cwd)

hostApi.provideClass('platform', new Platforms[platformType](config))
hostApi.provideClass('platform', new platforms[platformType](config))
}

function dryRunStub(method: string, ...args: any[]): void {
Expand Down Expand Up @@ -297,7 +312,7 @@ export class VcsPlatform implements VcsOnly {
}
}

async syncAttachment(kind: string, attachment: Buffer, opts: SyncAttachmentOpts = {}): Promise<unknown> {
async syncAttachment(kind: string, attachment: Buffer, opts = {}): Promise<unknown> {
if (!this._localMode) {
return this.mutHostApi.run('platform.syncAttachment', kind, attachment, opts)
}
Expand Down
14 changes: 12 additions & 2 deletions packages/pvm-vcs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@
"@pvm/core": "0.0.0-stub",
"@pvm/cowners": "0.0.0-stub",
"@pvm/vcs-git": "0.0.0-stub",
"@pvm/gitlab": "0.0.0-stub",
"@pvm/github": "0.0.0-stub",
"@pvm/vcs-fs": "0.0.0-stub",
"hosted-git-info": "^3.0.2",
"resolve-from": "^5.0.0",
"string-to-color": "^2.2.2"
},
"peerDependencies": {
"@pvm/gitlab": "0.0.0-stub",
"@pvm/github": "0.0.0-stub"
},
"peerDependenciesMeta": {
"@pvm/gitlab": {
"optional": true
},
"@pvm/github": {
"optional": true
}
}
}

0 comments on commit 7bd8a19

Please sign in to comment.